Problem 935

Count b in (0,1) such that the rolling square returns to its initial position within N rolls. F(10^8). Uses Mobius inversion with the Dirichlet hyperbola method, accelerated by a Du Jiao sieve for the Mertens function. Pure Flow port of the native C solver.

Answer759908921637225
Output759908921637225
StatusPASS
Native helperno
Runtime10 ms
Peak memory17680 KB
Time complexityO(n) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)O(n log log n)
Space complexityO(n^2)O(n)
ApproachFlow solutionMobius sieve
VerdictOptimal

Flow source

# Project Euler 935: Rolling Square
# Count b in (0,1) such that the rolling square returns to its initial
# position within N rolls. F(10^8).
# Uses Mobius inversion with the Dirichlet hyperbola method,
# accelerated by a Du Jiao sieve for the Mertens function.
# Pure Flow port of the native C solver.

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
    function malloc(n: i64) -> ptr<void>
    function pow(x: f64, y: f64) -> f64
    function printf(fmt: ptr<i8>, ...) -> i32
}

struct MemoEntry {
    n: i64
    val: i64
}

const MEMO_SIZE: i64 = 1048576
const MEMO_MASK: i64 = 1048575

let mut mu_arr: ptr<i8> = null as ptr<i8>
let mut M_small: ptr<i64> = null as ptr<i64>
let mut Modd_small: ptr<i64> = null as ptr<i64>
let mut sieve_limit: i64 = 0
let mut memo_M: ptr<MemoEntry> = null as ptr<MemoEntry>
let mut memo_Modd: ptr<MemoEntry> = null as ptr<MemoEntry>

function build_mu_prefix(limit: i64) -> void {
    sieve_limit = limit
    mu_arr = (calloc(limit + 1, 1)) as ptr<i8>
    let is_comp: ptr<i8> = (calloc(limit + 1, 1)) as ptr<i8>
    let primes: ptr<i64> = (malloc(limit / 4 * 8 + 800)) as ptr<i64>
    let mut nprimes: i64 = 0

    mu_arr[1] = 1
    let mut i: i64 = 2
    while i <= limit {
        if is_comp[i] == 0 {
            primes[nprimes] = i
            nprimes = nprimes + 1
            mu_arr[i] = -1
        }
        let mut j: i64 = 0
        while j < nprimes {
            let ip: i64 = i * primes[j]
            if ip > limit { break }
            is_comp[ip] = 1
            if i % primes[j] == 0 {
                mu_arr[ip] = 0
                break
            }
            mu_arr[ip] = -mu_arr[i]
            j = j + 1
        }
        i = i + 1
    }

    M_small = (calloc(limit + 1, 8)) as ptr<i64>
    Modd_small = (calloc(limit + 1, 8)) as ptr<i64>

    let mut s: i64 = 0
    let mut so: i64 = 0
    let mut ii: i64 = 1
    while ii <= limit {
        s = s + (mu_arr[ii] as i64)
        M_small[ii] = s
        if (ii & 1) != 0 {
            so = so + (mu_arr[ii] as i64)
        }
        Modd_small[ii] = so
        ii = ii + 1
    }

    free(is_comp as ptr<void>)
    free(primes as ptr<void>)
}

function memo_lookup(table: ptr<MemoEntry>, n: i64) -> i64 {
    let h: i64 = (n * 2654435761) & MEMO_MASK
    let mut i: i64 = 0
    while i < MEMO_SIZE {
        let idx: i64 = (h + i) & MEMO_MASK
        if table[idx].n == n && table[idx].val != 0 { return table[idx].val }
        if table[idx].val == 0 && table[idx].n == 0 { return 0 }
        i = i + 1
    }
    return 0
}

function memo_insert(table: ptr<MemoEntry>, n: i64, val: i64) -> void {
    let h: i64 = (n * 2654435761) & MEMO_MASK
    let mut i: i64 = 0
    while i < MEMO_SIZE {
        let idx: i64 = (h + i) & MEMO_MASK
        if table[idx].val == 0 {
            table[idx].n = n
            table[idx].val = val
            return
        }
        i = i + 1
    }
}

function M_func(n: i64) -> i64

function Modd_func(n: i64) -> i64

function M_func(n: i64) -> i64 {
    if n <= sieve_limit { return M_small[n] }
    let found: i64 = memo_lookup(memo_M, n)
    if found != 0 { return found }

    let mut res: i64 = 1
    let mut l: i64 = 2
    while l <= n {
        let q: i64 = n / l
        let r: i64 = n / q
        res = res - (r - l + 1) * M_func(q)
        l = r + 1
    }

    memo_insert(memo_M, n, res)
    return res
}

function Modd_func(n: i64) -> i64 {
    if n <= 0 { return 0 }
    if n <= sieve_limit { return Modd_small[n] }
    let found: i64 = memo_lookup(memo_Modd, n)
    if found != 0 { return found }

    let res: i64 = M_func(n) + Modd_func(n / 2)
    memo_insert(memo_Modd, n, res)
    return res
}

function tri(n: i64) -> i64 {
    return n * (n + 1) / 2
}

function sum_mu_odd(l: i64, r: i64) -> i64 {
    return Modd_func(r) - Modd_func(l - 1)
}

function sum_mu_2mod4(l: i64, r: i64) -> i64 {
    return -Modd_func(r / 2) + Modd_func((l - 1) / 2)
}

function class_sum(X: i64, cls: i32) -> i64 {
    let mut A: i64 = 0
    let mut B: i64 = 0
    let mut l: i64 = 1
    while l <= X {
        let q: i64 = X / l
        let r: i64 = X / q

        let odd_mu: i64 = sum_mu_odd(l, r)
        let mu2: i64 = sum_mu_2mod4(l, r)

        if cls == 0 {
            # div4
            A = A + q * ((q / 4) * odd_mu + (q / 2) * mu2)
            B = B + (4 * tri(q / 4)) * odd_mu + (2 * tri(q / 2)) * mu2
        } else {
            if cls == 1 {
                # 2mod4
                let c: i64 = (q + 2) / 4
                A = A + q * (c * odd_mu + ((q + 1) / 2) * mu2)
                B = B + (2 * c * c) * odd_mu + (tri(q) - 2 * tri(q / 2)) * mu2
            } else {
                # odd
                A = A + q * (((q + 1) / 2) * odd_mu)
                B = B + (tri(q) - 2 * tri(q / 2)) * odd_mu
            }
        }

        l = r + 1
    }
    return A - B
}

function F_935(N: i64) -> i64 {
    if N < 0 { return 0 }

    let X1: i64 = N + 1
    let X2: i64 = N / 2 + 1
    let X3: i64 = N / 4 + 1

    let mut res: i64 = 0
    res = res + class_sum(X1, 0)
    res = res + class_sum(X2, 1)
    res = res + class_sum(X3, 2)

    # Remove u=1 (odd class)
    res = res - (X3 - 1)

    # Integer L = h cases: 4*(h-1) rolls, h >= 2
    res = res + N / 4

    return res
}

function main() -> i32 {
    let mut N: i64 = 1
    let mut i: i32 = 0
    while i < 8 {
        N = N * 10
        i = i + 1
    }

    let max_X: i64 = N + 1
    let limit: i64 = (pow((max_X as f64), 2.0 / 3.0) as i64) + 10
    build_mu_prefix(limit)

    memo_M = (calloc(MEMO_SIZE, 16)) as ptr<MemoEntry>
    memo_Modd = (calloc(MEMO_SIZE, 16)) as ptr<MemoEntry>

    let result: i64 = F_935(N)

    free(mu_arr as ptr<void>)
    free(M_small as ptr<void>)
    free(Modd_small as ptr<void>)
    free(memo_M as ptr<void>)
    free(memo_Modd as ptr<void>)

    printf("%lld\n", result)
    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; }

typedef struct MemoEntry MemoEntry;

