Problem 984

Closed-form even polynomial for f(10^18) mod 10^9+7.

Answer885722296
Output885722296
StatusPASS
Native helperno
Runtime0 ms
Peak memory1072 KB
Time complexityO(n) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)O(1)
Space complexityO(1)O(1)
ApproachFlow solutionClosed-form formula
VerdictSuboptimal

Flow source

# Project Euler 984
# Closed-form even polynomial for f(10^18) mod 10^9+7.

const MOD: i64 = 1000000007

function modpow(base0: i64, exp0: i64) -> i64 {
    let mut r: i64 = 1
    let mut b: i64 = base0 % MOD
    let mut e: i64 = exp0
    while e > 0 {
        if (e & 1) != 0 {
            r = ((r as i128) * (b as i128) % (MOD as i128)) as i64
        }
        b = ((b as i128) * (b as i128) % (MOD as i128)) as i64
        e = e >> 1
    }
    return r
}

function f_even_mod(n: i64) -> i64 {
    let mut powers: [i64; 9]
    powers[0] = 1
    let x: i64 = n % MOD
    let mut i: i64 = 1
    while i <= 8 {
        powers[i] = ((powers[i - 1] as i128) * (x as i128) % (MOD as i128)) as i64
        i = i + 1
    }
    let mut total: i64 = (MOD - 419) % MOD
    # (num, den, power)
    let nums: [i64; 8] = [31, 31, 67, 41, 313, -5699, 16049, 29413]
    let dens: [i64; 8] = [40320, 3360, 1440, 320, 1440, 240, 420, 140]
    let pows: [i64; 8] = [8, 7, 6, 5, 4, 3, 2, 1]
    i = 0
    while i < 8 {
        let inv: i64 = modpow(dens[i], MOD - 2)
        let mut term: i64 = nums[i] % MOD
        if term < 0 { term = term + MOD }
        term = ((term as i128) * (powers[pows[i]] as i128) % (MOD as i128)) as i64
        term = ((term as i128) * (inv as i128) % (MOD as i128)) as i64
        total = (total + term) % MOD
        i = i + 1
    }
    return total
}

function main() -> i32 {
    printf("%lld\n", f_even_mod(1000000000000000000))
    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 modpow_i64_i64(int64_t base0, int64_t exp0);
int64_t f_even_mod_i64(int64_t n);
int32_t main(void);

static const int64_t MOD = 1000000007;

int64_t modpow_i64_i64(int64_t base0, int64_t exp0) {
    int64_t r = 1;
    int64_t b = FLOW_CHECKED_MOD((base0), (MOD));
    int64_t e = exp0;
    while (e > 0) {
        if ((e & 1) != 0) {
            r = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(r)) * ((__int128)(b)))), (((__int128)(MOD))))));
        }
        b = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(b)) * ((__int128)(b)))), (((__int128)(MOD))))));
        e = FLOW_CHECKED_SHR((e), (1));
    }
    return r;
}

int64_t f_even_mod_i64(int64_t n) {
    int64_t powers[9];
    powers[0] = 1;
    int64_t x = FLOW_CHECKED_MOD((n), (MOD));
    int64_t i = 1;
    while (i <= 8) {
        powers[i] = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)((((unsigned)((i - 1)) < 9) ? powers[(i - 1)] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)((i - 1)), 9), flow_fault_handler("array index out of bounds"), powers[0])))) * ((__int128)(x)))), (((__int128)(MOD))))));
        i = (i + 1);
    }
    int64_t total = FLOW_CHECKED_MOD(((MOD - 419)), (MOD));
    int64_t nums[8] = { 31, 31, 67, 41, 313, (-5699), 16049, 29413 };
    int64_t dens[8] = { 40320, 3360, 1440, 320, 1440, 240, 420, 140 };
    int64_t pows[8] = { 8, 7, 6, 5, 4, 3, 2, 1 };
    i = 0;
    while (i < 8) {
        int64_t inv = modpow_i64_i64((((unsigned)(i) < 8) ? dens[i] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i), 8), flow_fault_handler("array index out of bounds"), dens[0])), (MOD - 2));
        int64_t term = FLOW_CHECKED_MOD(((((unsigned)(i) < 8) ? nums[i] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i), 8), flow_fault_handler("array index out of bounds"), nums[0]))), (MOD));
        if (term < 0) {
            term = (term + MOD);
        }
        term = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(term)) * ((__int128)((((unsigned)((((unsigned)(i) < 8) ? pows[i] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i), 8), flow_fault_handler("array index out of bounds"), pows[0]))) < 9) ? powers[(((unsigned)(i) < 8) ? pows[i] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i), 8), flow_fault_handler("array index out of bounds"), pows[0]))] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)((((unsigned)(i) < 8) ? pows[i] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(i), 8), flow_fault_handler("array index out of bounds"), pows[0]))), 9), flow_fault_handler("array index out of bounds"), powers[0])))))), (((__int128)(MOD))))));
        term = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(term)) * ((__int128)(inv)))), (((__int128)(MOD))))));
        total = FLOW_CHECKED_MOD(((total + term)), (MOD));
        i = (i + 1);
    }
    return total;
}

