Problem 649

Low-Prime Chessboard Nim: M(10000019, 100) last 9 digits. Grundy numbers for subtraction game {2,3,5,7}, XOR convolution power.

Answer924668016
Output924668016
StatusPASS
Native helperno
Runtime30 ms
Peak memory1072 KB
Time complexityO(n^2) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n)
Space complexityO(1)O(n)
ApproachFlow solutionBig-integer arithmetic
VerdictSuboptimal

Flow source

# Project Euler 649
# Low-Prime Chessboard Nim: M(10000019, 100) last 9 digits.
# Grundy numbers for subtraction game {2,3,5,7}, XOR convolution power.

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

const MOD: i64 = 1000000000

# mex lookup for 5 values (0..4)
function mex5(mask: i64) -> i64 {
    let mut m: i64 = 0
    while (mask >> m) & 1 == 1 { m = m + 1 }
    return m
}

# Grundy frequencies for 1D subtraction game with moves {2,3,5,7}
function heap_grundy_freq(n: i64, freq: ptr<i64>) -> void {
    for i in 0..5 { freq[i] = 0 }
    if n <= 0 { return }

    let ring: ptr<i64> = calloc(8, 8)

    # Handle t=0..6 with boundary checks
    let limit: i64 = n
    if limit > 7 { limit = 7 }
    for t in 0..limit {
        let mut mask: i64 = 0
        if t >= 2 { mask = mask | (1 << ring[(t - 2) & 7]) }
        if t >= 3 { mask = mask | (1 << ring[(t - 3) & 7]) }
        if t >= 5 { mask = mask | (1 << ring[(t - 5) & 7]) }
        if t >= 7 { mask = mask | (1 << ring[(t - 7) & 7]) }
        let g: i64 = mex5(mask)
        ring[t & 7] = g
        freq[g] = freq[g] + 1
    }

    # From t>=7 all four moves available
    for t in 7..n {
        let mask: i64 = (1 << ring[(t - 2) & 7]) | (1 << ring[(t - 3) & 7]) | (1 << ring[(t - 5) & 7]) | (1 << ring[(t - 7) & 7])
        let g: i64 = mex5(mask)
        ring[t & 7] = g
        freq[g] = freq[g] + 1
    }

    free(ring)
}

# XOR convolution of length-8 vectors
function xor_conv(u: ptr<i64>, v: ptr<i64>, w: ptr<i64>, mod: i64) -> void {
    for i in 0..8 { w[i] = 0 }
    for i in 0..8 {
        if u[i] == 0 { continue }
        for j in 0..8 {
            if v[j] == 0 { continue }
            let idx: i64 = i ^ j
            w[idx] = (w[idx] + u[i] * v[j]) % mod
        }
    }
}

# XOR convolution power: base^exp
function xor_power(base: ptr<i64>, exp0: i64, res: ptr<i64>, mod: i64) -> void {
    let tmp: ptr<i64> = calloc(8, 8)
    let b: ptr<i64> = calloc(8, 8)
    for i in 0..8 { b[i] = base[i] }
    for i in 0..8 { res[i] = 0 }
    res[0] = 1
    let mut e: i64 = exp0
    while e > 0 {
        if (e & 1) == 1 {
            xor_conv(res, b, tmp, mod)
            for i in 0..8 { res[i] = tmp[i] }
        }
        xor_conv(b, b, tmp, mod)
        for i in 0..8 { b[i] = tmp[i] }
        e = e / 2
    }
    free(b)
    free(tmp)
}

function mod_pow(base0: i64, exp0: i64, mod: i64) -> i64 {
    let mut r: i64 = 1
    let mut b: i64 = base0 % mod
    let mut e: i64 = exp0
    while e > 0 {
        if (e & 1) == 1 {
            let t: i128 = (r as i128) * (b as i128) % (mod as i128)
            r = t as i64
        }
        let t2: i128 = (b as i128) * (b as i128) % (mod as i128)
        b = t2 as i64
        e = e / 2
    }
    return r
}