struct MemoEntry {
    int64_t n;
    int64_t val;
};

void build_mu_prefix_i64(int64_t limit);
int64_t memo_lookup_ptr_MemoEntry_i64(MemoEntry* table, int64_t n);
void memo_insert_ptr_MemoEntry_i64_i64(MemoEntry* table, int64_t n, int64_t val);
int64_t M_func_i64(int64_t n);
int64_t Modd_func_i64(int64_t n);
int64_t M_func_i64(int64_t n);
int64_t Modd_func_i64(int64_t n);
int64_t tri_i64(int64_t n);
int64_t sum_mu_odd_i64_i64(int64_t l, int64_t r);
int64_t sum_mu_2mod4_i64_i64(int64_t l, int64_t r);
int64_t class_sum_i64_i32(int64_t X, int32_t cls);
int64_t F_935_i64(int64_t N);
int32_t main(void);

static const int64_t MEMO_SIZE = 1048576;
static const int64_t MEMO_MASK = 1048575;

/* Module statics */
static int8_t* mu_arr = ((int8_t*)(NULL));
static int64_t* M_small = ((int64_t*)(NULL));
static int64_t* Modd_small = ((int64_t*)(NULL));
static int64_t sieve_limit = 0;
static MemoEntry* memo_M = ((MemoEntry*)(NULL));
static MemoEntry* memo_Modd = ((MemoEntry*)(NULL));






void build_mu_prefix_i64(int64_t limit) {
    sieve_limit = limit;
    mu_arr = ((int8_t*)(calloc((limit + 1), 1)));
    int8_t* is_comp = (int8_t*)(((int8_t*)(calloc((limit + 1), 1))));
    int64_t* primes = (int64_t*)(((int64_t*)(malloc(((FLOW_CHECKED_DIV((limit), (4)) * 8) + 800)))));
    int64_t nprimes = 0;
    mu_arr[1] = 1;
    int64_t i = 2;
    while (i <= limit) {
        if (is_comp[i] == 0) {
            primes[nprimes] = i;
            nprimes = (nprimes + 1);
            mu_arr[i] = (-1);
        }
        int64_t j = 0;
        while (j < nprimes) {
            int64_t ip = (i * primes[j]);
            if (ip > limit) {
                break;
            }
            is_comp[ip] = 1;
            if (FLOW_CHECKED_MOD((i), (primes[j])) == 0) {
                mu_arr[ip] = 0;
                break;
            }
            mu_arr[ip] = (-mu_arr[i]);
            j = (j + 1);
        }
        i = (i + 1);
    }
    M_small = ((int64_t*)(calloc((limit + 1), 8)));
    Modd_small = ((int64_t*)(calloc((limit + 1), 8)));
    int64_t s = 0;
    int64_t so = 0;
    int64_t ii = 1;
    while (ii <= limit) {
        s = (s + ((int64_t)(mu_arr[ii])));
        M_small[ii] = s;
        if ((ii & 1) != 0) {
            so = (so + ((int64_t)(mu_arr[ii])));
        }
        Modd_small[ii] = so;
        ii = (ii + 1);
    }
    free(((void*)(is_comp)));
    free(((void*)(primes)));
}

int64_t memo_lookup_ptr_MemoEntry_i64(MemoEntry* table, int64_t n) {
    int64_t h = ((n * 2654435761) & MEMO_MASK);
    int64_t i = 0;
    while (i < MEMO_SIZE) {
        int64_t idx = ((h + i) & MEMO_MASK);
        if ((table[idx].n == n && table[idx].val != 0)) {
            return table[idx].val;
        }
        if ((table[idx].val == 0 && table[idx].n == 0)) {
            return 0;
        }
        i = (i + 1);
    }
    return 0;
}

void memo_insert_ptr_MemoEntry_i64_i64(MemoEntry* table, int64_t n, int64_t val) {
    int64_t h = ((n * 2654435761) & MEMO_MASK);
    int64_t i = 0;
    while (i < MEMO_SIZE) {
        int64_t idx = ((h + i) & MEMO_MASK);
        if (table[idx].val == 0) {
            table[idx].n = n;
            table[idx].val = val;
            return;
        }
        i = (i + 1);
    }
}



int64_t M_func_i64(int64_t n) {
    if (n <= sieve_limit) {
        return M_small[n];
    }
    int64_t found = memo_lookup_ptr_MemoEntry_i64(memo_M, n);
    if (found != 0) {
        return found;
    }
    int64_t res = 1;
    int64_t l = 2;
    while (l <= n) {
        int64_t q = FLOW_CHECKED_DIV((n), (l));
        int64_t r = FLOW_CHECKED_DIV((n), (q));
        res = (res - (((r - l) + 1) * M_func_i64(q)));
        l = (r + 1);
    }
    memo_insert_ptr_MemoEntry_i64_i64(memo_M, n, res);
    return res;
}

int64_t Modd_func_i64(int64_t n) {
    if (n <= 0) {
        return 0;
    }
    if (n <= sieve_limit) {
        return Modd_small[n];
    }
    int64_t found = memo_lookup_ptr_MemoEntry_i64(memo_Modd, n);
    if (found != 0) {
        return found;
    }
    int64_t res = (M_func_i64(n) + Modd_func_i64(FLOW_CHECKED_DIV((n), (2))));
    memo_insert_ptr_MemoEntry_i64_i64(memo_Modd, n, res);
    return res;
}

int64_t tri_i64(int64_t n) {
    return FLOW_CHECKED_DIV(((n * (n + 1))), (2));
}

int64_t sum_mu_odd_i64_i64(int64_t l, int64_t r) {
    return (Modd_func_i64(r) - Modd_func_i64((l - 1)));
}

int64_t sum_mu_2mod4_i64_i64(int64_t l, int64_t r) {
    return ((-Modd_func_i64(FLOW_CHECKED_DIV((r), (2)))) + Modd_func_i64(FLOW_CHECKED_DIV(((l - 1)), (2))));
}

int64_t class_sum_i64_i32(int64_t X, int32_t cls) {
    int64_t A = 0;
    int64_t B = 0;
    int64_t l = 1;
    while (l <= X) {
        int64_t q = FLOW_CHECKED_DIV((X), (l));
        int64_t r = FLOW_CHECKED_DIV((X), (q));
        int64_t odd_mu = sum_mu_odd_i64_i64(l, r);
        int64_t mu2 = sum_mu_2mod4_i64_i64(l, r);
        if (cls == 0) {
            A = (A + (q * ((FLOW_CHECKED_DIV((q), (4)) * odd_mu) + (FLOW_CHECKED_DIV((q), (2)) * mu2))));
            B = ((B + ((4 * tri_i64(FLOW_CHECKED_DIV((q), (4)))) * odd_mu)) + ((2 * tri_i64(FLOW_CHECKED_DIV((q), (2)))) * mu2));
        } else {
            if (cls == 1) {
                int64_t c = FLOW_CHECKED_DIV(((q + 2)), (4));
                A = (A + (q * ((c * odd_mu) + (FLOW_CHECKED_DIV(((q + 1)), (2)) * mu2))));
                B = ((B + (((2 * c) * c) * odd_mu)) + ((tri_i64(q) - (2 * tri_i64(FLOW_CHECKED_DIV((q), (2))))) * mu2));
            } else {
                A = (A + (q * (FLOW_CHECKED_DIV(((q + 1)), (2)) * odd_mu)));
                B = (B + ((tri_i64(q) - (2 * tri_i64(FLOW_CHECKED_DIV((q), (2))))) * odd_mu));
            }
        }
        l = (r + 1);
    }
    return (A - B);
}

