Problem 918
Recursive Sequence Summation a(1)=1; a(2n)=2a(n); a(2n+1)=a(n)-3a(n+1) S(N)=4-a(N/2) (even); 4-3a(N/2+1) (odd). Find S(10^12).
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n) | ? |
| Space complexity | O(n) | ? |
| Approach | Flow solution | Not curated |
| Verdict | Unknown |
Flow source
# Project Euler 918
# Recursive Sequence Summation
# a(1)=1; a(2n)=2a(n); a(2n+1)=a(n)-3a(n+1)
# S(N)=4-a(N/2) (even); 4-3a(N/2+1) (odd). Find S(10^12).
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
const CAP: i64 = 1 << 20
let mut keys: ptr<i64> = null
let mut vals: ptr<i64> = null
let mut used: ptr<i8> = null
function hmix(x: i64) -> i64 {
let mut z: i64 = x + 0x9e3779b97f4a7c15
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9
z = (z ^ (z >> 27)) * 0x94d049bb133111eb
return z ^ (z >> 31)
}
function memo_get(n: i64) -> i64 {
let mut i: i64 = hmix(n) & (CAP - 1)
while used[i] != 0 {
if keys[i] == n { return vals[i] }
i = (i + 1) & (CAP - 1)
}
return 9223372036854775807
}
function memo_put(n: i64, v: i64) -> void {
let mut i: i64 = hmix(n) & (CAP - 1)
while used[i] != 0 {
if keys[i] == n {
vals[i] = v
return
}
i = (i + 1) & (CAP - 1)
}
used[i] = 1
keys[i] = n
vals[i] = v
}
function a(n: i64) -> i64 {
if n == 1 { return 1 }
let cached: i64 = memo_get(n)
if cached != 9223372036854775807 { return cached }
let mut res: i64 = 0
if (n & 1) == 0 {
res = 2 * a(n / 2)
} else {
res = a(n / 2) - 3 * a(n / 2 + 1)
}
memo_put(n, res)
return res
}
function S(N: i64) -> i64 {
if (N & 1) == 0 {
return 4 - a(N / 2)
}
return 4 - 3 * a(N / 2 + 1)
}
function main() -> i32 {
keys = calloc(CAP, 8)
vals = calloc(CAP, 8)
used = calloc(CAP, 1)
if keys == null || vals == null || used == null { return 1 }
printf("%lld\n", S(1000000000000))
free(keys)
free(vals)
free(used)
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 hmix_i64(int64_t x);
int64_t memo_get_i64(int64_t n);
void memo_put_i64_i64(int64_t n, int64_t v);
int64_t a_i64(int64_t n);
int64_t S_i64(int64_t N);
int32_t main(void);
static const int64_t CAP = FLOW_CHECKED_SHL((1), (20));
/* Module statics */
static int64_t* keys = NULL;
static int64_t* vals = NULL;
static int8_t* used = NULL;
int64_t hmix_i64(int64_t x) {
int64_t z = (x + ((__int128)0x9E3779B97F4A7C15ULL));
z = ((z ^ FLOW_CHECKED_SHR((z), (30))) * ((__int128)0xBF58476D1CE4E5B9ULL));
z = ((z ^ FLOW_CHECKED_SHR((z), (27))) * ((__int128)0x94D049BB133111EBULL));
return (z ^ FLOW_CHECKED_SHR((z), (31)));
}
int64_t memo_get_i64(int64_t n) {
int64_t i = (hmix_i64(n) & (CAP - 1));
while (used[i] != 0) {
if (keys[i] == n) {
return vals[i];
}
i = ((i + 1) & (CAP - 1));
}
return 9223372036854775807;
}
void memo_put_i64_i64(int64_t n, int64_t v) {
int64_t i = (hmix_i64(n) & (CAP - 1));
while (used[i] != 0) {
if (keys[i] == n) {
vals[i] = v;
return;
}
i = ((i + 1) & (CAP - 1));
}
used[i] = 1;
keys[i] = n;
vals[i] = v;
}
int64_t a_i64(int64_t n) {
if (n == 1) {
return 1;
}
int64_t cached = memo_get_i64(n);
if (cached != 9223372036854775807) {
return cached;
}
int64_t res = 0;
if ((n & 1) == 0) {
res = (2 * a_i64(FLOW_CHECKED_DIV((n), (2))));
} else {
res = (a_i64(FLOW_CHECKED_DIV((n), (2))) - (3 * a_i64((FLOW_CHECKED_DIV((n), (2)) + 1))));
}
memo_put_i64_i64(n, res);
return res;
}
int64_t S_i64(int64_t N) {
if ((N & 1) == 0) {
return (4 - a_i64(FLOW_CHECKED_DIV((N), (2))));
}
return (4 - (3 * a_i64((FLOW_CHECKED_DIV((N), (2)) + 1))));
}
int32_t main(void) {
keys = calloc(CAP, 8);
vals = calloc(CAP, 8);
used = calloc(CAP, 1);
if (((keys == NULL || vals == NULL) || used == NULL)) {
return 1;
}
printf("%lld\n", S_i64(1000000000000));
free(keys);
free(vals);
free(used);
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: CAP
llvm.mlir.global internal constant @CAP(1048576 : i64) : i64
// Module static: keys
llvm.mlir.global internal @keys() {addr_space = 0 : i32} : !llvm.ptr {
%0 = llvm.mlir.zero : !llvm.ptr
llvm.return %0 : !llvm.ptr
}
// Module static: vals
llvm.mlir.global internal @vals() {addr_space = 0 : i32} : !llvm.ptr {
%1 = llvm.mlir.zero : !llvm.ptr
llvm.return %1 : !llvm.ptr
}
// Module static: used
llvm.mlir.global internal @used() {addr_space = 0 : i32} : !llvm.ptr {
%2 = llvm.mlir.zero : !llvm.ptr
llvm.return %2 : !llvm.ptr
}
func.func @hmix(%arg0: i64) -> i64 {
%3 = arith.constant 11400714815028231189 : i32
%5 = arith.extsi %3 : i32 to i64
%4 = arith.addi %arg0, %5 : i64
%6 = llvm.mlir.constant(1 : i64) : i64
%7 = llvm.alloca %6 x i64 : (i64) -> !llvm.ptr
llvm.store %4, %7 : i64, !llvm.ptr
%8 = llvm.load %7 : !llvm.ptr -> i64
%9 = llvm.load %7 : !llvm.ptr -> i64
%10 = arith.constant 30 : i32
%12 = arith.extsi %10 : i32 to i64
%11 = arith.shrsi %9, %12 : i64
%13 = arith.xori %8, %11 : i64
%14 = arith.constant 13787848788861576633 : i32
%16 = arith.extsi %14 : i32 to i64
%15 = arith.muli %13, %16 : i64
llvm.store %15, %7 : i64, !llvm.ptr
%17 = llvm.load %7 : !llvm.ptr -> i64
%18 = llvm.load %7 : !llvm.ptr -> i64
%19 = arith.constant 27 : i32
%21 = arith.extsi %19 : i32 to i64
%20 = arith.shrsi %18, %21 : i64
%22 = arith.xori %17, %20 : i64
%23 = arith.constant 10723151776303878635 : i32
%25 = arith.extsi %23 : i32 to i64
%24 = arith.muli %22, %25 : i64
llvm.store %24, %7 : i64, !llvm.ptr
%26 = llvm.load %7 : !llvm.ptr -> i64
%27 = llvm.load %7 : !llvm.ptr -> i64
%28 = arith.constant 31 : i32
%30 = arith.extsi %28 : i32 to i64
%29 = arith.shrsi %27, %30 : i64
%31 = arith.xori %26, %29 : i64
func.return %31 : i64
}
func.func @memo_get(%arg0: i64) -> i64 {
%32 = func.call @hmix(%arg0) : (i64) -> i64
%33 = llvm.mlir.addressof @CAP : !llvm.ptr
%34 = llvm.load %33 : !llvm.ptr -> i64
%35 = arith.constant 1 : i32
%37 = arith.extsi %35 : i32 to i64
%36 = arith.subi %34, %37 : i64
%38 = arith.andi %32, %36 : i64
%39 = llvm.mlir.constant(1 : i64) : i64
%40 = llvm.alloca %39 x i64 : (i64) -> !llvm.ptr
llvm.store %38, %40 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%42 = llvm.mlir.addressof @used : !llvm.ptr
%43 = llvm.load %42 : !llvm.ptr -> !llvm.ptr
%44 = llvm.load %40 : !llvm.ptr -> i64
%45 = llvm.getelementptr %43[%44] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%41 = llvm.load %45 : !llvm.ptr -> i8
%46 = arith.constant 0 : i32
%48 = arith.extsi %41 : i8 to i32
%47 = arith.cmpi ne, %48, %46 : i32
cf.cond_br %47, ^bb1, ^bb2
^bb1:
%50 = llvm.mlir.addressof @keys : !llvm.ptr
%51 = llvm.load %50 : !llvm.ptr -> !llvm.ptr
%52 = llvm.load %40 : !llvm.ptr -> i64
%53 = llvm.getelementptr %51[%52] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%49 = llvm.load %53 : !llvm.ptr -> i64
%54 = arith.cmpi eq, %49, %arg0 : i64
cf.cond_br %54, ^bb3, ^bb4
^bb3:
%56 = llvm.mlir.addressof @vals : !llvm.ptr
%57 = llvm.load %56 : !llvm.ptr -> !llvm.ptr
%58 = llvm.load %40 : !llvm.ptr -> i64
%59 = llvm.getelementptr %57[%58] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%55 = llvm.load %59 : !llvm.ptr -> i64
func.return %55 : i64
^bb4:
cf.br ^bb5
^bb5:
%60 = llvm.load %40 : !llvm.ptr -> i64
%61 = arith.constant 1 : i32
%63 = arith.extsi %61 : i32 to i64
%62 = arith.addi %60, %63 : i64
%64 = llvm.mlir.addressof @CAP : !llvm.ptr
%65 = llvm.load %64 : !llvm.ptr -> i64
%66 = arith.constant 1 : i32
%68 = arith.extsi %66 : i32 to i64
%67 = arith.subi %65, %68 : i64
%69 = arith.andi %62, %67 : i64
llvm.store %69, %40 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%70 = arith.constant 9223372032559808511 : i32
%71 = arith.extsi %70 : i32 to i64
func.return %71 : i64
}
func.func @memo_put(%arg0: i64, %arg1: i64) -> () {
%72 = func.call @hmix(%arg0) : (i64) -> i64
%73 = llvm.mlir.addressof @CAP : !llvm.ptr
%74 = llvm.load %73 : !llvm.ptr -> i64
%75 = arith.constant 1 : i32
%77 = arith.extsi %75 : i32 to i64
%76 = arith.subi %74, %77 : i64
%78 = arith.andi %72, %76 : i64
%79 = llvm.mlir.constant(1 : i64) : i64
%80 = llvm.alloca %79 x i64 : (i64) -> !llvm.ptr
llvm.store %78, %80 : i64, !llvm.ptr
cf.br ^bb6
^bb6:
%82 = llvm.mlir.addressof @used : !llvm.ptr
%83 = llvm.load %82 : !llvm.ptr -> !llvm.ptr
%84 = llvm.load %80 : !llvm.ptr -> i64
%85 = llvm.getelementptr %83[%84] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%81 = llvm.load %85 : !llvm.ptr -> i8
%86 = arith.constant 0 : i32
%88 = arith.extsi %81 : i8 to i32
%87 = arith.cmpi ne, %88, %86 : i32
cf.cond_br %87, ^bb7, ^bb8
^bb7:
%90 = llvm.mlir.addressof @keys : !llvm.ptr
%91 = llvm.load %90 : !llvm.ptr -> !llvm.ptr
%92 = llvm.load %80 : !llvm.ptr -> i64
%93 = llvm.getelementptr %91[%92] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%89 = llvm.load %93 : !llvm.ptr -> i64
%94 = arith.cmpi eq, %89, %arg0 : i64
cf.cond_br %94, ^bb9, ^bb10
^bb9:
%95 = llvm.mlir.addressof @vals : !llvm.ptr
%96 = llvm.load %95 : !llvm.ptr -> !llvm.ptr
%97 = llvm.load %80 : !llvm.ptr -> i64
%98 = llvm.getelementptr %96[%97] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg1, %98 : i64, !llvm.ptr
func.return
^bb10:
cf.br ^bb11
^bb11:
%99 = llvm.load %80 : !llvm.ptr -> i64
%100 = arith.constant 1 : i32
%102 = arith.extsi %100 : i32 to i64
%101 = arith.addi %99, %102 : i64
%103 = llvm.mlir.addressof @CAP : !llvm.ptr
%104 = llvm.load %103 : !llvm.ptr -> i64
%105 = arith.constant 1 : i32
%107 = arith.extsi %105 : i32 to i64
%106 = arith.subi %104, %107 : i64
%108 = arith.andi %101, %106 : i64
llvm.store %108, %80 : i64, !llvm.ptr
cf.br ^bb6
^bb8:
%109 = arith.constant 1 : i32
%110 = llvm.mlir.addressof @used : !llvm.ptr
%111 = llvm.load %110 : !llvm.ptr -> !llvm.ptr
%112 = llvm.load %80 : !llvm.ptr -> i64
%113 = arith.trunci %109 : i32 to i8
%114 = llvm.getelementptr %111[%112] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %113, %114 : i8, !llvm.ptr
%115 = llvm.mlir.addressof @keys : !llvm.ptr
%116 = llvm.load %115 : !llvm.ptr -> !llvm.ptr
%117 = llvm.load %80 : !llvm.ptr -> i64
%118 = llvm.getelementptr %116[%117] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %118 : i64, !llvm.ptr
%119 = llvm.mlir.addressof @vals : !llvm.ptr
%120 = llvm.load %119 : !llvm.ptr -> !llvm.ptr
%121 = llvm.load %80 : !llvm.ptr -> i64
%122 = llvm.getelementptr %120[%121] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg1, %122 : i64, !llvm.ptr
func.return
}
func.func @a(%arg0: i64) -> i64 {
%123 = arith.constant 1 : i32
%125 = arith.extsi %123 : i32 to i64
%124 = arith.cmpi eq, %arg0, %125 : i64
cf.cond_br %124, ^bb12, ^bb13
^bb12:
%126 = arith.constant 1 : i32
%127 = arith.extsi %126 : i32 to i64
func.return %127 : i64
^bb13:
cf.br ^bb14
^bb14:
%128 = func.call @memo_get(%arg0) : (i64) -> i64
%129 = arith.constant 9223372032559808511 : i32
%131 = arith.extsi %129 : i32 to i64
%130 = arith.cmpi ne, %128, %131 : i64
cf.cond_br %130, ^bb15, ^bb16
^bb15:
func.return %128 : i64
^bb16:
cf.br ^bb17
^bb17:
%132 = arith.constant 0 : i32
%133 = arith.extsi %132 : i32 to i64
%134 = llvm.mlir.constant(1 : i64) : i64
%135 = llvm.alloca %134 x i64 : (i64) -> !llvm.ptr
llvm.store %133, %135 : i64, !llvm.ptr
%136 = arith.constant 1 : i32
%138 = arith.extsi %136 : i32 to i64
%137 = arith.andi %arg0, %138 : i64
%139 = arith.constant 0 : i32
%141 = arith.extsi %139 : i32 to i64
%140 = arith.cmpi eq, %137, %141 : i64
cf.cond_br %140, ^bb18, ^bb19
^bb18:
%142 = arith.constant 2 : i32
%144 = arith.constant 2 : i32
%146 = arith.extsi %144 : i32 to i64
%145 = arith.divsi %arg0, %146 : i64
%143 = func.call @a(%145) : (i64) -> i64
%148 = arith.extsi %142 : i32 to i64
%147 = arith.muli %148, %143 : i64
llvm.store %147, %135 : i64, !llvm.ptr
cf.br ^bb20
^bb19:
%150 = arith.constant 2 : i32
%152 = arith.extsi %150 : i32 to i64
%151 = arith.divsi %arg0, %152 : i64
%149 = func.call @a(%151) : (i64) -> i64
%153 = arith.constant 3 : i32
%155 = arith.constant 2 : i32
%157 = arith.extsi %155 : i32 to i64
%156 = arith.divsi %arg0, %157 : i64
%158 = arith.constant 1 : i32
%160 = arith.extsi %158 : i32 to i64
%159 = arith.addi %156, %160 : i64
%154 = func.call @a(%159) : (i64) -> i64
%162 = arith.extsi %153 : i32 to i64
%161 = arith.muli %162, %154 : i64
%163 = arith.subi %149, %161 : i64
llvm.store %163, %135 : i64, !llvm.ptr
cf.br ^bb20
^bb20:
%165 = llvm.load %135 : !llvm.ptr -> i64
func.call @memo_put(%arg0, %165) : (i64, i64) -> ()
%166 = llvm.load %135 : !llvm.ptr -> i64
func.return %166 : i64
}
func.func @S(%arg0: i64) -> i64 {
%167 = arith.constant 1 : i32
%169 = arith.extsi %167 : i32 to i64
%168 = arith.andi %arg0, %169 : i64
%170 = arith.constant 0 : i32
%172 = arith.extsi %170 : i32 to i64
%171 = arith.cmpi eq, %168, %172 : i64
cf.cond_br %171, ^bb21, ^bb22
^bb21:
%173 = arith.constant 4 : i32
%175 = arith.constant 2 : i32
%177 = arith.extsi %175 : i32 to i64
%176 = arith.divsi %arg0, %177 : i64
%174 = func.call @a(%176) : (i64) -> i64
%179 = arith.extsi %173 : i32 to i64
%178 = arith.subi %179, %174 : i64
func.return %178 : i64
^bb22:
cf.br ^bb23
^bb23:
%180 = arith.constant 4 : i32
%181 = arith.constant 3 : i32
%183 = arith.constant 2 : i32
%185 = arith.extsi %183 : i32 to i64
%184 = arith.divsi %arg0, %185 : i64
%186 = arith.constant 1 : i32
%188 = arith.extsi %186 : i32 to i64
%187 = arith.addi %184, %188 : i64
%182 = func.call @a(%187) : (i64) -> i64
%190 = arith.extsi %181 : i32 to i64
%189 = arith.muli %190, %182 : i64
%192 = arith.extsi %180 : i32 to i64
%191 = arith.subi %192, %189 : i64
func.return %191 : i64
}
func.func @main() -> i32 {
%194 = llvm.mlir.addressof @CAP : !llvm.ptr
%195 = llvm.load %194 : !llvm.ptr -> i64
%196 = arith.constant 8 : i32
%197 = arith.extsi %196 : i32 to i64
%193 = func.call @calloc(%195, %197) : (i64, i64) -> !llvm.ptr
%198 = llvm.mlir.addressof @keys : !llvm.ptr
llvm.store %193, %198 : !llvm.ptr, !llvm.ptr
%200 = llvm.mlir.addressof @CAP : !llvm.ptr
%201 = llvm.load %200 : !llvm.ptr -> i64
%202 = arith.constant 8 : i32
%203 = arith.extsi %202 : i32 to i64
%199 = func.call @calloc(%201, %203) : (i64, i64) -> !llvm.ptr
%204 = llvm.mlir.addressof @vals : !llvm.ptr
llvm.store %199, %204 : !llvm.ptr, !llvm.ptr
%206 = llvm.mlir.addressof @CAP : !llvm.ptr
%207 = llvm.load %206 : !llvm.ptr -> i64
%208 = arith.constant 1 : i32
%209 = arith.extsi %208 : i32 to i64
%205 = func.call @calloc(%207, %209) : (i64, i64) -> !llvm.ptr
%210 = llvm.mlir.addressof @used : !llvm.ptr
llvm.store %205, %210 : !llvm.ptr, !llvm.ptr
%211 = llvm.mlir.addressof @keys : !llvm.ptr
%212 = llvm.load %211 : !llvm.ptr -> !llvm.ptr
%213 = llvm.mlir.zero : !llvm.ptr
%214 = llvm.icmp "eq" %212, %213 : !llvm.ptr
%215 = scf.if %214 -> (i1) {
%216 = arith.constant true
scf.yield %216 : i1
} else {
%217 = llvm.mlir.addressof @vals : !llvm.ptr
%218 = llvm.load %217 : !llvm.ptr -> !llvm.ptr
%219 = llvm.mlir.zero : !llvm.ptr
%220 = llvm.icmp "eq" %218, %219 : !llvm.ptr
scf.yield %220 : i1
}
%221 = scf.if %215 -> (i1) {
%222 = arith.constant true
scf.yield %222 : i1
} else {
%223 = llvm.mlir.addressof @used : !llvm.ptr
%224 = llvm.load %223 : !llvm.ptr -> !llvm.ptr
%225 = llvm.mlir.zero : !llvm.ptr
%226 = llvm.icmp "eq" %224, %225 : !llvm.ptr
scf.yield %226 : i1
}
cf.cond_br %221, ^bb24, ^bb25
^bb24:
%227 = arith.constant 1 : i32
func.return %227 : i32
^bb25:
cf.br ^bb26
^bb26:
%228 = llvm.mlir.addressof @str_0 : !llvm.ptr
%230 = arith.constant 995705032704 : i32
%231 = arith.extsi %230 : i32 to i64
%229 = func.call @S(%231) : (i64) -> i64
%232 = llvm.call @printf(%228, %229) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%234 = llvm.mlir.addressof @keys : !llvm.ptr
%235 = llvm.load %234 : !llvm.ptr -> !llvm.ptr
func.call @free(%235) : (!llvm.ptr) -> ()
%237 = llvm.mlir.addressof @vals : !llvm.ptr
%238 = llvm.load %237 : !llvm.ptr -> !llvm.ptr
func.call @free(%238) : (!llvm.ptr) -> ()
%240 = llvm.mlir.addressof @used : !llvm.ptr
%241 = llvm.load %240 : !llvm.ptr -> !llvm.ptr
func.call @free(%241) : (!llvm.ptr) -> ()
%242 = arith.constant 0 : i32
func.return %242 : i32
}
}