← All problems
Problem 746
A Messy Dinner - S(2021) = sum_{k=2..2021} M(k) mod 1e9+7. Ported from native C to pure Flow.
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^2)O(n)
Approach Flow solution Addition chain DP
Verdict Suboptimal
Flow source
# Project Euler 746
# A Messy Dinner - S(2021) = sum_{k=2..2021} M(k) mod 1e9+7.
# Ported from native C to pure Flow.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
function malloc(n: i64) -> ptr<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 & 1) == 1 {
r = r * bb % MOD
}
bb = bb * bb % MOD
ee = ee >> 1
}
return r
}
function main() -> i32 {
let target: i64 = 2021
let max_n: i64 = target
if max_n < 10 {
max_n = 10
}
let n_max: i64 = 4 * max_n
let fact_arr: ptr<i64> = malloc((n_max + 1) * 8) as ptr<i64>
let invfact_arr: ptr<i64> = malloc((n_max + 1) * 8) as ptr<i64>
let inv_arr: ptr<i64> = calloc(max_n + 1, 8) as ptr<i64>
let pow4_arr: ptr<i64> = malloc((max_n + 1) * 8) as ptr<i64>
fact_arr[0] = 1
let mut i: i64 = 1
while i <= n_max {
fact_arr[i] = fact_arr[i - 1] * i % MOD
i = i + 1
}
invfact_arr[n_max] = modpow(fact_arr[n_max], MOD - 2)
i = n_max
while i >= 1 {
invfact_arr[i - 1] = invfact_arr[i] * i % MOD
i = i - 1
}
inv_arr[1] = 1
i = 2
while i <= max_n {
inv_arr[i] = MOD - (MOD / i) * inv_arr[MOD % i] % MOD
i = i + 1
}
pow4_arr[0] = 1
i = 1
while i <= max_n {
pow4_arr[i] = pow4_arr[i - 1] * 4 % MOD
i = i + 1
}
let mut acc: i64 = 0
let mut n: i64 = 2
while n <= target {
let mut total: i64 = 0
let mut nPk: i64 = 1
let mut k: i64 = 0
while k <= n {
if k > 0 {
nPk = nPk * (n - (k - 1)) % MOD
}
let mut D: i64 = 0
if k == 0 {
D = 1
} else {
D = (4 * n) % MOD
D = D * inv_arr[k] % MOD
let nk: i64 = 4 * n - 3 * k - 1
let nCk_val: i64 = fact_arr[nk] * invfact_arr[k - 1] % MOD * invfact_arr[nk - (k - 1)] % MOD
D = D * nCk_val % MOD
}
let rem: i64 = 2 * (n - k)
let ways_rest: i64 = fact_arr[rem] * fact_arr[rem] % MOD
let mut term: i64 = nPk
term = term * D % MOD
term = term * pow4_arr[k] % MOD
term = term * ways_rest % MOD
if (k & 1) == 1 {
total = (total - term) % MOD
} else {
total = (total + term) % MOD
}
k = k + 1
}
let Mn: i64 = (2 * total) % MOD
acc = acc + Mn
acc = acc % MOD
n = n + 1
}
let mut result: i64 = acc % MOD
if result < 0 {
result = result + MOD
}
free(fact_arr)
free(invfact_arr)
free(inv_arr)
free(pow4_arr)
printf("%lld\n", result)
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);
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 ((ee & 1) == 1) {
r = FLOW_CHECKED_MOD(((r * bb)), (MOD));
}
bb = FLOW_CHECKED_MOD(((bb * bb)), (MOD));
ee = FLOW_CHECKED_SHR((ee), (1));
}
return r;
}
int32_t main(void) {
int64_t target = 2021;
int64_t max_n = target;
if (max_n < 10) {
max_n = 10;
}
int64_t n_max = (4 * max_n);
int64_t* fact_arr = (int64_t*)(((int64_t*)(malloc(((n_max + 1) * 8)))));
int64_t* invfact_arr = (int64_t*)(((int64_t*)(malloc(((n_max + 1) * 8)))));
int64_t* inv_arr = (int64_t*)(((int64_t*)(calloc((max_n + 1), 8))));
int64_t* pow4_arr = (int64_t*)(((int64_t*)(malloc(((max_n + 1) * 8)))));
fact_arr[0] = 1;
int64_t i = 1;
while (i <= n_max) {
fact_arr[i] = FLOW_CHECKED_MOD(((fact_arr[(i - 1)] * i)), (MOD));
i = (i + 1);
}
invfact_arr[n_max] = modpow_i64_i64(fact_arr[n_max], (MOD - 2));
i = n_max;
while (i >= 1) {
invfact_arr[(i - 1)] = FLOW_CHECKED_MOD(((invfact_arr[i] * i)), (MOD));
i = (i - 1);
}
inv_arr[1] = 1;
i = 2;
while (i <= max_n) {
inv_arr[i] = (MOD - FLOW_CHECKED_MOD(((FLOW_CHECKED_DIV((MOD), (i)) * inv_arr[FLOW_CHECKED_MOD((MOD), (i))])), (MOD)));
i = (i + 1);
}
pow4_arr[0] = 1;
i = 1;
while (i <= max_n) {
pow4_arr[i] = FLOW_CHECKED_MOD(((pow4_arr[(i - 1)] * 4)), (MOD));
i = (i + 1);
}
int64_t acc = 0;
int64_t n = 2;
while (n <= target) {
int64_t total = 0;
int64_t nPk = 1;
int64_t k = 0;
while (k <= n) {
if (k > 0) {
nPk = FLOW_CHECKED_MOD(((nPk * (n - (k - 1)))), (MOD));
}
int64_t D = 0;
if (k == 0) {
D = 1;
} else {
D = FLOW_CHECKED_MOD(((4 * n)), (MOD));
D = FLOW_CHECKED_MOD(((D * inv_arr[k])), (MOD));
int64_t nk = (((4 * n) - (3 * k)) - 1);
int64_t nCk_val = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((fact_arr[nk] * invfact_arr[(k - 1)])), (MOD)) * invfact_arr[(nk - (k - 1))])), (MOD));
D = FLOW_CHECKED_MOD(((D * nCk_val)), (MOD));
}
int64_t rem = (2 * (n - k));
int64_t ways_rest = FLOW_CHECKED_MOD(((fact_arr[rem] * fact_arr[rem])), (MOD));
int64_t term = nPk;
term = FLOW_CHECKED_MOD(((term * D)), (MOD));
term = FLOW_CHECKED_MOD(((term * pow4_arr[k])), (MOD));
term = FLOW_CHECKED_MOD(((term * ways_rest)), (MOD));
if ((k & 1) == 1) {
total = FLOW_CHECKED_MOD(((total - term)), (MOD));
} else {
total = FLOW_CHECKED_MOD(((total + term)), (MOD));
}
k = (k + 1);
}
int64_t Mn = FLOW_CHECKED_MOD(((2 * total)), (MOD));
acc = (acc + Mn);
acc = FLOW_CHECKED_MOD((acc), (MOD));
n = (n + 1);
}
int64_t result = FLOW_CHECKED_MOD((acc), (MOD));
if (result < 0) {
result = (result + MOD);
}
free(fact_arr);
free(invfact_arr);
free(inv_arr);
free(pow4_arr);
printf("%lld\n", result);
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 private @malloc(i64) -> !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 1 : i32
%18 = arith.extsi %16 : i32 to i64
%17 = arith.andi %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 1 : i32
%37 = arith.extsi %35 : i32 to i64
%36 = arith.shrsi %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 @main() -> i32 {
%39 = arith.constant 2021 : i32
%40 = arith.extsi %39 : i32 to i64
%41 = arith.constant 10 : i32
%43 = arith.extsi %41 : i32 to i64
%42 = arith.cmpi slt, %40, %43 : i64
%44 = scf.if %42 -> (i64) {
%45 = arith.constant 10 : i32
%46 = arith.extsi %45 : i32 to i64
scf.yield %46 : i64
} else {
scf.yield %40 : i64
}
%47 = arith.constant 4 : i32
%49 = arith.extsi %47 : i32 to i64
%48 = arith.muli %49, %44 : i64
%51 = arith.constant 1 : i32
%53 = arith.extsi %51 : i32 to i64
%52 = arith.addi %48, %53 : i64
%54 = arith.constant 8 : i32
%56 = arith.extsi %54 : i32 to i64
%55 = arith.muli %52, %56 : i64
%50 = func.call @malloc(%55) : (i64) -> !llvm.ptr
%58 = arith.constant 1 : i32
%60 = arith.extsi %58 : i32 to i64
%59 = arith.addi %48, %60 : i64
%61 = arith.constant 8 : i32
%63 = arith.extsi %61 : i32 to i64
%62 = arith.muli %59, %63 : i64
%57 = func.call @malloc(%62) : (i64) -> !llvm.ptr
%65 = arith.constant 1 : i32
%67 = arith.extsi %65 : i32 to i64
%66 = arith.addi %44, %67 : i64
%68 = arith.constant 8 : i32
%69 = arith.extsi %68 : i32 to i64
%64 = func.call @calloc(%66, %69) : (i64, i64) -> !llvm.ptr
%71 = arith.constant 1 : i32
%73 = arith.extsi %71 : i32 to i64
%72 = arith.addi %44, %73 : i64
%74 = arith.constant 8 : i32
%76 = arith.extsi %74 : i32 to i64
%75 = arith.muli %72, %76 : i64
%70 = func.call @malloc(%75) : (i64) -> !llvm.ptr
%77 = arith.constant 1 : i32
%78 = arith.constant 0 : i32
%79 = arith.extsi %77 : i32 to i64
%80 = arith.extsi %78 : i32 to i64
%81 = llvm.getelementptr %50[%80] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %79, %81 : i64, !llvm.ptr
%82 = arith.constant 1 : i32
%83 = arith.extsi %82 : i32 to i64
%84 = llvm.mlir.constant(1 : i64) : i64
%85 = llvm.alloca %84 x i64 : (i64) -> !llvm.ptr
llvm.store %83, %85 : i64, !llvm.ptr
cf.br ^bb6
^bb6:
%86 = llvm.load %85 : !llvm.ptr -> i64
%87 = arith.cmpi sle, %86, %48 : i64
cf.cond_br %87, ^bb7, ^bb8
^bb7:
%89 = llvm.load %85 : !llvm.ptr -> i64
%90 = arith.constant 1 : i32
%92 = arith.extsi %90 : i32 to i64
%91 = arith.subi %89, %92 : i64
%93 = llvm.getelementptr %50[%91] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%88 = llvm.load %93 : !llvm.ptr -> i64
%94 = llvm.load %85 : !llvm.ptr -> i64
%95 = arith.muli %88, %94 : i64
%96 = llvm.mlir.addressof @MOD : !llvm.ptr
%97 = llvm.load %96 : !llvm.ptr -> i64
%98 = arith.remsi %95, %97 : i64
%99 = llvm.load %85 : !llvm.ptr -> i64
%100 = llvm.getelementptr %50[%99] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %98, %100 : i64, !llvm.ptr
%101 = llvm.load %85 : !llvm.ptr -> i64
%102 = arith.constant 1 : i32
%104 = arith.extsi %102 : i32 to i64
%103 = arith.addi %101, %104 : i64
llvm.store %103, %85 : i64, !llvm.ptr
cf.br ^bb6
^bb8:
%107 = llvm.getelementptr %50[%48] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%106 = llvm.load %107 : !llvm.ptr -> i64
%108 = llvm.mlir.addressof @MOD : !llvm.ptr
%109 = llvm.load %108 : !llvm.ptr -> i64
%110 = arith.constant 2 : i32
%112 = arith.extsi %110 : i32 to i64
%111 = arith.subi %109, %112 : i64
%105 = func.call @modpow(%106, %111) : (i64, i64) -> i64
%113 = llvm.getelementptr %57[%48] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %105, %113 : i64, !llvm.ptr
llvm.store %48, %85 : i64, !llvm.ptr
cf.br ^bb9
^bb9:
%114 = llvm.load %85 : !llvm.ptr -> i64
%115 = arith.constant 1 : i32
%117 = arith.extsi %115 : i32 to i64
%116 = arith.cmpi sge, %114, %117 : i64
cf.cond_br %116, ^bb10, ^bb11
^bb10:
%119 = llvm.load %85 : !llvm.ptr -> i64
%120 = llvm.getelementptr %57[%119] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%118 = llvm.load %120 : !llvm.ptr -> i64
%121 = llvm.load %85 : !llvm.ptr -> i64
%122 = arith.muli %118, %121 : i64
%123 = llvm.mlir.addressof @MOD : !llvm.ptr
%124 = llvm.load %123 : !llvm.ptr -> i64
%125 = arith.remsi %122, %124 : i64
%126 = llvm.load %85 : !llvm.ptr -> i64
%127 = arith.constant 1 : i32
%129 = arith.extsi %127 : i32 to i64
%128 = arith.subi %126, %129 : i64
%130 = llvm.getelementptr %57[%128] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %125, %130 : i64, !llvm.ptr
%131 = llvm.load %85 : !llvm.ptr -> i64
%132 = arith.constant 1 : i32
%134 = arith.extsi %132 : i32 to i64
%133 = arith.subi %131, %134 : i64
llvm.store %133, %85 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%135 = arith.constant 1 : i32
%136 = arith.constant 1 : i32
%137 = arith.extsi %135 : i32 to i64
%138 = arith.extsi %136 : i32 to i64
%139 = llvm.getelementptr %64[%138] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %137, %139 : i64, !llvm.ptr
%140 = arith.constant 2 : i32
%141 = arith.extsi %140 : i32 to i64
llvm.store %141, %85 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%142 = llvm.load %85 : !llvm.ptr -> i64
%143 = arith.cmpi sle, %142, %44 : i64
cf.cond_br %143, ^bb13, ^bb14
^bb13:
%144 = llvm.mlir.addressof @MOD : !llvm.ptr
%145 = llvm.load %144 : !llvm.ptr -> i64
%146 = llvm.mlir.addressof @MOD : !llvm.ptr
%147 = llvm.load %146 : !llvm.ptr -> i64
%148 = llvm.load %85 : !llvm.ptr -> i64
%149 = arith.divsi %147, %148 : i64
%151 = llvm.mlir.addressof @MOD : !llvm.ptr
%152 = llvm.load %151 : !llvm.ptr -> i64
%153 = llvm.load %85 : !llvm.ptr -> i64
%154 = arith.remsi %152, %153 : i64
%155 = llvm.getelementptr %64[%154] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%150 = llvm.load %155 : !llvm.ptr -> i64
%156 = arith.muli %149, %150 : i64
%157 = llvm.mlir.addressof @MOD : !llvm.ptr
%158 = llvm.load %157 : !llvm.ptr -> i64
%159 = arith.remsi %156, %158 : i64
%160 = arith.subi %145, %159 : i64
%161 = llvm.load %85 : !llvm.ptr -> i64
%162 = llvm.getelementptr %64[%161] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %160, %162 : i64, !llvm.ptr
%163 = llvm.load %85 : !llvm.ptr -> i64
%164 = arith.constant 1 : i32
%166 = arith.extsi %164 : i32 to i64
%165 = arith.addi %163, %166 : i64
llvm.store %165, %85 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%167 = arith.constant 1 : i32
%168 = arith.constant 0 : i32
%169 = arith.extsi %167 : i32 to i64
%170 = arith.extsi %168 : i32 to i64
%171 = llvm.getelementptr %70[%170] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %169, %171 : i64, !llvm.ptr
%172 = arith.constant 1 : i32
%173 = arith.extsi %172 : i32 to i64
llvm.store %173, %85 : i64, !llvm.ptr
cf.br ^bb15
^bb15:
%174 = llvm.load %85 : !llvm.ptr -> i64
%175 = arith.cmpi sle, %174, %44 : i64
cf.cond_br %175, ^bb16, ^bb17
^bb16:
%177 = llvm.load %85 : !llvm.ptr -> i64
%178 = arith.constant 1 : i32
%180 = arith.extsi %178 : i32 to i64
%179 = arith.subi %177, %180 : i64
%181 = llvm.getelementptr %70[%179] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%176 = llvm.load %181 : !llvm.ptr -> i64
%182 = arith.constant 4 : i32
%184 = arith.extsi %182 : i32 to i64
%183 = arith.muli %176, %184 : i64
%185 = llvm.mlir.addressof @MOD : !llvm.ptr
%186 = llvm.load %185 : !llvm.ptr -> i64
%187 = arith.remsi %183, %186 : i64
%188 = llvm.load %85 : !llvm.ptr -> i64
%189 = llvm.getelementptr %70[%188] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %187, %189 : i64, !llvm.ptr
%190 = llvm.load %85 : !llvm.ptr -> i64
%191 = arith.constant 1 : i32
%193 = arith.extsi %191 : i32 to i64
%192 = arith.addi %190, %193 : i64
llvm.store %192, %85 : i64, !llvm.ptr
cf.br ^bb15
^bb17:
%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 2 : 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
cf.br ^bb18
^bb18:
%202 = llvm.load %201 : !llvm.ptr -> i64
%203 = arith.cmpi sle, %202, %40 : i64
cf.cond_br %203, ^bb19, ^bb20
^bb19:
%204 = arith.constant 0 : i32
%205 = arith.extsi %204 : i32 to i64
%206 = llvm.mlir.constant(1 : i64) : i64
%207 = llvm.alloca %206 x i64 : (i64) -> !llvm.ptr
llvm.store %205, %207 : i64, !llvm.ptr
%208 = arith.constant 1 : i32
%209 = arith.extsi %208 : i32 to i64
%210 = llvm.mlir.constant(1 : i64) : i64
%211 = llvm.alloca %210 x i64 : (i64) -> !llvm.ptr
llvm.store %209, %211 : i64, !llvm.ptr
%212 = arith.constant 0 : i32
%213 = arith.extsi %212 : i32 to i64
%214 = llvm.mlir.constant(1 : i64) : i64
%215 = llvm.alloca %214 x i64 : (i64) -> !llvm.ptr
llvm.store %213, %215 : i64, !llvm.ptr
cf.br ^bb21
^bb21:
%216 = llvm.load %215 : !llvm.ptr -> i64
%217 = llvm.load %201 : !llvm.ptr -> i64
%218 = arith.cmpi sle, %216, %217 : i64
cf.cond_br %218, ^bb22, ^bb23
^bb22:
%219 = llvm.load %215 : !llvm.ptr -> i64
%220 = arith.constant 0 : i32
%222 = arith.extsi %220 : i32 to i64
%221 = arith.cmpi sgt, %219, %222 : i64
cf.cond_br %221, ^bb24, ^bb25
^bb24:
%223 = llvm.load %211 : !llvm.ptr -> i64
%224 = llvm.load %201 : !llvm.ptr -> i64
%225 = llvm.load %215 : !llvm.ptr -> i64
%226 = arith.constant 1 : i32
%228 = arith.extsi %226 : i32 to i64
%227 = arith.subi %225, %228 : i64
%229 = arith.subi %224, %227 : i64
%230 = arith.muli %223, %229 : i64
%231 = llvm.mlir.addressof @MOD : !llvm.ptr
%232 = llvm.load %231 : !llvm.ptr -> i64
%233 = arith.remsi %230, %232 : i64
llvm.store %233, %211 : i64, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%234 = arith.constant 0 : i32
%235 = arith.extsi %234 : i32 to i64
%236 = llvm.mlir.constant(1 : i64) : i64
%237 = llvm.alloca %236 x i64 : (i64) -> !llvm.ptr
llvm.store %235, %237 : i64, !llvm.ptr
%238 = llvm.load %215 : !llvm.ptr -> i64
%239 = arith.constant 0 : i32
%241 = arith.extsi %239 : i32 to i64
%240 = arith.cmpi eq, %238, %241 : i64
cf.cond_br %240, ^bb27, ^bb28
^bb27:
%242 = arith.constant 1 : i32
%243 = arith.extsi %242 : i32 to i64
llvm.store %243, %237 : i64, !llvm.ptr
cf.br ^bb29
^bb28:
%244 = arith.constant 4 : i32
%245 = llvm.load %201 : !llvm.ptr -> i64
%247 = arith.extsi %244 : i32 to i64
%246 = arith.muli %247, %245 : i64
%248 = llvm.mlir.addressof @MOD : !llvm.ptr
%249 = llvm.load %248 : !llvm.ptr -> i64
%250 = arith.remsi %246, %249 : i64
llvm.store %250, %237 : i64, !llvm.ptr
%251 = llvm.load %237 : !llvm.ptr -> i64
%253 = llvm.load %215 : !llvm.ptr -> i64
%254 = llvm.getelementptr %64[%253] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%252 = llvm.load %254 : !llvm.ptr -> i64
%255 = arith.muli %251, %252 : i64
%256 = llvm.mlir.addressof @MOD : !llvm.ptr
%257 = llvm.load %256 : !llvm.ptr -> i64
%258 = arith.remsi %255, %257 : i64
llvm.store %258, %237 : i64, !llvm.ptr
%259 = arith.constant 4 : i32
%260 = llvm.load %201 : !llvm.ptr -> i64
%262 = arith.extsi %259 : i32 to i64
%261 = arith.muli %262, %260 : i64
%263 = arith.constant 3 : i32
%264 = llvm.load %215 : !llvm.ptr -> i64
%266 = arith.extsi %263 : i32 to i64
%265 = arith.muli %266, %264 : i64
%267 = arith.subi %261, %265 : i64
%268 = arith.constant 1 : i32
%270 = arith.extsi %268 : i32 to i64
%269 = arith.subi %267, %270 : i64
%272 = llvm.getelementptr %50[%269] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%271 = llvm.load %272 : !llvm.ptr -> i64
%274 = llvm.load %215 : !llvm.ptr -> i64
%275 = arith.constant 1 : i32
%277 = arith.extsi %275 : i32 to i64
%276 = arith.subi %274, %277 : i64
%278 = llvm.getelementptr %57[%276] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%273 = llvm.load %278 : !llvm.ptr -> i64
%279 = arith.muli %271, %273 : i64
%280 = llvm.mlir.addressof @MOD : !llvm.ptr
%281 = llvm.load %280 : !llvm.ptr -> i64
%282 = arith.remsi %279, %281 : i64
%284 = llvm.load %215 : !llvm.ptr -> i64
%285 = arith.constant 1 : i32
%287 = arith.extsi %285 : i32 to i64
%286 = arith.subi %284, %287 : i64
%288 = arith.subi %269, %286 : i64
%289 = llvm.getelementptr %57[%288] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%283 = llvm.load %289 : !llvm.ptr -> i64
%290 = arith.muli %282, %283 : i64
%291 = llvm.mlir.addressof @MOD : !llvm.ptr
%292 = llvm.load %291 : !llvm.ptr -> i64
%293 = arith.remsi %290, %292 : i64
%294 = llvm.load %237 : !llvm.ptr -> i64
%295 = arith.muli %294, %293 : i64
%296 = llvm.mlir.addressof @MOD : !llvm.ptr
%297 = llvm.load %296 : !llvm.ptr -> i64
%298 = arith.remsi %295, %297 : i64
llvm.store %298, %237 : i64, !llvm.ptr
cf.br ^bb29
^bb29:
%299 = arith.constant 2 : i32
%300 = llvm.load %201 : !llvm.ptr -> i64
%301 = llvm.load %215 : !llvm.ptr -> i64
%302 = arith.subi %300, %301 : i64
%304 = arith.extsi %299 : i32 to i64
%303 = arith.muli %304, %302 : i64
%306 = llvm.getelementptr %50[%303] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%305 = llvm.load %306 : !llvm.ptr -> i64
%308 = llvm.getelementptr %50[%303] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%307 = llvm.load %308 : !llvm.ptr -> i64
%309 = arith.muli %305, %307 : i64
%310 = llvm.mlir.addressof @MOD : !llvm.ptr
%311 = llvm.load %310 : !llvm.ptr -> i64
%312 = arith.remsi %309, %311 : i64
%313 = llvm.load %211 : !llvm.ptr -> 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 = llvm.load %237 : !llvm.ptr -> i64
%318 = arith.muli %316, %317 : i64
%319 = llvm.mlir.addressof @MOD : !llvm.ptr
%320 = llvm.load %319 : !llvm.ptr -> i64
%321 = arith.remsi %318, %320 : i64
llvm.store %321, %315 : i64, !llvm.ptr
%322 = llvm.load %315 : !llvm.ptr -> i64
%324 = llvm.load %215 : !llvm.ptr -> i64
%325 = llvm.getelementptr %70[%324] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%323 = llvm.load %325 : !llvm.ptr -> i64
%326 = arith.muli %322, %323 : i64
%327 = llvm.mlir.addressof @MOD : !llvm.ptr
%328 = llvm.load %327 : !llvm.ptr -> i64
%329 = arith.remsi %326, %328 : i64
llvm.store %329, %315 : i64, !llvm.ptr
%330 = llvm.load %315 : !llvm.ptr -> i64
%331 = arith.muli %330, %312 : i64
%332 = llvm.mlir.addressof @MOD : !llvm.ptr
%333 = llvm.load %332 : !llvm.ptr -> i64
%334 = arith.remsi %331, %333 : i64
llvm.store %334, %315 : i64, !llvm.ptr
%335 = llvm.load %215 : !llvm.ptr -> i64
%336 = arith.constant 1 : i32
%338 = arith.extsi %336 : i32 to i64
%337 = arith.andi %335, %338 : i64
%339 = arith.constant 1 : i32
%341 = arith.extsi %339 : i32 to i64
%340 = arith.cmpi eq, %337, %341 : i64
cf.cond_br %340, ^bb30, ^bb31
^bb30:
%342 = llvm.load %207 : !llvm.ptr -> i64
%343 = llvm.load %315 : !llvm.ptr -> i64
%344 = arith.subi %342, %343 : i64
%345 = llvm.mlir.addressof @MOD : !llvm.ptr
%346 = llvm.load %345 : !llvm.ptr -> i64
%347 = arith.remsi %344, %346 : i64
llvm.store %347, %207 : i64, !llvm.ptr
cf.br ^bb32
^bb31:
%348 = llvm.load %207 : !llvm.ptr -> i64
%349 = llvm.load %315 : !llvm.ptr -> i64
%350 = arith.addi %348, %349 : i64
%351 = llvm.mlir.addressof @MOD : !llvm.ptr
%352 = llvm.load %351 : !llvm.ptr -> i64
%353 = arith.remsi %350, %352 : i64
llvm.store %353, %207 : i64, !llvm.ptr
cf.br ^bb32
^bb32:
%354 = llvm.load %215 : !llvm.ptr -> i64
%355 = arith.constant 1 : i32
%357 = arith.extsi %355 : i32 to i64
%356 = arith.addi %354, %357 : i64
llvm.store %356, %215 : i64, !llvm.ptr
cf.br ^bb21
^bb23:
%358 = arith.constant 2 : i32
%359 = llvm.load %207 : !llvm.ptr -> i64
%361 = arith.extsi %358 : i32 to i64
%360 = arith.muli %361, %359 : i64
%362 = llvm.mlir.addressof @MOD : !llvm.ptr
%363 = llvm.load %362 : !llvm.ptr -> i64
%364 = arith.remsi %360, %363 : i64
%365 = llvm.load %197 : !llvm.ptr -> i64
%366 = arith.addi %365, %364 : i64
llvm.store %366, %197 : i64, !llvm.ptr
%367 = llvm.load %197 : !llvm.ptr -> i64
%368 = llvm.mlir.addressof @MOD : !llvm.ptr
%369 = llvm.load %368 : !llvm.ptr -> i64
%370 = arith.remsi %367, %369 : i64
llvm.store %370, %197 : i64, !llvm.ptr
%371 = llvm.load %201 : !llvm.ptr -> i64
%372 = arith.constant 1 : i32
%374 = arith.extsi %372 : i32 to i64
%373 = arith.addi %371, %374 : i64
llvm.store %373, %201 : i64, !llvm.ptr
cf.br ^bb18
^bb20:
%375 = llvm.load %197 : !llvm.ptr -> i64
%376 = llvm.mlir.addressof @MOD : !llvm.ptr
%377 = llvm.load %376 : !llvm.ptr -> i64
%378 = arith.remsi %375, %377 : i64
%379 = llvm.mlir.constant(1 : i64) : i64
%380 = llvm.alloca %379 x i64 : (i64) -> !llvm.ptr
llvm.store %378, %380 : i64, !llvm.ptr
%381 = llvm.load %380 : !llvm.ptr -> i64
%382 = arith.constant 0 : i32
%384 = arith.extsi %382 : i32 to i64
%383 = arith.cmpi slt, %381, %384 : i64
cf.cond_br %383, ^bb33, ^bb34
^bb33:
%385 = llvm.load %380 : !llvm.ptr -> i64
%386 = llvm.mlir.addressof @MOD : !llvm.ptr
%387 = llvm.load %386 : !llvm.ptr -> i64
%388 = arith.addi %385, %387 : i64
llvm.store %388, %380 : i64, !llvm.ptr
cf.br ^bb35
^bb34:
cf.br ^bb35
^bb35:
func.call @free(%50) : (!llvm.ptr) -> ()
func.call @free(%57) : (!llvm.ptr) -> ()
func.call @free(%64) : (!llvm.ptr) -> ()
func.call @free(%70) : (!llvm.ptr) -> ()
%393 = llvm.mlir.addressof @str_0 : !llvm.ptr
%394 = llvm.load %380 : !llvm.ptr -> i64
%395 = llvm.call @printf(%393, %394) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%396 = arith.constant 0 : i32
func.return %396 : i32
}
}