Problem 773

Riffle Shuffles: F(97) mod 1_000_000_007.

Answer556206950
Output556206950
StatusPASS
Native helperno
Runtime0 ms
Peak memory1072 KB
Time complexityO(n) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)?
Space complexityO(n)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 773
# Riffle Shuffles: F(97) mod 1_000_000_007.

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

const MOD: i64 = 1000000007

function modpow(b: i64, e: i64) -> i64 {
    let mut r: i64 = 1
    let mut bb: i64 = b % MOD
    let mut ee: i64 = e
    while ee > 0 {
        if ee % 2 == 1 {
            r = r * bb % MOD
        }
        bb = bb * bb % MOD
        ee = ee / 2
    }
    return r
}

function is_prime_flow(n: i32) -> bool {
    if n < 2 { return false }
    let mut i: i32 = 2
    while i * i <= n {
        if n % i == 0 { return false }
        i = i + 1
    }
    return true
}

function main() -> i32 {
    let k: i32 = 97
    let primes: ptr<i64> = calloc(k as i64, 8)
    let mut cnt: i32 = 0
    let mut x: i32 = 7
    while cnt < k {
        if x % 10 == 7 && is_prime_flow(x) {
            primes[cnt] = x as i64
            cnt = cnt + 1
        }
        x = x + 2
    }

    let mut M_mod: i64 = 1
    let mut phi_mod: i64 = 1
    let mut i: i32 = 0
    while i < k {
        M_mod = M_mod * primes[i] % MOD
        phi_mod = phi_mod * (primes[i] - 1) % MOD
        i = i + 1
    }

    let q_table: array<i64, 4> = [7, 1, 3, 9]
    let mut A: i64 = 0
    let mut c: i64 = 1
    let mut s: i32 = 0
    while s <= k {
        let term: i64 = c * q_table[s % 4] % MOD
        if s % 2 == 1 {
            A = (A - term) % MOD
        } else {
            A = (A + term) % MOD
        }
        if s < k {
            c = c * ((k - s) as i64) % MOD
            c = c * modpow((s + 1) as i64, MOD - 2) % MOD
        }
        s = s + 1
    }
    if A < 0 {
        A = A + MOD
    }
    let result: i64 = M_mod * ((A + 5 * phi_mod) % MOD) % MOD
    printf("%lld\n", result)
    free(primes)
    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 b, int64_t e);
bool is_prime_flow_i32(int32_t n);
int32_t main(void);

static const int64_t MOD = 1000000007;



int64_t modpow_i64_i64(int64_t b, int64_t e) {
    int64_t r = 1;
    int64_t bb = FLOW_CHECKED_MOD((b), (MOD));
    int64_t ee = e;
    while (ee > 0) {
        if (FLOW_CHECKED_MOD((ee), (2)) == 1) {
            r = FLOW_CHECKED_MOD(((r * bb)), (MOD));
        }
        bb = FLOW_CHECKED_MOD(((bb * bb)), (MOD));
        ee = FLOW_CHECKED_DIV((ee), (2));
    }
    return r;
}

bool is_prime_flow_i32(int32_t n) {
    if (n < 2) {
        return 0;
    }
    int32_t i = 2;
    while ((i * i) <= n) {
        if (FLOW_CHECKED_MOD((n), (i)) == 0) {
            return 0;
        }
        i = (i + 1);
    }
    return 1;
}