int32_t main(void) {
    printf("%lld\n", f_even_mod_i64(1000000000000000000));
    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>
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  func.func @modpow(%arg0: i64, %arg1: i64) -> i64 {
    %0 = arith.constant 1 : 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
    %4 = llvm.mlir.addressof @MOD : !llvm.ptr
    %5 = llvm.load %4 : !llvm.ptr -> i64
    %6 = arith.remsi %arg0, %5 : i64
    %7 = llvm.mlir.constant(1 : i64) : i64
    %8 = llvm.alloca %7 x i64 : (i64) -> !llvm.ptr
    llvm.store %6, %8 : i64, !llvm.ptr
    %9 = llvm.mlir.constant(1 : i64) : i64
    %10 = llvm.alloca %9 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %10 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %11 = llvm.load %10 : !llvm.ptr -> i64
    %12 = arith.constant 0 : i32
    %14 = arith.extsi %12 : i32 to i64
    %13 = arith.cmpi sgt, %11, %14 : i64
    cf.cond_br %13, ^bb1, ^bb2
    ^bb1:
      %15 = llvm.load %10 : !llvm.ptr -> i64
      %16 = arith.constant 1 : i32
      %18 = arith.extsi %16 : i32 to i64
      %17 = arith.andi %15, %18 : i64
      %19 = arith.constant 0 : i32
      %21 = arith.extsi %19 : i32 to i64
      %20 = arith.cmpi ne, %17, %21 : i64
      cf.cond_br %20, ^bb3, ^bb4
      ^bb3:
        %22 = llvm.load %3 : !llvm.ptr -> i64
        %23 = arith.extsi %22 : i64 to i128
        %24 = llvm.load %8 : !llvm.ptr -> i64
        %25 = arith.extsi %24 : i64 to i128
        %27 = arith.trunci %23 : i128 to i64
        %28 = arith.trunci %25 : i128 to i64
        %26 = arith.muli %27, %28 : i64
        %29 = llvm.mlir.addressof @MOD : !llvm.ptr
        %30 = llvm.load %29 : !llvm.ptr -> i64
        %31 = arith.extsi %30 : i64 to i128
        %33 = arith.trunci %31 : i128 to i64
        %32 = arith.remsi %26, %33 : i64
        llvm.store %32, %3 : i64, !llvm.ptr
        cf.br ^bb5
      ^bb4:
        cf.br ^bb5
      ^bb5:
      %34 = llvm.load %8 : !llvm.ptr -> i64
      %35 = arith.extsi %34 : i64 to i128
      %36 = llvm.load %8 : !llvm.ptr -> i64
      %37 = arith.extsi %36 : i64 to i128
      %39 = arith.trunci %35 : i128 to i64
      %40 = arith.trunci %37 : i128 to i64
      %38 = arith.muli %39, %40 : i64
      %41 = llvm.mlir.addressof @MOD : !llvm.ptr
      %42 = llvm.load %41 : !llvm.ptr -> i64
      %43 = arith.extsi %42 : i64 to i128
      %45 = arith.trunci %43 : i128 to i64
      %44 = arith.remsi %38, %45 : i64
      llvm.store %44, %8 : i64, !llvm.ptr
      %46 = llvm.load %10 : !llvm.ptr -> i64
      %47 = arith.constant 1 : i32
      %49 = arith.extsi %47 : i32 to i64
      %48 = arith.shrsi %46, %49 : i64
      llvm.store %48, %10 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %50 = llvm.load %3 : !llvm.ptr -> i64
    func.return %50 : i64
  }
  func.func @f_even_mod(%arg0: i64) -> i64 {
    %51 = memref.alloca() {type = memref<9xi64>} : memref<9xi64>
    %52 = arith.constant 1 : i32
    %53 = arith.constant 0 : i32
    %54 = arith.index_cast %53 : i32 to index
    %55 = arith.extsi %52 : i32 to i64
    memref.store %55, %51[%54] : memref<9xi64>
    %56 = llvm.mlir.addressof @MOD : !llvm.ptr
    %57 = llvm.load %56 : !llvm.ptr -> i64
    %58 = arith.remsi %arg0, %57 : i64
    %59 = arith.constant 1 : 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
    cf.br ^bb6
    ^bb6:
    %63 = llvm.load %62 : !llvm.ptr -> i64
    %64 = arith.constant 8 : i32
    %66 = arith.extsi %64 : i32 to i64
    %65 = arith.cmpi sle, %63, %66 : i64
    cf.cond_br %65, ^bb7, ^bb8
    ^bb7:
      %68 = llvm.load %62 : !llvm.ptr -> i64
      %69 = arith.constant 1 : i32
      %71 = arith.extsi %69 : i32 to i64
      %70 = arith.subi %68, %71 : i64
      %72 = arith.index_cast %70 : i32 to index
      %67 = memref.load %51[%72] : memref<9xi64>
      %73 = arith.extsi %67 : i64 to i128
      %74 = arith.extsi %58 : i64 to i128
      %76 = arith.trunci %73 : i128 to i64
      %77 = arith.trunci %74 : i128 to i64
      %75 = arith.muli %76, %77 : i64
      %78 = llvm.mlir.addressof @MOD : !llvm.ptr
      %79 = llvm.load %78 : !llvm.ptr -> i64
      %80 = arith.extsi %79 : i64 to i128
      %82 = arith.trunci %80 : i128 to i64
      %81 = arith.remsi %75, %82 : i64
      %83 = llvm.load %62 : !llvm.ptr -> i64
      %84 = arith.index_cast %83 : i32 to index
      memref.store %81, %51[%84] : memref<9xi64>
      %85 = llvm.load %62 : !llvm.ptr -> i64
      %86 = arith.constant 1 : i32
      %88 = arith.extsi %86 : i32 to i64
      %87 = arith.addi %85, %88 : i64
      llvm.store %87, %62 : i64, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    %89 = llvm.mlir.addressof @MOD : !llvm.ptr
    %90 = llvm.load %89 : !llvm.ptr -> i64
    %91 = arith.constant 419 : i32
    %93 = arith.extsi %91 : i32 to i64
    %92 = arith.subi %90, %93 : i64
    %94 = llvm.mlir.addressof @MOD : !llvm.ptr
    %95 = llvm.load %94 : !llvm.ptr -> i64
    %96 = arith.remsi %92, %95 : i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %100 = arith.constant 31 : i32
    %101 = arith.constant 31 : i32
    %102 = arith.constant 67 : i32
    %103 = arith.constant 41 : i32
    %104 = arith.constant 313 : i32
    %105 = arith.constant 5699 : i32
    %107 = arith.constant 0 : i32
    %106 = arith.subi %107, %105 : i32
    %108 = arith.constant 16049 : i32
    %109 = arith.constant 29413 : i32
    %110 = llvm.mlir.constant(1 : i64) : i64
    %111 = llvm.alloca %110 x !llvm.array<8 x i64> : (i64) -> !llvm.ptr
    %112 = llvm.mlir.zero : !llvm.array<8 x i64>
    llvm.store %112, %111 : !llvm.array<8 x i64>, !llvm.ptr
    %113 = arith.extsi %100 : i32 to i64
    %114 = arith.extsi %101 : i32 to i64
    %115 = arith.extsi %102 : i32 to i64
    %116 = arith.extsi %103 : i32 to i64
    %117 = arith.extsi %104 : i32 to i64
    %118 = arith.extsi %106 : i32 to i64
    %119 = arith.extsi %108 : i32 to i64
    %120 = arith.extsi %109 : i32 to i64
    %121 = llvm.mlir.constant(0 : i64) : i64
    %122 = llvm.getelementptr %111[0, %121] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %113, %122 : i64, !llvm.ptr
    %123 = llvm.mlir.constant(1 : i64) : i64
    %124 = llvm.getelementptr %111[0, %123] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %114, %124 : i64, !llvm.ptr
    %125 = llvm.mlir.constant(2 : i64) : i64
    %126 = llvm.getelementptr %111[0, %125] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %115, %126 : i64, !llvm.ptr
    %127 = llvm.mlir.constant(3 : i64) : i64
    %128 = llvm.getelementptr %111[0, %127] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %116, %128 : i64, !llvm.ptr
    %129 = llvm.mlir.constant(4 : i64) : i64
    %130 = llvm.getelementptr %111[0, %129] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %117, %130 : i64, !llvm.ptr
    %131 = llvm.mlir.constant(5 : i64) : i64
    %132 = llvm.getelementptr %111[0, %131] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %118, %132 : i64, !llvm.ptr
    %133 = llvm.mlir.constant(6 : i64) : i64
    %134 = llvm.getelementptr %111[0, %133] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %119, %134 : i64, !llvm.ptr
    %135 = llvm.mlir.constant(7 : i64) : i64
    %136 = llvm.getelementptr %111[0, %135] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %120, %136 : i64, !llvm.ptr
    %138 = arith.constant 40320 : i32
    %139 = arith.constant 3360 : i32
    %140 = arith.constant 1440 : i32
    %141 = arith.constant 320 : i32
    %142 = arith.constant 1440 : i32
    %143 = arith.constant 240 : i32
    %144 = arith.constant 420 : i32
    %145 = arith.constant 140 : i32
    %146 = llvm.mlir.constant(1 : i64) : i64
    %147 = llvm.alloca %146 x !llvm.array<8 x i64> : (i64) -> !llvm.ptr
    %148 = llvm.mlir.zero : !llvm.array<8 x i64>
    llvm.store %148, %147 : !llvm.array<8 x i64>, !llvm.ptr
    %149 = arith.extsi %138 : i32 to i64
    %150 = arith.extsi %139 : i32 to i64
    %151 = arith.extsi %140 : i32 to i64
    %152 = arith.extsi %141 : i32 to i64
    %153 = arith.extsi %142 : i32 to i64
    %154 = arith.extsi %143 : i32 to i64
    %155 = arith.extsi %144 : i32 to i64
    %156 = arith.extsi %145 : i32 to i64
    %157 = llvm.mlir.constant(0 : i64) : i64
    %158 = llvm.getelementptr %147[0, %157] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %149, %158 : i64, !llvm.ptr
    %159 = llvm.mlir.constant(1 : i64) : i64
    %160 = llvm.getelementptr %147[0, %159] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %150, %160 : i64, !llvm.ptr
    %161 = llvm.mlir.constant(2 : i64) : i64
    %162 = llvm.getelementptr %147[0, %161] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %151, %162 : i64, !llvm.ptr
    %163 = llvm.mlir.constant(3 : i64) : i64
    %164 = llvm.getelementptr %147[0, %163] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %152, %164 : i64, !llvm.ptr
    %165 = llvm.mlir.constant(4 : i64) : i64
    %166 = llvm.getelementptr %147[0, %165] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %153, %166 : i64, !llvm.ptr
    %167 = llvm.mlir.constant(5 : i64) : i64
    %168 = llvm.getelementptr %147[0, %167] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %154, %168 : i64, !llvm.ptr
    %169 = llvm.mlir.constant(6 : i64) : i64
    %170 = llvm.getelementptr %147[0, %169] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %155, %170 : i64, !llvm.ptr
    %171 = llvm.mlir.constant(7 : i64) : i64
    %172 = llvm.getelementptr %147[0, %171] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %156, %172 : i64, !llvm.ptr
    %174 = arith.constant 8 : i32
    %175 = arith.constant 7 : i32
    %176 = arith.constant 6 : i32
    %177 = arith.constant 5 : i32
    %178 = arith.constant 4 : i32
    %179 = arith.constant 3 : i32
    %180 = arith.constant 2 : i32
    %181 = arith.constant 1 : i32
    %182 = llvm.mlir.constant(1 : i64) : i64
    %183 = llvm.alloca %182 x !llvm.array<8 x i64> : (i64) -> !llvm.ptr
    %184 = llvm.mlir.zero : !llvm.array<8 x i64>
    llvm.store %184, %183 : !llvm.array<8 x i64>, !llvm.ptr
    %185 = arith.extsi %174 : i32 to i64
    %186 = arith.extsi %175 : i32 to i64
    %187 = arith.extsi %176 : i32 to i64
    %188 = arith.extsi %177 : i32 to i64
    %189 = arith.extsi %178 : i32 to i64
    %190 = arith.extsi %179 : i32 to i64
    %191 = arith.extsi %180 : i32 to i64
    %192 = arith.extsi %181 : i32 to i64
    %193 = llvm.mlir.constant(0 : i64) : i64
    %194 = llvm.getelementptr %183[0, %193] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %185, %194 : i64, !llvm.ptr
    %195 = llvm.mlir.constant(1 : i64) : i64
    %196 = llvm.getelementptr %183[0, %195] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %186, %196 : i64, !llvm.ptr
    %197 = llvm.mlir.constant(2 : i64) : i64
    %198 = llvm.getelementptr %183[0, %197] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %187, %198 : i64, !llvm.ptr
    %199 = llvm.mlir.constant(3 : i64) : i64
    %200 = llvm.getelementptr %183[0, %199] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %188, %200 : i64, !llvm.ptr
    %201 = llvm.mlir.constant(4 : i64) : i64
    %202 = llvm.getelementptr %183[0, %201] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %189, %202 : i64, !llvm.ptr
    %203 = llvm.mlir.constant(5 : i64) : i64
    %204 = llvm.getelementptr %183[0, %203] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %190, %204 : i64, !llvm.ptr
    %205 = llvm.mlir.constant(6 : i64) : i64
    %206 = llvm.getelementptr %183[0, %205] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %191, %206 : i64, !llvm.ptr
    %207 = llvm.mlir.constant(7 : i64) : i64
    %208 = llvm.getelementptr %183[0, %207] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
    llvm.store %192, %208 : i64, !llvm.ptr
    %209 = arith.constant 0 : i32
    %210 = arith.extsi %209 : i32 to i64
    llvm.store %210, %62 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %211 = llvm.load %62 : !llvm.ptr -> i64
    %212 = arith.constant 8 : i32
    %214 = arith.extsi %212 : i32 to i64
    %213 = arith.cmpi slt, %211, %214 : i64
    cf.cond_br %213, ^bb10, ^bb11
    ^bb10:
      %217 = llvm.load %62 : !llvm.ptr -> i64
      %218 = llvm.getelementptr %147[0, %217] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
      %216 = llvm.load %218 : !llvm.ptr -> i64
      %219 = llvm.mlir.addressof @MOD : !llvm.ptr
      %220 = llvm.load %219 : !llvm.ptr -> i64
      %221 = arith.constant 2 : i32
      %223 = arith.extsi %221 : i32 to i64
      %222 = arith.subi %220, %223 : i64
      %215 = func.call @modpow(%216, %222) : (i64, i64) -> i64
      %225 = llvm.load %62 : !llvm.ptr -> i64
      %226 = llvm.getelementptr %111[0, %225] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
      %224 = llvm.load %226 : !llvm.ptr -> i64
      %227 = llvm.mlir.addressof @MOD : !llvm.ptr
      %228 = llvm.load %227 : !llvm.ptr -> i64
      %229 = arith.remsi %224, %228 : i64
      %230 = llvm.mlir.constant(1 : i64) : i64
      %231 = llvm.alloca %230 x i64 : (i64) -> !llvm.ptr
      llvm.store %229, %231 : i64, !llvm.ptr
      %232 = llvm.load %231 : !llvm.ptr -> i64
      %233 = arith.constant 0 : i32
      %235 = arith.extsi %233 : i32 to i64
      %234 = arith.cmpi slt, %232, %235 : i64
      cf.cond_br %234, ^bb12, ^bb13
      ^bb12:
        %236 = llvm.load %231 : !llvm.ptr -> i64
        %237 = llvm.mlir.addressof @MOD : !llvm.ptr
        %238 = llvm.load %237 : !llvm.ptr -> i64
        %239 = arith.addi %236, %238 : i64
        llvm.store %239, %231 : i64, !llvm.ptr
        cf.br ^bb14
      ^bb13:
        cf.br ^bb14
      ^bb14:
      %240 = llvm.load %231 : !llvm.ptr -> i64
      %241 = arith.extsi %240 : i64 to i128
      %244 = llvm.load %62 : !llvm.ptr -> i64
      %245 = llvm.getelementptr %183[0, %244] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<8 x i64>
      %243 = llvm.load %245 : !llvm.ptr -> i64
      %246 = arith.index_cast %243 : i32 to index
      %242 = memref.load %51[%246] : memref<9xi64>
      %247 = arith.extsi %242 : i64 to i128
      %249 = arith.trunci %241 : i128 to i64
      %250 = arith.trunci %247 : i128 to i64
      %248 = arith.muli %249, %250 : i64
      %251 = llvm.mlir.addressof @MOD : !llvm.ptr
      %252 = llvm.load %251 : !llvm.ptr -> i64
      %253 = arith.extsi %252 : i64 to i128
      %255 = arith.trunci %253 : i128 to i64
      %254 = arith.remsi %248, %255 : i64
      llvm.store %254, %231 : i64, !llvm.ptr
      %256 = llvm.load %231 : !llvm.ptr -> i64
      %257 = arith.extsi %256 : i64 to i128
      %258 = arith.extsi %215 : i64 to i128
      %260 = arith.trunci %257 : i128 to i64
      %261 = arith.trunci %258 : i128 to i64
      %259 = arith.muli %260, %261 : i64
      %262 = llvm.mlir.addressof @MOD : !llvm.ptr
      %263 = llvm.load %262 : !llvm.ptr -> i64
      %264 = arith.extsi %263 : i64 to i128
      %266 = arith.trunci %264 : i128 to i64
      %265 = arith.remsi %259, %266 : i64
      llvm.store %265, %231 : i64, !llvm.ptr
      %267 = llvm.load %98 : !llvm.ptr -> i64
      %268 = llvm.load %231 : !llvm.ptr -> i64
      %269 = arith.addi %267, %268 : i64
      %270 = llvm.mlir.addressof @MOD : !llvm.ptr
      %271 = llvm.load %270 : !llvm.ptr -> i64
      %272 = arith.remsi %269, %271 : i64
      llvm.store %272, %98 : i64, !llvm.ptr
      %273 = llvm.load %62 : !llvm.ptr -> i64
      %274 = arith.constant 1 : i32
      %276 = arith.extsi %274 : i32 to i64
      %275 = arith.addi %273, %276 : i64
      llvm.store %275, %62 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %277 = llvm.load %98 : !llvm.ptr -> i64
    func.return %277 : i64
  }
  func.func @main() -> i32 {
    %278 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %280 = arith.constant 999999995705032704 : i32
    %281 = arith.extsi %280 : i32 to i64
    %279 = func.call @f_even_mod(%281) : (i64) -> i64
    %282 = llvm.call @printf(%278, %279) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %283 = arith.constant 0 : i32
    func.return %283 : i32
  }
}