Problem 294

S(11^12) mod 10^9.

Answer789184709
Output789184709
StatusPASS
Native helperno
Runtime0 ms
Peak memory1104 KB
Time complexityO(n^4) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^4)O(n log n)
Space complexityO(n^2)O(n)
ApproachFlow solutionModular DP or matrix exponentiation
VerdictSuboptimal

Flow source

# Project Euler 294
# S(11^12) mod 10^9.

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

function poly_clear(p: ptr<i64>, n: i64) -> void {
    let mut i: i64 = 0
    while i < n {
        p[i] = 0
        i = i + 1
    }
}

function poly_copy(dst: ptr<i64>, src: ptr<i64>, n: i64) -> void {
    let mut i: i64 = 0
    while i < n {
        dst[i] = src[i]
        i = i + 1
    }
}

function poly_mul(a: ptr<i64>, b: ptr<i64>, out: ptr<i64>, mod: i64) -> void {
    let DEG: i64 = 24
    let BASE: i64 = 23
    poly_clear(out, DEG * BASE)
    let mut da: i64 = 0
    while da < DEG {
        let mut db: i64 = 0
        while db < DEG - da {
            let mut ra: i64 = 0
            while ra < BASE {
                let av: i64 = a[da * BASE + ra]
                if av != 0 {
                    let mut rb: i64 = 0
                    while rb < BASE {
                        let bv: i64 = b[db * BASE + rb]
                        if bv != 0 {
                            let idx: i64 = (da + db) * BASE + ((ra + rb) % BASE)
                            out[idx] = (out[idx] + av * bv) % mod
                        }
                        rb = rb + 1
                    }
                }
                ra = ra + 1
            }
            db = db + 1
        }
        da = da + 1
    }
}

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 % 2 == 1 { r = (r * b) % mod }
        b = (b * b) % mod
        e = e / 2
    }
    return r
}

function main() -> i32 {
    let MOD: i64 = 1000000000
    let BASE: i64 = 23
    let DEG: i64 = 24
    let PERIOD: i64 = 22
    let SZ: i64 = DEG * BASE
    let q: i64 = 142655835305
    let r0: i64 = 11

    let comb_q: ptr<i64> = calloc(24, 8)
    comb_q[0] = 1
    comb_q[1] = 655835305
    comb_q[2] = 314303860
    comb_q[3] = 752389860
    comb_q[4] = 263709430
    comb_q[5] = 880117686
    comb_q[6] = 105519300
    comb_q[7] = 95110100
    comb_q[8] = 97038725
    comb_q[9] = 225652925
    comb_q[10] = 86064080
    comb_q[11] = 481427600
    comb_q[12] = 465476200
    comb_q[13] = 539348200
    comb_q[14] = 302619600
    comb_q[15] = 95220240
    comb_q[16] = 607141850
    comb_q[17] = 568161450
    comb_q[18] = 343958200
    comb_q[19] = 674368600
    comb_q[20] = 82520980
    comb_q[21] = 306513300
    comb_q[22] = 52512600
    comb_q[23] = 690524600
    let comb_q1: ptr<i64> = calloc(24, 8)
    comb_q1[0] = 1
    comb_q1[1] = 655835306
    comb_q1[2] = 970139165
    comb_q1[3] = 66693720
    comb_q1[4] = 16099290
    comb_q1[5] = 143827116
    comb_q1[6] = 985636986
    comb_q1[7] = 200629400
    comb_q1[8] = 192148825
    comb_q1[9] = 322691650
    comb_q1[10] = 311717005
    comb_q1[11] = 567491680
    comb_q1[12] = 946903800
    comb_q1[13] = 4824400
    comb_q1[14] = 841967800
    comb_q1[15] = 397839840
    comb_q1[16] = 702362090
    comb_q1[17] = 175303300
    comb_q1[18] = 912119650
    comb_q1[19] = 18326800
    comb_q1[20] = 756889580
    comb_q1[21] = 389034280
    comb_q1[22] = 359025900
    comb_q1[23] = 743037200

    let acc: ptr<i64> = calloc(SZ, 8)
    acc[0] = 1
    let tmp: ptr<i64> = calloc(SZ, 8)
    let H: ptr<i64> = calloc(SZ, 8)
    let cur: ptr<i64> = calloc(SZ, 8)
    let hpow: ptr<i64> = calloc(SZ, 8)
    let nxt: ptr<i64> = calloc(SZ, 8)

    let mut r: i64 = 0
    while r < PERIOD {
        let Nn: i64 = q
        if r < r0 { Nn = q + 1 }
        let weight: i64 = mod_pow(10, r, BASE)
        poly_clear(H, SZ)
        let mut d: i64 = 1
        while d <= 9 {
            H[d * BASE + ((d * weight) % BASE)] = 1
            d = d + 1
        }
        # cur = (1+H)^Nn = sum_m C(Nn,m) H^m
        poly_clear(cur, SZ)
        cur[0] = 1
        poly_copy(hpow, H, SZ)
        let mut m: i64 = 1
        while m < DEG {
            let c: i64 = comb_q[m]
            if Nn == q + 1 { c = comb_q1[m] }
            if c != 0 {
                let mut i: i64 = 0
                while i < SZ {
                    if hpow[i] != 0 {
                        cur[i] = (cur[i] + hpow[i] * c) % MOD
                    }
                    i = i + 1
                }
            }
            if m + 1 < DEG {
                poly_mul(hpow, H, nxt, MOD)
                poly_copy(hpow, nxt, SZ)
            }
            m = m + 1
        }
        poly_mul(acc, cur, tmp, MOD)
        poly_copy(acc, tmp, SZ)
        r = r + 1
    }
    printf("%lld\n", acc[23 * BASE + 0])
    free(comb_q); free(comb_q1); free(acc); free(tmp); free(H); free(cur); free(hpow); free(nxt)
    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; }

