Problem 454

Diophantine Reciprocals III — F(10^12) via Möbius + floor sums.

Answer5435004633092
Output5435004633092
StatusPASS
Native helperno
Runtime1630 ms
Peak memory5824 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n log n)
Space complexityO(n^2)O(1)
ApproachFlow solutionDivisor-based Diophantine solver
VerdictSuboptimal

Flow source

# Project Euler 454
# Diophantine Reciprocals III — F(10^12) via Möbius + floor sums.

import euler.nt { isqrt }

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
}

function sum_floor_segment(x: i64, lo: i64, hi0: i64) -> i64 {
    if hi0 <= lo || x <= 0 { return 0 }
    let mut res: i64 = 0
    let mut i: i64 = lo + 1
    let hi: i64 = hi0
    while i <= hi {
        let q: i64 = x / i
        if q == 0 { break }
        let mut j: i64 = x / q
        if j > hi { j = hi }
        res = res + q * (j - i + 1)
        i = j + 1
    }
    return res
}

function F(L: i64) -> i64 {
    let B: i64 = isqrt(L)
    let spf: ptr<i32> = calloc(B + 1, 4)
    let primes: ptr<i32> = calloc(B / 5 + 16, 4)
    let pfac: ptr<i64> = calloc(16, 8)
    let divs: ptr<i64> = calloc(128, 8)
    let mus: ptr<i64> = calloc(128, 8)
    if spf == null || primes == null || pfac == null || divs == null || mus == null {
        return 0
    }
    let mut pc: i64 = 0
    let mut i: i64 = 2
    while i <= B {
        if spf[i] == 0 {
            spf[i] = i as i32
            primes[pc] = i as i32
            pc = pc + 1
        }
        let mut j: i64 = 0
        while j < pc {
            let p: i64 = primes[j] as i64
            let v: i64 = i * p
            if v > B { break }
            spf[v] = p as i32
            if p == (spf[i] as i64) { break }
            j = j + 1
        }
        i = i + 1
    }

    let mut total: i64 = 0
    let mut n: i64 = 2
    while n <= B {
        let mut tmp: i64 = n
        let mut pcount: i64 = 0
        let mut last: i64 = 0
        while tmp > 1 {
            let p: i64 = spf[tmp] as i64
            tmp = tmp / p
            if p != last {
                pfac[pcount] = p
                pcount = pcount + 1
                last = p
            }
        }
        divs[0] = 1
        mus[0] = 1
        let mut dcount: i64 = 1
        let mut pi: i64 = 0
        while pi < pcount {
            let p: i64 = pfac[pi]
            let m: i64 = dcount
            let mut di: i64 = 0
            while di < m {
                divs[dcount] = divs[di] * p
                mus[dcount] = 0 - mus[di]
                dcount = dcount + 1
                di = di + 1
            }
            pi = pi + 1
        }

        let Ln: i64 = L / n
        let mut idx: i64 = 0
        while idx < dcount {
            let d: i64 = divs[idx]
            let mu: i64 = mus[idx]
            let k: i64 = n / d
            if k > 1 {
                let x: i64 = Ln / d
                if x > 0 {
                    total = total + mu * sum_floor_segment(x, k, 2 * k - 1)
                }
            }
            idx = idx + 1
        }
        n = n + 1
    }

    free(divs)
    free(mus)
    free(pfac)
    free(spf)
    free(primes)
    return total
}

function main() -> i32 {
    if F(15) != 4 {
        printf("%lld\n", F(15))
        return 1
    }
    if F(1000) != 1069 {
        printf("%lld\n", F(1000))
        return 1
    }
    printf("%lld\n", F(1000000000000))
    return 0
}

Generated C

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
    while (flow_temp_head) {
        flow_temp_node* n = flow_temp_head;
        flow_temp_head = n->next;
        free(n);
    }
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
    flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
    if (!node) return NULL;
    node->next = flow_temp_head;
    flow_temp_head = node;
    if (!flow_temp_atexit_set) {
        flow_temp_atexit_set = 1;
        atexit(flow_temp_free_all);
    }
    return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
    size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
    char* r = (char*)flow_temp_alloc(la + lb + 1);
    if (!r) return NULL;
    if (la) memcpy(r, a, la);
    if (lb) memcpy(r + la, b, lb);
    r[la + lb] = '\0';
    return r;
}