int64_t F_935_i64(int64_t N) {
    if (N < 0) {
        return 0;
    }
    int64_t X1 = (N + 1);
    int64_t X2 = (FLOW_CHECKED_DIV((N), (2)) + 1);
    int64_t X3 = (FLOW_CHECKED_DIV((N), (4)) + 1);
    int64_t res = 0;
    res = (res + class_sum_i64_i32(X1, 0));
    res = (res + class_sum_i64_i32(X2, 1));
    res = (res + class_sum_i64_i32(X3, 2));
    res = (res - (X3 - 1));
    res = (res + FLOW_CHECKED_DIV((N), (4)));
    return res;
}

int32_t main(void) {
    int64_t N = 1;
    int32_t i = 0;
    while (i < 8) {
        N = (N * 10);
        i = (i + 1);
    }
    int64_t max_X = (N + 1);
    int64_t limit = (((int64_t)(pow(((double)(max_X)), (2.0 / 3.0)))) + 10);
    build_mu_prefix_i64(limit);
    memo_M = ((MemoEntry*)(calloc(MEMO_SIZE, 16)));
    memo_Modd = ((MemoEntry*)(calloc(MEMO_SIZE, 16)));
    int64_t result = F_935_i64(N);
    free(((void*)(mu_arr)));
    free(((void*)(M_small)));
    free(((void*)(Modd_small)));
    free(((void*)(memo_M)));
    free(((void*)(memo_Modd)));
    printf("%lld\n", result);
    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 private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func private @malloc(i64) -> !llvm.ptr
  func.func private @pow(f64, f64) -> f64

  // Struct: MemoEntry
  // Fields:
  //   n: i64
  //   val: i64
  // Constant: MEMO_SIZE
  llvm.mlir.global internal constant @MEMO_SIZE(1048576 : i64) : i64
  // Constant: MEMO_MASK
  llvm.mlir.global internal constant @MEMO_MASK(1048575 : i64) : i64
  // Module static: mu_arr
  llvm.mlir.global internal @mu_arr() {addr_space = 0 : i32} : !llvm.ptr {
    %0 = llvm.mlir.zero : !llvm.ptr
    llvm.return %0 : !llvm.ptr
  }
  // Module static: M_small
  llvm.mlir.global internal @M_small() {addr_space = 0 : i32} : !llvm.ptr {
    %1 = llvm.mlir.zero : !llvm.ptr
    llvm.return %1 : !llvm.ptr
  }
  // Module static: Modd_small
  llvm.mlir.global internal @Modd_small() {addr_space = 0 : i32} : !llvm.ptr {
    %2 = llvm.mlir.zero : !llvm.ptr
    llvm.return %2 : !llvm.ptr
  }
  // Module static: sieve_limit
  llvm.mlir.global internal @sieve_limit(0 : i64) : i64
  // Module static: memo_M
  llvm.mlir.global internal @memo_M() {addr_space = 0 : i32} : !llvm.ptr {
    %3 = llvm.mlir.zero : !llvm.ptr
    llvm.return %3 : !llvm.ptr
  }
  // Module static: memo_Modd
  llvm.mlir.global internal @memo_Modd() {addr_space = 0 : i32} : !llvm.ptr {
    %4 = llvm.mlir.zero : !llvm.ptr
    llvm.return %4 : !llvm.ptr
  }
  func.func @build_mu_prefix(%arg0: i64) -> () {
    %5 = llvm.mlir.addressof @sieve_limit : !llvm.ptr
    llvm.store %arg0, %5 : i64, !llvm.ptr
    %7 = arith.constant 1 : i32
    %9 = arith.extsi %7 : i32 to i64
    %8 = arith.addi %arg0, %9 : i64
    %10 = arith.constant 1 : i32
    %11 = arith.extsi %10 : i32 to i64
    %6 = func.call @calloc(%8, %11) : (i64, i64) -> !llvm.ptr
    %12 = llvm.mlir.addressof @mu_arr : !llvm.ptr
    llvm.store %6, %12 : !llvm.ptr, !llvm.ptr
    %14 = arith.constant 1 : i32
    %16 = arith.extsi %14 : i32 to i64
    %15 = arith.addi %arg0, %16 : i64
    %17 = arith.constant 1 : i32
    %18 = arith.extsi %17 : i32 to i64
    %13 = func.call @calloc(%15, %18) : (i64, i64) -> !llvm.ptr
    %20 = arith.constant 4 : i32
    %22 = arith.extsi %20 : i32 to i64
    %21 = arith.divsi %arg0, %22 : i64
    %23 = arith.constant 8 : i32
    %25 = arith.extsi %23 : i32 to i64
    %24 = arith.muli %21, %25 : i64
    %26 = arith.constant 800 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.addi %24, %28 : i64
    %19 = func.call @malloc(%27) : (i64) -> !llvm.ptr
    %29 = arith.constant 0 : i32
    %30 = arith.extsi %29 : i32 to i64
    %31 = llvm.mlir.constant(1 : i64) : i64
    %32 = llvm.alloca %31 x i64 : (i64) -> !llvm.ptr
    llvm.store %30, %32 : i64, !llvm.ptr
    %33 = arith.constant 1 : i32
    %34 = llvm.mlir.addressof @mu_arr : !llvm.ptr
    %35 = llvm.load %34 : !llvm.ptr -> !llvm.ptr
    %36 = arith.constant 1 : i32
    %37 = arith.trunci %33 : i32 to i8
    %38 = arith.extsi %36 : i32 to i64
    %39 = llvm.getelementptr %35[%38] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %37, %39 : i8, !llvm.ptr
    %40 = arith.constant 2 : i32
    %41 = arith.extsi %40 : i32 to i64
    %42 = llvm.mlir.constant(1 : i64) : i64
    %43 = llvm.alloca %42 x i64 : (i64) -> !llvm.ptr
    llvm.store %41, %43 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %44 = llvm.load %43 : !llvm.ptr -> i64
    %45 = arith.cmpi sle, %44, %arg0 : i64
    cf.cond_br %45, ^bb1, ^bb2
    ^bb1:
      %47 = llvm.load %43 : !llvm.ptr -> i64
      %48 = llvm.getelementptr %13[%47] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %46 = llvm.load %48 : !llvm.ptr -> i8
      %49 = arith.constant 0 : i32
      %51 = arith.extsi %46 : i8 to i32
      %50 = arith.cmpi eq, %51, %49 : i32
      cf.cond_br %50, ^bb3, ^bb4
      ^bb3:
        %52 = llvm.load %43 : !llvm.ptr -> i64
        %53 = llvm.load %32 : !llvm.ptr -> i64
        %54 = llvm.getelementptr %19[%53] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %52, %54 : i64, !llvm.ptr
        %55 = llvm.load %32 : !llvm.ptr -> i64
        %56 = arith.constant 1 : i32
        %58 = arith.extsi %56 : i32 to i64
        %57 = arith.addi %55, %58 : i64
        llvm.store %57, %32 : i64, !llvm.ptr
        %59 = arith.constant 1 : i32
        %61 = arith.constant 0 : i32
        %60 = arith.subi %61, %59 : i32
        %62 = llvm.mlir.addressof @mu_arr : !llvm.ptr
        %63 = llvm.load %62 : !llvm.ptr -> !llvm.ptr
        %64 = llvm.load %43 : !llvm.ptr -> i64
        %65 = arith.trunci %60 : i32 to i8
        %66 = llvm.getelementptr %63[%64] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %65, %66 : i8, !llvm.ptr
        cf.br ^bb5
      ^bb4:
        cf.br ^bb5
      ^bb5:
      %67 = arith.constant 0 : i32
      %68 = arith.extsi %67 : i32 to i64
      %69 = llvm.mlir.constant(1 : i64) : i64
      %70 = llvm.alloca %69 x i64 : (i64) -> !llvm.ptr
      llvm.store %68, %70 : i64, !llvm.ptr
      cf.br ^bb6
      ^bb6:
      %71 = llvm.load %70 : !llvm.ptr -> i64
      %72 = llvm.load %32 : !llvm.ptr -> i64
      %73 = arith.cmpi slt, %71, %72 : i64
      cf.cond_br %73, ^bb7, ^bb8
      ^bb7:
        %74 = llvm.load %43 : !llvm.ptr -> i64
        %76 = llvm.load %70 : !llvm.ptr -> i64
        %77 = llvm.getelementptr %19[%76] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %75 = llvm.load %77 : !llvm.ptr -> i64
        %78 = arith.muli %74, %75 : i64
        %79 = arith.cmpi sgt, %78, %arg0 : i64
        cf.cond_br %79, ^bb9, ^bb10
        ^bb9:
          cf.br ^bb8
        ^bb10:
          cf.br ^bb11
        ^bb11:
        %80 = arith.constant 1 : i32
        %81 = arith.trunci %80 : i32 to i8
        %82 = llvm.getelementptr %13[%78] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %81, %82 : i8, !llvm.ptr
        %83 = llvm.load %43 : !llvm.ptr -> i64
        %85 = llvm.load %70 : !llvm.ptr -> i64
        %86 = llvm.getelementptr %19[%85] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %84 = llvm.load %86 : !llvm.ptr -> i64
        %87 = arith.remsi %83, %84 : i64
        %88 = arith.constant 0 : i32
        %90 = arith.extsi %88 : i32 to i64
        %89 = arith.cmpi eq, %87, %90 : i64
        cf.cond_br %89, ^bb12, ^bb13
        ^bb12:
          %91 = arith.constant 0 : i32
          %92 = llvm.mlir.addressof @mu_arr : !llvm.ptr
          %93 = llvm.load %92 : !llvm.ptr -> !llvm.ptr
          %94 = arith.trunci %91 : i32 to i8
          %95 = llvm.getelementptr %93[%78] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %94, %95 : i8, !llvm.ptr
          cf.br ^bb8
        ^bb13:
          cf.br ^bb14
        ^bb14:
        %97 = llvm.mlir.addressof @mu_arr : !llvm.ptr
        %98 = llvm.load %97 : !llvm.ptr -> !llvm.ptr
        %99 = llvm.load %43 : !llvm.ptr -> i64
        %100 = llvm.getelementptr %98[%99] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %96 = llvm.load %100 : !llvm.ptr -> i8
        %102 = arith.constant 0 : i8
        %101 = arith.subi %102, %96 : i8
        %103 = llvm.mlir.addressof @mu_arr : !llvm.ptr
        %104 = llvm.load %103 : !llvm.ptr -> !llvm.ptr
        %105 = llvm.getelementptr %104[%78] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %101, %105 : i8, !llvm.ptr
        %106 = llvm.load %70 : !llvm.ptr -> i64
        %107 = arith.constant 1 : i32
        %109 = arith.extsi %107 : i32 to i64
        %108 = arith.addi %106, %109 : i64
        llvm.store %108, %70 : i64, !llvm.ptr
        cf.br ^bb6
      ^bb8:
      %110 = llvm.load %43 : !llvm.ptr -> i64
      %111 = arith.constant 1 : i32
      %113 = arith.extsi %111 : i32 to i64
      %112 = arith.addi %110, %113 : i64
      llvm.store %112, %43 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %115 = arith.constant 1 : i32
    %117 = arith.extsi %115 : i32 to i64
    %116 = arith.addi %arg0, %117 : i64
    %118 = arith.constant 8 : i32
    %119 = arith.extsi %118 : i32 to i64
    %114 = func.call @calloc(%116, %119) : (i64, i64) -> !llvm.ptr
    %120 = llvm.mlir.addressof @M_small : !llvm.ptr
    llvm.store %114, %120 : !llvm.ptr, !llvm.ptr
    %122 = arith.constant 1 : i32
    %124 = arith.extsi %122 : i32 to i64
    %123 = arith.addi %arg0, %124 : i64
    %125 = arith.constant 8 : i32
    %126 = arith.extsi %125 : i32 to i64
    %121 = func.call @calloc(%123, %126) : (i64, i64) -> !llvm.ptr
    %127 = llvm.mlir.addressof @Modd_small : !llvm.ptr
    llvm.store %121, %127 : !llvm.ptr, !llvm.ptr
    %128 = arith.constant 0 : i32
    %129 = arith.extsi %128 : i32 to i64
    %130 = llvm.mlir.constant(1 : i64) : i64
    %131 = llvm.alloca %130 x i64 : (i64) -> !llvm.ptr
    llvm.store %129, %131 : i64, !llvm.ptr
    %132 = arith.constant 0 : i32
    %133 = arith.extsi %132 : i32 to i64
    %134 = llvm.mlir.constant(1 : i64) : i64
    %135 = llvm.alloca %134 x i64 : (i64) -> !llvm.ptr
    llvm.store %133, %135 : i64, !llvm.ptr
    %136 = arith.constant 1 : i32
    %137 = arith.extsi %136 : i32 to i64
    %138 = llvm.mlir.constant(1 : i64) : i64
    %139 = llvm.alloca %138 x i64 : (i64) -> !llvm.ptr
    llvm.store %137, %139 : i64, !llvm.ptr
    cf.br ^bb15
    ^bb15:
    %140 = llvm.load %139 : !llvm.ptr -> i64
    %141 = arith.cmpi sle, %140, %arg0 : i64
    cf.cond_br %141, ^bb16, ^bb17
    ^bb16:
      %142 = llvm.load %131 : !llvm.ptr -> i64
      %144 = llvm.mlir.addressof @mu_arr : !llvm.ptr
      %145 = llvm.load %144 : !llvm.ptr -> !llvm.ptr
      %146 = llvm.load %139 : !llvm.ptr -> i64
      %147 = llvm.getelementptr %145[%146] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %143 = llvm.load %147 : !llvm.ptr -> i8
      %148 = arith.extsi %143 : i8 to i64
      %149 = arith.addi %142, %148 : i64
      llvm.store %149, %131 : i64, !llvm.ptr
      %150 = llvm.load %131 : !llvm.ptr -> i64
      %151 = llvm.mlir.addressof @M_small : !llvm.ptr
      %152 = llvm.load %151 : !llvm.ptr -> !llvm.ptr
      %153 = llvm.load %139 : !llvm.ptr -> i64
      %154 = llvm.getelementptr %152[%153] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %150, %154 : i64, !llvm.ptr
      %155 = llvm.load %139 : !llvm.ptr -> i64
      %156 = arith.constant 1 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.andi %155, %158 : i64
      %159 = arith.constant 0 : i32
      %161 = arith.extsi %159 : i32 to i64
      %160 = arith.cmpi ne, %157, %161 : i64
      cf.cond_br %160, ^bb18, ^bb19
      ^bb18:
        %162 = llvm.load %135 : !llvm.ptr -> i64
        %164 = llvm.mlir.addressof @mu_arr : !llvm.ptr
        %165 = llvm.load %164 : !llvm.ptr -> !llvm.ptr
        %166 = llvm.load %139 : !llvm.ptr -> i64
        %167 = llvm.getelementptr %165[%166] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %163 = llvm.load %167 : !llvm.ptr -> i8
        %168 = arith.extsi %163 : i8 to i64
        %169 = arith.addi %162, %168 : i64
        llvm.store %169, %135 : i64, !llvm.ptr
        cf.br ^bb20
      ^bb19:
        cf.br ^bb20
      ^bb20:
      %170 = llvm.load %135 : !llvm.ptr -> i64
      %171 = llvm.mlir.addressof @Modd_small : !llvm.ptr
      %172 = llvm.load %171 : !llvm.ptr -> !llvm.ptr
      %173 = llvm.load %139 : !llvm.ptr -> i64
      %174 = llvm.getelementptr %172[%173] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %170, %174 : i64, !llvm.ptr
      %175 = llvm.load %139 : !llvm.ptr -> i64
      %176 = arith.constant 1 : i32
      %178 = arith.extsi %176 : i32 to i64
      %177 = arith.addi %175, %178 : i64
      llvm.store %177, %139 : i64, !llvm.ptr
      cf.br ^bb15
    ^bb17:
    func.call @free(%13) : (!llvm.ptr) -> ()
    func.call @free(%19) : (!llvm.ptr) -> ()
    func.return
  }
  func.func @memo_lookup(%arg0: !llvm.ptr, %arg1: i64) -> i64 {
    %181 = arith.constant -1640531535 : i32
    %183 = arith.extsi %181 : i32 to i64
    %182 = arith.muli %arg1, %183 : i64
    %184 = llvm.mlir.addressof @MEMO_MASK : !llvm.ptr
    %185 = llvm.load %184 : !llvm.ptr -> i64
    %186 = arith.andi %182, %185 : i64
    %187 = arith.constant 0 : i32
    %188 = arith.extsi %187 : i32 to i64
    %189 = llvm.mlir.constant(1 : i64) : i64
    %190 = llvm.alloca %189 x i64 : (i64) -> !llvm.ptr
    llvm.store %188, %190 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %191 = llvm.load %190 : !llvm.ptr -> i64
    %192 = llvm.mlir.addressof @MEMO_SIZE : !llvm.ptr
    %193 = llvm.load %192 : !llvm.ptr -> i64
    %194 = arith.cmpi slt, %191, %193 : i64
    cf.cond_br %194, ^bb22, ^bb23
    ^bb22:
      %195 = llvm.load %190 : !llvm.ptr -> i64
      %196 = arith.addi %186, %195 : i64
      %197 = llvm.mlir.addressof @MEMO_MASK : !llvm.ptr
      %198 = llvm.load %197 : !llvm.ptr -> i64
      %199 = arith.andi %196, %198 : i64
      %201 = llvm.getelementptr %arg0[%199] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
      %200 = llvm.load %201 : !llvm.ptr -> !llvm.struct<(i64, i64)>
      %202 = llvm.getelementptr %arg0[%199] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
      %203 = llvm.getelementptr %202[0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
      %204 = llvm.load %203 : !llvm.ptr -> i64
      %205 = arith.cmpi eq, %204, %arg1 : i64
      %206 = scf.if %205 -> (i1) {
        %208 = llvm.getelementptr %arg0[%199] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
        %207 = llvm.load %208 : !llvm.ptr -> !llvm.struct<(i64, i64)>
        %209 = llvm.getelementptr %arg0[%199] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
        %210 = llvm.getelementptr %209[0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
        %211 = llvm.load %210 : !llvm.ptr -> i64
        %212 = arith.constant 0 : i32
        %214 = arith.extsi %212 : i32 to i64
        %213 = arith.cmpi ne, %211, %214 : i64
        scf.yield %213 : i1
      } else {
        %215 = arith.constant false
        scf.yield %215 : i1
      }
      cf.cond_br %206, ^bb24, ^bb25
      ^bb24:
        %217 = llvm.getelementptr %arg0[%199] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
        %216 = llvm.load %217 : !llvm.ptr -> !llvm.struct<(i64, i64)>
        %218 = llvm.getelementptr %arg0[%199] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
        %219 = llvm.getelementptr %218[0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
        %220 = llvm.load %219 : !llvm.ptr -> i64
        func.return %220 : i64
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %222 = llvm.getelementptr %arg0[%199] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
      %221 = llvm.load %222 : !llvm.ptr -> !llvm.struct<(i64, i64)>
      %223 = llvm.getelementptr %arg0[%199] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
      %224 = llvm.getelementptr %223[0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
      %225 = llvm.load %224 : !llvm.ptr -> i64
      %226 = arith.constant 0 : i32
      %228 = arith.extsi %226 : i32 to i64
      %227 = arith.cmpi eq, %225, %228 : i64
      %229 = scf.if %227 -> (i1) {
        %231 = llvm.getelementptr %arg0[%199] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
        %230 = llvm.load %231 : !llvm.ptr -> !llvm.struct<(i64, i64)>
        %232 = llvm.getelementptr %arg0[%199] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
        %233 = llvm.getelementptr %232[0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
        %234 = llvm.load %233 : !llvm.ptr -> i64
        %235 = arith.constant 0 : i32
        %237 = arith.extsi %235 : i32 to i64
        %236 = arith.cmpi eq, %234, %237 : i64
        scf.yield %236 : i1
      } else {
        %238 = arith.constant false
        scf.yield %238 : i1
      }
      cf.cond_br %229, ^bb27, ^bb28
      ^bb27:
        %239 = arith.constant 0 : i32
        %240 = arith.extsi %239 : i32 to i64
        func.return %240 : i64
      ^bb28:
        cf.br ^bb29
      ^bb29:
      %241 = llvm.load %190 : !llvm.ptr -> i64
      %242 = arith.constant 1 : i32
      %244 = arith.extsi %242 : i32 to i64
      %243 = arith.addi %241, %244 : i64
      llvm.store %243, %190 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %245 = arith.constant 0 : i32
    %246 = arith.extsi %245 : i32 to i64
    func.return %246 : i64
  }
  func.func @memo_insert(%arg0: !llvm.ptr, %arg1: i64, %arg2: i64) -> () {
    %247 = arith.constant -1640531535 : i32
    %249 = arith.extsi %247 : i32 to i64
    %248 = arith.muli %arg1, %249 : i64
    %250 = llvm.mlir.addressof @MEMO_MASK : !llvm.ptr
    %251 = llvm.load %250 : !llvm.ptr -> i64
    %252 = arith.andi %248, %251 : i64
    %253 = arith.constant 0 : i32
    %254 = arith.extsi %253 : i32 to i64
    %255 = llvm.mlir.constant(1 : i64) : i64
    %256 = llvm.alloca %255 x i64 : (i64) -> !llvm.ptr
    llvm.store %254, %256 : i64, !llvm.ptr
    cf.br ^bb30
    ^bb30:
    %257 = llvm.load %256 : !llvm.ptr -> i64
    %258 = llvm.mlir.addressof @MEMO_SIZE : !llvm.ptr
    %259 = llvm.load %258 : !llvm.ptr -> i64
    %260 = arith.cmpi slt, %257, %259 : i64
    cf.cond_br %260, ^bb31, ^bb32
    ^bb31:
      %261 = llvm.load %256 : !llvm.ptr -> i64
      %262 = arith.addi %252, %261 : i64
      %263 = llvm.mlir.addressof @MEMO_MASK : !llvm.ptr
      %264 = llvm.load %263 : !llvm.ptr -> i64
      %265 = arith.andi %262, %264 : i64
      %267 = llvm.getelementptr %arg0[%265] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
      %266 = llvm.load %267 : !llvm.ptr -> !llvm.struct<(i64, i64)>
      %268 = llvm.getelementptr %arg0[%265] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
      %269 = llvm.getelementptr %268[0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
      %270 = llvm.load %269 : !llvm.ptr -> i64
      %271 = arith.constant 0 : i32
      %273 = arith.extsi %271 : i32 to i64
      %272 = arith.cmpi eq, %270, %273 : i64
      cf.cond_br %272, ^bb33, ^bb34
      ^bb33:
        %274 = llvm.getelementptr %arg0[%265] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
        %275 = llvm.getelementptr %274[0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
        llvm.store %arg1, %275 : i64, !llvm.ptr
        %276 = llvm.getelementptr %arg0[%265] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.struct<(i64, i64)>
        %277 = llvm.getelementptr %276[0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(i64, i64)>
        llvm.store %arg2, %277 : i64, !llvm.ptr
        func.return
      ^bb34:
        cf.br ^bb35
      ^bb35:
      %278 = llvm.load %256 : !llvm.ptr -> i64
      %279 = arith.constant 1 : i32
      %281 = arith.extsi %279 : i32 to i64
      %280 = arith.addi %278, %281 : i64
      llvm.store %280, %256 : i64, !llvm.ptr
      cf.br ^bb30
    ^bb32:
    func.return
  }
  func.func @M_func(%arg0: i64) -> i64 {
  }
  func.func @Modd_func(%arg0: i64) -> i64 {
  }
  func.func @M_func(%arg0: i64) -> i64 {
    %282 = llvm.mlir.addressof @sieve_limit : !llvm.ptr
    %283 = llvm.load %282 : !llvm.ptr -> i64
    %284 = arith.cmpi sle, %arg0, %283 : i64
    cf.cond_br %284, ^bb36, ^bb37
    ^bb36:
      %286 = llvm.mlir.addressof @M_small : !llvm.ptr
      %287 = llvm.load %286 : !llvm.ptr -> !llvm.ptr
      %288 = llvm.getelementptr %287[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %285 = llvm.load %288 : !llvm.ptr -> i64
      func.return %285 : i64
    ^bb37:
      cf.br ^bb38
    ^bb38:
    %290 = llvm.mlir.addressof @memo_M : !llvm.ptr
    %291 = llvm.load %290 : !llvm.ptr -> !llvm.ptr
    %289 = func.call @memo_lookup(%291, %arg0) : (!llvm.ptr, i64) -> i64
    %292 = arith.constant 0 : i32
    %294 = arith.extsi %292 : i32 to i64
    %293 = arith.cmpi ne, %289, %294 : i64
    cf.cond_br %293, ^bb39, ^bb40
    ^bb39:
      func.return %289 : i64
    ^bb40:
      cf.br ^bb41
    ^bb41:
    %295 = arith.constant 1 : i32
    %296 = arith.extsi %295 : i32 to i64
    %297 = llvm.mlir.constant(1 : i64) : i64
    %298 = llvm.alloca %297 x i64 : (i64) -> !llvm.ptr
    llvm.store %296, %298 : i64, !llvm.ptr
    %299 = arith.constant 2 : i32
    %300 = arith.extsi %299 : i32 to i64
    %301 = llvm.mlir.constant(1 : i64) : i64
    %302 = llvm.alloca %301 x i64 : (i64) -> !llvm.ptr
    llvm.store %300, %302 : i64, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %303 = llvm.load %302 : !llvm.ptr -> i64
    %304 = arith.cmpi sle, %303, %arg0 : i64
    cf.cond_br %304, ^bb43, ^bb44
    ^bb43:
      %305 = llvm.load %302 : !llvm.ptr -> i64
      %306 = arith.divsi %arg0, %305 : i64
      %307 = arith.divsi %arg0, %306 : i64
      %308 = llvm.load %298 : !llvm.ptr -> i64
      %309 = llvm.load %302 : !llvm.ptr -> i64
      %310 = arith.subi %307, %309 : i64
      %311 = arith.constant 1 : i32
      %313 = arith.extsi %311 : i32 to i64
      %312 = arith.addi %310, %313 : i64
      %314 = func.call @M_func(%306) : (i64) -> i64
      %315 = arith.muli %312, %314 : i64
      %316 = arith.subi %308, %315 : i64
      llvm.store %316, %298 : i64, !llvm.ptr
      %317 = arith.constant 1 : i32
      %319 = arith.extsi %317 : i32 to i64
      %318 = arith.addi %307, %319 : i64
      llvm.store %318, %302 : i64, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    %321 = llvm.mlir.addressof @memo_M : !llvm.ptr
    %322 = llvm.load %321 : !llvm.ptr -> !llvm.ptr
    %323 = llvm.load %298 : !llvm.ptr -> i64
    func.call @memo_insert(%322, %arg0, %323) : (!llvm.ptr, i64, i64) -> ()
    %324 = llvm.load %298 : !llvm.ptr -> i64
    func.return %324 : i64
  }
  func.func @Modd_func(%arg0: i64) -> i64 {
    %325 = arith.constant 0 : i32
    %327 = arith.extsi %325 : i32 to i64
    %326 = arith.cmpi sle, %arg0, %327 : i64
    cf.cond_br %326, ^bb45, ^bb46
    ^bb45:
      %328 = arith.constant 0 : i32
      %329 = arith.extsi %328 : i32 to i64
      func.return %329 : i64
    ^bb46:
      cf.br ^bb47
    ^bb47:
    %330 = llvm.mlir.addressof @sieve_limit : !llvm.ptr
    %331 = llvm.load %330 : !llvm.ptr -> i64
    %332 = arith.cmpi sle, %arg0, %331 : i64
    cf.cond_br %332, ^bb48, ^bb49
    ^bb48:
      %334 = llvm.mlir.addressof @Modd_small : !llvm.ptr
      %335 = llvm.load %334 : !llvm.ptr -> !llvm.ptr
      %336 = llvm.getelementptr %335[%arg0] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %333 = llvm.load %336 : !llvm.ptr -> i64
      func.return %333 : i64
    ^bb49:
      cf.br ^bb50
    ^bb50:
    %338 = llvm.mlir.addressof @memo_Modd : !llvm.ptr
    %339 = llvm.load %338 : !llvm.ptr -> !llvm.ptr
    %337 = func.call @memo_lookup(%339, %arg0) : (!llvm.ptr, i64) -> i64
    %340 = arith.constant 0 : i32
    %342 = arith.extsi %340 : i32 to i64
    %341 = arith.cmpi ne, %337, %342 : i64
    cf.cond_br %341, ^bb51, ^bb52
    ^bb51:
      func.return %337 : i64
    ^bb52:
      cf.br ^bb53
    ^bb53:
    %343 = func.call @M_func(%arg0) : (i64) -> i64
    %345 = arith.constant 2 : i32
    %347 = arith.extsi %345 : i32 to i64
    %346 = arith.divsi %arg0, %347 : i64
    %344 = func.call @Modd_func(%346) : (i64) -> i64
    %348 = arith.addi %343, %344 : i64
    %350 = llvm.mlir.addressof @memo_Modd : !llvm.ptr
    %351 = llvm.load %350 : !llvm.ptr -> !llvm.ptr
    func.call @memo_insert(%351, %arg0, %348) : (!llvm.ptr, i64, i64) -> ()
    func.return %348 : i64
  }
  func.func @tri(%arg0: i64) -> i64 {
    %352 = arith.constant 1 : i32
    %354 = arith.extsi %352 : i32 to i64
    %353 = arith.addi %arg0, %354 : i64
    %355 = arith.muli %arg0, %353 : i64
    %356 = arith.constant 2 : i32
    %358 = arith.extsi %356 : i32 to i64
    %357 = arith.divsi %355, %358 : i64
    func.return %357 : i64
  }
  func.func @sum_mu_odd(%arg0: i64, %arg1: i64) -> i64 {
    %359 = func.call @Modd_func(%arg1) : (i64) -> i64
    %361 = arith.constant 1 : i32
    %363 = arith.extsi %361 : i32 to i64
    %362 = arith.subi %arg0, %363 : i64
    %360 = func.call @Modd_func(%362) : (i64) -> i64
    %364 = arith.subi %359, %360 : i64
    func.return %364 : i64
  }
  func.func @sum_mu_2mod4(%arg0: i64, %arg1: i64) -> i64 {
    %366 = arith.constant 2 : i32
    %368 = arith.extsi %366 : i32 to i64
    %367 = arith.divsi %arg1, %368 : i64
    %365 = func.call @Modd_func(%367) : (i64) -> i64
    %370 = arith.constant 0 : i64
    %369 = arith.subi %370, %365 : i64
    %372 = arith.constant 1 : i32
    %374 = arith.extsi %372 : i32 to i64
    %373 = arith.subi %arg0, %374 : i64
    %375 = arith.constant 2 : i32
    %377 = arith.extsi %375 : i32 to i64
    %376 = arith.divsi %373, %377 : i64
    %371 = func.call @Modd_func(%376) : (i64) -> i64
    %378 = arith.addi %369, %371 : i64
    func.return %378 : i64
  }
  func.func @class_sum(%arg0: i64, %arg1: i32) -> i64 {
    %379 = arith.constant 0 : i32
    %380 = arith.extsi %379 : i32 to i64
    %381 = llvm.mlir.constant(1 : i64) : i64
    %382 = llvm.alloca %381 x i64 : (i64) -> !llvm.ptr
    llvm.store %380, %382 : i64, !llvm.ptr
    %383 = arith.constant 0 : i32
    %384 = arith.extsi %383 : i32 to i64
    %385 = llvm.mlir.constant(1 : i64) : i64
    %386 = llvm.alloca %385 x i64 : (i64) -> !llvm.ptr
    llvm.store %384, %386 : i64, !llvm.ptr
    %387 = arith.constant 1 : i32
    %388 = arith.extsi %387 : i32 to i64
    %389 = llvm.mlir.constant(1 : i64) : i64
    %390 = llvm.alloca %389 x i64 : (i64) -> !llvm.ptr
    llvm.store %388, %390 : i64, !llvm.ptr
    cf.br ^bb54
    ^bb54:
    %391 = llvm.load %390 : !llvm.ptr -> i64
    %392 = arith.cmpi sle, %391, %arg0 : i64
    cf.cond_br %392, ^bb55, ^bb56
    ^bb55:
      %393 = llvm.load %390 : !llvm.ptr -> i64
      %394 = arith.divsi %arg0, %393 : i64
      %395 = arith.divsi %arg0, %394 : i64
      %397 = llvm.load %390 : !llvm.ptr -> i64
      %396 = func.call @sum_mu_odd(%397, %395) : (i64, i64) -> i64
      %399 = llvm.load %390 : !llvm.ptr -> i64
      %398 = func.call @sum_mu_2mod4(%399, %395) : (i64, i64) -> i64
      %400 = arith.constant 0 : i32
      %401 = arith.cmpi eq, %arg1, %400 : i32
      cf.cond_br %401, ^bb57, ^bb58
      ^bb57:
        %402 = llvm.load %382 : !llvm.ptr -> i64
        %403 = arith.constant 4 : i32
        %405 = arith.extsi %403 : i32 to i64
        %404 = arith.divsi %394, %405 : i64
        %406 = arith.muli %404, %396 : i64
        %407 = arith.constant 2 : i32
        %409 = arith.extsi %407 : i32 to i64
        %408 = arith.divsi %394, %409 : i64
        %410 = arith.muli %408, %398 : i64
        %411 = arith.addi %406, %410 : i64
        %412 = arith.muli %394, %411 : i64
        %413 = arith.addi %402, %412 : i64
        llvm.store %413, %382 : i64, !llvm.ptr
        %414 = llvm.load %386 : !llvm.ptr -> i64
        %415 = arith.constant 4 : i32
        %417 = arith.constant 4 : i32
        %419 = arith.extsi %417 : i32 to i64
        %418 = arith.divsi %394, %419 : i64
        %416 = func.call @tri(%418) : (i64) -> i64
        %421 = arith.extsi %415 : i32 to i64
        %420 = arith.muli %421, %416 : i64
        %422 = arith.muli %420, %396 : i64
        %423 = arith.addi %414, %422 : i64
        %424 = arith.constant 2 : i32
        %426 = arith.constant 2 : i32
        %428 = arith.extsi %426 : i32 to i64
        %427 = arith.divsi %394, %428 : i64
        %425 = func.call @tri(%427) : (i64) -> i64
        %430 = arith.extsi %424 : i32 to i64
        %429 = arith.muli %430, %425 : i64
        %431 = arith.muli %429, %398 : i64
        %432 = arith.addi %423, %431 : i64
        llvm.store %432, %386 : i64, !llvm.ptr
        cf.br ^bb59
      ^bb58:
        %433 = arith.constant 1 : i32
        %434 = arith.cmpi eq, %arg1, %433 : i32
        cf.cond_br %434, ^bb60, ^bb61
        ^bb60:
          %435 = arith.constant 2 : i32
          %437 = arith.extsi %435 : i32 to i64
          %436 = arith.addi %394, %437 : i64
          %438 = arith.constant 4 : i32
          %440 = arith.extsi %438 : i32 to i64
          %439 = arith.divsi %436, %440 : i64
          %441 = llvm.load %382 : !llvm.ptr -> i64
          %442 = arith.muli %439, %396 : i64
          %443 = arith.constant 1 : i32
          %445 = arith.extsi %443 : i32 to i64
          %444 = arith.addi %394, %445 : i64
          %446 = arith.constant 2 : i32
          %448 = arith.extsi %446 : i32 to i64
          %447 = arith.divsi %444, %448 : i64
          %449 = arith.muli %447, %398 : i64
          %450 = arith.addi %442, %449 : i64
          %451 = arith.muli %394, %450 : i64
          %452 = arith.addi %441, %451 : i64
          llvm.store %452, %382 : i64, !llvm.ptr
          %453 = llvm.load %386 : !llvm.ptr -> i64
          %454 = arith.constant 2 : i32
          %456 = arith.extsi %454 : i32 to i64
          %455 = arith.muli %456, %439 : i64
          %457 = arith.muli %455, %439 : i64
          %458 = arith.muli %457, %396 : i64
          %459 = arith.addi %453, %458 : i64
          %460 = func.call @tri(%394) : (i64) -> i64
          %461 = arith.constant 2 : i32
          %463 = arith.constant 2 : i32
          %465 = arith.extsi %463 : i32 to i64
          %464 = arith.divsi %394, %465 : i64
          %462 = func.call @tri(%464) : (i64) -> i64
          %467 = arith.extsi %461 : i32 to i64
          %466 = arith.muli %467, %462 : i64
          %468 = arith.subi %460, %466 : i64
          %469 = arith.muli %468, %398 : i64
          %470 = arith.addi %459, %469 : i64
          llvm.store %470, %386 : i64, !llvm.ptr
          cf.br ^bb62
        ^bb61:
          %471 = llvm.load %382 : !llvm.ptr -> i64
          %472 = arith.constant 1 : i32
          %474 = arith.extsi %472 : i32 to i64
          %473 = arith.addi %394, %474 : i64
          %475 = arith.constant 2 : i32
          %477 = arith.extsi %475 : i32 to i64
          %476 = arith.divsi %473, %477 : i64
          %478 = arith.muli %476, %396 : i64
          %479 = arith.muli %394, %478 : i64
          %480 = arith.addi %471, %479 : i64
          llvm.store %480, %382 : i64, !llvm.ptr
          %481 = llvm.load %386 : !llvm.ptr -> i64
          %482 = func.call @tri(%394) : (i64) -> i64
          %483 = arith.constant 2 : i32
          %485 = arith.constant 2 : i32
          %487 = arith.extsi %485 : i32 to i64
          %486 = arith.divsi %394, %487 : i64
          %484 = func.call @tri(%486) : (i64) -> i64
          %489 = arith.extsi %483 : i32 to i64
          %488 = arith.muli %489, %484 : i64
          %490 = arith.subi %482, %488 : i64
          %491 = arith.muli %490, %396 : i64
          %492 = arith.addi %481, %491 : i64
          llvm.store %492, %386 : i64, !llvm.ptr
          cf.br ^bb62
        ^bb62:
        cf.br ^bb59
      ^bb59:
      %493 = arith.constant 1 : i32
      %495 = arith.extsi %493 : i32 to i64
      %494 = arith.addi %395, %495 : i64
      llvm.store %494, %390 : i64, !llvm.ptr
      cf.br ^bb54
    ^bb56:
    %496 = llvm.load %382 : !llvm.ptr -> i64
    %497 = llvm.load %386 : !llvm.ptr -> i64
    %498 = arith.subi %496, %497 : i64
    func.return %498 : i64
  }
  func.func @F_935(%arg0: i64) -> i64 {
    %499 = arith.constant 0 : i32
    %501 = arith.extsi %499 : i32 to i64
    %500 = arith.cmpi slt, %arg0, %501 : i64
    cf.cond_br %500, ^bb63, ^bb64
    ^bb63:
      %502 = arith.constant 0 : i32
      %503 = arith.extsi %502 : i32 to i64
      func.return %503 : i64
    ^bb64:
      cf.br ^bb65
    ^bb65:
    %504 = arith.constant 1 : i32
    %506 = arith.extsi %504 : i32 to i64
    %505 = arith.addi %arg0, %506 : i64
    %507 = arith.constant 2 : i32
    %509 = arith.extsi %507 : i32 to i64
    %508 = arith.divsi %arg0, %509 : i64
    %510 = arith.constant 1 : i32
    %512 = arith.extsi %510 : i32 to i64
    %511 = arith.addi %508, %512 : i64
    %513 = arith.constant 4 : i32
    %515 = arith.extsi %513 : i32 to i64
    %514 = arith.divsi %arg0, %515 : i64
    %516 = arith.constant 1 : i32
    %518 = arith.extsi %516 : i32 to i64
    %517 = arith.addi %514, %518 : i64
    %519 = arith.constant 0 : i32
    %520 = arith.extsi %519 : i32 to i64
    %521 = llvm.mlir.constant(1 : i64) : i64
    %522 = llvm.alloca %521 x i64 : (i64) -> !llvm.ptr
    llvm.store %520, %522 : i64, !llvm.ptr
    %523 = llvm.load %522 : !llvm.ptr -> i64
    %525 = arith.constant 0 : i32
    %524 = func.call @class_sum(%505, %525) : (i64, i32) -> i64
    %526 = arith.addi %523, %524 : i64
    llvm.store %526, %522 : i64, !llvm.ptr
    %527 = llvm.load %522 : !llvm.ptr -> i64
    %529 = arith.constant 1 : i32
    %528 = func.call @class_sum(%511, %529) : (i64, i32) -> i64
    %530 = arith.addi %527, %528 : i64
    llvm.store %530, %522 : i64, !llvm.ptr
    %531 = llvm.load %522 : !llvm.ptr -> i64
    %533 = arith.constant 2 : i32
    %532 = func.call @class_sum(%517, %533) : (i64, i32) -> i64
    %534 = arith.addi %531, %532 : i64
    llvm.store %534, %522 : i64, !llvm.ptr
    %535 = llvm.load %522 : !llvm.ptr -> i64
    %536 = arith.constant 1 : i32
    %538 = arith.extsi %536 : i32 to i64
    %537 = arith.subi %517, %538 : i64
    %539 = arith.subi %535, %537 : i64
    llvm.store %539, %522 : i64, !llvm.ptr
    %540 = llvm.load %522 : !llvm.ptr -> i64
    %541 = arith.constant 4 : i32
    %543 = arith.extsi %541 : i32 to i64
    %542 = arith.divsi %arg0, %543 : i64
    %544 = arith.addi %540, %542 : i64
    llvm.store %544, %522 : i64, !llvm.ptr
    %545 = llvm.load %522 : !llvm.ptr -> i64
    func.return %545 : i64
  }
  func.func @main() -> i32 {
    %546 = arith.constant 1 : i32
    %547 = arith.extsi %546 : i32 to i64
    %548 = llvm.mlir.constant(1 : i64) : i64
    %549 = llvm.alloca %548 x i64 : (i64) -> !llvm.ptr
    llvm.store %547, %549 : i64, !llvm.ptr
    %550 = arith.constant 0 : i32
    %551 = llvm.mlir.constant(1 : i64) : i64
    %552 = llvm.alloca %551 x i32 : (i64) -> !llvm.ptr
    llvm.store %550, %552 : i32, !llvm.ptr
    cf.br ^bb66
    ^bb66:
    %553 = llvm.load %552 : !llvm.ptr -> i32
    %554 = arith.constant 8 : i32
    %555 = arith.cmpi slt, %553, %554 : i32
    cf.cond_br %555, ^bb67, ^bb68
    ^bb67:
      %556 = llvm.load %549 : !llvm.ptr -> i64
      %557 = arith.constant 10 : i32
      %559 = arith.extsi %557 : i32 to i64
      %558 = arith.muli %556, %559 : i64
      llvm.store %558, %549 : i64, !llvm.ptr
      %560 = llvm.load %552 : !llvm.ptr -> i32
      %561 = arith.constant 1 : i32
      %562 = arith.addi %560, %561 : i32
      llvm.store %562, %552 : i32, !llvm.ptr
      cf.br ^bb66
    ^bb68:
    %563 = llvm.load %549 : !llvm.ptr -> i64
    %564 = arith.constant 1 : i32
    %566 = arith.extsi %564 : i32 to i64
    %565 = arith.addi %563, %566 : i64
    %568 = arith.sitofp %565 : i64 to f64
    %569 = arith.constant 2.0 : f32
    %570 = arith.constant 3.0 : f32
    %571 = arith.divf %569, %570 : f32
    %572 = arith.extf %571 : f32 to f64
    %567 = func.call @pow(%568, %572) : (f64, f64) -> f64
    %573 = arith.fptosi %567 : f64 to i64
    %574 = arith.constant 10 : i32
    %576 = arith.extsi %574 : i32 to i64
    %575 = arith.addi %573, %576 : i64
    func.call @build_mu_prefix(%575) : (i64) -> ()
    %579 = llvm.mlir.addressof @MEMO_SIZE : !llvm.ptr
    %580 = llvm.load %579 : !llvm.ptr -> i64
    %581 = arith.constant 16 : i32
    %582 = arith.extsi %581 : i32 to i64
    %578 = func.call @calloc(%580, %582) : (i64, i64) -> !llvm.ptr
    %583 = llvm.mlir.addressof @memo_M : !llvm.ptr
    llvm.store %578, %583 : !llvm.ptr, !llvm.ptr
    %585 = llvm.mlir.addressof @MEMO_SIZE : !llvm.ptr
    %586 = llvm.load %585 : !llvm.ptr -> i64
    %587 = arith.constant 16 : i32
    %588 = arith.extsi %587 : i32 to i64
    %584 = func.call @calloc(%586, %588) : (i64, i64) -> !llvm.ptr
    %589 = llvm.mlir.addressof @memo_Modd : !llvm.ptr
    llvm.store %584, %589 : !llvm.ptr, !llvm.ptr
    %591 = llvm.load %549 : !llvm.ptr -> i64
    %590 = func.call @F_935(%591) : (i64) -> i64
    %593 = llvm.mlir.addressof @mu_arr : !llvm.ptr
    %594 = llvm.load %593 : !llvm.ptr -> !llvm.ptr
    func.call @free(%594) : (!llvm.ptr) -> ()
    %596 = llvm.mlir.addressof @M_small : !llvm.ptr
    %597 = llvm.load %596 : !llvm.ptr -> !llvm.ptr
    func.call @free(%597) : (!llvm.ptr) -> ()
    %599 = llvm.mlir.addressof @Modd_small : !llvm.ptr
    %600 = llvm.load %599 : !llvm.ptr -> !llvm.ptr
    func.call @free(%600) : (!llvm.ptr) -> ()
    %602 = llvm.mlir.addressof @memo_M : !llvm.ptr
    %603 = llvm.load %602 : !llvm.ptr -> !llvm.ptr
    func.call @free(%603) : (!llvm.ptr) -> ()
    %605 = llvm.mlir.addressof @memo_Modd : !llvm.ptr
    %606 = llvm.load %605 : !llvm.ptr -> !llvm.ptr
    func.call @free(%606) : (!llvm.ptr) -> ()
    %607 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %608 = llvm.call @printf(%607, %590) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %609 = arith.constant 0 : i32
    func.return %609 : i32
  }
}