Problem 888

Count losing positions (XOR of Grundy numbers = 0) with m piles, each size [1..N]. Uses a 16-point +/-1 filter over 4 bits of Grundy values.

Answer227429102
Output227429102
StatusPASS
Native helperno
Runtime10 ms
Peak memory1264 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n * k)
Space complexityO(n^2)O(n)
ApproachFlow solutionKey search and XOR decryption
VerdictUnknown

Flow source

# Project Euler 888: Coin Game
# Count losing positions (XOR of Grundy numbers = 0) with m piles, each size [1..N].
# Uses a 16-point +/-1 filter over 4 bits of Grundy values.

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

const N_VAL: i64 = 12491249
const M_VAL: i32 = 1249
const MOD: i64 = 912491249
const PRE: i32 = 322
const PERIOD: i32 = 11060
const SPLIT_LIMIT: i32 = 600

# ---- modular arithmetic with i128 ----

function mulmod(a: i64, b: i64, m: i64) -> i64 {
    return ((a as i128 * b as i128) % (m as i128)) as i64
}

function powmod(a0: i64, e0: i64, m: i64) -> i64 {
    let mut r: i64 = 1 % m
    let mut a: i64 = a0 % m
    if a < 0 { a = a + m }
    let mut e: i64 = e0
    while e > 0 {
        if (e & 1) == 1 { r = mulmod(r, a, m) }
        a = mulmod(a, a, m)
        e = e >> 1
    }
    return r
}

function inv_mod(a0: i64, modv: i64) -> i64 {
    let mut a: i64 = a0 % modv
    if a < 0 { a = a + modv }
    let mut x0: i64 = 1
    let mut x1: i64 = 0
    let mut aa: i64 = a
    let mut mm: i64 = modv
    while mm != 0 {
        let q: i64 = aa / mm
        let t: i64 = aa - q * mm
        aa = mm
        mm = t
        let t2: i64 = x0 - q * x1
        x0 = x1
        x1 = t2
    }
    if aa != 1 { return -1 }
    let mut result: i64 = x0 % modv
    if result < 0 { result = result + modv }
    return result
}

function popcount(x: i32) -> i32 {
    let mut n: i32 = 0
    let mut v: i32 = x
    while v != 0 {
        n = n + 1
        v = v & (v - 1)
    }
    return n
}

# ---- strip p from x: return x_without_p, set v via pointer ----

function strip_p(x: i64, p: i64, x_free: ptr<i64>, v: ptr<i32>) -> void {
    x_free[0] = x
    v[0] = 0
    while x_free[0] % p == 0 {
        x_free[0] = x_free[0] / p
        v[0] = v[0] + 1
    }
}

# ---- factor n into prime powers (parallel arrays) ----

function factor_prime_powers(n: i64, out_p: ptr<i64>, out_pe: ptr<i64>) -> i32 {
    let mut count: i32 = 0
    let mut x: i64 = n
    let mut p: i64 = 2
    while p * p <= x {
        if x % p == 0 {
            let mut pe: i64 = 1
            while x % p == 0 {
                x = x / p
                pe = pe * p
            }
            out_p[count] = p
            out_pe[count] = pe
            count = count + 1
        }
        if p == 2 { p = 3 } else { p = p + 2 }
    }
    if x > 1 {
        out_p[count] = x
        out_pe[count] = x
        count = count + 1
    }
    return count
}

# ---- compute Grundy numbers g[0..limit] ----

function compute_grundy(g: ptr<i32>, limit: i32, split_limit: i32) -> void {
    let mut n: i32 = 1
    while n <= limit {
        let mut seen: i32 = 0
        # REMOVE = {1, 2, 4, 9}
        if n >= 1 { seen = seen | (1 << g[n - 1]) }
        if n >= 2 { seen = seen | (1 << g[n - 2]) }
        if n >= 4 { seen = seen | (1 << g[n - 4]) }
        if n >= 9 { seen = seen | (1 << g[n - 9]) }

        let mut max_i: i32 = n - 1
        if split_limit > 0 && split_limit < n - 1 { max_i = split_limit }
        let mut i: i32 = 1
        while i <= max_i {
            seen = seen | (1 << (g[i] ^ g[n - i]))
            i = i + 1
        }
        let mut mex: i32 = 0
        while ((seen >> mex) & 1) == 1 {
            mex = mex + 1
        }
        g[n] = mex
        n = n + 1
    }
}

# ---- denominator tables (using parallel global arrays) ----

let mut dt_p: ptr<i64> = null
let mut dt_pe: ptr<i64> = null
let mut dt_den_free: ptr<ptr<i64> > = null
let mut dt_den_v: ptr<ptr<i32> > = null
let mut dt_inv_free: ptr<ptr<i64> > = null

function precompute_den_tables(idx: i32, p: i64, pe: i64, m: i32) -> void {
    dt_p[idx] = p
    dt_pe[idx] = pe
    dt_den_free[idx] = malloc(((m + 1) as i64) * 8) as ptr<i64>
    dt_den_v[idx] = malloc(((m + 1) as i64) * 4) as ptr<i32>
    dt_inv_free[idx] = malloc(((m + 1) as i64) * 8) as ptr<i64>
    dt_den_free[idx][0] = 1
    dt_inv_free[idx][0] = 1
    let mut i: i32 = 1
    while i <= m {
        let xf_ptr: ptr<i64> = malloc(8) as ptr<i64>
        let v_ptr: ptr<i32> = malloc(4) as ptr<i32>
        strip_p(i as i64, p, xf_ptr, v_ptr)
        dt_den_free[idx][i] = xf_ptr[0]
        dt_den_v[idx][i] = v_ptr[0]
        dt_inv_free[idx][i] = inv_mod(xf_ptr[0] % pe, pe)
        free(xf_ptr as ptr<void>)
        free(v_ptr as ptr<void>)
        i = i + 1
    }
}

# ---- coefficient of x^m in (1-x)^(-a) * (1+x)^(-(N-a)) mod p^e ----

function coeff_term_mod_prime_power(N_val: i64, m: i32, a: i64, idx: i32) -> i64 {
    let p: i64 = dt_p[idx]
    let pe: i64 = dt_pe[idx]
    let A: i64 = a
    let B: i64 = N_val - a

    let u: ptr<i64> = calloc((m + 1) as i64, 8) as ptr<i64>
    let w: ptr<i64> = calloc((m + 1) as i64, 8) as ptr<i64>

    u[0] = 1 % pe
    if A != 0 {
        let mut res: i64 = 1 % pe
        let mut exp: i32 = 0
        let mut i: i32 = 1
        while i <= m {
            let num: i64 = A + (i as i64) - 1
            let num_free_ptr: ptr<i64> = malloc(8) as ptr<i64>
            let v_num_ptr: ptr<i32> = malloc(4) as ptr<i32>
            strip_p(num, p, num_free_ptr, v_num_ptr)
            exp = exp + v_num_ptr[0]
            exp = exp - dt_den_v[idx][i]
            res = mulmod(res, num_free_ptr[0] % pe, pe)
            res = mulmod(res, dt_inv_free[idx][i], pe)
            u[i] = mulmod(res, powmod(p, exp as i64, pe), pe)
            free(num_free_ptr as ptr<void>)
            free(v_num_ptr as ptr<void>)
            i = i + 1
        }
    }

    w[0] = 1 % pe
    if B != 0 {
        let mut res: i64 = 1 % pe
        let mut exp: i32 = 0
        let mut i: i32 = 1
        while i <= m {
            let num: i64 = B + (i as i64) - 1
            let num_free_ptr: ptr<i64> = malloc(8) as ptr<i64>
            let v_num_ptr: ptr<i32> = malloc(4) as ptr<i32>
            strip_p(num, p, num_free_ptr, v_num_ptr)
            exp = exp + v_num_ptr[0]
            exp = exp - dt_den_v[idx][i]
            res = mulmod(res, num_free_ptr[0] % pe, pe)
            res = mulmod(res, dt_inv_free[idx][i], pe)
            let mut val: i64 = mulmod(res, powmod(p, exp as i64, pe), pe)
            if (i & 1) == 1 { val = (pe - val) % pe }
            w[i] = val
            free(num_free_ptr as ptr<void>)
            free(v_num_ptr as ptr<void>)
            i = i + 1
        }
    }

    let mut out: i64 = 0
    let mut i: i32 = 0
    while i <= m {
        out = (out + mulmod(u[i], w[m - i], pe)) % pe
        i = i + 1
    }

    free(u as ptr<void>)
    free(w as ptr<void>)
    return out
}

# ---- count Grundy values in [1..N] using periodicity ----

function grundy_counts_up_to(N_val: i64, g: ptr<i32>, pre: i32, period: i32, counts: ptr<i64>, max_g: i32) -> void {
    let mut k: i32 = 0
    while k < max_g {
        counts[k] = 0
        k = k + 1
    }
    if N_val <= 0 { return }

    if N_val < (pre as i64) {
        let mut n: i64 = 1
        while n <= N_val {
            counts[g[n]] = counts[g[n]] + 1
            n = n + 1
        }
        return
    }

    let mut n: i32 = 1
    while n < pre {
        counts[g[n]] = counts[g[n]] + 1
        n = n + 1
    }

    let per_counts: ptr<i64> = calloc(16, 8) as ptr<i64>
    let mut pn: i32 = pre
    while pn < pre + period {
        per_counts[g[pn]] = per_counts[g[pn]] + 1
        pn = pn + 1
    }

    let total_period_terms: i64 = N_val - (pre as i64) + 1
    let q: i64 = total_period_terms / (period as i64)
    let r: i64 = total_period_terms % (period as i64)

    k = 0
    while k < max_g {
        counts[k] = counts[k] + per_counts[k] * q
        k = k + 1
    }

    let mut rn: i64 = pre as i64
    while rn < (pre as i64) + r {
        counts[g[rn]] = counts[g[rn]] + 1
        rn = rn + 1
    }
    free(per_counts as ptr<void>)
}

function S_mod(N_val: i64, m: i32, modv: i64, g: ptr<i32>, pre: i32, period: i32) -> i64 {
    let max_g: i32 = 16
    let counts: ptr<i64> = calloc(16, 8) as ptr<i64>
    grundy_counts_up_to(N_val, g, pre, period, counts, max_g)

    let pp_p: ptr<i64> = calloc(20, 8) as ptr<i64>
    let pp_pe: ptr<i64> = calloc(20, 8) as ptr<i64>
    let npp: i32 = factor_prime_powers(modv, pp_p, pp_pe)

    let mods: ptr<i64> = calloc(20, 8) as ptr<i64>
    let Ms: ptr<i64> = calloc(20, 8) as ptr<i64>
    let inv_Ms: ptr<i64> = calloc(20, 8) as ptr<i64>
    let mut i: i32 = 0
    while i < npp {
        mods[i] = pp_pe[i]
        Ms[i] = modv / pp_pe[i]
        inv_Ms[i] = inv_mod(Ms[i] % pp_pe[i], pp_pe[i])
        i = i + 1
    }

    # allocate den table arrays
    dt_p = calloc(20, 8) as ptr<i64>
    dt_pe = calloc(20, 8) as ptr<i64>
    dt_den_free = calloc(20, 8) as ptr<ptr<i64> >
    dt_den_v = calloc(20, 8) as ptr<ptr<i32> >
    dt_inv_free = calloc(20, 8) as ptr<ptr<i64> >

    i = 0
    while i < npp {
        precompute_den_tables(i, pp_p[i], pp_pe[i], m)
        i = i + 1
    }

    let inv16: i64 = inv_mod(16, modv)
    let mut total: i64 = 0

    let mut s: i32 = 0
    while s < 16 {
        let mut a: i64 = 0
        let mut gv: i32 = 0
        while gv < max_g {
            if counts[gv] != 0 && (popcount(gv & s) & 1) == 0 {
                a = a + counts[gv]
            }
            gv = gv + 1
        }

        # CRT combine
        let mut x: i64 = 0
        i = 0
        while i < npp {
            let resid: i64 = coeff_term_mod_prime_power(N_val, m, a, i)
            x = (x + mulmod(mulmod(resid % mods[i], Ms[i], modv), inv_Ms[i], modv)) % modv
            i = i + 1
        }

        total = (total + x) % modv
        s = s + 1
    }

    # free den tables
    i = 0
    while i < npp {
        free(dt_den_free[i] as ptr<void>)
        free(dt_den_v[i] as ptr<void>)
        free(dt_inv_free[i] as ptr<void>)
        i = i + 1
    }
    free(dt_p as ptr<void>)
    free(dt_pe as ptr<void>)
    free(dt_den_free as ptr<void>)
    free(dt_den_v as ptr<void>)
    free(dt_inv_free as ptr<void>)
    free(counts as ptr<void>)
    free(pp_p as ptr<void>)
    free(pp_pe as ptr<void>)
    free(mods as ptr<void>)
    free(Ms as ptr<void>)
    free(inv_Ms as ptr<void>)

    return mulmod(total, inv16, modv)
}

function main() -> i32 {
    let precomp_limit: i32 = PRE + 2 * PERIOD
    let g_fast: ptr<i32> = malloc(((precomp_limit + 1) as i64) * 4) as ptr<i32>
    g_fast[0] = 0
    compute_grundy(g_fast, precomp_limit, SPLIT_LIMIT)

    let ans: i64 = S_mod(N_VAL, M_VAL, MOD, g_fast, PRE, PERIOD)

    printf("%lld\n", ans)
    free(g_fast as ptr<void>)
    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 mulmod_i64_i64_i64(int64_t a, int64_t b, int64_t m);
int64_t powmod_i64_i64_i64(int64_t a0, int64_t e0, int64_t m);
int64_t inv_mod_i64_i64(int64_t a0, int64_t modv);
int32_t popcount_i32(int32_t x);
void strip_p_i64_i64_ptr_i64_ptr_i32(int64_t x, int64_t p, int64_t* x_free, int32_t* v);
int32_t factor_prime_powers_i64_ptr_i64_ptr_i64(int64_t n, int64_t* out_p, int64_t* out_pe);
void compute_grundy_ptr_i32_i32_i32(int32_t* g, int32_t limit, int32_t split_limit);
void precompute_den_tables_i32_i64_i64_i32(int32_t idx, int64_t p, int64_t pe, int32_t m);
int64_t coeff_term_mod_prime_power_i64_i32_i64_i32(int64_t N_val, int32_t m, int64_t a, int32_t idx);
void grundy_counts_up_to_i64_ptr_i32_i32_i32_ptr_i64_i32(int64_t N_val, int32_t* g, int32_t pre, int32_t period, int64_t* counts, int32_t max_g);
int64_t S_mod_i64_i32_i64_ptr_i32_i32_i32(int64_t N_val, int32_t m, int64_t modv, int32_t* g, int32_t pre, int32_t period);
int32_t main(void);

static const int64_t N_VAL = 12491249;
static const int32_t M_VAL = 1249;
static const int64_t MOD = 912491249;
static const int32_t PRE = 322;
static const int32_t PERIOD = 11060;
static const int32_t SPLIT_LIMIT = 600;

/* Module statics */
static int64_t* dt_p = NULL;
static int64_t* dt_pe = NULL;
static int64_t** dt_den_free = NULL;
static int32_t** dt_den_v = NULL;
static int64_t** dt_inv_free = NULL;




int64_t mulmod_i64_i64_i64(int64_t a, int64_t b, int64_t m) {
    return ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(a)) * ((__int128)(b)))), (((__int128)(m))))));
}