#define __flow_in_arr(arr, val) __extension__ ({ \
    int _found = 0; \
    size_t _n = sizeof(arr)/sizeof((arr)[0]); \
    for (size_t _i = 0; _i < _n; _i++) { \
        if ((arr)[_i] == (val)) { _found = 1; break; } \
    } _found; })

/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
    fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
    abort();
#if defined(__GNUC__) || defined(__clang__)
    __builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")

#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif

#include <math.h>

void* _ui_state = NULL;

static inline float i32_to_f32(int32_t v) { return (float)v; }

/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }

int64_t gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
int64_t sum_floor_segment_i64_i64_i64(int64_t x, int64_t lo, int64_t hi0);
int64_t F_i64(int64_t L);
int32_t main(void);

int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t lcm_i64_i64(int64_t a, int64_t b) {
    if ((a == 0 || b == 0)) {
        return 0;
    }
    return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}

int64_t isqrt_i64(int64_t n) {
    if (n < 2) {
        return n;
    }
    int64_t x = n;
    int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
    while (y < x) {
        x = y;
        y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
    }
    return x;
}

int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    int64_t b = FLOW_CHECKED_MOD((b0), (mod));
    int64_t result = 0;
    while (b > 0) {
        if (FLOW_CHECKED_MOD((b), (2)) == 1) {
            result = FLOW_CHECKED_MOD(((result + a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * 2)), (mod));
        b = FLOW_CHECKED_DIV((b), (2));
    }
    return result;
}

int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    if (mod == 1) {
        return 0;
    }
    int64_t result = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            result = mulmod_i64_i64_i64(result, b, mod);
        }
        b = mulmod_i64_i64_i64(b, b, mod);
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return result;
}

bool is_prime_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    if (n < 4) {
        return 1;
    }
    if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
        return 0;
    }
    int64_t i = 5;
    while ((i * i) <= n) {
        if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
            return 0;
        }
        i = (i + 6);
    }
    return 1;
}



int64_t sum_floor_segment_i64_i64_i64(int64_t x, int64_t lo, int64_t hi0) {
    if ((hi0 <= lo || x <= 0)) {
        return 0;
    }
    int64_t res = 0;
    int64_t i = (lo + 1);
    int64_t hi = hi0;
    while (i <= hi) {
        int64_t q = FLOW_CHECKED_DIV((x), (i));
        if (q == 0) {
            break;
        }
        int64_t j = FLOW_CHECKED_DIV((x), (q));
        if (j > hi) {
            j = hi;
        }
        res = (res + (q * ((j - i) + 1)));
        i = (j + 1);
    }
    return res;
}

int64_t F_i64(int64_t L) {
    int64_t B = isqrt_i64(L);
    int32_t* spf = (int32_t*)(calloc((B + 1), 4));
    int32_t* primes = (int32_t*)(calloc((FLOW_CHECKED_DIV((B), (5)) + 16), 4));
    int64_t* pfac = (int64_t*)(calloc(16, 8));
    int64_t* divs = (int64_t*)(calloc(128, 8));
    int64_t* mus = (int64_t*)(calloc(128, 8));
    if (((((spf == NULL || primes == NULL) || pfac == NULL) || divs == NULL) || mus == NULL)) {
        return 0;
    }
    int64_t pc = 0;
    int64_t i = 2;
    while (i <= B) {
        if (spf[i] == 0) {
            spf[i] = ((int32_t)(i));
            primes[pc] = ((int32_t)(i));
            pc = (pc + 1);
        }
        int64_t j = 0;
        while (j < pc) {
            int64_t p = ((int64_t)(primes[j]));
            int64_t v = (i * p);
            if (v > B) {
                break;
            }
            spf[v] = ((int32_t)(p));
            if (p == ((int64_t)(spf[i]))) {
                break;
            }
            j = (j + 1);
        }
        i = (i + 1);
    }
    int64_t total = 0;
    int64_t n = 2;
    while (n <= B) {
        int64_t tmp = n;
        int64_t pcount = 0;
        int64_t last = 0;
        while (tmp > 1) {
            int64_t p = ((int64_t)(spf[tmp]));
            tmp = FLOW_CHECKED_DIV((tmp), (p));
            if (p != last) {
                pfac[pcount] = p;
                pcount = (pcount + 1);
                last = p;
            }
        }
        divs[0] = 1;
        mus[0] = 1;
        int64_t dcount = 1;
        int64_t pi = 0;
        while (pi < pcount) {
            int64_t p = pfac[pi];
            int64_t m = dcount;
            int64_t di = 0;
            while (di < m) {
                divs[dcount] = (divs[di] * p);
                mus[dcount] = (0 - mus[di]);
                dcount = (dcount + 1);
                di = (di + 1);
            }
            pi = (pi + 1);
        }
        int64_t Ln = FLOW_CHECKED_DIV((L), (n));
        int64_t idx = 0;
        while (idx < dcount) {
            int64_t d = divs[idx];
            int64_t mu = mus[idx];
            int64_t k = FLOW_CHECKED_DIV((n), (d));
            if (k > 1) {
                int64_t x = FLOW_CHECKED_DIV((Ln), (d));
                if (x > 0) {
                    total = (total + (mu * sum_floor_segment_i64_i64_i64(x, k, ((2 * k) - 1))));
                }
            }
            idx = (idx + 1);
        }
        n = (n + 1);
    }
    free(divs);
    free(mus);
    free(pfac);
    free(spf);
    free(primes);
    return total;
}