function main() -> i32 {
    let n: i64 = 10000019
    let c: i64 = 100

    # Grundy frequencies for 1D game
    let freq: ptr<i64> = calloc(5, 8)
    heap_grundy_freq(n, freq)

    # Board nimber counts: a[k] = #{(x,y) : g(x) XOR g(y) = k}
    let a: ptr<i64> = calloc(8, 8)
    for i in 0..5 {
        if freq[i] == 0 { continue }
        for j in 0..5 {
            if freq[j] == 0 { continue }
            a[i ^ j] = a[i ^ j] + freq[i] * freq[j]
        }
    }

    # Reduce mod
    let a_mod: ptr<i64> = calloc(8, 8)
    for i in 0..8 { a_mod[i] = a[i] % MOD }

    # XOR power: distribution of XOR of c coins
    let dist: ptr<i64> = calloc(8, 8)
    xor_power(a_mod, c, dist, MOD)

    let losing: i64 = dist[0]
    let total: i64 = mod_pow((n * n) % MOD, c, MOD)
    let ans: i64 = (total - losing % MOD + MOD) % MOD

    printf("%09lld\n", ans)

    free(dist)
    free(a_mod)
    free(a)
    free(freq)
    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 mex5_i64(int64_t mask);
void heap_grundy_freq_i64_ptr_i64(int64_t n, int64_t* freq);
void xor_conv_ptr_i64_ptr_i64_ptr_i64_i64(int64_t* u, int64_t* v, int64_t* w, int64_t mod);
void xor_power_ptr_i64_i64_ptr_i64_i64(int64_t* base, int64_t exp0, int64_t* res, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
int32_t main(void);

static const int64_t MOD = 1000000000;



int64_t mex5_i64(int64_t mask) {
    int64_t m = 0;
    while ((FLOW_CHECKED_SHR((mask), (m)) & 1 == 1)) {
        m = (m + 1);
    }
    return m;
}

void heap_grundy_freq_i64_ptr_i64(int64_t n, int64_t* freq) {
    int32_t __flow_step_1 = 1;
    for (int32_t i = 0; (0 <= 5) ? i < 5 : i > 5; i += (0 <= 5) ? 1 : -1) {
        freq[i] = 0;
    }
    if (n <= 0) {
        return;
    }
    int64_t* ring = (int64_t*)(calloc(8, 8));
    int64_t limit = n;
    if (limit > 7) {
        limit = 7;
    }
    int32_t __flow_step_2 = 1;
    for (int32_t t = 0; (0 <= limit) ? t < limit : t > limit; t += (0 <= limit) ? 1 : -1) {
        int64_t mask = 0;
        if (t >= 2) {
            mask = (mask | FLOW_CHECKED_SHL((1), (ring[((t - 2) & 7)])));
        }
        if (t >= 3) {
            mask = (mask | FLOW_CHECKED_SHL((1), (ring[((t - 3) & 7)])));
        }
        if (t >= 5) {
            mask = (mask | FLOW_CHECKED_SHL((1), (ring[((t - 5) & 7)])));
        }
        if (t >= 7) {
            mask = (mask | FLOW_CHECKED_SHL((1), (ring[((t - 7) & 7)])));
        }
        int64_t g = mex5_i64(mask);
        ring[(t & 7)] = g;
        freq[g] = (freq[g] + 1);
    }
    int32_t __flow_step_3 = 1;
    for (int32_t t = 7; (7 <= n) ? t < n : t > n; t += (7 <= n) ? 1 : -1) {
        int64_t mask = (((FLOW_CHECKED_SHL((1), (ring[((t - 2) & 7)])) | FLOW_CHECKED_SHL((1), (ring[((t - 3) & 7)]))) | FLOW_CHECKED_SHL((1), (ring[((t - 5) & 7)]))) | FLOW_CHECKED_SHL((1), (ring[((t - 7) & 7)])));
        int64_t g = mex5_i64(mask);
        ring[(t & 7)] = g;
        freq[g] = (freq[g] + 1);
    }
    free(ring);
}

void xor_conv_ptr_i64_ptr_i64_ptr_i64_i64(int64_t* u, int64_t* v, int64_t* w, int64_t mod) {
    int32_t __flow_step_4 = 1;
    for (int32_t i = 0; (0 <= 8) ? i < 8 : i > 8; i += (0 <= 8) ? 1 : -1) {
        w[i] = 0;
    }
    int32_t __flow_step_5 = 1;
    for (int32_t i = 0; (0 <= 8) ? i < 8 : i > 8; i += (0 <= 8) ? 1 : -1) {
        if (u[i] == 0) {
            continue;
        }
        int32_t __flow_step_6 = 1;
        for (int32_t j = 0; (0 <= 8) ? j < 8 : j > 8; j += (0 <= 8) ? 1 : -1) {
            if (v[j] == 0) {
                continue;
            }
            int64_t idx = (i ^ j);
            w[idx] = FLOW_CHECKED_MOD(((w[idx] + (u[i] * v[j]))), (mod));
        }
    }
}

void xor_power_ptr_i64_i64_ptr_i64_i64(int64_t* base, int64_t exp0, int64_t* res, int64_t mod) {
    int64_t* tmp = (int64_t*)(calloc(8, 8));
    int64_t* b = (int64_t*)(calloc(8, 8));
    int32_t __flow_step_7 = 1;
    for (int32_t i = 0; (0 <= 8) ? i < 8 : i > 8; i += (0 <= 8) ? 1 : -1) {
        b[i] = base[i];
    }
    int32_t __flow_step_8 = 1;
    for (int32_t i = 0; (0 <= 8) ? i < 8 : i > 8; i += (0 <= 8) ? 1 : -1) {
        res[i] = 0;
    }
    res[0] = 1;
    int64_t e = exp0;
    while (e > 0) {
        if ((e & 1) == 1) {
            xor_conv_ptr_i64_ptr_i64_ptr_i64_i64(res, b, tmp, mod);
            int32_t __flow_step_9 = 1;
            for (int32_t i = 0; (0 <= 8) ? i < 8 : i > 8; i += (0 <= 8) ? 1 : -1) {
                res[i] = tmp[i];
            }
        }
        xor_conv_ptr_i64_ptr_i64_ptr_i64_i64(b, b, tmp, mod);
        int32_t __flow_step_10 = 1;
        for (int32_t i = 0; (0 <= 8) ? i < 8 : i > 8; i += (0 <= 8) ? 1 : -1) {
            b[i] = tmp[i];
        }
        e = FLOW_CHECKED_DIV((e), (2));
    }
    free(b);
    free(tmp);
}

int64_t mod_pow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod) {
    int64_t r = 1;
    int64_t b = FLOW_CHECKED_MOD((base0), (mod));
    int64_t e = exp0;
    while (e > 0) {
        if ((e & 1) == 1) {
            __int128 t = FLOW_CHECKED_MOD(((((__int128)(r)) * ((__int128)(b)))), (((__int128)(mod))));
            r = ((int64_t)(t));
        }
        __int128 t2 = FLOW_CHECKED_MOD(((((__int128)(b)) * ((__int128)(b)))), (((__int128)(mod))));
        b = ((int64_t)(t2));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

int32_t main(void) {
    int64_t n = 10000019;
    int64_t c = 100;
    int64_t* freq = (int64_t*)(calloc(5, 8));
    heap_grundy_freq_i64_ptr_i64(n, freq);
    int64_t* a = (int64_t*)(calloc(8, 8));
    int32_t __flow_step_11 = 1;
    for (int32_t i = 0; (0 <= 5) ? i < 5 : i > 5; i += (0 <= 5) ? 1 : -1) {
        if (freq[i] == 0) {
            continue;
        }
        int32_t __flow_step_12 = 1;
        for (int32_t j = 0; (0 <= 5) ? j < 5 : j > 5; j += (0 <= 5) ? 1 : -1) {
            if (freq[j] == 0) {
                continue;
            }
            a[(i ^ j)] = (a[(i ^ j)] + (freq[i] * freq[j]));
        }
    }
    int64_t* a_mod = (int64_t*)(calloc(8, 8));
    int32_t __flow_step_13 = 1;
    for (int32_t i = 0; (0 <= 8) ? i < 8 : i > 8; i += (0 <= 8) ? 1 : -1) {
        a_mod[i] = FLOW_CHECKED_MOD((a[i]), (MOD));
    }
    int64_t* dist = (int64_t*)(calloc(8, 8));
    xor_power_ptr_i64_i64_ptr_i64_i64(a_mod, c, dist, MOD);
    int64_t losing = dist[0];
    int64_t total = mod_pow_i64_i64_i64(FLOW_CHECKED_MOD(((n * n)), (MOD)), c, MOD);
    int64_t ans = FLOW_CHECKED_MOD((((total - FLOW_CHECKED_MOD((losing), (MOD))) + MOD)), (MOD));
    printf("%09lld\n", ans);
    free(dist);
    free(a_mod);
    free(a);
    free(freq);
    return 0;
}

Generated MLIR

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