int64_t powmod_i64_i64_i64(int64_t a0, int64_t e0, int64_t m) {
    int64_t r = FLOW_CHECKED_MOD((1), (m));
    int64_t a = FLOW_CHECKED_MOD((a0), (m));
    if (a < 0) {
        a = (a + m);
    }
    int64_t e = e0;
    while (e > 0) {
        if ((e & 1) == 1) {
            r = mulmod_i64_i64_i64(r, a, m);
        }
        a = mulmod_i64_i64_i64(a, a, m);
        e = FLOW_CHECKED_SHR((e), (1));
    }
    return r;
}

int64_t inv_mod_i64_i64(int64_t a0, int64_t modv) {
    int64_t a = FLOW_CHECKED_MOD((a0), (modv));
    if (a < 0) {
        a = (a + modv);
    }
    int64_t x0 = 1;
    int64_t x1 = 0;
    int64_t aa = a;
    int64_t mm = modv;
    while (mm != 0) {
        int64_t q = FLOW_CHECKED_DIV((aa), (mm));
        int64_t t = (aa - (q * mm));
        aa = mm;
        mm = t;
        int64_t t2 = (x0 - (q * x1));
        x0 = x1;
        x1 = t2;
    }
    if (aa != 1) {
        return (-1);
    }
    int64_t result = FLOW_CHECKED_MOD((x0), (modv));
    if (result < 0) {
        result = (result + modv);
    }
    return result;
}

int32_t popcount_i32(int32_t x) {
    int32_t n = 0;
    int32_t v = x;
    while (v != 0) {
        n = (n + 1);
        v = (v & (v - 1));
    }
    return n;
}

void strip_p_i64_i64_ptr_i64_ptr_i32(int64_t x, int64_t p, int64_t* x_free, int32_t* v) {
    x_free[0] = x;
    v[0] = 0;
    while (FLOW_CHECKED_MOD((x_free[0]), (p)) == 0) {
        x_free[0] = FLOW_CHECKED_DIV((x_free[0]), (p));
        v[0] = (v[0] + 1);
    }
}

int32_t factor_prime_powers_i64_ptr_i64_ptr_i64(int64_t n, int64_t* out_p, int64_t* out_pe) {
    int32_t count = 0;
    int64_t x = n;
    int64_t p = 2;
    while ((p * p) <= x) {
        if (FLOW_CHECKED_MOD((x), (p)) == 0) {
            int64_t pe = 1;
            while (FLOW_CHECKED_MOD((x), (p)) == 0) {
                x = FLOW_CHECKED_DIV((x), (p));
                pe = (pe * p);
            }
            out_p[count] = p;
            out_pe[count] = pe;
            count = (count + 1);
        }
        if (p == 2) {
            p = 3;
        } else {
            p = (p + 2);
        }
    }
    if (x > 1) {
        out_p[count] = x;
        out_pe[count] = x;
        count = (count + 1);
    }
    return count;
}

void compute_grundy_ptr_i32_i32_i32(int32_t* g, int32_t limit, int32_t split_limit) {
    int32_t n = 1;
    while (n <= limit) {
        int32_t seen = 0;
        if (n >= 1) {
            seen = (seen | FLOW_CHECKED_SHL((1), (g[(n - 1)])));
        }
        if (n >= 2) {
            seen = (seen | FLOW_CHECKED_SHL((1), (g[(n - 2)])));
        }
        if (n >= 4) {
            seen = (seen | FLOW_CHECKED_SHL((1), (g[(n - 4)])));
        }
        if (n >= 9) {
            seen = (seen | FLOW_CHECKED_SHL((1), (g[(n - 9)])));
        }
        int32_t max_i = (n - 1);
        if ((split_limit > 0 && split_limit < (n - 1))) {
            max_i = split_limit;
        }
        int32_t i = 1;
        while (i <= max_i) {
            seen = (seen | FLOW_CHECKED_SHL((1), ((g[i] ^ g[(n - i)]))));
            i = (i + 1);
        }
        int32_t mex = 0;
        while ((FLOW_CHECKED_SHR((seen), (mex)) & 1) == 1) {
            mex = (mex + 1);
        }
        g[n] = mex;
        n = (n + 1);
    }
}

void precompute_den_tables_i32_i64_i64_i32(int32_t idx, int64_t p, int64_t pe, int32_t m) {
    dt_p[idx] = p;
    dt_pe[idx] = pe;
    dt_den_free[idx] = ((int64_t*)(malloc((((int64_t)((m + 1))) * 8))));
    dt_den_v[idx] = ((int32_t*)(malloc((((int64_t)((m + 1))) * 4))));
    dt_inv_free[idx] = ((int64_t*)(malloc((((int64_t)((m + 1))) * 8))));
    dt_den_free[idx][0] = 1;
    dt_inv_free[idx][0] = 1;
    int32_t i = 1;
    while (i <= m) {
        int64_t* xf_ptr = (int64_t*)(((int64_t*)(malloc(8))));
        int32_t* v_ptr = (int32_t*)(((int32_t*)(malloc(4))));
        strip_p_i64_i64_ptr_i64_ptr_i32(((int64_t)(i)), p, xf_ptr, v_ptr);
        dt_den_free[idx][i] = xf_ptr[0];
        dt_den_v[idx][i] = v_ptr[0];
        dt_inv_free[idx][i] = inv_mod_i64_i64(FLOW_CHECKED_MOD((xf_ptr[0]), (pe)), pe);
        free(((void*)(xf_ptr)));
        free(((void*)(v_ptr)));
        i = (i + 1);
    }
}

int64_t coeff_term_mod_prime_power_i64_i32_i64_i32(int64_t N_val, int32_t m, int64_t a, int32_t idx) {
    int64_t p = dt_p[idx];
    int64_t pe = dt_pe[idx];
    int64_t A = a;
    int64_t B = (N_val - a);
    int64_t* u = (int64_t*)(((int64_t*)(calloc(((int64_t)((m + 1))), 8))));
    int64_t* w = (int64_t*)(((int64_t*)(calloc(((int64_t)((m + 1))), 8))));
    u[0] = FLOW_CHECKED_MOD((1), (pe));
    if (A != 0) {
        int64_t res = FLOW_CHECKED_MOD((1), (pe));
        int32_t exp = 0;
        int32_t i = 1;
        while (i <= m) {
            int64_t num = ((A + ((int64_t)(i))) - 1);
            int64_t* num_free_ptr = (int64_t*)(((int64_t*)(malloc(8))));
            int32_t* v_num_ptr = (int32_t*)(((int32_t*)(malloc(4))));
            strip_p_i64_i64_ptr_i64_ptr_i32(num, p, num_free_ptr, v_num_ptr);
            exp = (exp + v_num_ptr[0]);
            exp = (exp - dt_den_v[idx][i]);
            res = mulmod_i64_i64_i64(res, FLOW_CHECKED_MOD((num_free_ptr[0]), (pe)), pe);
            res = mulmod_i64_i64_i64(res, dt_inv_free[idx][i], pe);
            u[i] = mulmod_i64_i64_i64(res, powmod_i64_i64_i64(p, ((int64_t)(exp)), pe), pe);
            free(((void*)(num_free_ptr)));
            free(((void*)(v_num_ptr)));
            i = (i + 1);
        }
    }
    w[0] = FLOW_CHECKED_MOD((1), (pe));
    if (B != 0) {
        int64_t res = FLOW_CHECKED_MOD((1), (pe));
        int32_t exp = 0;
        int32_t i = 1;
        while (i <= m) {
            int64_t num = ((B + ((int64_t)(i))) - 1);
            int64_t* num_free_ptr = (int64_t*)(((int64_t*)(malloc(8))));
            int32_t* v_num_ptr = (int32_t*)(((int32_t*)(malloc(4))));
            strip_p_i64_i64_ptr_i64_ptr_i32(num, p, num_free_ptr, v_num_ptr);
            exp = (exp + v_num_ptr[0]);
            exp = (exp - dt_den_v[idx][i]);
            res = mulmod_i64_i64_i64(res, FLOW_CHECKED_MOD((num_free_ptr[0]), (pe)), pe);
            res = mulmod_i64_i64_i64(res, dt_inv_free[idx][i], pe);
            int64_t val = mulmod_i64_i64_i64(res, powmod_i64_i64_i64(p, ((int64_t)(exp)), pe), pe);
            if ((i & 1) == 1) {
                val = FLOW_CHECKED_MOD(((pe - val)), (pe));
            }
            w[i] = val;
            free(((void*)(num_free_ptr)));
            free(((void*)(v_num_ptr)));
            i = (i + 1);
        }
    }
    int64_t out = 0;
    int32_t i = 0;
    while (i <= m) {
        out = FLOW_CHECKED_MOD(((out + mulmod_i64_i64_i64(u[i], w[(m - i)], pe))), (pe));
        i = (i + 1);
    }
    free(((void*)(u)));
    free(((void*)(w)));
    return out;
}

void grundy_counts_up_to_i64_ptr_i32_i32_i32_ptr_i64_i32(int64_t N_val, int32_t* g, int32_t pre, int32_t period, int64_t* counts, int32_t max_g) {
    int32_t k = 0;
    while (k < max_g) {
        counts[k] = 0;
        k = (k + 1);
    }
    if (N_val <= 0) {
        return;
    }
    if (N_val < ((int64_t)(pre))) {
        int64_t n = 1;
        while (n <= N_val) {
            counts[g[n]] = (counts[g[n]] + 1);
            n = (n + 1);
        }
        return;
    }
    int32_t n = 1;
    while (n < pre) {
        counts[g[n]] = (counts[g[n]] + 1);
        n = (n + 1);
    }
    int64_t* per_counts = (int64_t*)(((int64_t*)(calloc(16, 8))));
    int32_t pn = pre;
    while (pn < (pre + period)) {
        per_counts[g[pn]] = (per_counts[g[pn]] + 1);
        pn = (pn + 1);
    }
    int64_t total_period_terms = ((N_val - ((int64_t)(pre))) + 1);
    int64_t q = FLOW_CHECKED_DIV((total_period_terms), (((int64_t)(period))));
    int64_t r = FLOW_CHECKED_MOD((total_period_terms), (((int64_t)(period))));
    k = 0;
    while (k < max_g) {
        counts[k] = (counts[k] + (per_counts[k] * q));
        k = (k + 1);
    }
    int64_t rn = ((int64_t)(pre));
    while (rn < (((int64_t)(pre)) + r)) {
        counts[g[rn]] = (counts[g[rn]] + 1);
        rn = (rn + 1);
    }
    free(((void*)(per_counts)));
}

int64_t S_mod_i64_i32_i64_ptr_i32_i32_i32(int64_t N_val, int32_t m, int64_t modv, int32_t* g, int32_t pre, int32_t period) {
    int32_t max_g = 16;
    int64_t* counts = (int64_t*)(((int64_t*)(calloc(16, 8))));
    grundy_counts_up_to_i64_ptr_i32_i32_i32_ptr_i64_i32(N_val, g, pre, period, counts, max_g);
    int64_t* pp_p = (int64_t*)(((int64_t*)(calloc(20, 8))));
    int64_t* pp_pe = (int64_t*)(((int64_t*)(calloc(20, 8))));
    int32_t npp = factor_prime_powers_i64_ptr_i64_ptr_i64(modv, pp_p, pp_pe);
    int64_t* mods = (int64_t*)(((int64_t*)(calloc(20, 8))));
    int64_t* Ms = (int64_t*)(((int64_t*)(calloc(20, 8))));
    int64_t* inv_Ms = (int64_t*)(((int64_t*)(calloc(20, 8))));
    int32_t i = 0;
    while (i < npp) {
        mods[i] = pp_pe[i];
        Ms[i] = FLOW_CHECKED_DIV((modv), (pp_pe[i]));
        inv_Ms[i] = inv_mod_i64_i64(FLOW_CHECKED_MOD((Ms[i]), (pp_pe[i])), pp_pe[i]);
        i = (i + 1);
    }
    dt_p = ((int64_t*)(calloc(20, 8)));
    dt_pe = ((int64_t*)(calloc(20, 8)));
    dt_den_free = ((int64_t**)(calloc(20, 8)));
    dt_den_v = ((int32_t**)(calloc(20, 8)));
    dt_inv_free = ((int64_t**)(calloc(20, 8)));
    i = 0;
    while (i < npp) {
        precompute_den_tables_i32_i64_i64_i32(i, pp_p[i], pp_pe[i], m);
        i = (i + 1);
    }
    int64_t inv16 = inv_mod_i64_i64(16, modv);
    int64_t total = 0;
    int32_t s = 0;
    while (s < 16) {
        int64_t a = 0;
        int32_t gv = 0;
        while (gv < max_g) {
            if ((counts[gv] != 0 && (popcount_i32((gv & s)) & 1) == 0)) {
                a = (a + counts[gv]);
            }
            gv = (gv + 1);
        }
        int64_t x = 0;
        i = 0;
        while (i < npp) {
            int64_t resid = coeff_term_mod_prime_power_i64_i32_i64_i32(N_val, m, a, i);
            x = FLOW_CHECKED_MOD(((x + mulmod_i64_i64_i64(mulmod_i64_i64_i64(FLOW_CHECKED_MOD((resid), (mods[i])), Ms[i], modv), inv_Ms[i], modv))), (modv));
            i = (i + 1);
        }
        total = FLOW_CHECKED_MOD(((total + x)), (modv));
        s = (s + 1);
    }
    i = 0;
    while (i < npp) {
        free(((void*)(dt_den_free[i])));
        free(((void*)(dt_den_v[i])));
        free(((void*)(dt_inv_free[i])));
        i = (i + 1);
    }
    free(((void*)(dt_p)));
    free(((void*)(dt_pe)));
    free(((void*)(dt_den_free)));
    free(((void*)(dt_den_v)));
    free(((void*)(dt_inv_free)));
    free(((void*)(counts)));
    free(((void*)(pp_p)));
    free(((void*)(pp_pe)));
    free(((void*)(mods)));
    free(((void*)(Ms)));
    free(((void*)(inv_Ms)));
    return mulmod_i64_i64_i64(total, inv16, modv);
}