int32_t main(void) {
    if (F_i64(15) != 4) {
        printf("%lld\n", F_i64(15));
        return 1;
    }
    if (F_i64(1000) != 1069) {
        printf("%lld\n", F_i64(1000));
        return 1;
    }
    printf("%lld\n", F_i64(1000000000000));
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func @gcd(%arg0: i64, %arg1: i64) -> i64 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i64, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func @sum_floor_segment(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %175 = arith.cmpi sle, %arg2, %arg1 : i64
    %176 = scf.if %175 -> (i1) {
      %177 = arith.constant true
      scf.yield %177 : i1
    } else {
      %178 = arith.constant 0 : i32
      %180 = arith.extsi %178 : i32 to i64
      %179 = arith.cmpi sle, %arg0, %180 : i64
      scf.yield %179 : i1
    }
    cf.cond_br %176, ^bb42, ^bb43
    ^bb42:
      %181 = arith.constant 0 : i32
      %182 = arith.extsi %181 : i32 to i64
      func.return %182 : i64
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %183 = arith.constant 0 : i32
    %184 = arith.extsi %183 : i32 to i64
    %185 = llvm.mlir.constant(1 : i64) : i64
    %186 = llvm.alloca %185 x i64 : (i64) -> !llvm.ptr
    llvm.store %184, %186 : i64, !llvm.ptr
    %187 = arith.constant 1 : i32
    %189 = arith.extsi %187 : i32 to i64
    %188 = arith.addi %arg1, %189 : i64
    %190 = llvm.mlir.constant(1 : i64) : i64
    %191 = llvm.alloca %190 x i64 : (i64) -> !llvm.ptr
    llvm.store %188, %191 : i64, !llvm.ptr
    cf.br ^bb45
    ^bb45:
    %192 = llvm.load %191 : !llvm.ptr -> i64
    %193 = arith.cmpi sle, %192, %arg2 : i64
    cf.cond_br %193, ^bb46, ^bb47
    ^bb46:
      %194 = llvm.load %191 : !llvm.ptr -> i64
      %195 = arith.divsi %arg0, %194 : i64
      %196 = arith.constant 0 : i32
      %198 = arith.extsi %196 : i32 to i64
      %197 = arith.cmpi eq, %195, %198 : i64
      cf.cond_br %197, ^bb48, ^bb49
      ^bb48:
        cf.br ^bb47
      ^bb49:
        cf.br ^bb50
      ^bb50:
      %199 = arith.divsi %arg0, %195 : i64
      %200 = llvm.mlir.constant(1 : i64) : i64
      %201 = llvm.alloca %200 x i64 : (i64) -> !llvm.ptr
      llvm.store %199, %201 : i64, !llvm.ptr
      %202 = llvm.load %201 : !llvm.ptr -> i64
      %203 = arith.cmpi sgt, %202, %arg2 : i64
      cf.cond_br %203, ^bb51, ^bb52
      ^bb51:
        llvm.store %arg2, %201 : i64, !llvm.ptr
        cf.br ^bb53
      ^bb52:
        cf.br ^bb53
      ^bb53:
      %204 = llvm.load %186 : !llvm.ptr -> i64
      %205 = llvm.load %201 : !llvm.ptr -> i64
      %206 = llvm.load %191 : !llvm.ptr -> i64
      %207 = arith.subi %205, %206 : i64
      %208 = arith.constant 1 : i32
      %210 = arith.extsi %208 : i32 to i64
      %209 = arith.addi %207, %210 : i64
      %211 = arith.muli %195, %209 : i64
      %212 = arith.addi %204, %211 : i64
      llvm.store %212, %186 : i64, !llvm.ptr
      %213 = llvm.load %201 : !llvm.ptr -> i64
      %214 = arith.constant 1 : i32
      %216 = arith.extsi %214 : i32 to i64
      %215 = arith.addi %213, %216 : i64
      llvm.store %215, %191 : i64, !llvm.ptr
      cf.br ^bb45
    ^bb47:
    %217 = llvm.load %186 : !llvm.ptr -> i64
    func.return %217 : i64
  }
  func.func @F(%arg0: i64) -> i64 {
    %218 = func.call @isqrt(%arg0) : (i64) -> i64
    %220 = arith.constant 1 : i32
    %222 = arith.extsi %220 : i32 to i64
    %221 = arith.addi %218, %222 : i64
    %223 = arith.constant 4 : i32
    %224 = arith.extsi %223 : i32 to i64
    %219 = func.call @calloc(%221, %224) : (i64, i64) -> !llvm.ptr
    %226 = arith.constant 5 : i32
    %228 = arith.extsi %226 : i32 to i64
    %227 = arith.divsi %218, %228 : i64
    %229 = arith.constant 16 : i32
    %231 = arith.extsi %229 : i32 to i64
    %230 = arith.addi %227, %231 : i64
    %232 = arith.constant 4 : i32
    %233 = arith.extsi %232 : i32 to i64
    %225 = func.call @calloc(%230, %233) : (i64, i64) -> !llvm.ptr
    %235 = arith.constant 16 : i32
    %236 = arith.constant 8 : i32
    %237 = arith.extsi %235 : i32 to i64
    %238 = arith.extsi %236 : i32 to i64
    %234 = func.call @calloc(%237, %238) : (i64, i64) -> !llvm.ptr
    %240 = arith.constant 128 : i32
    %241 = arith.constant 8 : i32
    %242 = arith.extsi %240 : i32 to i64
    %243 = arith.extsi %241 : i32 to i64
    %239 = func.call @calloc(%242, %243) : (i64, i64) -> !llvm.ptr
    %245 = arith.constant 128 : i32
    %246 = arith.constant 8 : i32
    %247 = arith.extsi %245 : i32 to i64
    %248 = arith.extsi %246 : i32 to i64
    %244 = func.call @calloc(%247, %248) : (i64, i64) -> !llvm.ptr
    %249 = llvm.mlir.zero : !llvm.ptr
    %250 = llvm.icmp "eq" %219, %249 : !llvm.ptr
    %251 = scf.if %250 -> (i1) {
      %252 = arith.constant true
      scf.yield %252 : i1
    } else {
      %253 = llvm.mlir.zero : !llvm.ptr
      %254 = llvm.icmp "eq" %225, %253 : !llvm.ptr
      scf.yield %254 : i1
    }
    %255 = scf.if %251 -> (i1) {
      %256 = arith.constant true
      scf.yield %256 : i1
    } else {
      %257 = llvm.mlir.zero : !llvm.ptr
      %258 = llvm.icmp "eq" %234, %257 : !llvm.ptr
      scf.yield %258 : i1
    }
    %259 = scf.if %255 -> (i1) {
      %260 = arith.constant true
      scf.yield %260 : i1
    } else {
      %261 = llvm.mlir.zero : !llvm.ptr
      %262 = llvm.icmp "eq" %239, %261 : !llvm.ptr
      scf.yield %262 : i1
    }
    %263 = scf.if %259 -> (i1) {
      %264 = arith.constant true
      scf.yield %264 : i1
    } else {
      %265 = llvm.mlir.zero : !llvm.ptr
      %266 = llvm.icmp "eq" %244, %265 : !llvm.ptr
      scf.yield %266 : i1
    }
    cf.cond_br %263, ^bb54, ^bb55
    ^bb54:
      %267 = arith.constant 0 : i32
      %268 = arith.extsi %267 : i32 to i64
      func.return %268 : i64
    ^bb55:
      cf.br ^bb56
    ^bb56:
    %269 = arith.constant 0 : i32
    %270 = arith.extsi %269 : i32 to i64
    %271 = llvm.mlir.constant(1 : i64) : i64
    %272 = llvm.alloca %271 x i64 : (i64) -> !llvm.ptr
    llvm.store %270, %272 : i64, !llvm.ptr
    %273 = arith.constant 2 : i32
    %274 = arith.extsi %273 : i32 to i64
    %275 = llvm.mlir.constant(1 : i64) : i64
    %276 = llvm.alloca %275 x i64 : (i64) -> !llvm.ptr
    llvm.store %274, %276 : i64, !llvm.ptr
    cf.br ^bb57
    ^bb57:
    %277 = llvm.load %276 : !llvm.ptr -> i64
    %278 = arith.cmpi sle, %277, %218 : i64
    cf.cond_br %278, ^bb58, ^bb59
    ^bb58:
      %280 = llvm.load %276 : !llvm.ptr -> i64
      %281 = llvm.getelementptr %219[%280] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %279 = llvm.load %281 : !llvm.ptr -> i32
      %282 = arith.constant 0 : i32
      %283 = arith.cmpi eq, %279, %282 : i32
      cf.cond_br %283, ^bb60, ^bb61
      ^bb60:
        %284 = llvm.load %276 : !llvm.ptr -> i64
        %285 = arith.trunci %284 : i64 to i32
        %286 = llvm.load %276 : !llvm.ptr -> i64
        %287 = llvm.getelementptr %219[%286] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %285, %287 : i32, !llvm.ptr
        %288 = llvm.load %276 : !llvm.ptr -> i64
        %289 = arith.trunci %288 : i64 to i32
        %290 = llvm.load %272 : !llvm.ptr -> i64
        %291 = llvm.getelementptr %225[%290] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %289, %291 : i32, !llvm.ptr
        %292 = llvm.load %272 : !llvm.ptr -> i64
        %293 = arith.constant 1 : i32
        %295 = arith.extsi %293 : i32 to i64
        %294 = arith.addi %292, %295 : i64
        llvm.store %294, %272 : i64, !llvm.ptr
        cf.br ^bb62
      ^bb61:
        cf.br ^bb62
      ^bb62:
      %296 = arith.constant 0 : i32
      %297 = arith.extsi %296 : i32 to i64
      %298 = llvm.mlir.constant(1 : i64) : i64
      %299 = llvm.alloca %298 x i64 : (i64) -> !llvm.ptr
      llvm.store %297, %299 : i64, !llvm.ptr
      cf.br ^bb63
      ^bb63:
      %300 = llvm.load %299 : !llvm.ptr -> i64
      %301 = llvm.load %272 : !llvm.ptr -> i64
      %302 = arith.cmpi slt, %300, %301 : i64
      cf.cond_br %302, ^bb64, ^bb65
      ^bb64:
        %304 = llvm.load %299 : !llvm.ptr -> i64
        %305 = llvm.getelementptr %225[%304] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %303 = llvm.load %305 : !llvm.ptr -> i32
        %306 = arith.extsi %303 : i32 to i64
        %307 = llvm.load %276 : !llvm.ptr -> i64
        %308 = arith.muli %307, %306 : i64
        %309 = arith.cmpi sgt, %308, %218 : i64
        cf.cond_br %309, ^bb66, ^bb67
        ^bb66:
          cf.br ^bb65
        ^bb67:
          cf.br ^bb68
        ^bb68:
        %310 = arith.trunci %306 : i64 to i32
        %311 = llvm.getelementptr %219[%308] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %310, %311 : i32, !llvm.ptr
        %313 = llvm.load %276 : !llvm.ptr -> i64
        %314 = llvm.getelementptr %219[%313] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %312 = llvm.load %314 : !llvm.ptr -> i32
        %315 = arith.extsi %312 : i32 to i64
        %316 = arith.cmpi eq, %306, %315 : i64
        cf.cond_br %316, ^bb69, ^bb70
        ^bb69:
          cf.br ^bb65
        ^bb70:
          cf.br ^bb71
        ^bb71:
        %317 = llvm.load %299 : !llvm.ptr -> i64
        %318 = arith.constant 1 : i32
        %320 = arith.extsi %318 : i32 to i64
        %319 = arith.addi %317, %320 : i64
        llvm.store %319, %299 : i64, !llvm.ptr
        cf.br ^bb63
      ^bb65:
      %321 = llvm.load %276 : !llvm.ptr -> i64
      %322 = arith.constant 1 : i32
      %324 = arith.extsi %322 : i32 to i64
      %323 = arith.addi %321, %324 : i64
      llvm.store %323, %276 : i64, !llvm.ptr
      cf.br ^bb57
    ^bb59:
    %325 = arith.constant 0 : i32
    %326 = arith.extsi %325 : i32 to i64
    %327 = llvm.mlir.constant(1 : i64) : i64
    %328 = llvm.alloca %327 x i64 : (i64) -> !llvm.ptr
    llvm.store %326, %328 : i64, !llvm.ptr
    %329 = arith.constant 2 : i32
    %330 = arith.extsi %329 : i32 to i64
    %331 = llvm.mlir.constant(1 : i64) : i64
    %332 = llvm.alloca %331 x i64 : (i64) -> !llvm.ptr
    llvm.store %330, %332 : i64, !llvm.ptr
    cf.br ^bb72
    ^bb72:
    %333 = llvm.load %332 : !llvm.ptr -> i64
    %334 = arith.cmpi sle, %333, %218 : i64
    cf.cond_br %334, ^bb73, ^bb74
    ^bb73:
      %335 = llvm.load %332 : !llvm.ptr -> i64
      %336 = llvm.mlir.constant(1 : i64) : i64
      %337 = llvm.alloca %336 x i64 : (i64) -> !llvm.ptr
      llvm.store %335, %337 : i64, !llvm.ptr
      %338 = arith.constant 0 : i32
      %339 = arith.extsi %338 : i32 to i64
      %340 = llvm.mlir.constant(1 : i64) : i64
      %341 = llvm.alloca %340 x i64 : (i64) -> !llvm.ptr
      llvm.store %339, %341 : i64, !llvm.ptr
      %342 = arith.constant 0 : i32
      %343 = arith.extsi %342 : i32 to i64
      %344 = llvm.mlir.constant(1 : i64) : i64
      %345 = llvm.alloca %344 x i64 : (i64) -> !llvm.ptr
      llvm.store %343, %345 : i64, !llvm.ptr
      cf.br ^bb75
      ^bb75:
      %346 = llvm.load %337 : !llvm.ptr -> i64
      %347 = arith.constant 1 : i32
      %349 = arith.extsi %347 : i32 to i64
      %348 = arith.cmpi sgt, %346, %349 : i64
      cf.cond_br %348, ^bb76, ^bb77
      ^bb76:
        %351 = llvm.load %337 : !llvm.ptr -> i64
        %352 = llvm.getelementptr %219[%351] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %350 = llvm.load %352 : !llvm.ptr -> i32
        %353 = arith.extsi %350 : i32 to i64
        %354 = llvm.load %337 : !llvm.ptr -> i64
        %355 = arith.divsi %354, %353 : i64
        llvm.store %355, %337 : i64, !llvm.ptr
        %356 = llvm.load %345 : !llvm.ptr -> i64
        %357 = arith.cmpi ne, %353, %356 : i64
        cf.cond_br %357, ^bb78, ^bb79
        ^bb78:
          %358 = llvm.load %341 : !llvm.ptr -> i64
          %359 = llvm.getelementptr %234[%358] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %353, %359 : i64, !llvm.ptr
          %360 = llvm.load %341 : !llvm.ptr -> i64
          %361 = arith.constant 1 : i32
          %363 = arith.extsi %361 : i32 to i64
          %362 = arith.addi %360, %363 : i64
          llvm.store %362, %341 : i64, !llvm.ptr
          llvm.store %353, %345 : i64, !llvm.ptr
          cf.br ^bb80
        ^bb79:
          cf.br ^bb80
        ^bb80:
        cf.br ^bb75
      ^bb77:
      %364 = arith.constant 1 : i32
      %365 = arith.constant 0 : i32
      %366 = arith.extsi %364 : i32 to i64
      %367 = arith.extsi %365 : i32 to i64
      %368 = llvm.getelementptr %239[%367] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %366, %368 : i64, !llvm.ptr
      %369 = arith.constant 1 : i32
      %370 = arith.constant 0 : i32
      %371 = arith.extsi %369 : i32 to i64
      %372 = arith.extsi %370 : i32 to i64
      %373 = llvm.getelementptr %244[%372] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %371, %373 : i64, !llvm.ptr
      %374 = arith.constant 1 : i32
      %375 = arith.extsi %374 : i32 to i64
      %376 = llvm.mlir.constant(1 : i64) : i64
      %377 = llvm.alloca %376 x i64 : (i64) -> !llvm.ptr
      llvm.store %375, %377 : i64, !llvm.ptr
      %378 = arith.constant 0 : i32
      %379 = arith.extsi %378 : i32 to i64
      %380 = llvm.mlir.constant(1 : i64) : i64
      %381 = llvm.alloca %380 x i64 : (i64) -> !llvm.ptr
      llvm.store %379, %381 : i64, !llvm.ptr
      cf.br ^bb81
      ^bb81:
      %382 = llvm.load %381 : !llvm.ptr -> i64
      %383 = llvm.load %341 : !llvm.ptr -> i64
      %384 = arith.cmpi slt, %382, %383 : i64
      cf.cond_br %384, ^bb82, ^bb83
      ^bb82:
        %386 = llvm.load %381 : !llvm.ptr -> i64
        %387 = llvm.getelementptr %234[%386] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %385 = llvm.load %387 : !llvm.ptr -> i64
        %388 = llvm.load %377 : !llvm.ptr -> i64
        %389 = arith.constant 0 : i32
        %390 = arith.extsi %389 : i32 to i64
        %391 = llvm.mlir.constant(1 : i64) : i64
        %392 = llvm.alloca %391 x i64 : (i64) -> !llvm.ptr
        llvm.store %390, %392 : i64, !llvm.ptr
        cf.br ^bb84
        ^bb84:
        %393 = llvm.load %392 : !llvm.ptr -> i64
        %394 = arith.cmpi slt, %393, %388 : i64
        cf.cond_br %394, ^bb85, ^bb86
        ^bb85:
          %396 = llvm.load %392 : !llvm.ptr -> i64
          %397 = llvm.getelementptr %239[%396] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %395 = llvm.load %397 : !llvm.ptr -> i64
          %398 = arith.muli %395, %385 : i64
          %399 = llvm.load %377 : !llvm.ptr -> i64
          %400 = llvm.getelementptr %239[%399] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %398, %400 : i64, !llvm.ptr
          %401 = arith.constant 0 : i32
          %403 = llvm.load %392 : !llvm.ptr -> i64
          %404 = llvm.getelementptr %244[%403] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %402 = llvm.load %404 : !llvm.ptr -> i64
          %406 = arith.extsi %401 : i32 to i64
          %405 = arith.subi %406, %402 : i64
          %407 = llvm.load %377 : !llvm.ptr -> i64
          %408 = llvm.getelementptr %244[%407] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %405, %408 : i64, !llvm.ptr
          %409 = llvm.load %377 : !llvm.ptr -> i64
          %410 = arith.constant 1 : i32
          %412 = arith.extsi %410 : i32 to i64
          %411 = arith.addi %409, %412 : i64
          llvm.store %411, %377 : i64, !llvm.ptr
          %413 = llvm.load %392 : !llvm.ptr -> i64
          %414 = arith.constant 1 : i32
          %416 = arith.extsi %414 : i32 to i64
          %415 = arith.addi %413, %416 : i64
          llvm.store %415, %392 : i64, !llvm.ptr
          cf.br ^bb84
        ^bb86:
        %417 = llvm.load %381 : !llvm.ptr -> i64
        %418 = arith.constant 1 : i32
        %420 = arith.extsi %418 : i32 to i64
        %419 = arith.addi %417, %420 : i64
        llvm.store %419, %381 : i64, !llvm.ptr
        cf.br ^bb81
      ^bb83:
      %421 = llvm.load %332 : !llvm.ptr -> i64
      %422 = arith.divsi %arg0, %421 : i64
      %423 = arith.constant 0 : i32
      %424 = arith.extsi %423 : i32 to i64
      %425 = llvm.mlir.constant(1 : i64) : i64
      %426 = llvm.alloca %425 x i64 : (i64) -> !llvm.ptr
      llvm.store %424, %426 : i64, !llvm.ptr
      cf.br ^bb87
      ^bb87:
      %427 = llvm.load %426 : !llvm.ptr -> i64
      %428 = llvm.load %377 : !llvm.ptr -> i64
      %429 = arith.cmpi slt, %427, %428 : i64
      cf.cond_br %429, ^bb88, ^bb89
      ^bb88:
        %431 = llvm.load %426 : !llvm.ptr -> i64
        %432 = llvm.getelementptr %239[%431] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %430 = llvm.load %432 : !llvm.ptr -> i64
        %434 = llvm.load %426 : !llvm.ptr -> i64
        %435 = llvm.getelementptr %244[%434] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %433 = llvm.load %435 : !llvm.ptr -> i64
        %436 = llvm.load %332 : !llvm.ptr -> i64
        %437 = arith.divsi %436, %430 : i64
        %438 = arith.constant 1 : i32
        %440 = arith.extsi %438 : i32 to i64
        %439 = arith.cmpi sgt, %437, %440 : i64
        cf.cond_br %439, ^bb90, ^bb91
        ^bb90:
          %441 = arith.divsi %422, %430 : i64
          %442 = arith.constant 0 : i32
          %444 = arith.extsi %442 : i32 to i64
          %443 = arith.cmpi sgt, %441, %444 : i64
          cf.cond_br %443, ^bb93, ^bb94
          ^bb93:
            %445 = llvm.load %328 : !llvm.ptr -> i64
            %447 = arith.constant 2 : i32
            %449 = arith.extsi %447 : i32 to i64
            %448 = arith.muli %449, %437 : i64
            %450 = arith.constant 1 : i32
            %452 = arith.extsi %450 : i32 to i64
            %451 = arith.subi %448, %452 : i64
            %446 = func.call @sum_floor_segment(%441, %437, %451) : (i64, i64, i64) -> i64
            %453 = arith.muli %433, %446 : i64
            %454 = arith.addi %445, %453 : i64
            llvm.store %454, %328 : i64, !llvm.ptr
            cf.br ^bb95
          ^bb94:
            cf.br ^bb95
          ^bb95:
          cf.br ^bb92
        ^bb91:
          cf.br ^bb92
        ^bb92:
        %455 = llvm.load %426 : !llvm.ptr -> i64
        %456 = arith.constant 1 : i32
        %458 = arith.extsi %456 : i32 to i64
        %457 = arith.addi %455, %458 : i64
        llvm.store %457, %426 : i64, !llvm.ptr
        cf.br ^bb87
      ^bb89:
      %459 = llvm.load %332 : !llvm.ptr -> i64
      %460 = arith.constant 1 : i32
      %462 = arith.extsi %460 : i32 to i64
      %461 = arith.addi %459, %462 : i64
      llvm.store %461, %332 : i64, !llvm.ptr
      cf.br ^bb72
    ^bb74:
    func.call @free(%239) : (!llvm.ptr) -> ()
    func.call @free(%244) : (!llvm.ptr) -> ()
    func.call @free(%234) : (!llvm.ptr) -> ()
    func.call @free(%219) : (!llvm.ptr) -> ()
    func.call @free(%225) : (!llvm.ptr) -> ()
    %468 = llvm.load %328 : !llvm.ptr -> i64
    func.return %468 : i64
  }
  func.func @main() -> i32 {
    %470 = arith.constant 15 : i32
    %471 = arith.extsi %470 : i32 to i64
    %469 = func.call @F(%471) : (i64) -> i64
    %472 = arith.constant 4 : i32
    %474 = arith.extsi %472 : i32 to i64
    %473 = arith.cmpi ne, %469, %474 : i64
    cf.cond_br %473, ^bb96, ^bb97
    ^bb96:
      %475 = llvm.mlir.addressof @str_0 : !llvm.ptr
      %477 = arith.constant 15 : i32
      %478 = arith.extsi %477 : i32 to i64
      %476 = func.call @F(%478) : (i64) -> i64
      %479 = llvm.call @printf(%475, %476) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
      %480 = arith.constant 1 : i32
      func.return %480 : i32
    ^bb97:
      cf.br ^bb98
    ^bb98:
    %482 = arith.constant 1000 : i32
    %483 = arith.extsi %482 : i32 to i64
    %481 = func.call @F(%483) : (i64) -> i64
    %484 = arith.constant 1069 : i32
    %486 = arith.extsi %484 : i32 to i64
    %485 = arith.cmpi ne, %481, %486 : i64
    cf.cond_br %485, ^bb99, ^bb100
    ^bb99:
      %487 = llvm.mlir.addressof @str_0 : !llvm.ptr
      %489 = arith.constant 1000 : i32
      %490 = arith.extsi %489 : i32 to i64
      %488 = func.call @F(%490) : (i64) -> i64
      %491 = llvm.call @printf(%487, %488) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
      %492 = arith.constant 1 : i32
      func.return %492 : i32
    ^bb100:
      cf.br ^bb101
    ^bb101:
    %493 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %495 = arith.constant 995705032704 : i32
    %496 = arith.extsi %495 : i32 to i64
    %494 = func.call @F(%496) : (i64) -> i64
    %497 = llvm.call @printf(%493, %494) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %498 = arith.constant 0 : i32
    func.return %498 : i32
  }
}