Problem 539
Odd Elimination — S(10^18) mod 987654321 via memoized recurrence.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n) | ? |
| Space complexity | O(n^2) | ? |
| Approach | Flow solution | Not curated |
| Verdict | Unknown |
Flow source
# Project Euler 539
# Odd Elimination — S(10^18) mod 987654321 via memoized recurrence.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
const MOD: i64 = 987654321
const CAP: i64 = 1048576
function hslot(key: i64, keys: ptr<i64>, used: ptr<i8>) -> i64 {
let mut h: i64 = key % CAP
if h < 0 { h = h + CAP }
while used[h] == 1 && keys[h] != key {
h = h + 1
if h == CAP { h = 0 }
}
return h
}
function P(n: i64, pk: ptr<i64>, pv: ptr<i64>, pu: ptr<i8>) -> i64 {
if n == 1 { return 1 }
let s: i64 = hslot(n, pk, pu)
if pu[s] == 1 { return pv[s] }
let val: i64 = 2 * (1 + n / 2 - P(n / 2, pk, pv, pu))
pu[s] = 1
pk[s] = n
pv[s] = val
return val
}
function S(n: i64, sk: ptr<i64>, sv: ptr<i64>, su: ptr<i8>,
pk: ptr<i64>, pv: ptr<i64>, pu: ptr<i8>) -> i64 {
if n <= 0 { return 0 }
if n == 1 { return 1 }
let s: i64 = hslot(n, sk, su)
if su[s] == 1 { return sv[s] }
let mut val: i64 = 0
if (n & 1) == 1 {
let q: i64 = n / 2
let t: i128 = (1 as i128) + (2 as i128) * (q as i128) * ((q + 3) as i128)
- (4 as i128) * (S(q, sk, sv, su, pk, pv, pu) as i128)
val = ((t % (MOD as i128) + (MOD as i128)) % (MOD as i128)) as i64
} else {
let q: i64 = n / 2
let t: i128 = (2 as i128) * (q as i128) * (q as i128) + (4 as i128) * (q as i128) - (1 as i128)
- (4 as i128) * (S(q - 1, sk, sv, su, pk, pv, pu) as i128)
- (2 as i128) * ((P(q, pk, pv, pu) % MOD) as i128)
val = ((t % (MOD as i128) + (MOD as i128)) % (MOD as i128)) as i64
}
su[s] = 1
sk[s] = n
sv[s] = val
return val
}
function main() -> i32 {
let pk: ptr<i64> = calloc(CAP, 8)
let pv: ptr<i64> = calloc(CAP, 8)
let pu: ptr<i8> = calloc(CAP, 1)
let sk: ptr<i64> = calloc(CAP, 8)
let sv: ptr<i64> = calloc(CAP, 8)
let su: ptr<i8> = calloc(CAP, 1)
if pk == null || pv == null || pu == null || sk == null || sv == null || su == null {
return 1
}
let ans: i64 = S(1000000000000000000, sk, sv, su, pk, pv, pu)
printf("%lld\n", ans)
free(pk); free(pv); free(pu); free(sk); free(sv); free(su)
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 hslot_i64_ptr_i64_ptr_i8(int64_t key, int64_t* keys, int8_t* used);
int64_t P_i64_ptr_i64_ptr_i64_ptr_i8(int64_t n, int64_t* pk, int64_t* pv, int8_t* pu);
int64_t S_i64_ptr_i64_ptr_i64_ptr_i8_ptr_i64_ptr_i64_ptr_i8(int64_t n, int64_t* sk, int64_t* sv, int8_t* su, int64_t* pk, int64_t* pv, int8_t* pu);
int32_t main(void);
static const int64_t MOD = 987654321;
static const int64_t CAP = 1048576;
int64_t hslot_i64_ptr_i64_ptr_i8(int64_t key, int64_t* keys, int8_t* used) {
int64_t h = FLOW_CHECKED_MOD((key), (CAP));
if (h < 0) {
h = (h + CAP);
}
while ((used[h] == 1 && keys[h] != key)) {
h = (h + 1);
if (h == CAP) {
h = 0;
}
}
return h;
}
int64_t P_i64_ptr_i64_ptr_i64_ptr_i8(int64_t n, int64_t* pk, int64_t* pv, int8_t* pu) {
if (n == 1) {
return 1;
}
int64_t s = hslot_i64_ptr_i64_ptr_i8(n, pk, pu);
if (pu[s] == 1) {
return pv[s];
}
int64_t val = (2 * ((1 + FLOW_CHECKED_DIV((n), (2))) - P_i64_ptr_i64_ptr_i64_ptr_i8(FLOW_CHECKED_DIV((n), (2)), pk, pv, pu)));
pu[s] = 1;
pk[s] = n;
pv[s] = val;
return val;
}
int64_t S_i64_ptr_i64_ptr_i64_ptr_i8_ptr_i64_ptr_i64_ptr_i8(int64_t n, int64_t* sk, int64_t* sv, int8_t* su, int64_t* pk, int64_t* pv, int8_t* pu) {
if (n <= 0) {
return 0;
}
if (n == 1) {
return 1;
}
int64_t s = hslot_i64_ptr_i64_ptr_i8(n, sk, su);
if (su[s] == 1) {
return sv[s];
}
int64_t val = 0;
if ((n & 1) == 1) {
int64_t q = FLOW_CHECKED_DIV((n), (2));
__int128 t = ((((__int128)(1)) + ((((__int128)(2)) * ((__int128)(q))) * ((__int128)((q + 3))))) - (((__int128)(4)) * ((__int128)(S_i64_ptr_i64_ptr_i64_ptr_i8_ptr_i64_ptr_i64_ptr_i8(q, sk, sv, su, pk, pv, pu)))));
val = ((int64_t)(FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((t), (((__int128)(MOD)))) + ((__int128)(MOD)))), (((__int128)(MOD))))));
} else {
int64_t q = FLOW_CHECKED_DIV((n), (2));
__int128 t = ((((((((__int128)(2)) * ((__int128)(q))) * ((__int128)(q))) + (((__int128)(4)) * ((__int128)(q)))) - ((__int128)(1))) - (((__int128)(4)) * ((__int128)(S_i64_ptr_i64_ptr_i64_ptr_i8_ptr_i64_ptr_i64_ptr_i8((q - 1), sk, sv, su, pk, pv, pu))))) - (((__int128)(2)) * ((__int128)(FLOW_CHECKED_MOD((P_i64_ptr_i64_ptr_i64_ptr_i8(q, pk, pv, pu)), (MOD))))));
val = ((int64_t)(FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((t), (((__int128)(MOD)))) + ((__int128)(MOD)))), (((__int128)(MOD))))));
}
su[s] = 1;
sk[s] = n;
sv[s] = val;
return val;
}
int32_t main(void) {
int64_t* pk = (int64_t*)(calloc(CAP, 8));
int64_t* pv = (int64_t*)(calloc(CAP, 8));
int8_t* pu = (int8_t*)(calloc(CAP, 1));
int64_t* sk = (int64_t*)(calloc(CAP, 8));
int64_t* sv = (int64_t*)(calloc(CAP, 8));
int8_t* su = (int8_t*)(calloc(CAP, 1));
if ((((((pk == NULL || pv == NULL) || pu == NULL) || sk == NULL) || sv == NULL) || su == NULL)) {
return 1;
}
int64_t ans = S_i64_ptr_i64_ptr_i64_ptr_i8_ptr_i64_ptr_i64_ptr_i8(1000000000000000000, sk, sv, su, pk, pv, pu);
printf("%lld\n", ans);
free(pk);
free(pv);
free(pu);
free(sk);
free(sv);
free(su);
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(987654321 : i64) : i64
// Constant: CAP
llvm.mlir.global internal constant @CAP(1048576 : i64) : i64
func.func @hslot(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> i64 {
%0 = llvm.mlir.addressof @CAP : !llvm.ptr
%1 = llvm.load %0 : !llvm.ptr -> i64
%2 = arith.remsi %arg0, %1 : i64
%3 = llvm.mlir.constant(1 : i64) : i64
%4 = llvm.alloca %3 x i64 : (i64) -> !llvm.ptr
llvm.store %2, %4 : i64, !llvm.ptr
%5 = llvm.load %4 : !llvm.ptr -> i64
%6 = arith.constant 0 : i32
%8 = arith.extsi %6 : i32 to i64
%7 = arith.cmpi slt, %5, %8 : i64
cf.cond_br %7, ^bb0, ^bb1
^bb0:
%9 = llvm.load %4 : !llvm.ptr -> i64
%10 = llvm.mlir.addressof @CAP : !llvm.ptr
%11 = llvm.load %10 : !llvm.ptr -> i64
%12 = arith.addi %9, %11 : i64
llvm.store %12, %4 : i64, !llvm.ptr
cf.br ^bb2
^bb1:
cf.br ^bb2
^bb2:
cf.br ^bb3
^bb3:
%14 = llvm.load %4 : !llvm.ptr -> i64
%15 = llvm.getelementptr %arg2[%14] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%13 = llvm.load %15 : !llvm.ptr -> i8
%16 = arith.constant 1 : i32
%18 = arith.extsi %13 : i8 to i32
%17 = arith.cmpi eq, %18, %16 : i32
%19 = scf.if %17 -> (i1) {
%21 = llvm.load %4 : !llvm.ptr -> i64
%22 = llvm.getelementptr %arg1[%21] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%20 = llvm.load %22 : !llvm.ptr -> i64
%23 = arith.cmpi ne, %20, %arg0 : i64
scf.yield %23 : i1
} else {
%24 = arith.constant false
scf.yield %24 : i1
}
cf.cond_br %19, ^bb4, ^bb5
^bb4:
%25 = llvm.load %4 : !llvm.ptr -> i64
%26 = arith.constant 1 : i32
%28 = arith.extsi %26 : i32 to i64
%27 = arith.addi %25, %28 : i64
llvm.store %27, %4 : i64, !llvm.ptr
%29 = llvm.load %4 : !llvm.ptr -> i64
%30 = llvm.mlir.addressof @CAP : !llvm.ptr
%31 = llvm.load %30 : !llvm.ptr -> i64
%32 = arith.cmpi eq, %29, %31 : i64
cf.cond_br %32, ^bb6, ^bb7
^bb6:
%33 = arith.constant 0 : i32
%34 = arith.extsi %33 : i32 to i64
llvm.store %34, %4 : i64, !llvm.ptr
cf.br ^bb8
^bb7:
cf.br ^bb8
^bb8:
cf.br ^bb3
^bb5:
%35 = llvm.load %4 : !llvm.ptr -> i64
func.return %35 : i64
}
func.func @P(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> i64 {
%36 = arith.constant 1 : i32
%38 = arith.extsi %36 : i32 to i64
%37 = arith.cmpi eq, %arg0, %38 : i64
cf.cond_br %37, ^bb9, ^bb10
^bb9:
%39 = arith.constant 1 : i32
%40 = arith.extsi %39 : i32 to i64
func.return %40 : i64
^bb10:
cf.br ^bb11
^bb11:
%41 = func.call @hslot(%arg0, %arg1, %arg3) : (i64, !llvm.ptr, !llvm.ptr) -> i64
%43 = llvm.getelementptr %arg3[%41] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%42 = llvm.load %43 : !llvm.ptr -> i8
%44 = arith.constant 1 : i32
%46 = arith.extsi %42 : i8 to i32
%45 = arith.cmpi eq, %46, %44 : i32
cf.cond_br %45, ^bb12, ^bb13
^bb12:
%48 = llvm.getelementptr %arg2[%41] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%47 = llvm.load %48 : !llvm.ptr -> i64
func.return %47 : i64
^bb13:
cf.br ^bb14
^bb14:
%49 = arith.constant 2 : i32
%50 = arith.constant 1 : i32
%51 = arith.constant 2 : i32
%53 = arith.extsi %51 : i32 to i64
%52 = arith.divsi %arg0, %53 : i64
%55 = arith.extsi %50 : i32 to i64
%54 = arith.addi %55, %52 : i64
%57 = arith.constant 2 : i32
%59 = arith.extsi %57 : i32 to i64
%58 = arith.divsi %arg0, %59 : i64
%56 = func.call @P(%58, %arg1, %arg2, %arg3) : (i64, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> i64
%60 = arith.subi %54, %56 : i64
%62 = arith.extsi %49 : i32 to i64
%61 = arith.muli %62, %60 : i64
%63 = arith.constant 1 : i32
%64 = arith.trunci %63 : i32 to i8
%65 = llvm.getelementptr %arg3[%41] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %64, %65 : i8, !llvm.ptr
%66 = llvm.getelementptr %arg1[%41] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %66 : i64, !llvm.ptr
%67 = llvm.getelementptr %arg2[%41] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %61, %67 : i64, !llvm.ptr
func.return %61 : i64
}
func.func @S(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: !llvm.ptr, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: !llvm.ptr) -> i64 {
%68 = arith.constant 0 : i32
%70 = arith.extsi %68 : i32 to i64
%69 = arith.cmpi sle, %arg0, %70 : i64
cf.cond_br %69, ^bb15, ^bb16
^bb15:
%71 = arith.constant 0 : i32
%72 = arith.extsi %71 : i32 to i64
func.return %72 : i64
^bb16:
cf.br ^bb17
^bb17:
%73 = arith.constant 1 : i32
%75 = arith.extsi %73 : i32 to i64
%74 = arith.cmpi eq, %arg0, %75 : i64
cf.cond_br %74, ^bb18, ^bb19
^bb18:
%76 = arith.constant 1 : i32
%77 = arith.extsi %76 : i32 to i64
func.return %77 : i64
^bb19:
cf.br ^bb20
^bb20:
%78 = func.call @hslot(%arg0, %arg1, %arg3) : (i64, !llvm.ptr, !llvm.ptr) -> i64
%80 = llvm.getelementptr %arg3[%78] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%79 = llvm.load %80 : !llvm.ptr -> i8
%81 = arith.constant 1 : i32
%83 = arith.extsi %79 : i8 to i32
%82 = arith.cmpi eq, %83, %81 : i32
cf.cond_br %82, ^bb21, ^bb22
^bb21:
%85 = llvm.getelementptr %arg2[%78] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%84 = llvm.load %85 : !llvm.ptr -> i64
func.return %84 : i64
^bb22:
cf.br ^bb23
^bb23:
%86 = arith.constant 0 : i32
%87 = arith.extsi %86 : i32 to i64
%88 = llvm.mlir.constant(1 : i64) : i64
%89 = llvm.alloca %88 x i64 : (i64) -> !llvm.ptr
llvm.store %87, %89 : i64, !llvm.ptr
%90 = arith.constant 1 : i32
%92 = arith.extsi %90 : i32 to i64
%91 = arith.andi %arg0, %92 : i64
%93 = arith.constant 1 : i32
%95 = arith.extsi %93 : i32 to i64
%94 = arith.cmpi eq, %91, %95 : i64
cf.cond_br %94, ^bb24, ^bb25
^bb24:
%96 = arith.constant 2 : i32
%98 = arith.extsi %96 : i32 to i64
%97 = arith.divsi %arg0, %98 : i64
%99 = arith.constant 1 : i32
%100 = arith.extsi %99 : i32 to i128
%101 = arith.constant 2 : i32
%102 = arith.extsi %101 : i32 to i128
%103 = arith.extsi %97 : i64 to i128
%105 = arith.trunci %102 : i128 to i64
%106 = arith.trunci %103 : i128 to i64
%104 = arith.muli %105, %106 : i64
%107 = arith.constant 3 : i32
%109 = arith.extsi %107 : i32 to i64
%108 = arith.addi %97, %109 : i64
%110 = arith.extsi %108 : i64 to i128
%112 = arith.trunci %110 : i128 to i64
%111 = arith.muli %104, %112 : i64
%114 = arith.trunci %100 : i128 to i64
%113 = arith.addi %114, %111 : i64
%115 = arith.constant 4 : i32
%116 = arith.extsi %115 : i32 to i128
%117 = func.call @S(%97, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6) : (i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> i64
%118 = arith.extsi %117 : i64 to i128
%120 = arith.trunci %116 : i128 to i64
%121 = arith.trunci %118 : i128 to i64
%119 = arith.muli %120, %121 : i64
%122 = arith.subi %113, %119 : i64
%123 = arith.extsi %122 : i64 to i128
%124 = llvm.mlir.addressof @MOD : !llvm.ptr
%125 = llvm.load %124 : !llvm.ptr -> i64
%126 = arith.extsi %125 : i64 to i128
%128 = arith.trunci %123 : i128 to i64
%129 = arith.trunci %126 : i128 to i64
%127 = arith.remsi %128, %129 : i64
%130 = llvm.mlir.addressof @MOD : !llvm.ptr
%131 = llvm.load %130 : !llvm.ptr -> i64
%132 = arith.extsi %131 : i64 to i128
%134 = arith.trunci %132 : i128 to i64
%133 = arith.addi %127, %134 : i64
%135 = llvm.mlir.addressof @MOD : !llvm.ptr
%136 = llvm.load %135 : !llvm.ptr -> i64
%137 = arith.extsi %136 : i64 to i128
%139 = arith.trunci %137 : i128 to i64
%138 = arith.remsi %133, %139 : i64
llvm.store %138, %89 : i64, !llvm.ptr
cf.br ^bb26
^bb25:
%140 = arith.constant 2 : i32
%142 = arith.extsi %140 : i32 to i64
%141 = arith.divsi %arg0, %142 : i64
%143 = arith.constant 2 : i32
%144 = arith.extsi %143 : i32 to i128
%145 = arith.extsi %141 : i64 to i128
%147 = arith.trunci %144 : i128 to i64
%148 = arith.trunci %145 : i128 to i64
%146 = arith.muli %147, %148 : i64
%149 = arith.extsi %141 : i64 to i128
%151 = arith.trunci %149 : i128 to i64
%150 = arith.muli %146, %151 : i64
%152 = arith.constant 4 : i32
%153 = arith.extsi %152 : i32 to i128
%154 = arith.extsi %141 : i64 to i128
%156 = arith.trunci %153 : i128 to i64
%157 = arith.trunci %154 : i128 to i64
%155 = arith.muli %156, %157 : i64
%158 = arith.addi %150, %155 : i64
%159 = arith.constant 1 : i32
%160 = arith.extsi %159 : i32 to i128
%162 = arith.trunci %160 : i128 to i64
%161 = arith.subi %158, %162 : i64
%163 = arith.constant 4 : i32
%164 = arith.extsi %163 : i32 to i128
%166 = arith.constant 1 : i32
%168 = arith.extsi %166 : i32 to i64
%167 = arith.subi %141, %168 : i64
%165 = func.call @S(%167, %arg1, %arg2, %arg3, %arg4, %arg5, %arg6) : (i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> i64
%169 = arith.extsi %165 : i64 to i128
%171 = arith.trunci %164 : i128 to i64
%172 = arith.trunci %169 : i128 to i64
%170 = arith.muli %171, %172 : i64
%173 = arith.subi %161, %170 : i64
%174 = arith.constant 2 : i32
%175 = arith.extsi %174 : i32 to i128
%176 = func.call @P(%141, %arg4, %arg5, %arg6) : (i64, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> i64
%177 = llvm.mlir.addressof @MOD : !llvm.ptr
%178 = llvm.load %177 : !llvm.ptr -> i64
%179 = arith.remsi %176, %178 : i64
%180 = arith.extsi %179 : i64 to i128
%182 = arith.trunci %175 : i128 to i64
%183 = arith.trunci %180 : i128 to i64
%181 = arith.muli %182, %183 : i64
%184 = arith.subi %173, %181 : i64
%185 = arith.extsi %184 : i64 to i128
%186 = llvm.mlir.addressof @MOD : !llvm.ptr
%187 = llvm.load %186 : !llvm.ptr -> i64
%188 = arith.extsi %187 : i64 to i128
%190 = arith.trunci %185 : i128 to i64
%191 = arith.trunci %188 : i128 to i64
%189 = arith.remsi %190, %191 : i64
%192 = llvm.mlir.addressof @MOD : !llvm.ptr
%193 = llvm.load %192 : !llvm.ptr -> i64
%194 = arith.extsi %193 : i64 to i128
%196 = arith.trunci %194 : i128 to i64
%195 = arith.addi %189, %196 : i64
%197 = llvm.mlir.addressof @MOD : !llvm.ptr
%198 = llvm.load %197 : !llvm.ptr -> i64
%199 = arith.extsi %198 : i64 to i128
%201 = arith.trunci %199 : i128 to i64
%200 = arith.remsi %195, %201 : i64
llvm.store %200, %89 : i64, !llvm.ptr
cf.br ^bb26
^bb26:
%202 = arith.constant 1 : i32
%203 = arith.trunci %202 : i32 to i8
%204 = llvm.getelementptr %arg3[%78] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %203, %204 : i8, !llvm.ptr
%205 = llvm.getelementptr %arg1[%78] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %205 : i64, !llvm.ptr
%206 = llvm.load %89 : !llvm.ptr -> i64
%207 = llvm.getelementptr %arg2[%78] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %206, %207 : i64, !llvm.ptr
%208 = llvm.load %89 : !llvm.ptr -> i64
func.return %208 : i64
}
func.func @main() -> i32 {
%210 = llvm.mlir.addressof @CAP : !llvm.ptr
%211 = llvm.load %210 : !llvm.ptr -> i64
%212 = arith.constant 8 : i32
%213 = arith.extsi %212 : i32 to i64
%209 = func.call @calloc(%211, %213) : (i64, i64) -> !llvm.ptr
%215 = llvm.mlir.addressof @CAP : !llvm.ptr
%216 = llvm.load %215 : !llvm.ptr -> i64
%217 = arith.constant 8 : i32
%218 = arith.extsi %217 : i32 to i64
%214 = func.call @calloc(%216, %218) : (i64, i64) -> !llvm.ptr
%220 = llvm.mlir.addressof @CAP : !llvm.ptr
%221 = llvm.load %220 : !llvm.ptr -> i64
%222 = arith.constant 1 : i32
%223 = arith.extsi %222 : i32 to i64
%219 = func.call @calloc(%221, %223) : (i64, i64) -> !llvm.ptr
%225 = llvm.mlir.addressof @CAP : !llvm.ptr
%226 = llvm.load %225 : !llvm.ptr -> i64
%227 = arith.constant 8 : i32
%228 = arith.extsi %227 : i32 to i64
%224 = func.call @calloc(%226, %228) : (i64, i64) -> !llvm.ptr
%230 = llvm.mlir.addressof @CAP : !llvm.ptr
%231 = llvm.load %230 : !llvm.ptr -> i64
%232 = arith.constant 8 : i32
%233 = arith.extsi %232 : i32 to i64
%229 = func.call @calloc(%231, %233) : (i64, i64) -> !llvm.ptr
%235 = llvm.mlir.addressof @CAP : !llvm.ptr
%236 = llvm.load %235 : !llvm.ptr -> i64
%237 = arith.constant 1 : i32
%238 = arith.extsi %237 : i32 to i64
%234 = func.call @calloc(%236, %238) : (i64, i64) -> !llvm.ptr
%239 = llvm.mlir.zero : !llvm.ptr
%240 = llvm.icmp "eq" %209, %239 : !llvm.ptr
%241 = scf.if %240 -> (i1) {
%242 = arith.constant true
scf.yield %242 : i1
} else {
%243 = llvm.mlir.zero : !llvm.ptr
%244 = llvm.icmp "eq" %214, %243 : !llvm.ptr
scf.yield %244 : i1
}
%245 = scf.if %241 -> (i1) {
%246 = arith.constant true
scf.yield %246 : i1
} else {
%247 = llvm.mlir.zero : !llvm.ptr
%248 = llvm.icmp "eq" %219, %247 : !llvm.ptr
scf.yield %248 : i1
}
%249 = scf.if %245 -> (i1) {
%250 = arith.constant true
scf.yield %250 : i1
} else {
%251 = llvm.mlir.zero : !llvm.ptr
%252 = llvm.icmp "eq" %224, %251 : !llvm.ptr
scf.yield %252 : i1
}
%253 = scf.if %249 -> (i1) {
%254 = arith.constant true
scf.yield %254 : i1
} else {
%255 = llvm.mlir.zero : !llvm.ptr
%256 = llvm.icmp "eq" %229, %255 : !llvm.ptr
scf.yield %256 : i1
}
%257 = scf.if %253 -> (i1) {
%258 = arith.constant true
scf.yield %258 : i1
} else {
%259 = llvm.mlir.zero : !llvm.ptr
%260 = llvm.icmp "eq" %234, %259 : !llvm.ptr
scf.yield %260 : i1
}
cf.cond_br %257, ^bb27, ^bb28
^bb27:
%261 = arith.constant 1 : i32
func.return %261 : i32
^bb28:
cf.br ^bb29
^bb29:
%263 = arith.constant 999999995705032704 : i32
%264 = arith.extsi %263 : i32 to i64
%262 = func.call @S(%264, %224, %229, %234, %209, %214, %219) : (i64, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> i64
%265 = llvm.mlir.addressof @str_0 : !llvm.ptr
%266 = llvm.call @printf(%265, %262) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%209) : (!llvm.ptr) -> ()
func.call @free(%214) : (!llvm.ptr) -> ()
func.call @free(%219) : (!llvm.ptr) -> ()
func.call @free(%224) : (!llvm.ptr) -> ()
func.call @free(%229) : (!llvm.ptr) -> ()
func.call @free(%234) : (!llvm.ptr) -> ()
%273 = arith.constant 0 : i32
func.return %273 : i32
}
}