int32_t main(void) {
    int32_t precomp_limit = (PRE + (2 * PERIOD));
    int32_t* g_fast = (int32_t*)(((int32_t*)(malloc((((int64_t)((precomp_limit + 1))) * 4)))));
    g_fast[0] = 0;
    compute_grundy_ptr_i32_i32_i32(g_fast, precomp_limit, SPLIT_LIMIT);
    int64_t ans = S_mod_i64_i32_i64_ptr_i32_i32_i32(N_VAL, M_VAL, MOD, g_fast, PRE, PERIOD);
    printf("%lld\n", ans);
    free(((void*)(g_fast)));
    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 @malloc(i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  // Constant: N_VAL
  llvm.mlir.global internal constant @N_VAL(12491249 : i64) : i64
  // Constant: M_VAL
  llvm.mlir.global internal constant @M_VAL(1249 : i32) : i32
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(912491249 : i64) : i64
  // Constant: PRE
  llvm.mlir.global internal constant @PRE(322 : i32) : i32
  // Constant: PERIOD
  llvm.mlir.global internal constant @PERIOD(11060 : i32) : i32
  // Constant: SPLIT_LIMIT
  llvm.mlir.global internal constant @SPLIT_LIMIT(600 : i32) : i32
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %0 = arith.extsi %arg0 : i64 to i128
    %1 = arith.extsi %arg1 : i64 to i128
    %3 = arith.trunci %0 : i128 to i64
    %4 = arith.trunci %1 : i128 to i64
    %2 = arith.muli %3, %4 : i64
    %5 = arith.extsi %arg2 : i64 to i128
    %7 = arith.trunci %5 : i128 to i64
    %6 = arith.remsi %2, %7 : i64
    func.return %6 : i64
  }
  func.func @powmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %8 = arith.constant 1 : i32
    %10 = arith.extsi %8 : i32 to i64
    %9 = arith.remsi %10, %arg2 : i64
    %11 = llvm.mlir.constant(1 : i64) : i64
    %12 = llvm.alloca %11 x i64 : (i64) -> !llvm.ptr
    llvm.store %9, %12 : i64, !llvm.ptr
    %13 = arith.remsi %arg0, %arg2 : i64
    %14 = llvm.mlir.constant(1 : i64) : i64
    %15 = llvm.alloca %14 x i64 : (i64) -> !llvm.ptr
    llvm.store %13, %15 : i64, !llvm.ptr
    %16 = llvm.load %15 : !llvm.ptr -> i64
    %17 = arith.constant 0 : i32
    %19 = arith.extsi %17 : i32 to i64
    %18 = arith.cmpi slt, %16, %19 : i64
    cf.cond_br %18, ^bb0, ^bb1
    ^bb0:
      %20 = llvm.load %15 : !llvm.ptr -> i64
      %21 = arith.addi %20, %arg2 : i64
      llvm.store %21, %15 : i64, !llvm.ptr
      cf.br ^bb2
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %22 = llvm.mlir.constant(1 : i64) : i64
    %23 = llvm.alloca %22 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %23 : i64, !llvm.ptr
    cf.br ^bb3
    ^bb3:
    %24 = llvm.load %23 : !llvm.ptr -> i64
    %25 = arith.constant 0 : i32
    %27 = arith.extsi %25 : i32 to i64
    %26 = arith.cmpi sgt, %24, %27 : i64
    cf.cond_br %26, ^bb4, ^bb5
    ^bb4:
      %28 = llvm.load %23 : !llvm.ptr -> i64
      %29 = arith.constant 1 : i32
      %31 = arith.extsi %29 : i32 to i64
      %30 = arith.andi %28, %31 : i64
      %32 = arith.constant 1 : i32
      %34 = arith.extsi %32 : i32 to i64
      %33 = arith.cmpi eq, %30, %34 : i64
      cf.cond_br %33, ^bb6, ^bb7
      ^bb6:
        %36 = llvm.load %12 : !llvm.ptr -> i64
        %37 = llvm.load %15 : !llvm.ptr -> i64
        %35 = func.call @mulmod(%36, %37, %arg2) : (i64, i64, i64) -> i64
        llvm.store %35, %12 : i64, !llvm.ptr
        cf.br ^bb8
      ^bb7:
        cf.br ^bb8
      ^bb8:
      %39 = llvm.load %15 : !llvm.ptr -> i64
      %40 = llvm.load %15 : !llvm.ptr -> i64
      %38 = func.call @mulmod(%39, %40, %arg2) : (i64, i64, i64) -> i64
      llvm.store %38, %15 : i64, !llvm.ptr
      %41 = llvm.load %23 : !llvm.ptr -> i64
      %42 = arith.constant 1 : i32
      %44 = arith.extsi %42 : i32 to i64
      %43 = arith.shrsi %41, %44 : i64
      llvm.store %43, %23 : i64, !llvm.ptr
      cf.br ^bb3
    ^bb5:
    %45 = llvm.load %12 : !llvm.ptr -> i64
    func.return %45 : i64
  }
  func.func @inv_mod(%arg0: i64, %arg1: i64) -> i64 {
    %46 = arith.remsi %arg0, %arg1 : i64
    %47 = llvm.mlir.constant(1 : i64) : i64
    %48 = llvm.alloca %47 x i64 : (i64) -> !llvm.ptr
    llvm.store %46, %48 : i64, !llvm.ptr
    %49 = llvm.load %48 : !llvm.ptr -> i64
    %50 = arith.constant 0 : i32
    %52 = arith.extsi %50 : i32 to i64
    %51 = arith.cmpi slt, %49, %52 : i64
    cf.cond_br %51, ^bb9, ^bb10
    ^bb9:
      %53 = llvm.load %48 : !llvm.ptr -> i64
      %54 = arith.addi %53, %arg1 : i64
      llvm.store %54, %48 : i64, !llvm.ptr
      cf.br ^bb11
    ^bb10:
      cf.br ^bb11
    ^bb11:
    %55 = arith.constant 1 : i32
    %56 = arith.extsi %55 : i32 to i64
    %57 = llvm.mlir.constant(1 : i64) : i64
    %58 = llvm.alloca %57 x i64 : (i64) -> !llvm.ptr
    llvm.store %56, %58 : i64, !llvm.ptr
    %59 = arith.constant 0 : i32
    %60 = arith.extsi %59 : i32 to i64
    %61 = llvm.mlir.constant(1 : i64) : i64
    %62 = llvm.alloca %61 x i64 : (i64) -> !llvm.ptr
    llvm.store %60, %62 : i64, !llvm.ptr
    %63 = llvm.load %48 : !llvm.ptr -> i64
    %64 = llvm.mlir.constant(1 : i64) : i64
    %65 = llvm.alloca %64 x i64 : (i64) -> !llvm.ptr
    llvm.store %63, %65 : i64, !llvm.ptr
    %66 = llvm.mlir.constant(1 : i64) : i64
    %67 = llvm.alloca %66 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %67 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %68 = llvm.load %67 : !llvm.ptr -> i64
    %69 = arith.constant 0 : i32
    %71 = arith.extsi %69 : i32 to i64
    %70 = arith.cmpi ne, %68, %71 : i64
    cf.cond_br %70, ^bb13, ^bb14
    ^bb13:
      %72 = llvm.load %65 : !llvm.ptr -> i64
      %73 = llvm.load %67 : !llvm.ptr -> i64
      %74 = arith.divsi %72, %73 : i64
      %75 = llvm.load %65 : !llvm.ptr -> i64
      %76 = llvm.load %67 : !llvm.ptr -> i64
      %77 = arith.muli %74, %76 : i64
      %78 = arith.subi %75, %77 : i64
      %79 = llvm.load %67 : !llvm.ptr -> i64
      llvm.store %79, %65 : i64, !llvm.ptr
      llvm.store %78, %67 : i64, !llvm.ptr
      %80 = llvm.load %58 : !llvm.ptr -> i64
      %81 = llvm.load %62 : !llvm.ptr -> i64
      %82 = arith.muli %74, %81 : i64
      %83 = arith.subi %80, %82 : i64
      %84 = llvm.load %62 : !llvm.ptr -> i64
      llvm.store %84, %58 : i64, !llvm.ptr
      llvm.store %83, %62 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %85 = llvm.load %65 : !llvm.ptr -> i64
    %86 = arith.constant 1 : i32
    %88 = arith.extsi %86 : i32 to i64
    %87 = arith.cmpi ne, %85, %88 : i64
    cf.cond_br %87, ^bb15, ^bb16
    ^bb15:
      %89 = arith.constant 1 : i32
      %91 = arith.constant 0 : i32
      %90 = arith.subi %91, %89 : i32
      %92 = arith.extsi %90 : i32 to i64
      func.return %92 : i64
    ^bb16:
      cf.br ^bb17
    ^bb17:
    %93 = llvm.load %58 : !llvm.ptr -> i64
    %94 = arith.remsi %93, %arg1 : i64
    %95 = llvm.mlir.constant(1 : i64) : i64
    %96 = llvm.alloca %95 x i64 : (i64) -> !llvm.ptr
    llvm.store %94, %96 : i64, !llvm.ptr
    %97 = llvm.load %96 : !llvm.ptr -> i64
    %98 = arith.constant 0 : i32
    %100 = arith.extsi %98 : i32 to i64
    %99 = arith.cmpi slt, %97, %100 : i64
    cf.cond_br %99, ^bb18, ^bb19
    ^bb18:
      %101 = llvm.load %96 : !llvm.ptr -> i64
      %102 = arith.addi %101, %arg1 : i64
      llvm.store %102, %96 : i64, !llvm.ptr
      cf.br ^bb20
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %103 = llvm.load %96 : !llvm.ptr -> i64
    func.return %103 : i64
  }
  func.func @popcount(%arg0: i32) -> i32 {
    %104 = arith.constant 0 : i32
    %105 = llvm.mlir.constant(1 : i64) : i64
    %106 = llvm.alloca %105 x i32 : (i64) -> !llvm.ptr
    llvm.store %104, %106 : i32, !llvm.ptr
    %107 = llvm.mlir.constant(1 : i64) : i64
    %108 = llvm.alloca %107 x i32 : (i64) -> !llvm.ptr
    llvm.store %arg0, %108 : i32, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %109 = llvm.load %108 : !llvm.ptr -> i32
    %110 = arith.constant 0 : i32
    %111 = arith.cmpi ne, %109, %110 : i32
    cf.cond_br %111, ^bb22, ^bb23
    ^bb22:
      %112 = llvm.load %106 : !llvm.ptr -> i32
      %113 = arith.constant 1 : i32
      %114 = arith.addi %112, %113 : i32
      llvm.store %114, %106 : i32, !llvm.ptr
      %115 = llvm.load %108 : !llvm.ptr -> i32
      %116 = llvm.load %108 : !llvm.ptr -> i32
      %117 = arith.constant 1 : i32
      %118 = arith.subi %116, %117 : i32
      %119 = arith.andi %115, %118 : i32
      llvm.store %119, %108 : i32, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %120 = llvm.load %106 : !llvm.ptr -> i32
    func.return %120 : i32
  }
  func.func @strip_p(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> () {
    %121 = arith.constant 0 : i32
    %122 = arith.extsi %121 : i32 to i64
    %123 = llvm.getelementptr %arg2[%122] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %arg0, %123 : i64, !llvm.ptr
    %124 = arith.constant 0 : i32
    %125 = arith.constant 0 : i32
    %126 = arith.extsi %125 : i32 to i64
    %127 = llvm.getelementptr %arg3[%126] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    llvm.store %124, %127 : i32, !llvm.ptr
    cf.br ^bb24
    ^bb24:
    %129 = arith.constant 0 : i32
    %130 = arith.extsi %129 : i32 to i64
    %131 = llvm.getelementptr %arg2[%130] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %128 = llvm.load %131 : !llvm.ptr -> i64
    %132 = arith.remsi %128, %arg1 : i64
    %133 = arith.constant 0 : i32
    %135 = arith.extsi %133 : i32 to i64
    %134 = arith.cmpi eq, %132, %135 : i64
    cf.cond_br %134, ^bb25, ^bb26
    ^bb25:
      %137 = arith.constant 0 : i32
      %138 = arith.extsi %137 : i32 to i64
      %139 = llvm.getelementptr %arg2[%138] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %136 = llvm.load %139 : !llvm.ptr -> i64
      %140 = arith.divsi %136, %arg1 : i64
      %141 = arith.constant 0 : i32
      %142 = arith.extsi %141 : i32 to i64
      %143 = llvm.getelementptr %arg2[%142] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %140, %143 : i64, !llvm.ptr
      %145 = arith.constant 0 : i32
      %146 = arith.extsi %145 : i32 to i64
      %147 = llvm.getelementptr %arg3[%146] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %144 = llvm.load %147 : !llvm.ptr -> i32
      %148 = arith.constant 1 : i32
      %149 = arith.addi %144, %148 : i32
      %150 = arith.constant 0 : i32
      %151 = arith.extsi %150 : i32 to i64
      %152 = llvm.getelementptr %arg3[%151] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %149, %152 : i32, !llvm.ptr
      cf.br ^bb24
    ^bb26:
    func.return
  }
  func.func @factor_prime_powers(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> i32 {
    %153 = arith.constant 0 : i32
    %154 = llvm.mlir.constant(1 : i64) : i64
    %155 = llvm.alloca %154 x i32 : (i64) -> !llvm.ptr
    llvm.store %153, %155 : i32, !llvm.ptr
    %156 = llvm.mlir.constant(1 : i64) : i64
    %157 = llvm.alloca %156 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %157 : i64, !llvm.ptr
    %158 = arith.constant 2 : i32
    %159 = arith.extsi %158 : i32 to i64
    %160 = llvm.mlir.constant(1 : i64) : i64
    %161 = llvm.alloca %160 x i64 : (i64) -> !llvm.ptr
    llvm.store %159, %161 : i64, !llvm.ptr
    cf.br ^bb27
    ^bb27:
    %162 = llvm.load %161 : !llvm.ptr -> i64
    %163 = llvm.load %161 : !llvm.ptr -> i64
    %164 = arith.muli %162, %163 : i64
    %165 = llvm.load %157 : !llvm.ptr -> i64
    %166 = arith.cmpi sle, %164, %165 : i64
    cf.cond_br %166, ^bb28, ^bb29
    ^bb28:
      %167 = llvm.load %157 : !llvm.ptr -> i64
      %168 = llvm.load %161 : !llvm.ptr -> i64
      %169 = arith.remsi %167, %168 : i64
      %170 = arith.constant 0 : i32
      %172 = arith.extsi %170 : i32 to i64
      %171 = arith.cmpi eq, %169, %172 : i64
      cf.cond_br %171, ^bb30, ^bb31
      ^bb30:
        %173 = arith.constant 1 : i32
        %174 = arith.extsi %173 : i32 to i64
        %175 = llvm.mlir.constant(1 : i64) : i64
        %176 = llvm.alloca %175 x i64 : (i64) -> !llvm.ptr
        llvm.store %174, %176 : i64, !llvm.ptr
        cf.br ^bb33
        ^bb33:
        %177 = llvm.load %157 : !llvm.ptr -> i64
        %178 = llvm.load %161 : !llvm.ptr -> i64
        %179 = arith.remsi %177, %178 : i64
        %180 = arith.constant 0 : i32
        %182 = arith.extsi %180 : i32 to i64
        %181 = arith.cmpi eq, %179, %182 : i64
        cf.cond_br %181, ^bb34, ^bb35
        ^bb34:
          %183 = llvm.load %157 : !llvm.ptr -> i64
          %184 = llvm.load %161 : !llvm.ptr -> i64
          %185 = arith.divsi %183, %184 : i64
          llvm.store %185, %157 : i64, !llvm.ptr
          %186 = llvm.load %176 : !llvm.ptr -> i64
          %187 = llvm.load %161 : !llvm.ptr -> i64
          %188 = arith.muli %186, %187 : i64
          llvm.store %188, %176 : i64, !llvm.ptr
          cf.br ^bb33
        ^bb35:
        %189 = llvm.load %161 : !llvm.ptr -> i64
        %190 = llvm.load %155 : !llvm.ptr -> i32
        %191 = arith.extsi %190 : i32 to i64
        %192 = llvm.getelementptr %arg1[%191] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %189, %192 : i64, !llvm.ptr
        %193 = llvm.load %176 : !llvm.ptr -> i64
        %194 = llvm.load %155 : !llvm.ptr -> i32
        %195 = arith.extsi %194 : i32 to i64
        %196 = llvm.getelementptr %arg2[%195] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %193, %196 : i64, !llvm.ptr
        %197 = llvm.load %155 : !llvm.ptr -> i32
        %198 = arith.constant 1 : i32
        %199 = arith.addi %197, %198 : i32
        llvm.store %199, %155 : i32, !llvm.ptr
        cf.br ^bb32
      ^bb31:
        cf.br ^bb32
      ^bb32:
      %200 = llvm.load %161 : !llvm.ptr -> i64
      %201 = arith.constant 2 : i32
      %203 = arith.extsi %201 : i32 to i64
      %202 = arith.cmpi eq, %200, %203 : i64
      cf.cond_br %202, ^bb36, ^bb37
      ^bb36:
        %204 = arith.constant 3 : i32
        %205 = arith.extsi %204 : i32 to i64
        llvm.store %205, %161 : i64, !llvm.ptr
        cf.br ^bb38
      ^bb37:
        %206 = llvm.load %161 : !llvm.ptr -> i64
        %207 = arith.constant 2 : i32
        %209 = arith.extsi %207 : i32 to i64
        %208 = arith.addi %206, %209 : i64
        llvm.store %208, %161 : i64, !llvm.ptr
        cf.br ^bb38
      ^bb38:
      cf.br ^bb27
    ^bb29:
    %210 = llvm.load %157 : !llvm.ptr -> i64
    %211 = arith.constant 1 : i32
    %213 = arith.extsi %211 : i32 to i64
    %212 = arith.cmpi sgt, %210, %213 : i64
    cf.cond_br %212, ^bb39, ^bb40
    ^bb39:
      %214 = llvm.load %157 : !llvm.ptr -> i64
      %215 = llvm.load %155 : !llvm.ptr -> i32
      %216 = arith.extsi %215 : i32 to i64
      %217 = llvm.getelementptr %arg1[%216] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %214, %217 : i64, !llvm.ptr
      %218 = llvm.load %157 : !llvm.ptr -> i64
      %219 = llvm.load %155 : !llvm.ptr -> i32
      %220 = arith.extsi %219 : i32 to i64
      %221 = llvm.getelementptr %arg2[%220] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %218, %221 : i64, !llvm.ptr
      %222 = llvm.load %155 : !llvm.ptr -> i32
      %223 = arith.constant 1 : i32
      %224 = arith.addi %222, %223 : i32
      llvm.store %224, %155 : i32, !llvm.ptr
      cf.br ^bb41
    ^bb40:
      cf.br ^bb41
    ^bb41:
    %225 = llvm.load %155 : !llvm.ptr -> i32
    func.return %225 : i32
  }
  func.func @compute_grundy(%arg0: !llvm.ptr, %arg1: i32, %arg2: i32) -> () {
    %226 = arith.constant 1 : i32
    %227 = llvm.mlir.constant(1 : i64) : i64
    %228 = llvm.alloca %227 x i32 : (i64) -> !llvm.ptr
    llvm.store %226, %228 : i32, !llvm.ptr
    cf.br ^bb42
    ^bb42:
    %229 = llvm.load %228 : !llvm.ptr -> i32
    %230 = arith.cmpi sle, %229, %arg1 : i32
    cf.cond_br %230, ^bb43, ^bb44
    ^bb43:
      %231 = arith.constant 0 : i32
      %232 = llvm.mlir.constant(1 : i64) : i64
      %233 = llvm.alloca %232 x i32 : (i64) -> !llvm.ptr
      llvm.store %231, %233 : i32, !llvm.ptr
      %234 = llvm.load %228 : !llvm.ptr -> i32
      %235 = arith.constant 1 : i32
      %236 = arith.cmpi sge, %234, %235 : i32
      cf.cond_br %236, ^bb45, ^bb46
      ^bb45:
        %237 = llvm.load %233 : !llvm.ptr -> i32
        %238 = arith.constant 1 : i32
        %240 = llvm.load %228 : !llvm.ptr -> i32
        %241 = arith.constant 1 : i32
        %242 = arith.subi %240, %241 : i32
        %243 = arith.extsi %242 : i32 to i64
        %244 = llvm.getelementptr %arg0[%243] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %239 = llvm.load %244 : !llvm.ptr -> i32
        %245 = arith.shli %238, %239 : i32
        %246 = arith.ori %237, %245 : i32
        llvm.store %246, %233 : i32, !llvm.ptr
        cf.br ^bb47
      ^bb46:
        cf.br ^bb47
      ^bb47:
      %247 = llvm.load %228 : !llvm.ptr -> i32
      %248 = arith.constant 2 : i32
      %249 = arith.cmpi sge, %247, %248 : i32
      cf.cond_br %249, ^bb48, ^bb49
      ^bb48:
        %250 = llvm.load %233 : !llvm.ptr -> i32
        %251 = arith.constant 1 : i32
        %253 = llvm.load %228 : !llvm.ptr -> i32
        %254 = arith.constant 2 : i32
        %255 = arith.subi %253, %254 : i32
        %256 = arith.extsi %255 : i32 to i64
        %257 = llvm.getelementptr %arg0[%256] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %252 = llvm.load %257 : !llvm.ptr -> i32
        %258 = arith.shli %251, %252 : i32
        %259 = arith.ori %250, %258 : i32
        llvm.store %259, %233 : i32, !llvm.ptr
        cf.br ^bb50
      ^bb49:
        cf.br ^bb50
      ^bb50:
      %260 = llvm.load %228 : !llvm.ptr -> i32
      %261 = arith.constant 4 : i32
      %262 = arith.cmpi sge, %260, %261 : i32
      cf.cond_br %262, ^bb51, ^bb52
      ^bb51:
        %263 = llvm.load %233 : !llvm.ptr -> i32
        %264 = arith.constant 1 : i32
        %266 = llvm.load %228 : !llvm.ptr -> i32
        %267 = arith.constant 4 : i32
        %268 = arith.subi %266, %267 : i32
        %269 = arith.extsi %268 : i32 to i64
        %270 = llvm.getelementptr %arg0[%269] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %265 = llvm.load %270 : !llvm.ptr -> i32
        %271 = arith.shli %264, %265 : i32
        %272 = arith.ori %263, %271 : i32
        llvm.store %272, %233 : i32, !llvm.ptr
        cf.br ^bb53
      ^bb52:
        cf.br ^bb53
      ^bb53:
      %273 = llvm.load %228 : !llvm.ptr -> i32
      %274 = arith.constant 9 : i32
      %275 = arith.cmpi sge, %273, %274 : i32
      cf.cond_br %275, ^bb54, ^bb55
      ^bb54:
        %276 = llvm.load %233 : !llvm.ptr -> i32
        %277 = arith.constant 1 : i32
        %279 = llvm.load %228 : !llvm.ptr -> i32
        %280 = arith.constant 9 : i32
        %281 = arith.subi %279, %280 : i32
        %282 = arith.extsi %281 : i32 to i64
        %283 = llvm.getelementptr %arg0[%282] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %278 = llvm.load %283 : !llvm.ptr -> i32
        %284 = arith.shli %277, %278 : i32
        %285 = arith.ori %276, %284 : i32
        llvm.store %285, %233 : i32, !llvm.ptr
        cf.br ^bb56
      ^bb55:
        cf.br ^bb56
      ^bb56:
      %286 = llvm.load %228 : !llvm.ptr -> i32
      %287 = arith.constant 1 : i32
      %288 = arith.subi %286, %287 : i32
      %289 = llvm.mlir.constant(1 : i64) : i64
      %290 = llvm.alloca %289 x i32 : (i64) -> !llvm.ptr
      llvm.store %288, %290 : i32, !llvm.ptr
      %291 = arith.constant 0 : i32
      %292 = arith.cmpi sgt, %arg2, %291 : i32
      %293 = scf.if %292 -> (i1) {
        %294 = llvm.load %228 : !llvm.ptr -> i32
        %295 = arith.constant 1 : i32
        %296 = arith.subi %294, %295 : i32
        %297 = arith.cmpi slt, %arg2, %296 : i32
        scf.yield %297 : i1
      } else {
        %298 = arith.constant false
        scf.yield %298 : i1
      }
      cf.cond_br %293, ^bb57, ^bb58
      ^bb57:
        llvm.store %arg2, %290 : i32, !llvm.ptr
        cf.br ^bb59
      ^bb58:
        cf.br ^bb59
      ^bb59:
      %299 = arith.constant 1 : i32
      %300 = llvm.mlir.constant(1 : i64) : i64
      %301 = llvm.alloca %300 x i32 : (i64) -> !llvm.ptr
      llvm.store %299, %301 : i32, !llvm.ptr
      cf.br ^bb60
      ^bb60:
      %302 = llvm.load %301 : !llvm.ptr -> i32
      %303 = llvm.load %290 : !llvm.ptr -> i32
      %304 = arith.cmpi sle, %302, %303 : i32
      cf.cond_br %304, ^bb61, ^bb62
      ^bb61:
        %305 = llvm.load %233 : !llvm.ptr -> i32
        %306 = arith.constant 1 : i32
        %308 = llvm.load %301 : !llvm.ptr -> i32
        %309 = arith.extsi %308 : i32 to i64
        %310 = llvm.getelementptr %arg0[%309] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %307 = llvm.load %310 : !llvm.ptr -> i32
        %312 = llvm.load %228 : !llvm.ptr -> i32
        %313 = llvm.load %301 : !llvm.ptr -> i32
        %314 = arith.subi %312, %313 : i32
        %315 = arith.extsi %314 : i32 to i64
        %316 = llvm.getelementptr %arg0[%315] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %311 = llvm.load %316 : !llvm.ptr -> i32
        %317 = arith.xori %307, %311 : i32
        %318 = arith.shli %306, %317 : i32
        %319 = arith.ori %305, %318 : i32
        llvm.store %319, %233 : i32, !llvm.ptr
        %320 = llvm.load %301 : !llvm.ptr -> i32
        %321 = arith.constant 1 : i32
        %322 = arith.addi %320, %321 : i32
        llvm.store %322, %301 : i32, !llvm.ptr
        cf.br ^bb60
      ^bb62:
      %323 = arith.constant 0 : i32
      %324 = llvm.mlir.constant(1 : i64) : i64
      %325 = llvm.alloca %324 x i32 : (i64) -> !llvm.ptr
      llvm.store %323, %325 : i32, !llvm.ptr
      cf.br ^bb63
      ^bb63:
      %326 = llvm.load %233 : !llvm.ptr -> i32
      %327 = llvm.load %325 : !llvm.ptr -> i32
      %328 = arith.shrsi %326, %327 : i32
      %329 = arith.constant 1 : i32
      %330 = arith.andi %328, %329 : i32
      %331 = arith.constant 1 : i32
      %332 = arith.cmpi eq, %330, %331 : i32
      cf.cond_br %332, ^bb64, ^bb65
      ^bb64:
        %333 = llvm.load %325 : !llvm.ptr -> i32
        %334 = arith.constant 1 : i32
        %335 = arith.addi %333, %334 : i32
        llvm.store %335, %325 : i32, !llvm.ptr
        cf.br ^bb63
      ^bb65:
      %336 = llvm.load %325 : !llvm.ptr -> i32
      %337 = llvm.load %228 : !llvm.ptr -> i32
      %338 = arith.extsi %337 : i32 to i64
      %339 = llvm.getelementptr %arg0[%338] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %336, %339 : i32, !llvm.ptr
      %340 = llvm.load %228 : !llvm.ptr -> i32
      %341 = arith.constant 1 : i32
      %342 = arith.addi %340, %341 : i32
      llvm.store %342, %228 : i32, !llvm.ptr
      cf.br ^bb42
    ^bb44:
    func.return
  }
  // Module static: dt_p
  llvm.mlir.global internal @dt_p() {addr_space = 0 : i32} : !llvm.ptr {
    %343 = llvm.mlir.zero : !llvm.ptr
    llvm.return %343 : !llvm.ptr
  }
  // Module static: dt_pe
  llvm.mlir.global internal @dt_pe() {addr_space = 0 : i32} : !llvm.ptr {
    %344 = llvm.mlir.zero : !llvm.ptr
    llvm.return %344 : !llvm.ptr
  }
  // Module static: dt_den_free
  llvm.mlir.global internal @dt_den_free() {addr_space = 0 : i32} : !llvm.ptr {
    %345 = llvm.mlir.zero : !llvm.ptr
    llvm.return %345 : !llvm.ptr
  }
  // Module static: dt_den_v
  llvm.mlir.global internal @dt_den_v() {addr_space = 0 : i32} : !llvm.ptr {
    %346 = llvm.mlir.zero : !llvm.ptr
    llvm.return %346 : !llvm.ptr
  }
  // Module static: dt_inv_free
  llvm.mlir.global internal @dt_inv_free() {addr_space = 0 : i32} : !llvm.ptr {
    %347 = llvm.mlir.zero : !llvm.ptr
    llvm.return %347 : !llvm.ptr
  }
  func.func @precompute_den_tables(%arg0: i32, %arg1: i64, %arg2: i64, %arg3: i32) -> () {
    %348 = llvm.mlir.addressof @dt_p : !llvm.ptr
    %349 = llvm.load %348 : !llvm.ptr -> !llvm.ptr
    %350 = arith.extsi %arg0 : i32 to i64
    %351 = llvm.getelementptr %349[%350] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %arg1, %351 : i64, !llvm.ptr
    %352 = llvm.mlir.addressof @dt_pe : !llvm.ptr
    %353 = llvm.load %352 : !llvm.ptr -> !llvm.ptr
    %354 = arith.extsi %arg0 : i32 to i64
    %355 = llvm.getelementptr %353[%354] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %arg2, %355 : i64, !llvm.ptr
    %357 = arith.constant 1 : i32
    %358 = arith.addi %arg3, %357 : i32
    %359 = arith.extsi %358 : i32 to i64
    %360 = arith.constant 8 : i32
    %362 = arith.extsi %360 : i32 to i64
    %361 = arith.muli %359, %362 : i64
    %356 = func.call @malloc(%361) : (i64) -> !llvm.ptr
    %363 = llvm.mlir.addressof @dt_den_free : !llvm.ptr
    %364 = llvm.load %363 : !llvm.ptr -> !llvm.ptr
    %365 = arith.extsi %arg0 : i32 to i64
    %366 = llvm.getelementptr %364[%365] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
    llvm.store %356, %366 : !llvm.ptr, !llvm.ptr
    %368 = arith.constant 1 : i32
    %369 = arith.addi %arg3, %368 : i32
    %370 = arith.extsi %369 : i32 to i64
    %371 = arith.constant 4 : i32
    %373 = arith.extsi %371 : i32 to i64
    %372 = arith.muli %370, %373 : i64
    %367 = func.call @malloc(%372) : (i64) -> !llvm.ptr
    %374 = llvm.mlir.addressof @dt_den_v : !llvm.ptr
    %375 = llvm.load %374 : !llvm.ptr -> !llvm.ptr
    %376 = arith.extsi %arg0 : i32 to i64
    %377 = llvm.getelementptr %375[%376] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
    llvm.store %367, %377 : !llvm.ptr, !llvm.ptr
    %379 = arith.constant 1 : i32
    %380 = arith.addi %arg3, %379 : i32
    %381 = arith.extsi %380 : i32 to i64
    %382 = arith.constant 8 : i32
    %384 = arith.extsi %382 : i32 to i64
    %383 = arith.muli %381, %384 : i64
    %378 = func.call @malloc(%383) : (i64) -> !llvm.ptr
    %385 = llvm.mlir.addressof @dt_inv_free : !llvm.ptr
    %386 = llvm.load %385 : !llvm.ptr -> !llvm.ptr
    %387 = arith.extsi %arg0 : i32 to i64
    %388 = llvm.getelementptr %386[%387] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
    llvm.store %378, %388 : !llvm.ptr, !llvm.ptr
    %389 = arith.constant 1 : i32
    %391 = llvm.mlir.addressof @dt_den_free : !llvm.ptr
    %392 = llvm.load %391 : !llvm.ptr -> !llvm.ptr
    %393 = arith.extsi %arg0 : i32 to i64
    %394 = llvm.getelementptr %392[%393] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
    %390 = llvm.load %394 : !llvm.ptr -> !llvm.ptr
    %395 = arith.constant 0 : i32
    %396 = arith.extsi %389 : i32 to i64
    %397 = arith.extsi %395 : i32 to i64
    %398 = llvm.getelementptr %390[%397] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %396, %398 : i64, !llvm.ptr
    %399 = arith.constant 1 : i32
    %401 = llvm.mlir.addressof @dt_inv_free : !llvm.ptr
    %402 = llvm.load %401 : !llvm.ptr -> !llvm.ptr
    %403 = arith.extsi %arg0 : i32 to i64
    %404 = llvm.getelementptr %402[%403] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
    %400 = llvm.load %404 : !llvm.ptr -> !llvm.ptr
    %405 = arith.constant 0 : i32
    %406 = arith.extsi %399 : i32 to i64
    %407 = arith.extsi %405 : i32 to i64
    %408 = llvm.getelementptr %400[%407] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %406, %408 : i64, !llvm.ptr
    %409 = arith.constant 1 : i32
    %410 = llvm.mlir.constant(1 : i64) : i64
    %411 = llvm.alloca %410 x i32 : (i64) -> !llvm.ptr
    llvm.store %409, %411 : i32, !llvm.ptr
    cf.br ^bb66
    ^bb66:
    %412 = llvm.load %411 : !llvm.ptr -> i32
    %413 = arith.cmpi sle, %412, %arg3 : i32
    cf.cond_br %413, ^bb67, ^bb68
    ^bb67:
      %415 = arith.constant 8 : i32
      %416 = arith.extsi %415 : i32 to i64
      %414 = func.call @malloc(%416) : (i64) -> !llvm.ptr
      %418 = arith.constant 4 : i32
      %419 = arith.extsi %418 : i32 to i64
      %417 = func.call @malloc(%419) : (i64) -> !llvm.ptr
      %421 = llvm.load %411 : !llvm.ptr -> i32
      %422 = arith.extsi %421 : i32 to i64
      func.call @strip_p(%422, %arg1, %414, %417) : (i64, i64, !llvm.ptr, !llvm.ptr) -> ()
      %424 = arith.constant 0 : i32
      %425 = arith.extsi %424 : i32 to i64
      %426 = llvm.getelementptr %414[%425] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %423 = llvm.load %426 : !llvm.ptr -> i64
      %428 = llvm.mlir.addressof @dt_den_free : !llvm.ptr
      %429 = llvm.load %428 : !llvm.ptr -> !llvm.ptr
      %430 = arith.extsi %arg0 : i32 to i64
      %431 = llvm.getelementptr %429[%430] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
      %427 = llvm.load %431 : !llvm.ptr -> !llvm.ptr
      %432 = llvm.load %411 : !llvm.ptr -> i32
      %433 = arith.extsi %432 : i32 to i64
      %434 = llvm.getelementptr %427[%433] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %423, %434 : i64, !llvm.ptr
      %436 = arith.constant 0 : i32
      %437 = arith.extsi %436 : i32 to i64
      %438 = llvm.getelementptr %417[%437] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %435 = llvm.load %438 : !llvm.ptr -> i32
      %440 = llvm.mlir.addressof @dt_den_v : !llvm.ptr
      %441 = llvm.load %440 : !llvm.ptr -> !llvm.ptr
      %442 = arith.extsi %arg0 : i32 to i64
      %443 = llvm.getelementptr %441[%442] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
      %439 = llvm.load %443 : !llvm.ptr -> !llvm.ptr
      %444 = llvm.load %411 : !llvm.ptr -> i32
      %445 = arith.extsi %444 : i32 to i64
      %446 = llvm.getelementptr %439[%445] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %435, %446 : i32, !llvm.ptr
      %449 = arith.constant 0 : i32
      %450 = arith.extsi %449 : i32 to i64
      %451 = llvm.getelementptr %414[%450] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %448 = llvm.load %451 : !llvm.ptr -> i64
      %452 = arith.remsi %448, %arg2 : i64
      %447 = func.call @inv_mod(%452, %arg2) : (i64, i64) -> i64
      %454 = llvm.mlir.addressof @dt_inv_free : !llvm.ptr
      %455 = llvm.load %454 : !llvm.ptr -> !llvm.ptr
      %456 = arith.extsi %arg0 : i32 to i64
      %457 = llvm.getelementptr %455[%456] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
      %453 = llvm.load %457 : !llvm.ptr -> !llvm.ptr
      %458 = llvm.load %411 : !llvm.ptr -> i32
      %459 = arith.extsi %458 : i32 to i64
      %460 = llvm.getelementptr %453[%459] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %447, %460 : i64, !llvm.ptr
      func.call @free(%414) : (!llvm.ptr) -> ()
      func.call @free(%417) : (!llvm.ptr) -> ()
      %463 = llvm.load %411 : !llvm.ptr -> i32
      %464 = arith.constant 1 : i32
      %465 = arith.addi %463, %464 : i32
      llvm.store %465, %411 : i32, !llvm.ptr
      cf.br ^bb66
    ^bb68:
    func.return
  }
  func.func @coeff_term_mod_prime_power(%arg0: i64, %arg1: i32, %arg2: i64, %arg3: i32) -> i64 {
    %467 = llvm.mlir.addressof @dt_p : !llvm.ptr
    %468 = llvm.load %467 : !llvm.ptr -> !llvm.ptr
    %469 = arith.extsi %arg3 : i32 to i64
    %470 = llvm.getelementptr %468[%469] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %466 = llvm.load %470 : !llvm.ptr -> i64
    %472 = llvm.mlir.addressof @dt_pe : !llvm.ptr
    %473 = llvm.load %472 : !llvm.ptr -> !llvm.ptr
    %474 = arith.extsi %arg3 : i32 to i64
    %475 = llvm.getelementptr %473[%474] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %471 = llvm.load %475 : !llvm.ptr -> i64
    %476 = arith.subi %arg0, %arg2 : i64
    %478 = arith.constant 1 : i32
    %479 = arith.addi %arg1, %478 : i32
    %480 = arith.extsi %479 : i32 to i64
    %481 = arith.constant 8 : i32
    %482 = arith.extsi %481 : i32 to i64
    %477 = func.call @calloc(%480, %482) : (i64, i64) -> !llvm.ptr
    %484 = arith.constant 1 : i32
    %485 = arith.addi %arg1, %484 : i32
    %486 = arith.extsi %485 : i32 to i64
    %487 = arith.constant 8 : i32
    %488 = arith.extsi %487 : i32 to i64
    %483 = func.call @calloc(%486, %488) : (i64, i64) -> !llvm.ptr
    %489 = arith.constant 1 : i32
    %491 = arith.extsi %489 : i32 to i64
    %490 = arith.remsi %491, %471 : i64
    %492 = arith.constant 0 : i32
    %493 = arith.extsi %492 : i32 to i64
    %494 = llvm.getelementptr %477[%493] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %490, %494 : i64, !llvm.ptr
    %495 = arith.constant 0 : i32
    %497 = arith.extsi %495 : i32 to i64
    %496 = arith.cmpi ne, %arg2, %497 : i64
    cf.cond_br %496, ^bb69, ^bb70
    ^bb69:
      %498 = arith.constant 1 : i32
      %500 = arith.extsi %498 : i32 to i64
      %499 = arith.remsi %500, %471 : i64
      %501 = llvm.mlir.constant(1 : i64) : i64
      %502 = llvm.alloca %501 x i64 : (i64) -> !llvm.ptr
      llvm.store %499, %502 : i64, !llvm.ptr
      %503 = arith.constant 0 : i32
      %504 = llvm.mlir.constant(1 : i64) : i64
      %505 = llvm.alloca %504 x i32 : (i64) -> !llvm.ptr
      llvm.store %503, %505 : i32, !llvm.ptr
      %506 = arith.constant 1 : i32
      %507 = llvm.mlir.constant(1 : i64) : i64
      %508 = llvm.alloca %507 x i32 : (i64) -> !llvm.ptr
      llvm.store %506, %508 : i32, !llvm.ptr
      cf.br ^bb72
      ^bb72:
      %509 = llvm.load %508 : !llvm.ptr -> i32
      %510 = arith.cmpi sle, %509, %arg1 : i32
      cf.cond_br %510, ^bb73, ^bb74
      ^bb73:
        %511 = llvm.load %508 : !llvm.ptr -> i32
        %512 = arith.extsi %511 : i32 to i64
        %513 = arith.addi %arg2, %512 : i64
        %514 = arith.constant 1 : i32
        %516 = arith.extsi %514 : i32 to i64
        %515 = arith.subi %513, %516 : i64
        %518 = arith.constant 8 : i32
        %519 = arith.extsi %518 : i32 to i64
        %517 = func.call @malloc(%519) : (i64) -> !llvm.ptr
        %521 = arith.constant 4 : i32
        %522 = arith.extsi %521 : i32 to i64
        %520 = func.call @malloc(%522) : (i64) -> !llvm.ptr
        func.call @strip_p(%515, %466, %517, %520) : (i64, i64, !llvm.ptr, !llvm.ptr) -> ()
        %524 = llvm.load %505 : !llvm.ptr -> i32
        %526 = arith.constant 0 : i32
        %527 = arith.extsi %526 : i32 to i64
        %528 = llvm.getelementptr %520[%527] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %525 = llvm.load %528 : !llvm.ptr -> i32
        %529 = arith.addi %524, %525 : i32
        llvm.store %529, %505 : i32, !llvm.ptr
        %530 = llvm.load %505 : !llvm.ptr -> i32
        %533 = llvm.mlir.addressof @dt_den_v : !llvm.ptr
        %534 = llvm.load %533 : !llvm.ptr -> !llvm.ptr
        %535 = arith.extsi %arg3 : i32 to i64
        %536 = llvm.getelementptr %534[%535] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
        %532 = llvm.load %536 : !llvm.ptr -> !llvm.ptr
        %537 = llvm.load %508 : !llvm.ptr -> i32
        %538 = arith.extsi %537 : i32 to i64
        %539 = llvm.getelementptr %532[%538] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %531 = llvm.load %539 : !llvm.ptr -> i32
        %540 = arith.subi %530, %531 : i32
        llvm.store %540, %505 : i32, !llvm.ptr
        %542 = llvm.load %502 : !llvm.ptr -> i64
        %544 = arith.constant 0 : i32
        %545 = arith.extsi %544 : i32 to i64
        %546 = llvm.getelementptr %517[%545] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %543 = llvm.load %546 : !llvm.ptr -> i64
        %547 = arith.remsi %543, %471 : i64
        %541 = func.call @mulmod(%542, %547, %471) : (i64, i64, i64) -> i64
        llvm.store %541, %502 : i64, !llvm.ptr
        %549 = llvm.load %502 : !llvm.ptr -> i64
        %552 = llvm.mlir.addressof @dt_inv_free : !llvm.ptr
        %553 = llvm.load %552 : !llvm.ptr -> !llvm.ptr
        %554 = arith.extsi %arg3 : i32 to i64
        %555 = llvm.getelementptr %553[%554] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
        %551 = llvm.load %555 : !llvm.ptr -> !llvm.ptr
        %556 = llvm.load %508 : !llvm.ptr -> i32
        %557 = arith.extsi %556 : i32 to i64
        %558 = llvm.getelementptr %551[%557] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %550 = llvm.load %558 : !llvm.ptr -> i64
        %548 = func.call @mulmod(%549, %550, %471) : (i64, i64, i64) -> i64
        llvm.store %548, %502 : i64, !llvm.ptr
        %560 = llvm.load %502 : !llvm.ptr -> i64
        %562 = llvm.load %505 : !llvm.ptr -> i32
        %563 = arith.extsi %562 : i32 to i64
        %561 = func.call @powmod(%466, %563, %471) : (i64, i64, i64) -> i64
        %559 = func.call @mulmod(%560, %561, %471) : (i64, i64, i64) -> i64
        %564 = llvm.load %508 : !llvm.ptr -> i32
        %565 = arith.extsi %564 : i32 to i64
        %566 = llvm.getelementptr %477[%565] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %559, %566 : i64, !llvm.ptr
        func.call @free(%517) : (!llvm.ptr) -> ()
        func.call @free(%520) : (!llvm.ptr) -> ()
        %569 = llvm.load %508 : !llvm.ptr -> i32
        %570 = arith.constant 1 : i32
        %571 = arith.addi %569, %570 : i32
        llvm.store %571, %508 : i32, !llvm.ptr
        cf.br ^bb72
      ^bb74:
      cf.br ^bb71
    ^bb70:
      cf.br ^bb71
    ^bb71:
    %572 = arith.constant 1 : i32
    %574 = arith.extsi %572 : i32 to i64
    %573 = arith.remsi %574, %471 : i64
    %575 = arith.constant 0 : i32
    %576 = arith.extsi %575 : i32 to i64
    %577 = llvm.getelementptr %483[%576] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %573, %577 : i64, !llvm.ptr
    %578 = arith.constant 0 : i32
    %580 = arith.extsi %578 : i32 to i64
    %579 = arith.cmpi ne, %476, %580 : i64
    cf.cond_br %579, ^bb75, ^bb76
    ^bb75:
      %581 = arith.constant 1 : i32
      %583 = arith.extsi %581 : i32 to i64
      %582 = arith.remsi %583, %471 : i64
      %584 = llvm.mlir.constant(1 : i64) : i64
      %585 = llvm.alloca %584 x i64 : (i64) -> !llvm.ptr
      llvm.store %582, %585 : i64, !llvm.ptr
      %586 = arith.constant 0 : i32
      %587 = llvm.mlir.constant(1 : i64) : i64
      %588 = llvm.alloca %587 x i32 : (i64) -> !llvm.ptr
      llvm.store %586, %588 : i32, !llvm.ptr
      %589 = arith.constant 1 : i32
      %590 = llvm.mlir.constant(1 : i64) : i64
      %591 = llvm.alloca %590 x i32 : (i64) -> !llvm.ptr
      llvm.store %589, %591 : i32, !llvm.ptr
      cf.br ^bb78
      ^bb78:
      %592 = llvm.load %591 : !llvm.ptr -> i32
      %593 = arith.cmpi sle, %592, %arg1 : i32
      cf.cond_br %593, ^bb79, ^bb80
      ^bb79:
        %594 = llvm.load %591 : !llvm.ptr -> i32
        %595 = arith.extsi %594 : i32 to i64
        %596 = arith.addi %476, %595 : i64
        %597 = arith.constant 1 : i32
        %599 = arith.extsi %597 : i32 to i64
        %598 = arith.subi %596, %599 : i64
        %601 = arith.constant 8 : i32
        %602 = arith.extsi %601 : i32 to i64
        %600 = func.call @malloc(%602) : (i64) -> !llvm.ptr
        %604 = arith.constant 4 : i32
        %605 = arith.extsi %604 : i32 to i64
        %603 = func.call @malloc(%605) : (i64) -> !llvm.ptr
        func.call @strip_p(%598, %466, %600, %603) : (i64, i64, !llvm.ptr, !llvm.ptr) -> ()
        %607 = llvm.load %588 : !llvm.ptr -> i32
        %609 = arith.constant 0 : i32
        %610 = arith.extsi %609 : i32 to i64
        %611 = llvm.getelementptr %603[%610] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %608 = llvm.load %611 : !llvm.ptr -> i32
        %612 = arith.addi %607, %608 : i32
        llvm.store %612, %588 : i32, !llvm.ptr
        %613 = llvm.load %588 : !llvm.ptr -> i32
        %616 = llvm.mlir.addressof @dt_den_v : !llvm.ptr
        %617 = llvm.load %616 : !llvm.ptr -> !llvm.ptr
        %618 = arith.extsi %arg3 : i32 to i64
        %619 = llvm.getelementptr %617[%618] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
        %615 = llvm.load %619 : !llvm.ptr -> !llvm.ptr
        %620 = llvm.load %591 : !llvm.ptr -> i32
        %621 = arith.extsi %620 : i32 to i64
        %622 = llvm.getelementptr %615[%621] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %614 = llvm.load %622 : !llvm.ptr -> i32
        %623 = arith.subi %613, %614 : i32
        llvm.store %623, %588 : i32, !llvm.ptr
        %625 = llvm.load %585 : !llvm.ptr -> i64
        %627 = arith.constant 0 : i32
        %628 = arith.extsi %627 : i32 to i64
        %629 = llvm.getelementptr %600[%628] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %626 = llvm.load %629 : !llvm.ptr -> i64
        %630 = arith.remsi %626, %471 : i64
        %624 = func.call @mulmod(%625, %630, %471) : (i64, i64, i64) -> i64
        llvm.store %624, %585 : i64, !llvm.ptr
        %632 = llvm.load %585 : !llvm.ptr -> i64
        %635 = llvm.mlir.addressof @dt_inv_free : !llvm.ptr
        %636 = llvm.load %635 : !llvm.ptr -> !llvm.ptr
        %637 = arith.extsi %arg3 : i32 to i64
        %638 = llvm.getelementptr %636[%637] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
        %634 = llvm.load %638 : !llvm.ptr -> !llvm.ptr
        %639 = llvm.load %591 : !llvm.ptr -> i32
        %640 = arith.extsi %639 : i32 to i64
        %641 = llvm.getelementptr %634[%640] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %633 = llvm.load %641 : !llvm.ptr -> i64
        %631 = func.call @mulmod(%632, %633, %471) : (i64, i64, i64) -> i64
        llvm.store %631, %585 : i64, !llvm.ptr
        %643 = llvm.load %585 : !llvm.ptr -> i64
        %645 = llvm.load %588 : !llvm.ptr -> i32
        %646 = arith.extsi %645 : i32 to i64
        %644 = func.call @powmod(%466, %646, %471) : (i64, i64, i64) -> i64
        %642 = func.call @mulmod(%643, %644, %471) : (i64, i64, i64) -> i64
        %647 = llvm.mlir.constant(1 : i64) : i64
        %648 = llvm.alloca %647 x i64 : (i64) -> !llvm.ptr
        llvm.store %642, %648 : i64, !llvm.ptr
        %649 = llvm.load %591 : !llvm.ptr -> i32
        %650 = arith.constant 1 : i32
        %651 = arith.andi %649, %650 : i32
        %652 = arith.constant 1 : i32
        %653 = arith.cmpi eq, %651, %652 : i32
        cf.cond_br %653, ^bb81, ^bb82
        ^bb81:
          %654 = llvm.load %648 : !llvm.ptr -> i64
          %655 = arith.subi %471, %654 : i64
          %656 = arith.remsi %655, %471 : i64
          llvm.store %656, %648 : i64, !llvm.ptr
          cf.br ^bb83
        ^bb82:
          cf.br ^bb83
        ^bb83:
        %657 = llvm.load %648 : !llvm.ptr -> i64
        %658 = llvm.load %591 : !llvm.ptr -> i32
        %659 = arith.extsi %658 : i32 to i64
        %660 = llvm.getelementptr %483[%659] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %657, %660 : i64, !llvm.ptr
        func.call @free(%600) : (!llvm.ptr) -> ()
        func.call @free(%603) : (!llvm.ptr) -> ()
        %663 = llvm.load %591 : !llvm.ptr -> i32
        %664 = arith.constant 1 : i32
        %665 = arith.addi %663, %664 : i32
        llvm.store %665, %591 : i32, !llvm.ptr
        cf.br ^bb78
      ^bb80:
      cf.br ^bb77
    ^bb76:
      cf.br ^bb77
    ^bb77:
    %666 = arith.constant 0 : i32
    %667 = arith.extsi %666 : i32 to i64
    %668 = llvm.mlir.constant(1 : i64) : i64
    %669 = llvm.alloca %668 x i64 : (i64) -> !llvm.ptr
    llvm.store %667, %669 : i64, !llvm.ptr
    %670 = arith.constant 0 : i32
    %671 = llvm.mlir.constant(1 : i64) : i64
    %672 = llvm.alloca %671 x i32 : (i64) -> !llvm.ptr
    llvm.store %670, %672 : i32, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %673 = llvm.load %672 : !llvm.ptr -> i32
    %674 = arith.cmpi sle, %673, %arg1 : i32
    cf.cond_br %674, ^bb85, ^bb86
    ^bb85:
      %675 = llvm.load %669 : !llvm.ptr -> i64
      %678 = llvm.load %672 : !llvm.ptr -> i32
      %679 = arith.extsi %678 : i32 to i64
      %680 = llvm.getelementptr %477[%679] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %677 = llvm.load %680 : !llvm.ptr -> i64
      %682 = llvm.load %672 : !llvm.ptr -> i32
      %683 = arith.subi %arg1, %682 : i32
      %684 = arith.extsi %683 : i32 to i64
      %685 = llvm.getelementptr %483[%684] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %681 = llvm.load %685 : !llvm.ptr -> i64
      %676 = func.call @mulmod(%677, %681, %471) : (i64, i64, i64) -> i64
      %686 = arith.addi %675, %676 : i64
      %687 = arith.remsi %686, %471 : i64
      llvm.store %687, %669 : i64, !llvm.ptr
      %688 = llvm.load %672 : !llvm.ptr -> i32
      %689 = arith.constant 1 : i32
      %690 = arith.addi %688, %689 : i32
      llvm.store %690, %672 : i32, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    func.call @free(%477) : (!llvm.ptr) -> ()
    func.call @free(%483) : (!llvm.ptr) -> ()
    %693 = llvm.load %669 : !llvm.ptr -> i64
    func.return %693 : i64
  }
  func.func @grundy_counts_up_to(%arg0: i64, %arg1: !llvm.ptr, %arg2: i32, %arg3: i32, %arg4: !llvm.ptr, %arg5: i32) -> () {
    %694 = arith.constant 0 : i32
    %695 = llvm.mlir.constant(1 : i64) : i64
    %696 = llvm.alloca %695 x i32 : (i64) -> !llvm.ptr
    llvm.store %694, %696 : i32, !llvm.ptr
    cf.br ^bb87
    ^bb87:
    %697 = llvm.load %696 : !llvm.ptr -> i32
    %698 = arith.cmpi slt, %697, %arg5 : i32
    cf.cond_br %698, ^bb88, ^bb89
    ^bb88:
      %699 = arith.constant 0 : i32
      %700 = llvm.load %696 : !llvm.ptr -> i32
      %701 = arith.extsi %699 : i32 to i64
      %702 = arith.extsi %700 : i32 to i64
      %703 = llvm.getelementptr %arg4[%702] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %701, %703 : i64, !llvm.ptr
      %704 = llvm.load %696 : !llvm.ptr -> i32
      %705 = arith.constant 1 : i32
      %706 = arith.addi %704, %705 : i32
      llvm.store %706, %696 : i32, !llvm.ptr
      cf.br ^bb87
    ^bb89:
    %707 = arith.constant 0 : i32
    %709 = arith.extsi %707 : i32 to i64
    %708 = arith.cmpi sle, %arg0, %709 : i64
    cf.cond_br %708, ^bb90, ^bb91
    ^bb90:
      func.return
    ^bb91:
      cf.br ^bb92
    ^bb92:
    %710 = arith.extsi %arg2 : i32 to i64
    %711 = arith.cmpi slt, %arg0, %710 : i64
    cf.cond_br %711, ^bb93, ^bb94
    ^bb93:
      %712 = arith.constant 1 : i32
      %713 = arith.extsi %712 : i32 to i64
      %714 = llvm.mlir.constant(1 : i64) : i64
      %715 = llvm.alloca %714 x i64 : (i64) -> !llvm.ptr
      llvm.store %713, %715 : i64, !llvm.ptr
      cf.br ^bb96
      ^bb96:
      %716 = llvm.load %715 : !llvm.ptr -> i64
      %717 = arith.cmpi sle, %716, %arg0 : i64
      cf.cond_br %717, ^bb97, ^bb98
      ^bb97:
        %720 = llvm.load %715 : !llvm.ptr -> i64
        %721 = llvm.getelementptr %arg1[%720] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %719 = llvm.load %721 : !llvm.ptr -> i32
        %722 = arith.extsi %719 : i32 to i64
        %723 = llvm.getelementptr %arg4[%722] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %718 = llvm.load %723 : !llvm.ptr -> i64
        %724 = arith.constant 1 : i32
        %726 = arith.extsi %724 : i32 to i64
        %725 = arith.addi %718, %726 : i64
        %728 = llvm.load %715 : !llvm.ptr -> i64
        %729 = llvm.getelementptr %arg1[%728] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %727 = llvm.load %729 : !llvm.ptr -> i32
        %730 = arith.extsi %727 : i32 to i64
        %731 = llvm.getelementptr %arg4[%730] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %725, %731 : i64, !llvm.ptr
        %732 = llvm.load %715 : !llvm.ptr -> i64
        %733 = arith.constant 1 : i32
        %735 = arith.extsi %733 : i32 to i64
        %734 = arith.addi %732, %735 : i64
        llvm.store %734, %715 : i64, !llvm.ptr
        cf.br ^bb96
      ^bb98:
      func.return
    ^bb94:
      cf.br ^bb95
    ^bb95:
    %736 = arith.constant 1 : i32
    %737 = llvm.mlir.constant(1 : i64) : i64
    %738 = llvm.alloca %737 x i32 : (i64) -> !llvm.ptr
    llvm.store %736, %738 : i32, !llvm.ptr
    cf.br ^bb99
    ^bb99:
    %739 = llvm.load %738 : !llvm.ptr -> i32
    %740 = arith.cmpi slt, %739, %arg2 : i32
    cf.cond_br %740, ^bb100, ^bb101
    ^bb100:
      %743 = llvm.load %738 : !llvm.ptr -> i32
      %744 = arith.extsi %743 : i32 to i64
      %745 = llvm.getelementptr %arg1[%744] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %742 = llvm.load %745 : !llvm.ptr -> i32
      %746 = arith.extsi %742 : i32 to i64
      %747 = llvm.getelementptr %arg4[%746] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %741 = llvm.load %747 : !llvm.ptr -> i64
      %748 = arith.constant 1 : i32
      %750 = arith.extsi %748 : i32 to i64
      %749 = arith.addi %741, %750 : i64
      %752 = llvm.load %738 : !llvm.ptr -> i32
      %753 = arith.extsi %752 : i32 to i64
      %754 = llvm.getelementptr %arg1[%753] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %751 = llvm.load %754 : !llvm.ptr -> i32
      %755 = arith.extsi %751 : i32 to i64
      %756 = llvm.getelementptr %arg4[%755] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %749, %756 : i64, !llvm.ptr
      %757 = llvm.load %738 : !llvm.ptr -> i32
      %758 = arith.constant 1 : i32
      %759 = arith.addi %757, %758 : i32
      llvm.store %759, %738 : i32, !llvm.ptr
      cf.br ^bb99
    ^bb101:
    %761 = arith.constant 16 : i32
    %762 = arith.constant 8 : i32
    %763 = arith.extsi %761 : i32 to i64
    %764 = arith.extsi %762 : i32 to i64
    %760 = func.call @calloc(%763, %764) : (i64, i64) -> !llvm.ptr
    %765 = llvm.mlir.constant(1 : i64) : i64
    %766 = llvm.alloca %765 x i32 : (i64) -> !llvm.ptr
    llvm.store %arg2, %766 : i32, !llvm.ptr
    cf.br ^bb102
    ^bb102:
    %767 = llvm.load %766 : !llvm.ptr -> i32
    %768 = arith.addi %arg2, %arg3 : i32
    %769 = arith.cmpi slt, %767, %768 : i32
    cf.cond_br %769, ^bb103, ^bb104
    ^bb103:
      %772 = llvm.load %766 : !llvm.ptr -> i32
      %773 = arith.extsi %772 : i32 to i64
      %774 = llvm.getelementptr %arg1[%773] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %771 = llvm.load %774 : !llvm.ptr -> i32
      %775 = arith.extsi %771 : i32 to i64
      %776 = llvm.getelementptr %760[%775] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %770 = llvm.load %776 : !llvm.ptr -> i64
      %777 = arith.constant 1 : i32
      %779 = arith.extsi %777 : i32 to i64
      %778 = arith.addi %770, %779 : i64
      %781 = llvm.load %766 : !llvm.ptr -> i32
      %782 = arith.extsi %781 : i32 to i64
      %783 = llvm.getelementptr %arg1[%782] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %780 = llvm.load %783 : !llvm.ptr -> i32
      %784 = arith.extsi %780 : i32 to i64
      %785 = llvm.getelementptr %760[%784] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %778, %785 : i64, !llvm.ptr
      %786 = llvm.load %766 : !llvm.ptr -> i32
      %787 = arith.constant 1 : i32
      %788 = arith.addi %786, %787 : i32
      llvm.store %788, %766 : i32, !llvm.ptr
      cf.br ^bb102
    ^bb104:
    %789 = arith.extsi %arg2 : i32 to i64
    %790 = arith.subi %arg0, %789 : i64
    %791 = arith.constant 1 : i32
    %793 = arith.extsi %791 : i32 to i64
    %792 = arith.addi %790, %793 : i64
    %794 = arith.extsi %arg3 : i32 to i64
    %795 = arith.divsi %792, %794 : i64
    %796 = arith.extsi %arg3 : i32 to i64
    %797 = arith.remsi %792, %796 : i64
    %798 = arith.constant 0 : i32
    llvm.store %798, %696 : i32, !llvm.ptr
    cf.br ^bb105
    ^bb105:
    %799 = llvm.load %696 : !llvm.ptr -> i32
    %800 = arith.cmpi slt, %799, %arg5 : i32
    cf.cond_br %800, ^bb106, ^bb107
    ^bb106:
      %802 = llvm.load %696 : !llvm.ptr -> i32
      %803 = arith.extsi %802 : i32 to i64
      %804 = llvm.getelementptr %arg4[%803] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %801 = llvm.load %804 : !llvm.ptr -> i64
      %806 = llvm.load %696 : !llvm.ptr -> i32
      %807 = arith.extsi %806 : i32 to i64
      %808 = llvm.getelementptr %760[%807] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %805 = llvm.load %808 : !llvm.ptr -> i64
      %809 = arith.muli %805, %795 : i64
      %810 = arith.addi %801, %809 : i64
      %811 = llvm.load %696 : !llvm.ptr -> i32
      %812 = arith.extsi %811 : i32 to i64
      %813 = llvm.getelementptr %arg4[%812] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %810, %813 : i64, !llvm.ptr
      %814 = llvm.load %696 : !llvm.ptr -> i32
      %815 = arith.constant 1 : i32
      %816 = arith.addi %814, %815 : i32
      llvm.store %816, %696 : i32, !llvm.ptr
      cf.br ^bb105
    ^bb107:
    %817 = arith.extsi %arg2 : i32 to i64
    %818 = llvm.mlir.constant(1 : i64) : i64
    %819 = llvm.alloca %818 x i64 : (i64) -> !llvm.ptr
    llvm.store %817, %819 : i64, !llvm.ptr
    cf.br ^bb108
    ^bb108:
    %820 = llvm.load %819 : !llvm.ptr -> i64
    %821 = arith.extsi %arg2 : i32 to i64
    %822 = arith.addi %821, %797 : i64
    %823 = arith.cmpi slt, %820, %822 : i64
    cf.cond_br %823, ^bb109, ^bb110
    ^bb109:
      %826 = llvm.load %819 : !llvm.ptr -> i64
      %827 = llvm.getelementptr %arg1[%826] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %825 = llvm.load %827 : !llvm.ptr -> i32
      %828 = arith.extsi %825 : i32 to i64
      %829 = llvm.getelementptr %arg4[%828] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %824 = llvm.load %829 : !llvm.ptr -> i64
      %830 = arith.constant 1 : i32
      %832 = arith.extsi %830 : i32 to i64
      %831 = arith.addi %824, %832 : i64
      %834 = llvm.load %819 : !llvm.ptr -> i64
      %835 = llvm.getelementptr %arg1[%834] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %833 = llvm.load %835 : !llvm.ptr -> i32
      %836 = arith.extsi %833 : i32 to i64
      %837 = llvm.getelementptr %arg4[%836] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %831, %837 : i64, !llvm.ptr
      %838 = llvm.load %819 : !llvm.ptr -> i64
      %839 = arith.constant 1 : i32
      %841 = arith.extsi %839 : i32 to i64
      %840 = arith.addi %838, %841 : i64
      llvm.store %840, %819 : i64, !llvm.ptr
      cf.br ^bb108
    ^bb110:
    func.call @free(%760) : (!llvm.ptr) -> ()
    func.return
  }
  func.func @S_mod(%arg0: i64, %arg1: i32, %arg2: i64, %arg3: !llvm.ptr, %arg4: i32, %arg5: i32) -> i64 {
    %843 = arith.constant 16 : i32
    %845 = arith.constant 16 : i32
    %846 = arith.constant 8 : i32
    %847 = arith.extsi %845 : i32 to i64
    %848 = arith.extsi %846 : i32 to i64
    %844 = func.call @calloc(%847, %848) : (i64, i64) -> !llvm.ptr
    func.call @grundy_counts_up_to(%arg0, %arg3, %arg4, %arg5, %844, %843) : (i64, !llvm.ptr, i32, i32, !llvm.ptr, i32) -> ()
    %851 = arith.constant 20 : i32
    %852 = arith.constant 8 : i32
    %853 = arith.extsi %851 : i32 to i64
    %854 = arith.extsi %852 : i32 to i64
    %850 = func.call @calloc(%853, %854) : (i64, i64) -> !llvm.ptr
    %856 = arith.constant 20 : i32
    %857 = arith.constant 8 : i32
    %858 = arith.extsi %856 : i32 to i64
    %859 = arith.extsi %857 : i32 to i64
    %855 = func.call @calloc(%858, %859) : (i64, i64) -> !llvm.ptr
    %860 = func.call @factor_prime_powers(%arg2, %850, %855) : (i64, !llvm.ptr, !llvm.ptr) -> i32
    %862 = arith.constant 20 : i32
    %863 = arith.constant 8 : i32
    %864 = arith.extsi %862 : i32 to i64
    %865 = arith.extsi %863 : i32 to i64
    %861 = func.call @calloc(%864, %865) : (i64, i64) -> !llvm.ptr
    %867 = arith.constant 20 : i32
    %868 = arith.constant 8 : i32
    %869 = arith.extsi %867 : i32 to i64
    %870 = arith.extsi %868 : i32 to i64
    %866 = func.call @calloc(%869, %870) : (i64, i64) -> !llvm.ptr
    %872 = arith.constant 20 : i32
    %873 = arith.constant 8 : i32
    %874 = arith.extsi %872 : i32 to i64
    %875 = arith.extsi %873 : i32 to i64
    %871 = func.call @calloc(%874, %875) : (i64, i64) -> !llvm.ptr
    %876 = arith.constant 0 : i32
    %877 = llvm.mlir.constant(1 : i64) : i64
    %878 = llvm.alloca %877 x i32 : (i64) -> !llvm.ptr
    llvm.store %876, %878 : i32, !llvm.ptr
    cf.br ^bb111
    ^bb111:
    %879 = llvm.load %878 : !llvm.ptr -> i32
    %880 = arith.cmpi slt, %879, %860 : i32
    cf.cond_br %880, ^bb112, ^bb113
    ^bb112:
      %882 = llvm.load %878 : !llvm.ptr -> i32
      %883 = arith.extsi %882 : i32 to i64
      %884 = llvm.getelementptr %855[%883] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %881 = llvm.load %884 : !llvm.ptr -> i64
      %885 = llvm.load %878 : !llvm.ptr -> i32
      %886 = arith.extsi %885 : i32 to i64
      %887 = llvm.getelementptr %861[%886] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %881, %887 : i64, !llvm.ptr
      %889 = llvm.load %878 : !llvm.ptr -> i32
      %890 = arith.extsi %889 : i32 to i64
      %891 = llvm.getelementptr %855[%890] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %888 = llvm.load %891 : !llvm.ptr -> i64
      %892 = arith.divsi %arg2, %888 : i64
      %893 = llvm.load %878 : !llvm.ptr -> i32
      %894 = arith.extsi %893 : i32 to i64
      %895 = llvm.getelementptr %866[%894] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %892, %895 : i64, !llvm.ptr
      %898 = llvm.load %878 : !llvm.ptr -> i32
      %899 = arith.extsi %898 : i32 to i64
      %900 = llvm.getelementptr %866[%899] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %897 = llvm.load %900 : !llvm.ptr -> i64
      %902 = llvm.load %878 : !llvm.ptr -> i32
      %903 = arith.extsi %902 : i32 to i64
      %904 = llvm.getelementptr %855[%903] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %901 = llvm.load %904 : !llvm.ptr -> i64
      %905 = arith.remsi %897, %901 : i64
      %907 = llvm.load %878 : !llvm.ptr -> i32
      %908 = arith.extsi %907 : i32 to i64
      %909 = llvm.getelementptr %855[%908] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %906 = llvm.load %909 : !llvm.ptr -> i64
      %896 = func.call @inv_mod(%905, %906) : (i64, i64) -> i64
      %910 = llvm.load %878 : !llvm.ptr -> i32
      %911 = arith.extsi %910 : i32 to i64
      %912 = llvm.getelementptr %871[%911] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %896, %912 : i64, !llvm.ptr
      %913 = llvm.load %878 : !llvm.ptr -> i32
      %914 = arith.constant 1 : i32
      %915 = arith.addi %913, %914 : i32
      llvm.store %915, %878 : i32, !llvm.ptr
      cf.br ^bb111
    ^bb113:
    %917 = arith.constant 20 : i32
    %918 = arith.constant 8 : i32
    %919 = arith.extsi %917 : i32 to i64
    %920 = arith.extsi %918 : i32 to i64
    %916 = func.call @calloc(%919, %920) : (i64, i64) -> !llvm.ptr
    %921 = llvm.mlir.addressof @dt_p : !llvm.ptr
    llvm.store %916, %921 : !llvm.ptr, !llvm.ptr
    %923 = arith.constant 20 : i32
    %924 = arith.constant 8 : i32
    %925 = arith.extsi %923 : i32 to i64
    %926 = arith.extsi %924 : i32 to i64
    %922 = func.call @calloc(%925, %926) : (i64, i64) -> !llvm.ptr
    %927 = llvm.mlir.addressof @dt_pe : !llvm.ptr
    llvm.store %922, %927 : !llvm.ptr, !llvm.ptr
    %929 = arith.constant 20 : i32
    %930 = arith.constant 8 : i32
    %931 = arith.extsi %929 : i32 to i64
    %932 = arith.extsi %930 : i32 to i64
    %928 = func.call @calloc(%931, %932) : (i64, i64) -> !llvm.ptr
    %933 = llvm.mlir.addressof @dt_den_free : !llvm.ptr
    llvm.store %928, %933 : !llvm.ptr, !llvm.ptr
    %935 = arith.constant 20 : i32
    %936 = arith.constant 8 : i32
    %937 = arith.extsi %935 : i32 to i64
    %938 = arith.extsi %936 : i32 to i64
    %934 = func.call @calloc(%937, %938) : (i64, i64) -> !llvm.ptr
    %939 = llvm.mlir.addressof @dt_den_v : !llvm.ptr
    llvm.store %934, %939 : !llvm.ptr, !llvm.ptr
    %941 = arith.constant 20 : i32
    %942 = arith.constant 8 : i32
    %943 = arith.extsi %941 : i32 to i64
    %944 = arith.extsi %942 : i32 to i64
    %940 = func.call @calloc(%943, %944) : (i64, i64) -> !llvm.ptr
    %945 = llvm.mlir.addressof @dt_inv_free : !llvm.ptr
    llvm.store %940, %945 : !llvm.ptr, !llvm.ptr
    %946 = arith.constant 0 : i32
    llvm.store %946, %878 : i32, !llvm.ptr
    cf.br ^bb114
    ^bb114:
    %947 = llvm.load %878 : !llvm.ptr -> i32
    %948 = arith.cmpi slt, %947, %860 : i32
    cf.cond_br %948, ^bb115, ^bb116
    ^bb115:
      %950 = llvm.load %878 : !llvm.ptr -> i32
      %952 = llvm.load %878 : !llvm.ptr -> i32
      %953 = arith.extsi %952 : i32 to i64
      %954 = llvm.getelementptr %850[%953] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %951 = llvm.load %954 : !llvm.ptr -> i64
      %956 = llvm.load %878 : !llvm.ptr -> i32
      %957 = arith.extsi %956 : i32 to i64
      %958 = llvm.getelementptr %855[%957] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %955 = llvm.load %958 : !llvm.ptr -> i64
      func.call @precompute_den_tables(%950, %951, %955, %arg1) : (i32, i64, i64, i32) -> ()
      %959 = llvm.load %878 : !llvm.ptr -> i32
      %960 = arith.constant 1 : i32
      %961 = arith.addi %959, %960 : i32
      llvm.store %961, %878 : i32, !llvm.ptr
      cf.br ^bb114
    ^bb116:
    %963 = arith.constant 16 : i32
    %964 = arith.extsi %963 : i32 to i64
    %962 = func.call @inv_mod(%964, %arg2) : (i64, i64) -> i64
    %965 = arith.constant 0 : i32
    %966 = arith.extsi %965 : i32 to i64
    %967 = llvm.mlir.constant(1 : i64) : i64
    %968 = llvm.alloca %967 x i64 : (i64) -> !llvm.ptr
    llvm.store %966, %968 : i64, !llvm.ptr
    %969 = arith.constant 0 : i32
    %970 = llvm.mlir.constant(1 : i64) : i64
    %971 = llvm.alloca %970 x i32 : (i64) -> !llvm.ptr
    llvm.store %969, %971 : i32, !llvm.ptr
    cf.br ^bb117
    ^bb117:
    %972 = llvm.load %971 : !llvm.ptr -> i32
    %973 = arith.constant 16 : i32
    %974 = arith.cmpi slt, %972, %973 : i32
    cf.cond_br %974, ^bb118, ^bb119
    ^bb118:
      %975 = arith.constant 0 : i32
      %976 = arith.extsi %975 : i32 to i64
      %977 = llvm.mlir.constant(1 : i64) : i64
      %978 = llvm.alloca %977 x i64 : (i64) -> !llvm.ptr
      llvm.store %976, %978 : i64, !llvm.ptr
      %979 = arith.constant 0 : i32
      %980 = llvm.mlir.constant(1 : i64) : i64
      %981 = llvm.alloca %980 x i32 : (i64) -> !llvm.ptr
      llvm.store %979, %981 : i32, !llvm.ptr
      cf.br ^bb120
      ^bb120:
      %982 = llvm.load %981 : !llvm.ptr -> i32
      %983 = arith.cmpi slt, %982, %843 : i32
      cf.cond_br %983, ^bb121, ^bb122
      ^bb121:
        %985 = llvm.load %981 : !llvm.ptr -> i32
        %986 = arith.extsi %985 : i32 to i64
        %987 = llvm.getelementptr %844[%986] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %984 = llvm.load %987 : !llvm.ptr -> i64
        %988 = arith.constant 0 : i32
        %990 = arith.extsi %988 : i32 to i64
        %989 = arith.cmpi ne, %984, %990 : i64
        %991 = scf.if %989 -> (i1) {
          %993 = llvm.load %981 : !llvm.ptr -> i32
          %994 = llvm.load %971 : !llvm.ptr -> i32
          %995 = arith.andi %993, %994 : i32
          %992 = func.call @popcount(%995) : (i32) -> i32
          %996 = arith.constant 1 : i32
          %997 = arith.andi %992, %996 : i32
          %998 = arith.constant 0 : i32
          %999 = arith.cmpi eq, %997, %998 : i32
          scf.yield %999 : i1
        } else {
          %1000 = arith.constant false
          scf.yield %1000 : i1
        }
        cf.cond_br %991, ^bb123, ^bb124
        ^bb123:
          %1001 = llvm.load %978 : !llvm.ptr -> i64
          %1003 = llvm.load %981 : !llvm.ptr -> i32
          %1004 = arith.extsi %1003 : i32 to i64
          %1005 = llvm.getelementptr %844[%1004] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %1002 = llvm.load %1005 : !llvm.ptr -> i64
          %1006 = arith.addi %1001, %1002 : i64
          llvm.store %1006, %978 : i64, !llvm.ptr
          cf.br ^bb125
        ^bb124:
          cf.br ^bb125
        ^bb125:
        %1007 = llvm.load %981 : !llvm.ptr -> i32
        %1008 = arith.constant 1 : i32
        %1009 = arith.addi %1007, %1008 : i32
        llvm.store %1009, %981 : i32, !llvm.ptr
        cf.br ^bb120
      ^bb122:
      %1010 = arith.constant 0 : i32
      %1011 = arith.extsi %1010 : i32 to i64
      %1012 = llvm.mlir.constant(1 : i64) : i64
      %1013 = llvm.alloca %1012 x i64 : (i64) -> !llvm.ptr
      llvm.store %1011, %1013 : i64, !llvm.ptr
      %1014 = arith.constant 0 : i32
      llvm.store %1014, %878 : i32, !llvm.ptr
      cf.br ^bb126
      ^bb126:
      %1015 = llvm.load %878 : !llvm.ptr -> i32
      %1016 = arith.cmpi slt, %1015, %860 : i32
      cf.cond_br %1016, ^bb127, ^bb128
      ^bb127:
        %1018 = llvm.load %978 : !llvm.ptr -> i64
        %1019 = llvm.load %878 : !llvm.ptr -> i32
        %1017 = func.call @coeff_term_mod_prime_power(%arg0, %arg1, %1018, %1019) : (i64, i32, i64, i32) -> i64
        %1020 = llvm.load %1013 : !llvm.ptr -> i64
        %1024 = llvm.load %878 : !llvm.ptr -> i32
        %1025 = arith.extsi %1024 : i32 to i64
        %1026 = llvm.getelementptr %861[%1025] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %1023 = llvm.load %1026 : !llvm.ptr -> i64
        %1027 = arith.remsi %1017, %1023 : i64
        %1029 = llvm.load %878 : !llvm.ptr -> i32
        %1030 = arith.extsi %1029 : i32 to i64
        %1031 = llvm.getelementptr %866[%1030] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %1028 = llvm.load %1031 : !llvm.ptr -> i64
        %1022 = func.call @mulmod(%1027, %1028, %arg2) : (i64, i64, i64) -> i64
        %1033 = llvm.load %878 : !llvm.ptr -> i32
        %1034 = arith.extsi %1033 : i32 to i64
        %1035 = llvm.getelementptr %871[%1034] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %1032 = llvm.load %1035 : !llvm.ptr -> i64
        %1021 = func.call @mulmod(%1022, %1032, %arg2) : (i64, i64, i64) -> i64
        %1036 = arith.addi %1020, %1021 : i64
        %1037 = arith.remsi %1036, %arg2 : i64
        llvm.store %1037, %1013 : i64, !llvm.ptr
        %1038 = llvm.load %878 : !llvm.ptr -> i32
        %1039 = arith.constant 1 : i32
        %1040 = arith.addi %1038, %1039 : i32
        llvm.store %1040, %878 : i32, !llvm.ptr
        cf.br ^bb126
      ^bb128:
      %1041 = llvm.load %968 : !llvm.ptr -> i64
      %1042 = llvm.load %1013 : !llvm.ptr -> i64
      %1043 = arith.addi %1041, %1042 : i64
      %1044 = arith.remsi %1043, %arg2 : i64
      llvm.store %1044, %968 : i64, !llvm.ptr
      %1045 = llvm.load %971 : !llvm.ptr -> i32
      %1046 = arith.constant 1 : i32
      %1047 = arith.addi %1045, %1046 : i32
      llvm.store %1047, %971 : i32, !llvm.ptr
      cf.br ^bb117
    ^bb119:
    %1048 = arith.constant 0 : i32
    llvm.store %1048, %878 : i32, !llvm.ptr
    cf.br ^bb129
    ^bb129:
    %1049 = llvm.load %878 : !llvm.ptr -> i32
    %1050 = arith.cmpi slt, %1049, %860 : i32
    cf.cond_br %1050, ^bb130, ^bb131
    ^bb130:
      %1053 = llvm.mlir.addressof @dt_den_free : !llvm.ptr
      %1054 = llvm.load %1053 : !llvm.ptr -> !llvm.ptr
      %1055 = llvm.load %878 : !llvm.ptr -> i32
      %1056 = arith.extsi %1055 : i32 to i64
      %1057 = llvm.getelementptr %1054[%1056] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
      %1052 = llvm.load %1057 : !llvm.ptr -> !llvm.ptr
      func.call @free(%1052) : (!llvm.ptr) -> ()
      %1060 = llvm.mlir.addressof @dt_den_v : !llvm.ptr
      %1061 = llvm.load %1060 : !llvm.ptr -> !llvm.ptr
      %1062 = llvm.load %878 : !llvm.ptr -> i32
      %1063 = arith.extsi %1062 : i32 to i64
      %1064 = llvm.getelementptr %1061[%1063] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
      %1059 = llvm.load %1064 : !llvm.ptr -> !llvm.ptr
      func.call @free(%1059) : (!llvm.ptr) -> ()
      %1067 = llvm.mlir.addressof @dt_inv_free : !llvm.ptr
      %1068 = llvm.load %1067 : !llvm.ptr -> !llvm.ptr
      %1069 = llvm.load %878 : !llvm.ptr -> i32
      %1070 = arith.extsi %1069 : i32 to i64
      %1071 = llvm.getelementptr %1068[%1070] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.ptr
      %1066 = llvm.load %1071 : !llvm.ptr -> !llvm.ptr
      func.call @free(%1066) : (!llvm.ptr) -> ()
      %1072 = llvm.load %878 : !llvm.ptr -> i32
      %1073 = arith.constant 1 : i32
      %1074 = arith.addi %1072, %1073 : i32
      llvm.store %1074, %878 : i32, !llvm.ptr
      cf.br ^bb129
    ^bb131:
    %1076 = llvm.mlir.addressof @dt_p : !llvm.ptr
    %1077 = llvm.load %1076 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1077) : (!llvm.ptr) -> ()
    %1079 = llvm.mlir.addressof @dt_pe : !llvm.ptr
    %1080 = llvm.load %1079 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1080) : (!llvm.ptr) -> ()
    %1082 = llvm.mlir.addressof @dt_den_free : !llvm.ptr
    %1083 = llvm.load %1082 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1083) : (!llvm.ptr) -> ()
    %1085 = llvm.mlir.addressof @dt_den_v : !llvm.ptr
    %1086 = llvm.load %1085 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1086) : (!llvm.ptr) -> ()
    %1088 = llvm.mlir.addressof @dt_inv_free : !llvm.ptr
    %1089 = llvm.load %1088 : !llvm.ptr -> !llvm.ptr
    func.call @free(%1089) : (!llvm.ptr) -> ()
    func.call @free(%844) : (!llvm.ptr) -> ()
    func.call @free(%850) : (!llvm.ptr) -> ()
    func.call @free(%855) : (!llvm.ptr) -> ()
    func.call @free(%861) : (!llvm.ptr) -> ()
    func.call @free(%866) : (!llvm.ptr) -> ()
    func.call @free(%871) : (!llvm.ptr) -> ()
    %1097 = llvm.load %968 : !llvm.ptr -> i64
    %1096 = func.call @mulmod(%1097, %962, %arg2) : (i64, i64, i64) -> i64
    func.return %1096 : i64
  }
  func.func @main() -> i32 {
    %1098 = llvm.mlir.addressof @PRE : !llvm.ptr
    %1099 = llvm.load %1098 : !llvm.ptr -> i32
    %1100 = arith.constant 2 : i32
    %1101 = llvm.mlir.addressof @PERIOD : !llvm.ptr
    %1102 = llvm.load %1101 : !llvm.ptr -> i32
    %1103 = arith.muli %1100, %1102 : i32
    %1104 = arith.addi %1099, %1103 : i32
    %1106 = arith.constant 1 : i32
    %1107 = arith.addi %1104, %1106 : i32
    %1108 = arith.extsi %1107 : i32 to i64
    %1109 = arith.constant 4 : i32
    %1111 = arith.extsi %1109 : i32 to i64
    %1110 = arith.muli %1108, %1111 : i64
    %1105 = func.call @malloc(%1110) : (i64) -> !llvm.ptr
    %1112 = arith.constant 0 : i32
    %1113 = arith.constant 0 : i32
    %1114 = arith.extsi %1113 : i32 to i64
    %1115 = llvm.getelementptr %1105[%1114] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    llvm.store %1112, %1115 : i32, !llvm.ptr
    %1117 = llvm.mlir.addressof @SPLIT_LIMIT : !llvm.ptr
    %1118 = llvm.load %1117 : !llvm.ptr -> i32
    func.call @compute_grundy(%1105, %1104, %1118) : (!llvm.ptr, i32, i32) -> ()
    %1120 = llvm.mlir.addressof @N_VAL : !llvm.ptr
    %1121 = llvm.load %1120 : !llvm.ptr -> i64
    %1122 = llvm.mlir.addressof @M_VAL : !llvm.ptr
    %1123 = llvm.load %1122 : !llvm.ptr -> i32
    %1124 = llvm.mlir.addressof @MOD : !llvm.ptr
    %1125 = llvm.load %1124 : !llvm.ptr -> i64
    %1126 = llvm.mlir.addressof @PRE : !llvm.ptr
    %1127 = llvm.load %1126 : !llvm.ptr -> i32
    %1128 = llvm.mlir.addressof @PERIOD : !llvm.ptr
    %1129 = llvm.load %1128 : !llvm.ptr -> i32
    %1119 = func.call @S_mod(%1121, %1123, %1125, %1105, %1127, %1129) : (i64, i32, i64, !llvm.ptr, i32, i32) -> i64
    %1130 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %1131 = llvm.call @printf(%1130, %1119) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%1105) : (!llvm.ptr) -> ()
    %1133 = arith.constant 0 : i32
    func.return %1133 : i32
  }
}