void poly_clear_ptr_i64_i64(int64_t* p, int64_t n);
void poly_copy_ptr_i64_ptr_i64_i64(int64_t* dst, int64_t* src, int64_t n);
void poly_mul_ptr_i64_ptr_i64_ptr_i64_i64(int64_t* a, int64_t* b, int64_t* out, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
int32_t main(void);



void poly_clear_ptr_i64_i64(int64_t* p, int64_t n) {
    int64_t i = 0;
    while (i < n) {
        p[i] = 0;
        i = (i + 1);
    }
}

void poly_copy_ptr_i64_ptr_i64_i64(int64_t* dst, int64_t* src, int64_t n) {
    int64_t i = 0;
    while (i < n) {
        dst[i] = src[i];
        i = (i + 1);
    }
}

void poly_mul_ptr_i64_ptr_i64_ptr_i64_i64(int64_t* a, int64_t* b, int64_t* out, int64_t mod) {
    int64_t DEG = 24;
    int64_t BASE = 23;
    poly_clear_ptr_i64_i64(out, (DEG * BASE));
    int64_t da = 0;
    while (da < DEG) {
        int64_t db = 0;
        while (db < (DEG - da)) {
            int64_t ra = 0;
            while (ra < BASE) {
                int64_t av = a[((da * BASE) + ra)];
                if (av != 0) {
                    int64_t rb = 0;
                    while (rb < BASE) {
                        int64_t bv = b[((db * BASE) + rb)];
                        if (bv != 0) {
                            int64_t idx = (((da + db) * BASE) + FLOW_CHECKED_MOD(((ra + rb)), (BASE)));
                            out[idx] = FLOW_CHECKED_MOD(((out[idx] + (av * bv))), (mod));
                        }
                        rb = (rb + 1);
                    }
                }
                ra = (ra + 1);
            }
            db = (db + 1);
        }
        da = (da + 1);
    }
}

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 (FLOW_CHECKED_MOD((e), (2)) == 1) {
            r = FLOW_CHECKED_MOD(((r * b)), (mod));
        }
        b = FLOW_CHECKED_MOD(((b * b)), (mod));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

int32_t main(void) {
    int64_t MOD = 1000000000;
    int64_t BASE = 23;
    int64_t DEG = 24;
    int64_t PERIOD = 22;
    int64_t SZ = (DEG * BASE);
    int64_t q = 142655835305;
    int64_t r0 = 11;
    int64_t* comb_q = (int64_t*)(calloc(24, 8));
    comb_q[0] = 1;
    comb_q[1] = 655835305;
    comb_q[2] = 314303860;
    comb_q[3] = 752389860;
    comb_q[4] = 263709430;
    comb_q[5] = 880117686;
    comb_q[6] = 105519300;
    comb_q[7] = 95110100;
    comb_q[8] = 97038725;
    comb_q[9] = 225652925;
    comb_q[10] = 86064080;
    comb_q[11] = 481427600;
    comb_q[12] = 465476200;
    comb_q[13] = 539348200;
    comb_q[14] = 302619600;
    comb_q[15] = 95220240;
    comb_q[16] = 607141850;
    comb_q[17] = 568161450;
    comb_q[18] = 343958200;
    comb_q[19] = 674368600;
    comb_q[20] = 82520980;
    comb_q[21] = 306513300;
    comb_q[22] = 52512600;
    comb_q[23] = 690524600;
    int64_t* comb_q1 = (int64_t*)(calloc(24, 8));
    comb_q1[0] = 1;
    comb_q1[1] = 655835306;
    comb_q1[2] = 970139165;
    comb_q1[3] = 66693720;
    comb_q1[4] = 16099290;
    comb_q1[5] = 143827116;
    comb_q1[6] = 985636986;
    comb_q1[7] = 200629400;
    comb_q1[8] = 192148825;
    comb_q1[9] = 322691650;
    comb_q1[10] = 311717005;
    comb_q1[11] = 567491680;
    comb_q1[12] = 946903800;
    comb_q1[13] = 4824400;
    comb_q1[14] = 841967800;
    comb_q1[15] = 397839840;
    comb_q1[16] = 702362090;
    comb_q1[17] = 175303300;
    comb_q1[18] = 912119650;
    comb_q1[19] = 18326800;
    comb_q1[20] = 756889580;
    comb_q1[21] = 389034280;
    comb_q1[22] = 359025900;
    comb_q1[23] = 743037200;
    int64_t* acc = (int64_t*)(calloc(SZ, 8));
    acc[0] = 1;
    int64_t* tmp = (int64_t*)(calloc(SZ, 8));
    int64_t* H = (int64_t*)(calloc(SZ, 8));
    int64_t* cur = (int64_t*)(calloc(SZ, 8));
    int64_t* hpow = (int64_t*)(calloc(SZ, 8));
    int64_t* nxt = (int64_t*)(calloc(SZ, 8));
    int64_t r = 0;
    while (r < PERIOD) {
        int64_t Nn = q;
        if (r < r0) {
            Nn = (q + 1);
        }
        int64_t weight = mod_pow_i64_i64_i64(10, r, BASE);
        poly_clear_ptr_i64_i64(H, SZ);
        int64_t d = 1;
        while (d <= 9) {
            H[((d * BASE) + FLOW_CHECKED_MOD(((d * weight)), (BASE)))] = 1;
            d = (d + 1);
        }
        poly_clear_ptr_i64_i64(cur, SZ);
        cur[0] = 1;
        poly_copy_ptr_i64_ptr_i64_i64(hpow, H, SZ);
        int64_t m = 1;
        while (m < DEG) {
            int64_t c = comb_q[m];
            if (Nn == (q + 1)) {
                c = comb_q1[m];
            }
            if (c != 0) {
                int64_t i = 0;
                while (i < SZ) {
                    if (hpow[i] != 0) {
                        cur[i] = FLOW_CHECKED_MOD(((cur[i] + (hpow[i] * c))), (MOD));
                    }
                    i = (i + 1);
                }
            }
            if ((m + 1) < DEG) {
                poly_mul_ptr_i64_ptr_i64_ptr_i64_i64(hpow, H, nxt, MOD);
                poly_copy_ptr_i64_ptr_i64_i64(hpow, nxt, SZ);
            }
            m = (m + 1);
        }
        poly_mul_ptr_i64_ptr_i64_ptr_i64_i64(acc, cur, tmp, MOD);
        poly_copy_ptr_i64_ptr_i64_i64(acc, tmp, SZ);
        r = (r + 1);
    }
    printf("%lld\n", acc[((23 * BASE) + 0)]);
    free(comb_q);
    free(comb_q1);
    free(acc);
    free(tmp);
    free(H);
    free(cur);
    free(hpow);
    free(nxt);
    return 0;
}

Generated MLIR

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