Problem 378

Tr(6e7) last 18 digits: decreasing dT triples via Fenwick trees.

Answer147534623725724718
Output147534623725724718
StatusPASS
Native helperno
Runtime3060 ms
Peak memory294928 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)?
Space complexityO(n^2)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 378
# Tr(6e7) last 18 digits: decreasing dT triples via Fenwick trees.

import euler.nt { isqrt }

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

function fenwick_sum(bit: ptr<i64>, idx0: i64) -> i64 {
    let mut idx: i64 = idx0
    let mut s: i64 = 0
    while idx > 0 {
        s = s + bit[idx]
        idx = idx & (idx - 1)
    }
    return s
}

function fenwick_add(bit: ptr<i64>, size: i64, idx0: i64, delta: i64) -> void {
    let mut idx: i64 = idx0
    while idx <= size {
        bit[idx] = bit[idx] + delta
        idx = idx + (idx & (0 - idx))
    }
}

function main() -> i32 {
    let N: i64 = 60000000
    let MOD: i64 = 1000000000000000000
    let limit: i64 = N + 1
    let spf_odd: ptr<i32> = calloc((limit >> 1) + 1, 4)
    let root: i64 = isqrt(limit)
    let mut p: i64 = 3
    while p <= root {
        if spf_odd[p >> 1] == 0 {
            let step: i64 = p << 1
            let mut m: i64 = p * p
            while m <= limit {
                let idx: i64 = m >> 1
                if spf_odd[idx] == 0 { spf_odd[idx] = p as i32 }
                m = m + step
            }
        }
        p = p + 2
    }

    let tau: ptr<i16> = calloc(limit + 1, 2)
    let expv: ptr<i8> = calloc(limit + 1, 1)
    tau[1] = 1
    let mut x: i64 = 2
    while x <= limit {
        if (x & 1) == 0 {
            let m: i64 = x >> 1
            if (m & 1) == 0 {
                let e: i64 = (expv[m] as i64) + 1
                expv[x] = e as i8
                tau[x] = (((tau[m] as i64) / e) * (e + 1)) as i16
            } else {
                expv[x] = 1
                tau[x] = ((tau[m] as i64) * 2) as i16
            }
        } else {
            let sp: i64 = spf_odd[x >> 1] as i64
            if sp == 0 {
                expv[x] = 1
                tau[x] = 2
            } else {
                let m: i64 = x / sp
                if m % sp == 0 {
                    let e: i64 = (expv[m] as i64) + 1
                    expv[x] = e as i8
                    tau[x] = (((tau[m] as i64) / e) * (e + 1)) as i16
                } else {
                    expv[x] = 1
                    tau[x] = ((tau[m] as i64) * 2) as i16
                }
            }
        }
        x = x + 1
    }

    let mut size: i64 = 1 << 16
    let bit1: ptr<i64> = calloc(size + 2, 8)
    let bit2: ptr<i64> = calloc(size + 2, 8)
    let mut seen: i64 = 0
    let mut total_pairs: i64 = 0
    let mut ans: i64 = 0
    let mut i: i64 = 1
    while i <= N {
        let mut xv: i64 = 0
        if (i & 1) == 0 {
            xv = (tau[i >> 1] as i64) * (tau[i + 1] as i64)
        } else {
            xv = (tau[i] as i64) * (tau[(i + 1) >> 1] as i64)
        }
        if xv > size {
            # grow - realloc not always safe with Flow ptr types; use large enough size
            # dT max for this range is well under 2000, so 1<<16 is enough
            printf("BIT overflow %lld\n", xv)
            return 1
        }
        let leq: i64 = fenwick_sum(bit1, xv)
        let pairs_here: i64 = seen - leq
        let pairs_leq: i64 = fenwick_sum(bit2, xv)
        let triples_here: i64 = total_pairs - pairs_leq
        ans = ans + triples_here
        if ans >= MOD { ans = ans % MOD }
        if ans < 0 { ans = ans % MOD; if ans < 0 { ans = ans + MOD } }
        total_pairs = total_pairs + pairs_here
        fenwick_add(bit2, size, xv, pairs_here)
        fenwick_add(bit1, size, xv, 1)
        seen = seen + 1
        i = i + 1
    }
    printf("%lld\n", ans)
    free(bit2)
    free(bit1)
    free(expv)
    free(tau)
    free(spf_odd)
    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 fenwick_sum_ptr_i64_i64(int64_t* bit, int64_t idx0);
void fenwick_add_ptr_i64_i64_i64_i64(int64_t* bit, int64_t size, int64_t idx0, int64_t delta);
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 fenwick_sum_ptr_i64_i64(int64_t* bit, int64_t idx0) {
    int64_t idx = idx0;
    int64_t s = 0;
    while (idx > 0) {
        s = (s + bit[idx]);
        idx = (idx & (idx - 1));
    }
    return s;
}

void fenwick_add_ptr_i64_i64_i64_i64(int64_t* bit, int64_t size, int64_t idx0, int64_t delta) {
    int64_t idx = idx0;
    while (idx <= size) {
        bit[idx] = (bit[idx] + delta);
        idx = (idx + (idx & (0 - idx)));
    }
}

int32_t main(void) {
    int64_t N = 60000000;
    int64_t MOD = 1000000000000000000;
    int64_t limit = (N + 1);
    int32_t* spf_odd = (int32_t*)(calloc((FLOW_CHECKED_SHR((limit), (1)) + 1), 4));
    int64_t root = isqrt_i64(limit);
    int64_t p = 3;
    while (p <= root) {
        if (spf_odd[FLOW_CHECKED_SHR((p), (1))] == 0) {
            int64_t step = FLOW_CHECKED_SHL((p), (1));
            int64_t m = (p * p);
            while (m <= limit) {
                int64_t idx = FLOW_CHECKED_SHR((m), (1));
                if (spf_odd[idx] == 0) {
                    spf_odd[idx] = ((int32_t)(p));
                }
                m = (m + step);
            }
        }
        p = (p + 2);
    }
    int16_t* tau = (int16_t*)(calloc((limit + 1), 2));
    int8_t* expv = (int8_t*)(calloc((limit + 1), 1));
    tau[1] = 1;
    int64_t x = 2;
    while (x <= limit) {
        if ((x & 1) == 0) {
            int64_t m = FLOW_CHECKED_SHR((x), (1));
            if ((m & 1) == 0) {
                int64_t e = (((int64_t)(expv[m])) + 1);
                expv[x] = ((int8_t)(e));
                tau[x] = ((int16_t)((FLOW_CHECKED_DIV((((int64_t)(tau[m]))), (e)) * (e + 1))));
            } else {
                expv[x] = 1;
                tau[x] = ((int16_t)((((int64_t)(tau[m])) * 2)));
            }
        } else {
            int64_t sp = ((int64_t)(spf_odd[FLOW_CHECKED_SHR((x), (1))]));
            if (sp == 0) {
                expv[x] = 1;
                tau[x] = 2;
            } else {
                int64_t m = FLOW_CHECKED_DIV((x), (sp));
                if (FLOW_CHECKED_MOD((m), (sp)) == 0) {
                    int64_t e = (((int64_t)(expv[m])) + 1);
                    expv[x] = ((int8_t)(e));
                    tau[x] = ((int16_t)((FLOW_CHECKED_DIV((((int64_t)(tau[m]))), (e)) * (e + 1))));
                } else {
                    expv[x] = 1;
                    tau[x] = ((int16_t)((((int64_t)(tau[m])) * 2)));
                }
            }
        }
        x = (x + 1);
    }
    int64_t size = FLOW_CHECKED_SHL((1), (16));
    int64_t* bit1 = (int64_t*)(calloc((size + 2), 8));
    int64_t* bit2 = (int64_t*)(calloc((size + 2), 8));
    int64_t seen = 0;
    int64_t total_pairs = 0;
    int64_t ans = 0;
    int64_t i = 1;
    while (i <= N) {
        int64_t xv = 0;
        if ((i & 1) == 0) {
            xv = (((int64_t)(tau[FLOW_CHECKED_SHR((i), (1))])) * ((int64_t)(tau[(i + 1)])));
        } else {
            xv = (((int64_t)(tau[i])) * ((int64_t)(tau[FLOW_CHECKED_SHR(((i + 1)), (1))])));
        }
        if (xv > size) {
            printf("BIT overflow %lld\n", xv);
            return 1;
        }
        int64_t leq = fenwick_sum_ptr_i64_i64(bit1, xv);
        int64_t pairs_here = (seen - leq);
        int64_t pairs_leq = fenwick_sum_ptr_i64_i64(bit2, xv);
        int64_t triples_here = (total_pairs - pairs_leq);
        ans = (ans + triples_here);
        if (ans >= MOD) {
            ans = FLOW_CHECKED_MOD((ans), (MOD));
        }
        if (ans < 0) {
            ans = FLOW_CHECKED_MOD((ans), (MOD));
            if (ans < 0) {
                ans = (ans + MOD);
            }
        }
        total_pairs = (total_pairs + pairs_here);
        fenwick_add_ptr_i64_i64_i64_i64(bit2, size, xv, pairs_here);
        fenwick_add_ptr_i64_i64_i64_i64(bit1, size, xv, 1);
        seen = (seen + 1);
        i = (i + 1);
    }
    printf("%lld\n", ans);
    free(bit2);
    free(bit1);
    free(expv);
    free(tau);
    free(spf_odd);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("BIT overflow %lld\n\00") {addr_space = 0 : i32} : !llvm.array<19 x i8>
  llvm.mlir.global internal constant @str_1("%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 private @realloc(!llvm.ptr, i64) -> !llvm.ptr
  func.func @fenwick_sum(%arg0: !llvm.ptr, %arg1: i64) -> i64 {
    %175 = llvm.mlir.constant(1 : i64) : i64
    %176 = llvm.alloca %175 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %176 : i64, !llvm.ptr
    %177 = arith.constant 0 : i32
    %178 = arith.extsi %177 : i32 to i64
    %179 = llvm.mlir.constant(1 : i64) : i64
    %180 = llvm.alloca %179 x i64 : (i64) -> !llvm.ptr
    llvm.store %178, %180 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %181 = llvm.load %176 : !llvm.ptr -> i64
    %182 = arith.constant 0 : i32
    %184 = arith.extsi %182 : i32 to i64
    %183 = arith.cmpi sgt, %181, %184 : i64
    cf.cond_br %183, ^bb43, ^bb44
    ^bb43:
      %185 = llvm.load %180 : !llvm.ptr -> i64
      %187 = llvm.load %176 : !llvm.ptr -> i64
      %188 = llvm.getelementptr %arg0[%187] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %186 = llvm.load %188 : !llvm.ptr -> i64
      %189 = arith.addi %185, %186 : i64
      llvm.store %189, %180 : i64, !llvm.ptr
      %190 = llvm.load %176 : !llvm.ptr -> i64
      %191 = llvm.load %176 : !llvm.ptr -> i64
      %192 = arith.constant 1 : i32
      %194 = arith.extsi %192 : i32 to i64
      %193 = arith.subi %191, %194 : i64
      %195 = arith.andi %190, %193 : i64
      llvm.store %195, %176 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %196 = llvm.load %180 : !llvm.ptr -> i64
    func.return %196 : i64
  }
  func.func @fenwick_add(%arg0: !llvm.ptr, %arg1: i64, %arg2: i64, %arg3: i64) -> () {
    %197 = llvm.mlir.constant(1 : i64) : i64
    %198 = llvm.alloca %197 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg2, %198 : i64, !llvm.ptr
    cf.br ^bb45
    ^bb45:
    %199 = llvm.load %198 : !llvm.ptr -> i64
    %200 = arith.cmpi sle, %199, %arg1 : i64
    cf.cond_br %200, ^bb46, ^bb47
    ^bb46:
      %202 = llvm.load %198 : !llvm.ptr -> i64
      %203 = llvm.getelementptr %arg0[%202] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %201 = llvm.load %203 : !llvm.ptr -> i64
      %204 = arith.addi %201, %arg3 : i64
      %205 = llvm.load %198 : !llvm.ptr -> i64
      %206 = llvm.getelementptr %arg0[%205] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %204, %206 : i64, !llvm.ptr
      %207 = llvm.load %198 : !llvm.ptr -> i64
      %208 = llvm.load %198 : !llvm.ptr -> i64
      %209 = arith.constant 0 : i32
      %210 = llvm.load %198 : !llvm.ptr -> i64
      %212 = arith.extsi %209 : i32 to i64
      %211 = arith.subi %212, %210 : i64
      %213 = arith.andi %208, %211 : i64
      %214 = arith.addi %207, %213 : i64
      llvm.store %214, %198 : i64, !llvm.ptr
      cf.br ^bb45
    ^bb47:
    func.return
  }
  func.func @main() -> i32 {
    %215 = arith.constant 60000000 : i32
    %216 = arith.extsi %215 : i32 to i64
    %217 = arith.constant 999999995705032704 : i32
    %218 = arith.extsi %217 : i32 to i64
    %219 = arith.constant 1 : i32
    %221 = arith.extsi %219 : i32 to i64
    %220 = arith.addi %216, %221 : i64
    %223 = arith.constant 1 : i32
    %225 = arith.extsi %223 : i32 to i64
    %224 = arith.shrsi %220, %225 : i64
    %226 = arith.constant 1 : i32
    %228 = arith.extsi %226 : i32 to i64
    %227 = arith.addi %224, %228 : i64
    %229 = arith.constant 4 : i32
    %230 = arith.extsi %229 : i32 to i64
    %222 = func.call @calloc(%227, %230) : (i64, i64) -> !llvm.ptr
    %231 = func.call @isqrt(%220) : (i64) -> i64
    %232 = arith.constant 3 : i32
    %233 = arith.extsi %232 : i32 to i64
    %234 = llvm.mlir.constant(1 : i64) : i64
    %235 = llvm.alloca %234 x i64 : (i64) -> !llvm.ptr
    llvm.store %233, %235 : i64, !llvm.ptr
    cf.br ^bb48
    ^bb48:
    %236 = llvm.load %235 : !llvm.ptr -> i64
    %237 = arith.cmpi sle, %236, %231 : i64
    cf.cond_br %237, ^bb49, ^bb50
    ^bb49:
      %239 = llvm.load %235 : !llvm.ptr -> i64
      %240 = arith.constant 1 : i32
      %242 = arith.extsi %240 : i32 to i64
      %241 = arith.shrsi %239, %242 : i64
      %243 = llvm.getelementptr %222[%241] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %238 = llvm.load %243 : !llvm.ptr -> i32
      %244 = arith.constant 0 : i32
      %245 = arith.cmpi eq, %238, %244 : i32
      cf.cond_br %245, ^bb51, ^bb52
      ^bb51:
        %246 = llvm.load %235 : !llvm.ptr -> i64
        %247 = arith.constant 1 : i32
        %249 = arith.extsi %247 : i32 to i64
        %248 = arith.shli %246, %249 : i64
        %250 = llvm.load %235 : !llvm.ptr -> i64
        %251 = llvm.load %235 : !llvm.ptr -> i64
        %252 = arith.muli %250, %251 : i64
        %253 = llvm.mlir.constant(1 : i64) : i64
        %254 = llvm.alloca %253 x i64 : (i64) -> !llvm.ptr
        llvm.store %252, %254 : i64, !llvm.ptr
        cf.br ^bb54
        ^bb54:
        %255 = llvm.load %254 : !llvm.ptr -> i64
        %256 = arith.cmpi sle, %255, %220 : i64
        cf.cond_br %256, ^bb55, ^bb56
        ^bb55:
          %257 = llvm.load %254 : !llvm.ptr -> i64
          %258 = arith.constant 1 : i32
          %260 = arith.extsi %258 : i32 to i64
          %259 = arith.shrsi %257, %260 : i64
          %262 = llvm.getelementptr %222[%259] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %261 = llvm.load %262 : !llvm.ptr -> i32
          %263 = arith.constant 0 : i32
          %264 = arith.cmpi eq, %261, %263 : i32
          cf.cond_br %264, ^bb57, ^bb58
          ^bb57:
            %265 = llvm.load %235 : !llvm.ptr -> i64
            %266 = arith.trunci %265 : i64 to i32
            %267 = llvm.getelementptr %222[%259] : (!llvm.ptr, i64) -> !llvm.ptr, i32
            llvm.store %266, %267 : i32, !llvm.ptr
            cf.br ^bb59
          ^bb58:
            cf.br ^bb59
          ^bb59:
          %268 = llvm.load %254 : !llvm.ptr -> i64
          %269 = arith.addi %268, %248 : i64
          llvm.store %269, %254 : i64, !llvm.ptr
          cf.br ^bb54
        ^bb56:
        cf.br ^bb53
      ^bb52:
        cf.br ^bb53
      ^bb53:
      %270 = llvm.load %235 : !llvm.ptr -> i64
      %271 = arith.constant 2 : i32
      %273 = arith.extsi %271 : i32 to i64
      %272 = arith.addi %270, %273 : i64
      llvm.store %272, %235 : i64, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    %275 = arith.constant 1 : i32
    %277 = arith.extsi %275 : i32 to i64
    %276 = arith.addi %220, %277 : i64
    %278 = arith.constant 2 : i32
    %279 = arith.extsi %278 : i32 to i64
    %274 = func.call @calloc(%276, %279) : (i64, i64) -> !llvm.ptr
    %281 = arith.constant 1 : i32
    %283 = arith.extsi %281 : i32 to i64
    %282 = arith.addi %220, %283 : i64
    %284 = arith.constant 1 : i32
    %285 = arith.extsi %284 : i32 to i64
    %280 = func.call @calloc(%282, %285) : (i64, i64) -> !llvm.ptr
    %286 = arith.constant 1 : i32
    %287 = arith.constant 1 : i32
    %288 = arith.trunci %286 : i32 to i16
    %289 = arith.extsi %287 : i32 to i64
    %290 = llvm.getelementptr %274[%289] : (!llvm.ptr, i64) -> !llvm.ptr, i16
    llvm.store %288, %290 : i16, !llvm.ptr
    %291 = arith.constant 2 : i32
    %292 = arith.extsi %291 : i32 to i64
    %293 = llvm.mlir.constant(1 : i64) : i64
    %294 = llvm.alloca %293 x i64 : (i64) -> !llvm.ptr
    llvm.store %292, %294 : i64, !llvm.ptr
    cf.br ^bb60
    ^bb60:
    %295 = llvm.load %294 : !llvm.ptr -> i64
    %296 = arith.cmpi sle, %295, %220 : i64
    cf.cond_br %296, ^bb61, ^bb62
    ^bb61:
      %297 = llvm.load %294 : !llvm.ptr -> i64
      %298 = arith.constant 1 : i32
      %300 = arith.extsi %298 : i32 to i64
      %299 = arith.andi %297, %300 : i64
      %301 = arith.constant 0 : i32
      %303 = arith.extsi %301 : i32 to i64
      %302 = arith.cmpi eq, %299, %303 : i64
      cf.cond_br %302, ^bb63, ^bb64
      ^bb63:
        %304 = llvm.load %294 : !llvm.ptr -> i64
        %305 = arith.constant 1 : i32
        %307 = arith.extsi %305 : i32 to i64
        %306 = arith.shrsi %304, %307 : i64
        %308 = arith.constant 1 : i32
        %310 = arith.extsi %308 : i32 to i64
        %309 = arith.andi %306, %310 : i64
        %311 = arith.constant 0 : i32
        %313 = arith.extsi %311 : i32 to i64
        %312 = arith.cmpi eq, %309, %313 : i64
        cf.cond_br %312, ^bb66, ^bb67
        ^bb66:
          %315 = llvm.getelementptr %280[%306] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          %314 = llvm.load %315 : !llvm.ptr -> i8
          %316 = arith.extsi %314 : i8 to i64
          %317 = arith.constant 1 : i32
          %319 = arith.extsi %317 : i32 to i64
          %318 = arith.addi %316, %319 : i64
          %320 = arith.trunci %318 : i64 to i8
          %321 = llvm.load %294 : !llvm.ptr -> i64
          %322 = llvm.getelementptr %280[%321] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %320, %322 : i8, !llvm.ptr
          %324 = llvm.getelementptr %274[%306] : (!llvm.ptr, i64) -> !llvm.ptr, i16
          %323 = llvm.load %324 : !llvm.ptr -> i16
          %325 = arith.extsi %323 : i16 to i64
          %326 = arith.divsi %325, %318 : i64
          %327 = arith.constant 1 : i32
          %329 = arith.extsi %327 : i32 to i64
          %328 = arith.addi %318, %329 : i64
          %330 = arith.muli %326, %328 : i64
          %331 = arith.trunci %330 : i64 to i16
          %332 = llvm.load %294 : !llvm.ptr -> i64
          %333 = llvm.getelementptr %274[%332] : (!llvm.ptr, i64) -> !llvm.ptr, i16
          llvm.store %331, %333 : i16, !llvm.ptr
          cf.br ^bb68
        ^bb67:
          %334 = arith.constant 1 : i32
          %335 = llvm.load %294 : !llvm.ptr -> i64
          %336 = arith.trunci %334 : i32 to i8
          %337 = llvm.getelementptr %280[%335] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %336, %337 : i8, !llvm.ptr
          %339 = llvm.getelementptr %274[%306] : (!llvm.ptr, i64) -> !llvm.ptr, i16
          %338 = llvm.load %339 : !llvm.ptr -> i16
          %340 = arith.extsi %338 : i16 to i64
          %341 = arith.constant 2 : i32
          %343 = arith.extsi %341 : i32 to i64
          %342 = arith.muli %340, %343 : i64
          %344 = arith.trunci %342 : i64 to i16
          %345 = llvm.load %294 : !llvm.ptr -> i64
          %346 = llvm.getelementptr %274[%345] : (!llvm.ptr, i64) -> !llvm.ptr, i16
          llvm.store %344, %346 : i16, !llvm.ptr
          cf.br ^bb68
        ^bb68:
        cf.br ^bb65
      ^bb64:
        %348 = llvm.load %294 : !llvm.ptr -> i64
        %349 = arith.constant 1 : i32
        %351 = arith.extsi %349 : i32 to i64
        %350 = arith.shrsi %348, %351 : i64
        %352 = llvm.getelementptr %222[%350] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %347 = llvm.load %352 : !llvm.ptr -> i32
        %353 = arith.extsi %347 : i32 to i64
        %354 = arith.constant 0 : i32
        %356 = arith.extsi %354 : i32 to i64
        %355 = arith.cmpi eq, %353, %356 : i64
        cf.cond_br %355, ^bb69, ^bb70
        ^bb69:
          %357 = arith.constant 1 : i32
          %358 = llvm.load %294 : !llvm.ptr -> i64
          %359 = arith.trunci %357 : i32 to i8
          %360 = llvm.getelementptr %280[%358] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %359, %360 : i8, !llvm.ptr
          %361 = arith.constant 2 : i32
          %362 = llvm.load %294 : !llvm.ptr -> i64
          %363 = arith.trunci %361 : i32 to i16
          %364 = llvm.getelementptr %274[%362] : (!llvm.ptr, i64) -> !llvm.ptr, i16
          llvm.store %363, %364 : i16, !llvm.ptr
          cf.br ^bb71
        ^bb70:
          %365 = llvm.load %294 : !llvm.ptr -> i64
          %366 = arith.divsi %365, %353 : i64
          %367 = arith.remsi %366, %353 : i64
          %368 = arith.constant 0 : i32
          %370 = arith.extsi %368 : i32 to i64
          %369 = arith.cmpi eq, %367, %370 : i64
          cf.cond_br %369, ^bb72, ^bb73
          ^bb72:
            %372 = llvm.getelementptr %280[%366] : (!llvm.ptr, i64) -> !llvm.ptr, i8
            %371 = llvm.load %372 : !llvm.ptr -> i8
            %373 = arith.extsi %371 : i8 to i64
            %374 = arith.constant 1 : i32
            %376 = arith.extsi %374 : i32 to i64
            %375 = arith.addi %373, %376 : i64
            %377 = arith.trunci %375 : i64 to i8
            %378 = llvm.load %294 : !llvm.ptr -> i64
            %379 = llvm.getelementptr %280[%378] : (!llvm.ptr, i64) -> !llvm.ptr, i8
            llvm.store %377, %379 : i8, !llvm.ptr
            %381 = llvm.getelementptr %274[%366] : (!llvm.ptr, i64) -> !llvm.ptr, i16
            %380 = llvm.load %381 : !llvm.ptr -> i16
            %382 = arith.extsi %380 : i16 to i64
            %383 = arith.divsi %382, %375 : i64
            %384 = arith.constant 1 : i32
            %386 = arith.extsi %384 : i32 to i64
            %385 = arith.addi %375, %386 : i64
            %387 = arith.muli %383, %385 : i64
            %388 = arith.trunci %387 : i64 to i16
            %389 = llvm.load %294 : !llvm.ptr -> i64
            %390 = llvm.getelementptr %274[%389] : (!llvm.ptr, i64) -> !llvm.ptr, i16
            llvm.store %388, %390 : i16, !llvm.ptr
            cf.br ^bb74
          ^bb73:
            %391 = arith.constant 1 : i32
            %392 = llvm.load %294 : !llvm.ptr -> i64
            %393 = arith.trunci %391 : i32 to i8
            %394 = llvm.getelementptr %280[%392] : (!llvm.ptr, i64) -> !llvm.ptr, i8
            llvm.store %393, %394 : i8, !llvm.ptr
            %396 = llvm.getelementptr %274[%366] : (!llvm.ptr, i64) -> !llvm.ptr, i16
            %395 = llvm.load %396 : !llvm.ptr -> i16
            %397 = arith.extsi %395 : i16 to i64
            %398 = arith.constant 2 : i32
            %400 = arith.extsi %398 : i32 to i64
            %399 = arith.muli %397, %400 : i64
            %401 = arith.trunci %399 : i64 to i16
            %402 = llvm.load %294 : !llvm.ptr -> i64
            %403 = llvm.getelementptr %274[%402] : (!llvm.ptr, i64) -> !llvm.ptr, i16
            llvm.store %401, %403 : i16, !llvm.ptr
            cf.br ^bb74
          ^bb74:
          cf.br ^bb71
        ^bb71:
        cf.br ^bb65
      ^bb65:
      %404 = llvm.load %294 : !llvm.ptr -> i64
      %405 = arith.constant 1 : i32
      %407 = arith.extsi %405 : i32 to i64
      %406 = arith.addi %404, %407 : i64
      llvm.store %406, %294 : i64, !llvm.ptr
      cf.br ^bb60
    ^bb62:
    %408 = arith.constant 1 : i32
    %409 = arith.constant 16 : i32
    %410 = arith.shli %408, %409 : i32
    %411 = arith.extsi %410 : i32 to i64
    %412 = llvm.mlir.constant(1 : i64) : i64
    %413 = llvm.alloca %412 x i64 : (i64) -> !llvm.ptr
    llvm.store %411, %413 : i64, !llvm.ptr
    %415 = llvm.load %413 : !llvm.ptr -> i64
    %416 = arith.constant 2 : i32
    %418 = arith.extsi %416 : i32 to i64
    %417 = arith.addi %415, %418 : i64
    %419 = arith.constant 8 : i32
    %420 = arith.extsi %419 : i32 to i64
    %414 = func.call @calloc(%417, %420) : (i64, i64) -> !llvm.ptr
    %422 = llvm.load %413 : !llvm.ptr -> i64
    %423 = arith.constant 2 : i32
    %425 = arith.extsi %423 : i32 to i64
    %424 = arith.addi %422, %425 : i64
    %426 = arith.constant 8 : i32
    %427 = arith.extsi %426 : i32 to i64
    %421 = func.call @calloc(%424, %427) : (i64, i64) -> !llvm.ptr
    %428 = arith.constant 0 : i32
    %429 = arith.extsi %428 : i32 to i64
    %430 = llvm.mlir.constant(1 : i64) : i64
    %431 = llvm.alloca %430 x i64 : (i64) -> !llvm.ptr
    llvm.store %429, %431 : i64, !llvm.ptr
    %432 = arith.constant 0 : i32
    %433 = arith.extsi %432 : i32 to i64
    %434 = llvm.mlir.constant(1 : i64) : i64
    %435 = llvm.alloca %434 x i64 : (i64) -> !llvm.ptr
    llvm.store %433, %435 : i64, !llvm.ptr
    %436 = arith.constant 0 : i32
    %437 = arith.extsi %436 : i32 to i64
    %438 = llvm.mlir.constant(1 : i64) : i64
    %439 = llvm.alloca %438 x i64 : (i64) -> !llvm.ptr
    llvm.store %437, %439 : i64, !llvm.ptr
    %440 = arith.constant 1 : i32
    %441 = arith.extsi %440 : i32 to i64
    %442 = llvm.mlir.constant(1 : i64) : i64
    %443 = llvm.alloca %442 x i64 : (i64) -> !llvm.ptr
    llvm.store %441, %443 : i64, !llvm.ptr
    cf.br ^bb75
    ^bb75:
    %444 = llvm.load %443 : !llvm.ptr -> i64
    %445 = arith.cmpi sle, %444, %216 : i64
    cf.cond_br %445, ^bb76, ^bb77
    ^bb76:
      %446 = arith.constant 0 : i32
      %447 = arith.extsi %446 : i32 to i64
      %448 = llvm.mlir.constant(1 : i64) : i64
      %449 = llvm.alloca %448 x i64 : (i64) -> !llvm.ptr
      llvm.store %447, %449 : i64, !llvm.ptr
      %450 = llvm.load %443 : !llvm.ptr -> i64
      %451 = arith.constant 1 : i32
      %453 = arith.extsi %451 : i32 to i64
      %452 = arith.andi %450, %453 : i64
      %454 = arith.constant 0 : i32
      %456 = arith.extsi %454 : i32 to i64
      %455 = arith.cmpi eq, %452, %456 : i64
      cf.cond_br %455, ^bb78, ^bb79
      ^bb78:
        %458 = llvm.load %443 : !llvm.ptr -> i64
        %459 = arith.constant 1 : i32
        %461 = arith.extsi %459 : i32 to i64
        %460 = arith.shrsi %458, %461 : i64
        %462 = llvm.getelementptr %274[%460] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        %457 = llvm.load %462 : !llvm.ptr -> i16
        %463 = arith.extsi %457 : i16 to i64
        %465 = llvm.load %443 : !llvm.ptr -> i64
        %466 = arith.constant 1 : i32
        %468 = arith.extsi %466 : i32 to i64
        %467 = arith.addi %465, %468 : i64
        %469 = llvm.getelementptr %274[%467] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        %464 = llvm.load %469 : !llvm.ptr -> i16
        %470 = arith.extsi %464 : i16 to i64
        %471 = arith.muli %463, %470 : i64
        llvm.store %471, %449 : i64, !llvm.ptr
        cf.br ^bb80
      ^bb79:
        %473 = llvm.load %443 : !llvm.ptr -> i64
        %474 = llvm.getelementptr %274[%473] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        %472 = llvm.load %474 : !llvm.ptr -> i16
        %475 = arith.extsi %472 : i16 to i64
        %477 = llvm.load %443 : !llvm.ptr -> i64
        %478 = arith.constant 1 : i32
        %480 = arith.extsi %478 : i32 to i64
        %479 = arith.addi %477, %480 : i64
        %481 = arith.constant 1 : i32
        %483 = arith.extsi %481 : i32 to i64
        %482 = arith.shrsi %479, %483 : i64
        %484 = llvm.getelementptr %274[%482] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        %476 = llvm.load %484 : !llvm.ptr -> i16
        %485 = arith.extsi %476 : i16 to i64
        %486 = arith.muli %475, %485 : i64
        llvm.store %486, %449 : i64, !llvm.ptr
        cf.br ^bb80
      ^bb80:
      %487 = llvm.load %449 : !llvm.ptr -> i64
      %488 = llvm.load %413 : !llvm.ptr -> i64
      %489 = arith.cmpi sgt, %487, %488 : i64
      cf.cond_br %489, ^bb81, ^bb82
      ^bb81:
        %490 = llvm.mlir.addressof @str_0 : !llvm.ptr
        %491 = llvm.load %449 : !llvm.ptr -> i64
        %492 = llvm.call @printf(%490, %491) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
        %493 = arith.constant 1 : i32
        func.return %493 : i32
      ^bb82:
        cf.br ^bb83
      ^bb83:
      %495 = llvm.load %449 : !llvm.ptr -> i64
      %494 = func.call @fenwick_sum(%414, %495) : (!llvm.ptr, i64) -> i64
      %496 = llvm.load %431 : !llvm.ptr -> i64
      %497 = arith.subi %496, %494 : i64
      %499 = llvm.load %449 : !llvm.ptr -> i64
      %498 = func.call @fenwick_sum(%421, %499) : (!llvm.ptr, i64) -> i64
      %500 = llvm.load %435 : !llvm.ptr -> i64
      %501 = arith.subi %500, %498 : i64
      %502 = llvm.load %439 : !llvm.ptr -> i64
      %503 = arith.addi %502, %501 : i64
      llvm.store %503, %439 : i64, !llvm.ptr
      %504 = llvm.load %439 : !llvm.ptr -> i64
      %505 = arith.cmpi sge, %504, %218 : i64
      cf.cond_br %505, ^bb84, ^bb85
      ^bb84:
        %506 = llvm.load %439 : !llvm.ptr -> i64
        %507 = arith.remsi %506, %218 : i64
        llvm.store %507, %439 : i64, !llvm.ptr
        cf.br ^bb86
      ^bb85:
        cf.br ^bb86
      ^bb86:
      %508 = llvm.load %439 : !llvm.ptr -> i64
      %509 = arith.constant 0 : i32
      %511 = arith.extsi %509 : i32 to i64
      %510 = arith.cmpi slt, %508, %511 : i64
      cf.cond_br %510, ^bb87, ^bb88
      ^bb87:
        %512 = llvm.load %439 : !llvm.ptr -> i64
        %513 = arith.remsi %512, %218 : i64
        llvm.store %513, %439 : i64, !llvm.ptr
        %514 = llvm.load %439 : !llvm.ptr -> i64
        %515 = arith.constant 0 : i32
        %517 = arith.extsi %515 : i32 to i64
        %516 = arith.cmpi slt, %514, %517 : i64
        cf.cond_br %516, ^bb90, ^bb91
        ^bb90:
          %518 = llvm.load %439 : !llvm.ptr -> i64
          %519 = arith.addi %518, %218 : i64
          llvm.store %519, %439 : i64, !llvm.ptr
          cf.br ^bb92
        ^bb91:
          cf.br ^bb92
        ^bb92:
        cf.br ^bb89
      ^bb88:
        cf.br ^bb89
      ^bb89:
      %520 = llvm.load %435 : !llvm.ptr -> i64
      %521 = arith.addi %520, %497 : i64
      llvm.store %521, %435 : i64, !llvm.ptr
      %523 = llvm.load %413 : !llvm.ptr -> i64
      %524 = llvm.load %449 : !llvm.ptr -> i64
      func.call @fenwick_add(%421, %523, %524, %497) : (!llvm.ptr, i64, i64, i64) -> ()
      %526 = llvm.load %413 : !llvm.ptr -> i64
      %527 = llvm.load %449 : !llvm.ptr -> i64
      %528 = arith.constant 1 : i32
      %529 = arith.extsi %528 : i32 to i64
      func.call @fenwick_add(%414, %526, %527, %529) : (!llvm.ptr, i64, i64, i64) -> ()
      %530 = llvm.load %431 : !llvm.ptr -> i64
      %531 = arith.constant 1 : i32
      %533 = arith.extsi %531 : i32 to i64
      %532 = arith.addi %530, %533 : i64
      llvm.store %532, %431 : i64, !llvm.ptr
      %534 = llvm.load %443 : !llvm.ptr -> i64
      %535 = arith.constant 1 : i32
      %537 = arith.extsi %535 : i32 to i64
      %536 = arith.addi %534, %537 : i64
      llvm.store %536, %443 : i64, !llvm.ptr
      cf.br ^bb75
    ^bb77:
    %538 = llvm.mlir.addressof @str_1 : !llvm.ptr
    %539 = llvm.load %439 : !llvm.ptr -> i64
    %540 = llvm.call @printf(%538, %539) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%421) : (!llvm.ptr) -> ()
    func.call @free(%414) : (!llvm.ptr) -> ()
    func.call @free(%280) : (!llvm.ptr) -> ()
    func.call @free(%274) : (!llvm.ptr) -> ()
    func.call @free(%222) : (!llvm.ptr) -> ()
    %546 = arith.constant 0 : i32
    func.return %546 : i32
  }
}