← All problems
Problem 423
S(5e7) mod 10^9+7 for consecutive die-throw match counts.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n^2)O(n log n)
Space complexity O(n)O(n)
Approach Flow solution Modular DP or matrix exponentiation
Verdict Suboptimal
Flow source
# Project Euler 423
# S(5e7) mod 10^9+7 for consecutive die-throw match counts.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function main() -> i32 {
let L: i64 = 50000000
let MOD: i64 = 1000000007
let size: i64 = L / 2 + 1
let odd: ptr<i8> = calloc(size, 1)
if odd == null { return 1 }
let mut i: i64 = 0
while i < size {
odd[i] = 1
i = i + 1
}
odd[0] = 0
let mut p: i64 = 3
while p * p <= L {
if odd[p >> 1] != 0 {
let mut cur: i64 = (p * p) >> 1
while cur < size {
odd[cur] = 0
cur = cur + p
}
}
p = p + 2
}
let mut pi_L: i64 = 1
i = 1
while i < size {
if odd[i] != 0 { pi_L = pi_L + 1 }
i = i + 1
}
let d_L: i64 = L - pi_L
let max_needed: i64 = d_L
if pi_L + 1 > max_needed { max_needed = pi_L + 1 }
max_needed = max_needed + 2
let inv: ptr<i64> = calloc(max_needed + 1, 8)
if inv == null { return 1 }
inv[1] = 1
i = 2
while i <= max_needed {
inv[i] = MOD - ((MOD / i) * inv[MOD % i]) % MOD
i = i + 1
}
let inv5: i64 = 400000003 # pow(5, MOD-2, MOD)
let mut C: i64 = 6
let mut b: i64 = 6
let mut k: i64 = 0
let mut d: i64 = 1
let mut S: i64 = 6
# n=2 prime
C = 36
b = 6
k = 1
d = 1
S = (S + C) % MOD
let mut n: i64 = 2
while n <= L - 2 {
let m: i64 = n + 1
let mut C1: i64 = 0
let mut b1: i64 = 0
let mut k1: i64 = 0
let mut d1: i64 = 0
if odd[m >> 1] != 0 {
let mut extra: i64 = (b * inv5) % MOD
extra = (extra * (d - 1)) % MOD
extra = (extra * inv[k + 1]) % MOD
C1 = (6 * C + 5 * extra) % MOD
b1 = (b + 5 * extra) % MOD
k1 = k + 1
d1 = d
} else {
C1 = (6 * C - b) % MOD
if C1 < 0 { C1 = C1 + MOD }
b1 = (b * 5) % MOD
b1 = (b1 * n) % MOD
b1 = (b1 * inv[d]) % MOD
k1 = k
d1 = d + 1
}
S = (S + C1) % MOD
let mut C2: i64 = (6 * C1 - b1) % MOD
if C2 < 0 { C2 = C2 + MOD }
let mut b2: i64 = (b1 * 5) % MOD
b2 = (b2 * m) % MOD
b2 = (b2 * inv[d1]) % MOD
S = (S + C2) % MOD
C = C2
b = b2
k = k1
d = d1 + 1
n = m + 1
}
printf("%lld\n", S)
free(inv)
free(odd)
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; }
int32_t main(void);
int32_t main(void) {
int64_t L = 50000000;
int64_t MOD = 1000000007;
int64_t size = (FLOW_CHECKED_DIV((L), (2)) + 1);
int8_t* odd = (int8_t*)(calloc(size, 1));
if (odd == NULL) {
return 1;
}
int64_t i = 0;
while (i < size) {
odd[i] = 1;
i = (i + 1);
}
odd[0] = 0;
int64_t p = 3;
while ((p * p) <= L) {
if (odd[FLOW_CHECKED_SHR((p), (1))] != 0) {
int64_t cur = FLOW_CHECKED_SHR(((p * p)), (1));
while (cur < size) {
odd[cur] = 0;
cur = (cur + p);
}
}
p = (p + 2);
}
int64_t pi_L = 1;
i = 1;
while (i < size) {
if (odd[i] != 0) {
pi_L = (pi_L + 1);
}
i = (i + 1);
}
int64_t d_L = (L - pi_L);
int64_t max_needed = d_L;
if ((pi_L + 1) > max_needed) {
max_needed = (pi_L + 1);
}
max_needed = (max_needed + 2);
int64_t* inv = (int64_t*)(calloc((max_needed + 1), 8));
if (inv == NULL) {
return 1;
}
inv[1] = 1;
i = 2;
while (i <= max_needed) {
inv[i] = (MOD - FLOW_CHECKED_MOD(((FLOW_CHECKED_DIV((MOD), (i)) * inv[FLOW_CHECKED_MOD((MOD), (i))])), (MOD)));
i = (i + 1);
}
int64_t inv5 = 400000003;
int64_t C = 6;
int64_t b = 6;
int64_t k = 0;
int64_t d = 1;
int64_t S = 6;
C = 36;
b = 6;
k = 1;
d = 1;
S = FLOW_CHECKED_MOD(((S + C)), (MOD));
int64_t n = 2;
while (n <= (L - 2)) {
int64_t m = (n + 1);
int64_t C1 = 0;
int64_t b1 = 0;
int64_t k1 = 0;
int64_t d1 = 0;
if (odd[FLOW_CHECKED_SHR((m), (1))] != 0) {
int64_t extra = FLOW_CHECKED_MOD(((b * inv5)), (MOD));
extra = FLOW_CHECKED_MOD(((extra * (d - 1))), (MOD));
extra = FLOW_CHECKED_MOD(((extra * inv[(k + 1)])), (MOD));
C1 = FLOW_CHECKED_MOD((((6 * C) + (5 * extra))), (MOD));
b1 = FLOW_CHECKED_MOD(((b + (5 * extra))), (MOD));
k1 = (k + 1);
d1 = d;
} else {
C1 = FLOW_CHECKED_MOD((((6 * C) - b)), (MOD));
if (C1 < 0) {
C1 = (C1 + MOD);
}
b1 = FLOW_CHECKED_MOD(((b * 5)), (MOD));
b1 = FLOW_CHECKED_MOD(((b1 * n)), (MOD));
b1 = FLOW_CHECKED_MOD(((b1 * inv[d])), (MOD));
k1 = k;
d1 = (d + 1);
}
S = FLOW_CHECKED_MOD(((S + C1)), (MOD));
int64_t C2 = FLOW_CHECKED_MOD((((6 * C1) - b1)), (MOD));
if (C2 < 0) {
C2 = (C2 + MOD);
}
int64_t b2 = FLOW_CHECKED_MOD(((b1 * 5)), (MOD));
b2 = FLOW_CHECKED_MOD(((b2 * m)), (MOD));
b2 = FLOW_CHECKED_MOD(((b2 * inv[d1])), (MOD));
S = FLOW_CHECKED_MOD(((S + C2)), (MOD));
C = C2;
b = b2;
k = k1;
d = (d1 + 1);
n = (m + 1);
}
printf("%lld\n", S);
free(inv);
free(odd);
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 @main() -> i32 {
%0 = arith.constant 50000000 : i32
%1 = arith.extsi %0 : i32 to i64
%2 = arith.constant 1000000007 : i32
%3 = arith.extsi %2 : i32 to i64
%4 = arith.constant 2 : i32
%6 = arith.extsi %4 : i32 to i64
%5 = arith.divsi %1, %6 : i64
%7 = arith.constant 1 : i32
%9 = arith.extsi %7 : i32 to i64
%8 = arith.addi %5, %9 : i64
%11 = arith.constant 1 : i32
%12 = arith.extsi %11 : i32 to i64
%10 = func.call @calloc(%8, %12) : (i64, i64) -> !llvm.ptr
%13 = llvm.mlir.zero : !llvm.ptr
%14 = llvm.icmp "eq" %10, %13 : !llvm.ptr
cf.cond_br %14, ^bb0, ^bb1
^bb0:
%15 = arith.constant 1 : i32
func.return %15 : i32
^bb1:
cf.br ^bb2
^bb2:
%16 = arith.constant 0 : i32
%17 = arith.extsi %16 : i32 to i64
%18 = llvm.mlir.constant(1 : i64) : i64
%19 = llvm.alloca %18 x i64 : (i64) -> !llvm.ptr
llvm.store %17, %19 : i64, !llvm.ptr
cf.br ^bb3
^bb3:
%20 = llvm.load %19 : !llvm.ptr -> i64
%21 = arith.cmpi slt, %20, %8 : i64
cf.cond_br %21, ^bb4, ^bb5
^bb4:
%22 = arith.constant 1 : i32
%23 = llvm.load %19 : !llvm.ptr -> i64
%24 = arith.trunci %22 : i32 to i8
%25 = llvm.getelementptr %10[%23] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %24, %25 : i8, !llvm.ptr
%26 = llvm.load %19 : !llvm.ptr -> i64
%27 = arith.constant 1 : i32
%29 = arith.extsi %27 : i32 to i64
%28 = arith.addi %26, %29 : i64
llvm.store %28, %19 : i64, !llvm.ptr
cf.br ^bb3
^bb5:
%30 = arith.constant 0 : i32
%31 = arith.constant 0 : i32
%32 = arith.trunci %30 : i32 to i8
%33 = arith.extsi %31 : i32 to i64
%34 = llvm.getelementptr %10[%33] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %32, %34 : i8, !llvm.ptr
%35 = arith.constant 3 : 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 = llvm.load %38 : !llvm.ptr -> i64
%41 = arith.muli %39, %40 : i64
%42 = arith.cmpi sle, %41, %1 : i64
cf.cond_br %42, ^bb7, ^bb8
^bb7:
%44 = llvm.load %38 : !llvm.ptr -> i64
%45 = arith.constant 1 : i32
%47 = arith.extsi %45 : i32 to i64
%46 = arith.shrsi %44, %47 : i64
%48 = llvm.getelementptr %10[%46] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%43 = llvm.load %48 : !llvm.ptr -> i8
%49 = arith.constant 0 : i32
%51 = arith.extsi %43 : i8 to i32
%50 = arith.cmpi ne, %51, %49 : i32
cf.cond_br %50, ^bb9, ^bb10
^bb9:
%52 = llvm.load %38 : !llvm.ptr -> i64
%53 = llvm.load %38 : !llvm.ptr -> i64
%54 = arith.muli %52, %53 : i64
%55 = arith.constant 1 : i32
%57 = arith.extsi %55 : i32 to i64
%56 = arith.shrsi %54, %57 : i64
%58 = llvm.mlir.constant(1 : i64) : i64
%59 = llvm.alloca %58 x i64 : (i64) -> !llvm.ptr
llvm.store %56, %59 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%60 = llvm.load %59 : !llvm.ptr -> i64
%61 = arith.cmpi slt, %60, %8 : i64
cf.cond_br %61, ^bb13, ^bb14
^bb13:
%62 = arith.constant 0 : i32
%63 = llvm.load %59 : !llvm.ptr -> i64
%64 = arith.trunci %62 : i32 to i8
%65 = llvm.getelementptr %10[%63] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %64, %65 : i8, !llvm.ptr
%66 = llvm.load %59 : !llvm.ptr -> i64
%67 = llvm.load %38 : !llvm.ptr -> i64
%68 = arith.addi %66, %67 : i64
llvm.store %68, %59 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
cf.br ^bb11
^bb10:
cf.br ^bb11
^bb11:
%69 = llvm.load %38 : !llvm.ptr -> i64
%70 = arith.constant 2 : i32
%72 = arith.extsi %70 : i32 to i64
%71 = arith.addi %69, %72 : i64
llvm.store %71, %38 : i64, !llvm.ptr
cf.br ^bb6
^bb8:
%73 = arith.constant 1 : i32
%74 = arith.extsi %73 : i32 to i64
%75 = llvm.mlir.constant(1 : i64) : i64
%76 = llvm.alloca %75 x i64 : (i64) -> !llvm.ptr
llvm.store %74, %76 : i64, !llvm.ptr
%77 = arith.constant 1 : i32
%78 = arith.extsi %77 : i32 to i64
llvm.store %78, %19 : i64, !llvm.ptr
cf.br ^bb15
^bb15:
%79 = llvm.load %19 : !llvm.ptr -> i64
%80 = arith.cmpi slt, %79, %8 : i64
cf.cond_br %80, ^bb16, ^bb17
^bb16:
%82 = llvm.load %19 : !llvm.ptr -> i64
%83 = llvm.getelementptr %10[%82] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%81 = llvm.load %83 : !llvm.ptr -> i8
%84 = arith.constant 0 : i32
%86 = arith.extsi %81 : i8 to i32
%85 = arith.cmpi ne, %86, %84 : i32
cf.cond_br %85, ^bb18, ^bb19
^bb18:
%87 = llvm.load %76 : !llvm.ptr -> i64
%88 = arith.constant 1 : i32
%90 = arith.extsi %88 : i32 to i64
%89 = arith.addi %87, %90 : i64
llvm.store %89, %76 : i64, !llvm.ptr
cf.br ^bb20
^bb19:
cf.br ^bb20
^bb20:
%91 = llvm.load %19 : !llvm.ptr -> i64
%92 = arith.constant 1 : i32
%94 = arith.extsi %92 : i32 to i64
%93 = arith.addi %91, %94 : i64
llvm.store %93, %19 : i64, !llvm.ptr
cf.br ^bb15
^bb17:
%95 = llvm.load %76 : !llvm.ptr -> i64
%96 = arith.subi %1, %95 : i64
%97 = llvm.load %76 : !llvm.ptr -> i64
%98 = arith.constant 1 : i32
%100 = arith.extsi %98 : i32 to i64
%99 = arith.addi %97, %100 : i64
%101 = arith.cmpi sgt, %99, %96 : i64
%102 = scf.if %101 -> (i64) {
%103 = llvm.load %76 : !llvm.ptr -> i64
%104 = arith.constant 1 : i32
%106 = arith.extsi %104 : i32 to i64
%105 = arith.addi %103, %106 : i64
scf.yield %105 : i64
} else {
scf.yield %96 : i64
}
%107 = arith.constant 2 : i32
%109 = arith.extsi %107 : i32 to i64
%108 = arith.addi %102, %109 : i64
%111 = arith.constant 1 : i32
%113 = arith.extsi %111 : i32 to i64
%112 = arith.addi %108, %113 : i64
%114 = arith.constant 8 : i32
%115 = arith.extsi %114 : i32 to i64
%110 = func.call @calloc(%112, %115) : (i64, i64) -> !llvm.ptr
%116 = llvm.mlir.zero : !llvm.ptr
%117 = llvm.icmp "eq" %110, %116 : !llvm.ptr
cf.cond_br %117, ^bb21, ^bb22
^bb21:
%118 = arith.constant 1 : i32
func.return %118 : i32
^bb22:
cf.br ^bb23
^bb23:
%119 = arith.constant 1 : i32
%120 = arith.constant 1 : i32
%121 = arith.extsi %119 : i32 to i64
%122 = arith.extsi %120 : i32 to i64
%123 = llvm.getelementptr %110[%122] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %121, %123 : i64, !llvm.ptr
%124 = arith.constant 2 : i32
%125 = arith.extsi %124 : i32 to i64
llvm.store %125, %19 : i64, !llvm.ptr
cf.br ^bb24
^bb24:
%126 = llvm.load %19 : !llvm.ptr -> i64
%127 = arith.cmpi sle, %126, %108 : i64
cf.cond_br %127, ^bb25, ^bb26
^bb25:
%128 = llvm.load %19 : !llvm.ptr -> i64
%129 = arith.divsi %3, %128 : i64
%131 = llvm.load %19 : !llvm.ptr -> i64
%132 = arith.remsi %3, %131 : i64
%133 = llvm.getelementptr %110[%132] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%130 = llvm.load %133 : !llvm.ptr -> i64
%134 = arith.muli %129, %130 : i64
%135 = arith.remsi %134, %3 : i64
%136 = arith.subi %3, %135 : i64
%137 = llvm.load %19 : !llvm.ptr -> i64
%138 = llvm.getelementptr %110[%137] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %136, %138 : i64, !llvm.ptr
%139 = llvm.load %19 : !llvm.ptr -> i64
%140 = arith.constant 1 : i32
%142 = arith.extsi %140 : i32 to i64
%141 = arith.addi %139, %142 : i64
llvm.store %141, %19 : i64, !llvm.ptr
cf.br ^bb24
^bb26:
%143 = arith.constant 400000003 : i32
%144 = arith.extsi %143 : i32 to i64
%145 = arith.constant 6 : i32
%146 = arith.extsi %145 : i32 to i64
%147 = llvm.mlir.constant(1 : i64) : i64
%148 = llvm.alloca %147 x i64 : (i64) -> !llvm.ptr
llvm.store %146, %148 : i64, !llvm.ptr
%149 = arith.constant 6 : i32
%150 = arith.extsi %149 : i32 to i64
%151 = llvm.mlir.constant(1 : i64) : i64
%152 = llvm.alloca %151 x i64 : (i64) -> !llvm.ptr
llvm.store %150, %152 : i64, !llvm.ptr
%153 = arith.constant 0 : i32
%154 = arith.extsi %153 : i32 to i64
%155 = llvm.mlir.constant(1 : i64) : i64
%156 = llvm.alloca %155 x i64 : (i64) -> !llvm.ptr
llvm.store %154, %156 : i64, !llvm.ptr
%157 = arith.constant 1 : i32
%158 = arith.extsi %157 : i32 to i64
%159 = llvm.mlir.constant(1 : i64) : i64
%160 = llvm.alloca %159 x i64 : (i64) -> !llvm.ptr
llvm.store %158, %160 : i64, !llvm.ptr
%161 = arith.constant 6 : i32
%162 = arith.extsi %161 : i32 to i64
%163 = llvm.mlir.constant(1 : i64) : i64
%164 = llvm.alloca %163 x i64 : (i64) -> !llvm.ptr
llvm.store %162, %164 : i64, !llvm.ptr
%165 = arith.constant 36 : i32
%166 = arith.extsi %165 : i32 to i64
llvm.store %166, %148 : i64, !llvm.ptr
%167 = arith.constant 6 : i32
%168 = arith.extsi %167 : i32 to i64
llvm.store %168, %152 : i64, !llvm.ptr
%169 = arith.constant 1 : i32
%170 = arith.extsi %169 : i32 to i64
llvm.store %170, %156 : i64, !llvm.ptr
%171 = arith.constant 1 : i32
%172 = arith.extsi %171 : i32 to i64
llvm.store %172, %160 : i64, !llvm.ptr
%173 = llvm.load %164 : !llvm.ptr -> i64
%174 = llvm.load %148 : !llvm.ptr -> i64
%175 = arith.addi %173, %174 : i64
%176 = arith.remsi %175, %3 : i64
llvm.store %176, %164 : i64, !llvm.ptr
%177 = arith.constant 2 : i32
%178 = arith.extsi %177 : i32 to i64
%179 = llvm.mlir.constant(1 : i64) : i64
%180 = llvm.alloca %179 x i64 : (i64) -> !llvm.ptr
llvm.store %178, %180 : i64, !llvm.ptr
cf.br ^bb27
^bb27:
%181 = llvm.load %180 : !llvm.ptr -> i64
%182 = arith.constant 2 : i32
%184 = arith.extsi %182 : i32 to i64
%183 = arith.subi %1, %184 : i64
%185 = arith.cmpi sle, %181, %183 : i64
cf.cond_br %185, ^bb28, ^bb29
^bb28:
%186 = llvm.load %180 : !llvm.ptr -> i64
%187 = arith.constant 1 : i32
%189 = arith.extsi %187 : i32 to i64
%188 = arith.addi %186, %189 : i64
%190 = arith.constant 0 : i32
%191 = arith.extsi %190 : i32 to i64
%192 = llvm.mlir.constant(1 : i64) : i64
%193 = llvm.alloca %192 x i64 : (i64) -> !llvm.ptr
llvm.store %191, %193 : i64, !llvm.ptr
%194 = arith.constant 0 : i32
%195 = arith.extsi %194 : i32 to i64
%196 = llvm.mlir.constant(1 : i64) : i64
%197 = llvm.alloca %196 x i64 : (i64) -> !llvm.ptr
llvm.store %195, %197 : i64, !llvm.ptr
%198 = arith.constant 0 : i32
%199 = arith.extsi %198 : i32 to i64
%200 = llvm.mlir.constant(1 : i64) : i64
%201 = llvm.alloca %200 x i64 : (i64) -> !llvm.ptr
llvm.store %199, %201 : i64, !llvm.ptr
%202 = arith.constant 0 : i32
%203 = arith.extsi %202 : i32 to i64
%204 = llvm.mlir.constant(1 : i64) : i64
%205 = llvm.alloca %204 x i64 : (i64) -> !llvm.ptr
llvm.store %203, %205 : i64, !llvm.ptr
%207 = arith.constant 1 : i32
%209 = arith.extsi %207 : i32 to i64
%208 = arith.shrsi %188, %209 : i64
%210 = llvm.getelementptr %10[%208] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%206 = llvm.load %210 : !llvm.ptr -> i8
%211 = arith.constant 0 : i32
%213 = arith.extsi %206 : i8 to i32
%212 = arith.cmpi ne, %213, %211 : i32
cf.cond_br %212, ^bb30, ^bb31
^bb30:
%214 = llvm.load %152 : !llvm.ptr -> i64
%215 = arith.muli %214, %144 : i64
%216 = arith.remsi %215, %3 : i64
%217 = llvm.mlir.constant(1 : i64) : i64
%218 = llvm.alloca %217 x i64 : (i64) -> !llvm.ptr
llvm.store %216, %218 : i64, !llvm.ptr
%219 = llvm.load %218 : !llvm.ptr -> i64
%220 = llvm.load %160 : !llvm.ptr -> i64
%221 = arith.constant 1 : i32
%223 = arith.extsi %221 : i32 to i64
%222 = arith.subi %220, %223 : i64
%224 = arith.muli %219, %222 : i64
%225 = arith.remsi %224, %3 : i64
llvm.store %225, %218 : i64, !llvm.ptr
%226 = llvm.load %218 : !llvm.ptr -> i64
%228 = llvm.load %156 : !llvm.ptr -> i64
%229 = arith.constant 1 : i32
%231 = arith.extsi %229 : i32 to i64
%230 = arith.addi %228, %231 : i64
%232 = llvm.getelementptr %110[%230] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%227 = llvm.load %232 : !llvm.ptr -> i64
%233 = arith.muli %226, %227 : i64
%234 = arith.remsi %233, %3 : i64
llvm.store %234, %218 : i64, !llvm.ptr
%235 = arith.constant 6 : i32
%236 = llvm.load %148 : !llvm.ptr -> i64
%238 = arith.extsi %235 : i32 to i64
%237 = arith.muli %238, %236 : i64
%239 = arith.constant 5 : i32
%240 = llvm.load %218 : !llvm.ptr -> i64
%242 = arith.extsi %239 : i32 to i64
%241 = arith.muli %242, %240 : i64
%243 = arith.addi %237, %241 : i64
%244 = arith.remsi %243, %3 : i64
llvm.store %244, %193 : i64, !llvm.ptr
%245 = llvm.load %152 : !llvm.ptr -> i64
%246 = arith.constant 5 : i32
%247 = llvm.load %218 : !llvm.ptr -> i64
%249 = arith.extsi %246 : i32 to i64
%248 = arith.muli %249, %247 : i64
%250 = arith.addi %245, %248 : i64
%251 = arith.remsi %250, %3 : i64
llvm.store %251, %197 : i64, !llvm.ptr
%252 = llvm.load %156 : !llvm.ptr -> i64
%253 = arith.constant 1 : i32
%255 = arith.extsi %253 : i32 to i64
%254 = arith.addi %252, %255 : i64
llvm.store %254, %201 : i64, !llvm.ptr
%256 = llvm.load %160 : !llvm.ptr -> i64
llvm.store %256, %205 : i64, !llvm.ptr
cf.br ^bb32
^bb31:
%257 = arith.constant 6 : i32
%258 = llvm.load %148 : !llvm.ptr -> i64
%260 = arith.extsi %257 : i32 to i64
%259 = arith.muli %260, %258 : i64
%261 = llvm.load %152 : !llvm.ptr -> i64
%262 = arith.subi %259, %261 : i64
%263 = arith.remsi %262, %3 : i64
llvm.store %263, %193 : i64, !llvm.ptr
%264 = llvm.load %193 : !llvm.ptr -> i64
%265 = arith.constant 0 : i32
%267 = arith.extsi %265 : i32 to i64
%266 = arith.cmpi slt, %264, %267 : i64
cf.cond_br %266, ^bb33, ^bb34
^bb33:
%268 = llvm.load %193 : !llvm.ptr -> i64
%269 = arith.addi %268, %3 : i64
llvm.store %269, %193 : i64, !llvm.ptr
cf.br ^bb35
^bb34:
cf.br ^bb35
^bb35:
%270 = llvm.load %152 : !llvm.ptr -> i64
%271 = arith.constant 5 : i32
%273 = arith.extsi %271 : i32 to i64
%272 = arith.muli %270, %273 : i64
%274 = arith.remsi %272, %3 : i64
llvm.store %274, %197 : i64, !llvm.ptr
%275 = llvm.load %197 : !llvm.ptr -> i64
%276 = llvm.load %180 : !llvm.ptr -> i64
%277 = arith.muli %275, %276 : i64
%278 = arith.remsi %277, %3 : i64
llvm.store %278, %197 : i64, !llvm.ptr
%279 = llvm.load %197 : !llvm.ptr -> i64
%281 = llvm.load %160 : !llvm.ptr -> i64
%282 = llvm.getelementptr %110[%281] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%280 = llvm.load %282 : !llvm.ptr -> i64
%283 = arith.muli %279, %280 : i64
%284 = arith.remsi %283, %3 : i64
llvm.store %284, %197 : i64, !llvm.ptr
%285 = llvm.load %156 : !llvm.ptr -> i64
llvm.store %285, %201 : i64, !llvm.ptr
%286 = llvm.load %160 : !llvm.ptr -> i64
%287 = arith.constant 1 : i32
%289 = arith.extsi %287 : i32 to i64
%288 = arith.addi %286, %289 : i64
llvm.store %288, %205 : i64, !llvm.ptr
cf.br ^bb32
^bb32:
%290 = llvm.load %164 : !llvm.ptr -> i64
%291 = llvm.load %193 : !llvm.ptr -> i64
%292 = arith.addi %290, %291 : i64
%293 = arith.remsi %292, %3 : i64
llvm.store %293, %164 : i64, !llvm.ptr
%294 = arith.constant 6 : i32
%295 = llvm.load %193 : !llvm.ptr -> i64
%297 = arith.extsi %294 : i32 to i64
%296 = arith.muli %297, %295 : i64
%298 = llvm.load %197 : !llvm.ptr -> i64
%299 = arith.subi %296, %298 : i64
%300 = arith.remsi %299, %3 : i64
%301 = llvm.mlir.constant(1 : i64) : i64
%302 = llvm.alloca %301 x i64 : (i64) -> !llvm.ptr
llvm.store %300, %302 : i64, !llvm.ptr
%303 = llvm.load %302 : !llvm.ptr -> i64
%304 = arith.constant 0 : i32
%306 = arith.extsi %304 : i32 to i64
%305 = arith.cmpi slt, %303, %306 : i64
cf.cond_br %305, ^bb36, ^bb37
^bb36:
%307 = llvm.load %302 : !llvm.ptr -> i64
%308 = arith.addi %307, %3 : i64
llvm.store %308, %302 : i64, !llvm.ptr
cf.br ^bb38
^bb37:
cf.br ^bb38
^bb38:
%309 = llvm.load %197 : !llvm.ptr -> i64
%310 = arith.constant 5 : i32
%312 = arith.extsi %310 : i32 to i64
%311 = arith.muli %309, %312 : i64
%313 = arith.remsi %311, %3 : i64
%314 = llvm.mlir.constant(1 : i64) : i64
%315 = llvm.alloca %314 x i64 : (i64) -> !llvm.ptr
llvm.store %313, %315 : i64, !llvm.ptr
%316 = llvm.load %315 : !llvm.ptr -> i64
%317 = arith.muli %316, %188 : i64
%318 = arith.remsi %317, %3 : i64
llvm.store %318, %315 : i64, !llvm.ptr
%319 = llvm.load %315 : !llvm.ptr -> i64
%321 = llvm.load %205 : !llvm.ptr -> i64
%322 = llvm.getelementptr %110[%321] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%320 = llvm.load %322 : !llvm.ptr -> i64
%323 = arith.muli %319, %320 : i64
%324 = arith.remsi %323, %3 : i64
llvm.store %324, %315 : i64, !llvm.ptr
%325 = llvm.load %164 : !llvm.ptr -> i64
%326 = llvm.load %302 : !llvm.ptr -> i64
%327 = arith.addi %325, %326 : i64
%328 = arith.remsi %327, %3 : i64
llvm.store %328, %164 : i64, !llvm.ptr
%329 = llvm.load %302 : !llvm.ptr -> i64
llvm.store %329, %148 : i64, !llvm.ptr
%330 = llvm.load %315 : !llvm.ptr -> i64
llvm.store %330, %152 : i64, !llvm.ptr
%331 = llvm.load %201 : !llvm.ptr -> i64
llvm.store %331, %156 : i64, !llvm.ptr
%332 = llvm.load %205 : !llvm.ptr -> i64
%333 = arith.constant 1 : i32
%335 = arith.extsi %333 : i32 to i64
%334 = arith.addi %332, %335 : i64
llvm.store %334, %160 : i64, !llvm.ptr
%336 = arith.constant 1 : i32
%338 = arith.extsi %336 : i32 to i64
%337 = arith.addi %188, %338 : i64
llvm.store %337, %180 : i64, !llvm.ptr
cf.br ^bb27
^bb29:
%339 = llvm.mlir.addressof @str_0 : !llvm.ptr
%340 = llvm.load %164 : !llvm.ptr -> i64
%341 = llvm.call @printf(%339, %340) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%110) : (!llvm.ptr) -> ()
func.call @free(%10) : (!llvm.ptr) -> ()
%344 = arith.constant 0 : i32
func.return %344 : i32
}
}