int32_t main(void) {
    int32_t k = 97;
    int64_t* primes = (int64_t*)(calloc(((int64_t)(k)), 8));
    int32_t cnt = 0;
    int32_t x = 7;
    while (cnt < k) {
        if ((FLOW_CHECKED_MOD((x), (10)) == 7 && is_prime_flow_i32(x))) {
            primes[cnt] = ((int64_t)(x));
            cnt = (cnt + 1);
        }
        x = (x + 2);
    }
    int64_t M_mod = 1;
    int64_t phi_mod = 1;
    int32_t i = 0;
    while (i < k) {
        M_mod = FLOW_CHECKED_MOD(((M_mod * primes[i])), (MOD));
        phi_mod = FLOW_CHECKED_MOD(((phi_mod * (primes[i] - 1))), (MOD));
        i = (i + 1);
    }
    int64_t q_table[4] = { 7, 1, 3, 9 };
    int64_t A = 0;
    int64_t c = 1;
    int32_t s = 0;
    while (s <= k) {
        int64_t term = FLOW_CHECKED_MOD(((c * (((unsigned)(FLOW_CHECKED_MOD((s), (4))) < 4) ? q_table[FLOW_CHECKED_MOD((s), (4))] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(FLOW_CHECKED_MOD((s), (4))), 4), flow_fault_handler("array index out of bounds"), q_table[0])))), (MOD));
        if (FLOW_CHECKED_MOD((s), (2)) == 1) {
            A = FLOW_CHECKED_MOD(((A - term)), (MOD));
        } else {
            A = FLOW_CHECKED_MOD(((A + term)), (MOD));
        }
        if (s < k) {
            c = FLOW_CHECKED_MOD(((c * ((int64_t)((k - s))))), (MOD));
            c = FLOW_CHECKED_MOD(((c * modpow_i64_i64(((int64_t)((s + 1))), (MOD - 2)))), (MOD));
        }
        s = (s + 1);
    }
    if (A < 0) {
        A = (A + MOD);
    }
    int64_t result = FLOW_CHECKED_MOD(((M_mod * FLOW_CHECKED_MOD(((A + (5 * phi_mod))), (MOD)))), (MOD));
    printf("%lld\n", result);
    free(primes);
    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) -> ()
  // 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 2 : i32
      %18 = arith.extsi %16 : i32 to i64
      %17 = arith.remsi %15, %18 : i64
      %19 = arith.constant 1 : i32
      %21 = arith.extsi %19 : i32 to i64
      %20 = arith.cmpi eq, %17, %21 : i64
      cf.cond_br %20, ^bb3, ^bb4
      ^bb3:
        %22 = llvm.load %3 : !llvm.ptr -> i64
        %23 = llvm.load %8 : !llvm.ptr -> i64
        %24 = arith.muli %22, %23 : i64
        %25 = llvm.mlir.addressof @MOD : !llvm.ptr
        %26 = llvm.load %25 : !llvm.ptr -> i64
        %27 = arith.remsi %24, %26 : i64
        llvm.store %27, %3 : i64, !llvm.ptr
        cf.br ^bb5
      ^bb4:
        cf.br ^bb5
      ^bb5:
      %28 = llvm.load %8 : !llvm.ptr -> i64
      %29 = llvm.load %8 : !llvm.ptr -> i64
      %30 = arith.muli %28, %29 : i64
      %31 = llvm.mlir.addressof @MOD : !llvm.ptr
      %32 = llvm.load %31 : !llvm.ptr -> i64
      %33 = arith.remsi %30, %32 : i64
      llvm.store %33, %8 : i64, !llvm.ptr
      %34 = llvm.load %10 : !llvm.ptr -> i64
      %35 = arith.constant 2 : i32
      %37 = arith.extsi %35 : i32 to i64
      %36 = arith.divsi %34, %37 : i64
      llvm.store %36, %10 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %38 = llvm.load %3 : !llvm.ptr -> i64
    func.return %38 : i64
  }
  func.func @is_prime_flow(%arg0: i32) -> i1 {
    %39 = arith.constant 2 : i32
    %40 = arith.cmpi slt, %arg0, %39 : i32
    cf.cond_br %40, ^bb6, ^bb7
    ^bb6:
      %41 = arith.constant 0 : i1
      func.return %41 : i1
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %42 = arith.constant 2 : i32
    %43 = llvm.mlir.constant(1 : i64) : i64
    %44 = llvm.alloca %43 x i32 : (i64) -> !llvm.ptr
    llvm.store %42, %44 : i32, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %45 = llvm.load %44 : !llvm.ptr -> i32
    %46 = llvm.load %44 : !llvm.ptr -> i32
    %47 = arith.muli %45, %46 : i32
    %48 = arith.cmpi sle, %47, %arg0 : i32
    cf.cond_br %48, ^bb10, ^bb11
    ^bb10:
      %49 = llvm.load %44 : !llvm.ptr -> i32
      %50 = arith.remsi %arg0, %49 : i32
      %51 = arith.constant 0 : i32
      %52 = arith.cmpi eq, %50, %51 : i32
      cf.cond_br %52, ^bb12, ^bb13
      ^bb12:
        %53 = arith.constant 0 : i1
        func.return %53 : i1
      ^bb13:
        cf.br ^bb14
      ^bb14:
      %54 = llvm.load %44 : !llvm.ptr -> i32
      %55 = arith.constant 1 : i32
      %56 = arith.addi %54, %55 : i32
      llvm.store %56, %44 : i32, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %57 = arith.constant 1 : i1
    func.return %57 : i1
  }
  func.func @main() -> i32 {
    %58 = arith.constant 97 : i32
    %60 = arith.extsi %58 : i32 to i64
    %61 = arith.constant 8 : i32
    %62 = arith.extsi %61 : i32 to i64
    %59 = func.call @calloc(%60, %62) : (i64, i64) -> !llvm.ptr
    %63 = arith.constant 0 : i32
    %64 = llvm.mlir.constant(1 : i64) : i64
    %65 = llvm.alloca %64 x i32 : (i64) -> !llvm.ptr
    llvm.store %63, %65 : i32, !llvm.ptr
    %66 = arith.constant 7 : i32
    %67 = llvm.mlir.constant(1 : i64) : i64
    %68 = llvm.alloca %67 x i32 : (i64) -> !llvm.ptr
    llvm.store %66, %68 : i32, !llvm.ptr
    cf.br ^bb15
    ^bb15:
    %69 = llvm.load %65 : !llvm.ptr -> i32
    %70 = arith.cmpi slt, %69, %58 : i32
    cf.cond_br %70, ^bb16, ^bb17
    ^bb16:
      %71 = llvm.load %68 : !llvm.ptr -> i32
      %72 = arith.constant 10 : i32
      %73 = arith.remsi %71, %72 : i32
      %74 = arith.constant 7 : i32
      %75 = arith.cmpi eq, %73, %74 : i32
      %76 = scf.if %75 -> (i1) {
        %78 = llvm.load %68 : !llvm.ptr -> i32
        %77 = func.call @is_prime_flow(%78) : (i32) -> i1
        scf.yield %77 : i1
      } else {
        %79 = arith.constant false
        scf.yield %79 : i1
      }
      cf.cond_br %76, ^bb18, ^bb19
      ^bb18:
        %80 = llvm.load %68 : !llvm.ptr -> i32
        %81 = arith.extsi %80 : i32 to i64
        %82 = llvm.load %65 : !llvm.ptr -> i32
        %83 = arith.extsi %82 : i32 to i64
        %84 = llvm.getelementptr %59[%83] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %81, %84 : i64, !llvm.ptr
        %85 = llvm.load %65 : !llvm.ptr -> i32
        %86 = arith.constant 1 : i32
        %87 = arith.addi %85, %86 : i32
        llvm.store %87, %65 : i32, !llvm.ptr
        cf.br ^bb20
      ^bb19:
        cf.br ^bb20
      ^bb20:
      %88 = llvm.load %68 : !llvm.ptr -> i32
      %89 = arith.constant 2 : i32
      %90 = arith.addi %88, %89 : i32
      llvm.store %90, %68 : i32, !llvm.ptr
      cf.br ^bb15
    ^bb17:
    %91 = arith.constant 1 : i32
    %92 = arith.extsi %91 : i32 to i64
    %93 = llvm.mlir.constant(1 : i64) : i64
    %94 = llvm.alloca %93 x i64 : (i64) -> !llvm.ptr
    llvm.store %92, %94 : i64, !llvm.ptr
    %95 = arith.constant 1 : i32
    %96 = arith.extsi %95 : i32 to i64
    %97 = llvm.mlir.constant(1 : i64) : i64
    %98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
    llvm.store %96, %98 : i64, !llvm.ptr
    %99 = arith.constant 0 : i32
    %100 = llvm.mlir.constant(1 : i64) : i64
    %101 = llvm.alloca %100 x i32 : (i64) -> !llvm.ptr
    llvm.store %99, %101 : i32, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %102 = llvm.load %101 : !llvm.ptr -> i32
    %103 = arith.cmpi slt, %102, %58 : i32
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %104 = llvm.load %94 : !llvm.ptr -> i64
      %106 = llvm.load %101 : !llvm.ptr -> i32
      %107 = arith.extsi %106 : i32 to i64
      %108 = llvm.getelementptr %59[%107] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %105 = llvm.load %108 : !llvm.ptr -> i64
      %109 = arith.muli %104, %105 : i64
      %110 = llvm.mlir.addressof @MOD : !llvm.ptr
      %111 = llvm.load %110 : !llvm.ptr -> i64
      %112 = arith.remsi %109, %111 : i64
      llvm.store %112, %94 : i64, !llvm.ptr
      %113 = llvm.load %98 : !llvm.ptr -> i64
      %115 = llvm.load %101 : !llvm.ptr -> i32
      %116 = arith.extsi %115 : i32 to i64
      %117 = llvm.getelementptr %59[%116] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %114 = llvm.load %117 : !llvm.ptr -> i64
      %118 = arith.constant 1 : i32
      %120 = arith.extsi %118 : i32 to i64
      %119 = arith.subi %114, %120 : i64
      %121 = arith.muli %113, %119 : i64
      %122 = llvm.mlir.addressof @MOD : !llvm.ptr
      %123 = llvm.load %122 : !llvm.ptr -> i64
      %124 = arith.remsi %121, %123 : i64
      llvm.store %124, %98 : i64, !llvm.ptr
      %125 = llvm.load %101 : !llvm.ptr -> i32
      %126 = arith.constant 1 : i32
      %127 = arith.addi %125, %126 : i32
      llvm.store %127, %101 : i32, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %129 = arith.constant 7 : i32
    %130 = arith.constant 1 : i32
    %131 = arith.constant 3 : i32
    %132 = arith.constant 9 : i32
    %133 = llvm.mlir.constant(1 : i64) : i64
    %134 = llvm.alloca %133 x !llvm.array<4 x i64> : (i64) -> !llvm.ptr
    %135 = llvm.mlir.zero : !llvm.array<4 x i64>
    llvm.store %135, %134 : !llvm.array<4 x i64>, !llvm.ptr
    %136 = arith.extsi %129 : i32 to i64
    %137 = arith.extsi %130 : i32 to i64
    %138 = arith.extsi %131 : i32 to i64
    %139 = arith.extsi %132 : i32 to i64
    %140 = llvm.mlir.constant(0 : i64) : i64
    %141 = llvm.getelementptr %134[0, %140] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<4 x i64>
    llvm.store %136, %141 : i64, !llvm.ptr
    %142 = llvm.mlir.constant(1 : i64) : i64
    %143 = llvm.getelementptr %134[0, %142] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<4 x i64>
    llvm.store %137, %143 : i64, !llvm.ptr
    %144 = llvm.mlir.constant(2 : i64) : i64
    %145 = llvm.getelementptr %134[0, %144] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<4 x i64>
    llvm.store %138, %145 : i64, !llvm.ptr
    %146 = llvm.mlir.constant(3 : i64) : i64
    %147 = llvm.getelementptr %134[0, %146] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<4 x i64>
    llvm.store %139, %147 : i64, !llvm.ptr
    %148 = arith.constant 0 : i32
    %149 = arith.extsi %148 : i32 to i64
    %150 = llvm.mlir.constant(1 : i64) : i64
    %151 = llvm.alloca %150 x i64 : (i64) -> !llvm.ptr
    llvm.store %149, %151 : i64, !llvm.ptr
    %152 = arith.constant 1 : i32
    %153 = arith.extsi %152 : i32 to i64
    %154 = llvm.mlir.constant(1 : i64) : i64
    %155 = llvm.alloca %154 x i64 : (i64) -> !llvm.ptr
    llvm.store %153, %155 : i64, !llvm.ptr
    %156 = arith.constant 0 : i32
    %157 = llvm.mlir.constant(1 : i64) : i64
    %158 = llvm.alloca %157 x i32 : (i64) -> !llvm.ptr
    llvm.store %156, %158 : i32, !llvm.ptr
    cf.br ^bb24
    ^bb24:
    %159 = llvm.load %158 : !llvm.ptr -> i32
    %160 = arith.cmpi sle, %159, %58 : i32
    cf.cond_br %160, ^bb25, ^bb26
    ^bb25:
      %161 = llvm.load %155 : !llvm.ptr -> i64
      %163 = llvm.load %158 : !llvm.ptr -> i32
      %164 = arith.constant 4 : i32
      %165 = arith.remsi %163, %164 : i32
      %166 = arith.extsi %165 : i32 to i64
      %167 = llvm.getelementptr %134[0, %166] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<4 x i64>
      %162 = llvm.load %167 : !llvm.ptr -> i64
      %168 = arith.muli %161, %162 : i64
      %169 = llvm.mlir.addressof @MOD : !llvm.ptr
      %170 = llvm.load %169 : !llvm.ptr -> i64
      %171 = arith.remsi %168, %170 : i64
      %172 = llvm.load %158 : !llvm.ptr -> i32
      %173 = arith.constant 2 : i32
      %174 = arith.remsi %172, %173 : i32
      %175 = arith.constant 1 : i32
      %176 = arith.cmpi eq, %174, %175 : i32
      cf.cond_br %176, ^bb27, ^bb28
      ^bb27:
        %177 = llvm.load %151 : !llvm.ptr -> i64
        %178 = arith.subi %177, %171 : i64
        %179 = llvm.mlir.addressof @MOD : !llvm.ptr
        %180 = llvm.load %179 : !llvm.ptr -> i64
        %181 = arith.remsi %178, %180 : i64
        llvm.store %181, %151 : i64, !llvm.ptr
        cf.br ^bb29
      ^bb28:
        %182 = llvm.load %151 : !llvm.ptr -> i64
        %183 = arith.addi %182, %171 : i64
        %184 = llvm.mlir.addressof @MOD : !llvm.ptr
        %185 = llvm.load %184 : !llvm.ptr -> i64
        %186 = arith.remsi %183, %185 : i64
        llvm.store %186, %151 : i64, !llvm.ptr
        cf.br ^bb29
      ^bb29:
      %187 = llvm.load %158 : !llvm.ptr -> i32
      %188 = arith.cmpi slt, %187, %58 : i32
      cf.cond_br %188, ^bb30, ^bb31
      ^bb30:
        %189 = llvm.load %155 : !llvm.ptr -> i64
        %190 = llvm.load %158 : !llvm.ptr -> i32
        %191 = arith.subi %58, %190 : i32
        %192 = arith.extsi %191 : i32 to i64
        %193 = arith.muli %189, %192 : i64
        %194 = llvm.mlir.addressof @MOD : !llvm.ptr
        %195 = llvm.load %194 : !llvm.ptr -> i64
        %196 = arith.remsi %193, %195 : i64
        llvm.store %196, %155 : i64, !llvm.ptr
        %197 = llvm.load %155 : !llvm.ptr -> i64
        %199 = llvm.load %158 : !llvm.ptr -> i32
        %200 = arith.constant 1 : i32
        %201 = arith.addi %199, %200 : i32
        %202 = arith.extsi %201 : i32 to i64
        %203 = llvm.mlir.addressof @MOD : !llvm.ptr
        %204 = llvm.load %203 : !llvm.ptr -> i64
        %205 = arith.constant 2 : i32
        %207 = arith.extsi %205 : i32 to i64
        %206 = arith.subi %204, %207 : i64
        %198 = func.call @modpow(%202, %206) : (i64, i64) -> i64
        %208 = arith.muli %197, %198 : i64
        %209 = llvm.mlir.addressof @MOD : !llvm.ptr
        %210 = llvm.load %209 : !llvm.ptr -> i64
        %211 = arith.remsi %208, %210 : i64
        llvm.store %211, %155 : i64, !llvm.ptr
        cf.br ^bb32
      ^bb31:
        cf.br ^bb32
      ^bb32:
      %212 = llvm.load %158 : !llvm.ptr -> i32
      %213 = arith.constant 1 : i32
      %214 = arith.addi %212, %213 : i32
      llvm.store %214, %158 : i32, !llvm.ptr
      cf.br ^bb24
    ^bb26:
    %215 = llvm.load %151 : !llvm.ptr -> i64
    %216 = arith.constant 0 : i32
    %218 = arith.extsi %216 : i32 to i64
    %217 = arith.cmpi slt, %215, %218 : i64
    cf.cond_br %217, ^bb33, ^bb34
    ^bb33:
      %219 = llvm.load %151 : !llvm.ptr -> i64
      %220 = llvm.mlir.addressof @MOD : !llvm.ptr
      %221 = llvm.load %220 : !llvm.ptr -> i64
      %222 = arith.addi %219, %221 : i64
      llvm.store %222, %151 : i64, !llvm.ptr
      cf.br ^bb35
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %223 = llvm.load %94 : !llvm.ptr -> i64
    %224 = llvm.load %151 : !llvm.ptr -> i64
    %225 = arith.constant 5 : i32
    %226 = llvm.load %98 : !llvm.ptr -> i64
    %228 = arith.extsi %225 : i32 to i64
    %227 = arith.muli %228, %226 : i64
    %229 = arith.addi %224, %227 : i64
    %230 = llvm.mlir.addressof @MOD : !llvm.ptr
    %231 = llvm.load %230 : !llvm.ptr -> i64
    %232 = arith.remsi %229, %231 : i64
    %233 = arith.muli %223, %232 : i64
    %234 = llvm.mlir.addressof @MOD : !llvm.ptr
    %235 = llvm.load %234 : !llvm.ptr -> i64
    %236 = arith.remsi %233, %235 : i64
    %237 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %238 = llvm.call @printf(%237, %236) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%59) : (!llvm.ptr) -> ()
    %240 = arith.constant 0 : i32
    func.return %240 : i32
  }
}