Problem 161
Triomino tilings of a 9x12 grid.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n) | O(n * s) |
| Space complexity | O(n) | O(s) |
| Approach | Flow solution | Tiling DP with state |
| Verdict | Unknown |
Flow source
# Project Euler 161
# Triomino tilings of a 9x12 grid.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function cache_get(keys: ptr<i64>, vals: ptr<i64>, used: ptr<i8>, cap: i64, key: i64) -> i64 {
let mut slot: i64 = key
if slot < 0 { slot = -slot }
slot = slot & (cap - 1)
while used[slot] != 0 {
if keys[slot] == key { return vals[slot] }
slot = (slot + 1) & (cap - 1)
}
return -1
}
function cache_put(keys: ptr<i64>, vals: ptr<i64>, used: ptr<i8>, cap: i64, key: i64, val: i64) -> void {
let mut slot: i64 = key
if slot < 0 { slot = -slot }
slot = slot & (cap - 1)
while used[slot] != 0 && keys[slot] != key {
slot = (slot + 1) & (cap - 1)
}
used[slot] = 1
keys[slot] = key
vals[slot] = val
}
function use_cell(pos: i32, row: i32) -> i32 {
let mask: i32 = 1 << pos
if (row & mask) != 0 { return -1 }
return row | mask
}
function search(rows_left: i32, row_a: i32, row_b: i32, row_c: i32, width: i32,
keys: ptr<i64>, vals: ptr<i64>, used: ptr<i8>, cap: i64) -> i64 {
if rows_left == 0 { return 1 }
let full_row: i32 = (1 << width) - 1
if row_a == full_row {
return search(rows_left - 1, row_b, row_c, 0, width, keys, vals, used, cap)
}
let mut pos: i32 = 0
while (row_a & (1 << pos)) != 0 {
pos = pos + 1
}
let mut hash_value: i64 = rows_left as i64
hash_value = (hash_value << width) | (row_a as i64)
hash_value = (hash_value << width) | (row_b as i64)
hash_value = (hash_value << width) | (row_c as i64)
let cached: i64 = cache_get(keys, vals, used, cap, hash_value)
if cached >= 0 { return cached }
let mut result: i64 = 0
if rows_left >= 2 && pos < width - 1 {
let mut a: i32 = use_cell(pos, row_a)
if a >= 0 {
a = use_cell(pos + 1, a)
if a >= 0 {
let b: i32 = use_cell(pos, row_b)
if b >= 0 {
result = result + search(rows_left, a, b, row_c, width, keys, vals, used, cap)
}
}
}
}
if rows_left >= 2 && pos < width - 1 {
let mut a: i32 = use_cell(pos, row_a)
if a >= 0 {
a = use_cell(pos + 1, a)
if a >= 0 {
let b: i32 = use_cell(pos + 1, row_b)
if b >= 0 {
result = result + search(rows_left, a, b, row_c, width, keys, vals, used, cap)
}
}
}
}
if rows_left >= 2 && pos < width - 1 {
let a: i32 = use_cell(pos, row_a)
if a >= 0 {
let mut b: i32 = use_cell(pos, row_b)
if b >= 0 {
b = use_cell(pos + 1, b)
if b >= 0 {
result = result + search(rows_left, a, b, row_c, width, keys, vals, used, cap)
}
}
}
}
if rows_left >= 2 && pos > 0 {
let a: i32 = use_cell(pos, row_a)
if a >= 0 {
let mut b: i32 = use_cell(pos - 1, row_b)
if b >= 0 {
b = use_cell(pos, b)
if b >= 0 {
result = result + search(rows_left, a, b, row_c, width, keys, vals, used, cap)
}
}
}
}
if rows_left >= 3 {
let a: i32 = use_cell(pos, row_a)
if a >= 0 {
let b: i32 = use_cell(pos, row_b)
if b >= 0 {
let c: i32 = use_cell(pos, row_c)
if c >= 0 {
result = result + search(rows_left, a, b, c, width, keys, vals, used, cap)
}
}
}
}
if rows_left >= 1 && pos < width - 2 {
let mut a: i32 = use_cell(pos, row_a)
if a >= 0 {
a = use_cell(pos + 1, a)
if a >= 0 {
a = use_cell(pos + 2, a)
if a >= 0 {
result = result + search(rows_left, a, row_b, row_c, width, keys, vals, used, cap)
}
}
}
}
cache_put(keys, vals, used, cap, hash_value, result)
return result
}
function main() -> i32 {
let cap: i64 = 2097152
let keys: ptr<i64> = calloc(cap, 8)
let vals: ptr<i64> = calloc(cap, 8)
let used: ptr<i8> = calloc(cap, 1)
if keys == null || vals == null || used == null { return 1 }
let ans: i64 = search(12, 0, 0, 0, 9, keys, vals, used, cap)
printf("%lld\n", ans)
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 cache_get_ptr_i64_ptr_i64_ptr_i8_i64_i64(int64_t* keys, int64_t* vals, int8_t* used, int64_t cap, int64_t key);
void cache_put_ptr_i64_ptr_i64_ptr_i8_i64_i64_i64(int64_t* keys, int64_t* vals, int8_t* used, int64_t cap, int64_t key, int64_t val);
int32_t use_cell_i32_i32(int32_t pos, int32_t row);
int64_t search_i32_i32_i32_i32_i32_ptr_i64_ptr_i64_ptr_i8_i64(int32_t rows_left, int32_t row_a, int32_t row_b, int32_t row_c, int32_t width, int64_t* keys, int64_t* vals, int8_t* used, int64_t cap);
int32_t main(void);
int64_t cache_get_ptr_i64_ptr_i64_ptr_i8_i64_i64(int64_t* keys, int64_t* vals, int8_t* used, int64_t cap, int64_t key) {
int64_t slot = key;
if (slot < 0) {
slot = (-slot);
}
slot = (slot & (cap - 1));
while (used[slot] != 0) {
if (keys[slot] == key) {
return vals[slot];
}
slot = ((slot + 1) & (cap - 1));
}
return (-1);
}
void cache_put_ptr_i64_ptr_i64_ptr_i8_i64_i64_i64(int64_t* keys, int64_t* vals, int8_t* used, int64_t cap, int64_t key, int64_t val) {
int64_t slot = key;
if (slot < 0) {
slot = (-slot);
}
slot = (slot & (cap - 1));
while ((used[slot] != 0 && keys[slot] != key)) {
slot = ((slot + 1) & (cap - 1));
}
used[slot] = 1;
keys[slot] = key;
vals[slot] = val;
}
int32_t use_cell_i32_i32(int32_t pos, int32_t row) {
int32_t mask = FLOW_CHECKED_SHL((1), (pos));
if ((row & mask) != 0) {
return (-1);
}
return (row | mask);
}
int64_t search_i32_i32_i32_i32_i32_ptr_i64_ptr_i64_ptr_i8_i64(int32_t rows_left, int32_t row_a, int32_t row_b, int32_t row_c, int32_t width, int64_t* keys, int64_t* vals, int8_t* used, int64_t cap) {
if (rows_left == 0) {
return 1;
}
int32_t full_row = (FLOW_CHECKED_SHL((1), (width)) - 1);
if (row_a == full_row) {
return search_i32_i32_i32_i32_i32_ptr_i64_ptr_i64_ptr_i8_i64((rows_left - 1), row_b, row_c, 0, width, keys, vals, used, cap);
}
int32_t pos = 0;
while ((row_a & FLOW_CHECKED_SHL((1), (pos))) != 0) {
pos = (pos + 1);
}
int64_t hash_value = ((int64_t)(rows_left));
hash_value = (FLOW_CHECKED_SHL((hash_value), (width)) | ((int64_t)(row_a)));
hash_value = (FLOW_CHECKED_SHL((hash_value), (width)) | ((int64_t)(row_b)));
hash_value = (FLOW_CHECKED_SHL((hash_value), (width)) | ((int64_t)(row_c)));
int64_t cached = cache_get_ptr_i64_ptr_i64_ptr_i8_i64_i64(keys, vals, used, cap, hash_value);
if (cached >= 0) {
return cached;
}
int64_t result = 0;
if ((rows_left >= 2 && pos < (width - 1))) {
int32_t a = use_cell_i32_i32(pos, row_a);
if (a >= 0) {
a = use_cell_i32_i32((pos + 1), a);
if (a >= 0) {
int32_t b = use_cell_i32_i32(pos, row_b);
if (b >= 0) {
result = (result + search_i32_i32_i32_i32_i32_ptr_i64_ptr_i64_ptr_i8_i64(rows_left, a, b, row_c, width, keys, vals, used, cap));
}
}
}
}
if ((rows_left >= 2 && pos < (width - 1))) {
int32_t a = use_cell_i32_i32(pos, row_a);
if (a >= 0) {
a = use_cell_i32_i32((pos + 1), a);
if (a >= 0) {
int32_t b = use_cell_i32_i32((pos + 1), row_b);
if (b >= 0) {
result = (result + search_i32_i32_i32_i32_i32_ptr_i64_ptr_i64_ptr_i8_i64(rows_left, a, b, row_c, width, keys, vals, used, cap));
}
}
}
}
if ((rows_left >= 2 && pos < (width - 1))) {
int32_t a = use_cell_i32_i32(pos, row_a);
if (a >= 0) {
int32_t b = use_cell_i32_i32(pos, row_b);
if (b >= 0) {
b = use_cell_i32_i32((pos + 1), b);
if (b >= 0) {
result = (result + search_i32_i32_i32_i32_i32_ptr_i64_ptr_i64_ptr_i8_i64(rows_left, a, b, row_c, width, keys, vals, used, cap));
}
}
}
}
if ((rows_left >= 2 && pos > 0)) {
int32_t a = use_cell_i32_i32(pos, row_a);
if (a >= 0) {
int32_t b = use_cell_i32_i32((pos - 1), row_b);
if (b >= 0) {
b = use_cell_i32_i32(pos, b);
if (b >= 0) {
result = (result + search_i32_i32_i32_i32_i32_ptr_i64_ptr_i64_ptr_i8_i64(rows_left, a, b, row_c, width, keys, vals, used, cap));
}
}
}
}
if (rows_left >= 3) {
int32_t a = use_cell_i32_i32(pos, row_a);
if (a >= 0) {
int32_t b = use_cell_i32_i32(pos, row_b);
if (b >= 0) {
int32_t c = use_cell_i32_i32(pos, row_c);
if (c >= 0) {
result = (result + search_i32_i32_i32_i32_i32_ptr_i64_ptr_i64_ptr_i8_i64(rows_left, a, b, c, width, keys, vals, used, cap));
}
}
}
}
if ((rows_left >= 1 && pos < (width - 2))) {
int32_t a = use_cell_i32_i32(pos, row_a);
if (a >= 0) {
a = use_cell_i32_i32((pos + 1), a);
if (a >= 0) {
a = use_cell_i32_i32((pos + 2), a);
if (a >= 0) {
result = (result + search_i32_i32_i32_i32_i32_ptr_i64_ptr_i64_ptr_i8_i64(rows_left, a, row_b, row_c, width, keys, vals, used, cap));
}
}
}
}
cache_put_ptr_i64_ptr_i64_ptr_i8_i64_i64_i64(keys, vals, used, cap, hash_value, result);
return result;
}
int32_t main(void) {
int64_t cap = 2097152;
int64_t* keys = (int64_t*)(calloc(cap, 8));
int64_t* vals = (int64_t*)(calloc(cap, 8));
int8_t* used = (int8_t*)(calloc(cap, 1));
if (((keys == NULL || vals == NULL) || used == NULL)) {
return 1;
}
int64_t ans = search_i32_i32_i32_i32_i32_ptr_i64_ptr_i64_ptr_i8_i64(12, 0, 0, 0, 9, keys, vals, used, cap);
printf("%lld\n", ans);
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) -> ()
func.func @cache_get(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: i64, %arg4: i64) -> i64 {
%0 = llvm.mlir.constant(1 : i64) : i64
%1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
llvm.store %arg4, %1 : i64, !llvm.ptr
%2 = llvm.load %1 : !llvm.ptr -> i64
%3 = arith.constant 0 : i32
%5 = arith.extsi %3 : i32 to i64
%4 = arith.cmpi slt, %2, %5 : i64
cf.cond_br %4, ^bb0, ^bb1
^bb0:
%6 = llvm.load %1 : !llvm.ptr -> i64
%8 = arith.constant 0 : i64
%7 = arith.subi %8, %6 : i64
llvm.store %7, %1 : i64, !llvm.ptr
cf.br ^bb2
^bb1:
cf.br ^bb2
^bb2:
%9 = llvm.load %1 : !llvm.ptr -> i64
%10 = arith.constant 1 : i32
%12 = arith.extsi %10 : i32 to i64
%11 = arith.subi %arg3, %12 : i64
%13 = arith.andi %9, %11 : i64
llvm.store %13, %1 : i64, !llvm.ptr
cf.br ^bb3
^bb3:
%15 = llvm.load %1 : !llvm.ptr -> i64
%16 = llvm.getelementptr %arg2[%15] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%14 = llvm.load %16 : !llvm.ptr -> i8
%17 = arith.constant 0 : i32
%19 = arith.extsi %14 : i8 to i32
%18 = arith.cmpi ne, %19, %17 : i32
cf.cond_br %18, ^bb4, ^bb5
^bb4:
%21 = llvm.load %1 : !llvm.ptr -> i64
%22 = llvm.getelementptr %arg0[%21] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%20 = llvm.load %22 : !llvm.ptr -> i64
%23 = arith.cmpi eq, %20, %arg4 : i64
cf.cond_br %23, ^bb6, ^bb7
^bb6:
%25 = llvm.load %1 : !llvm.ptr -> i64
%26 = llvm.getelementptr %arg1[%25] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%24 = llvm.load %26 : !llvm.ptr -> i64
func.return %24 : i64
^bb7:
cf.br ^bb8
^bb8:
%27 = llvm.load %1 : !llvm.ptr -> i64
%28 = arith.constant 1 : i32
%30 = arith.extsi %28 : i32 to i64
%29 = arith.addi %27, %30 : i64
%31 = arith.constant 1 : i32
%33 = arith.extsi %31 : i32 to i64
%32 = arith.subi %arg3, %33 : i64
%34 = arith.andi %29, %32 : i64
llvm.store %34, %1 : i64, !llvm.ptr
cf.br ^bb3
^bb5:
%35 = arith.constant 1 : i32
%37 = arith.constant 0 : i32
%36 = arith.subi %37, %35 : i32
%38 = arith.extsi %36 : i32 to i64
func.return %38 : i64
}
func.func @cache_put(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: i64, %arg4: i64, %arg5: i64) -> () {
%39 = llvm.mlir.constant(1 : i64) : i64
%40 = llvm.alloca %39 x i64 : (i64) -> !llvm.ptr
llvm.store %arg4, %40 : i64, !llvm.ptr
%41 = llvm.load %40 : !llvm.ptr -> i64
%42 = arith.constant 0 : i32
%44 = arith.extsi %42 : i32 to i64
%43 = arith.cmpi slt, %41, %44 : i64
cf.cond_br %43, ^bb9, ^bb10
^bb9:
%45 = llvm.load %40 : !llvm.ptr -> i64
%47 = arith.constant 0 : i64
%46 = arith.subi %47, %45 : i64
llvm.store %46, %40 : i64, !llvm.ptr
cf.br ^bb11
^bb10:
cf.br ^bb11
^bb11:
%48 = llvm.load %40 : !llvm.ptr -> i64
%49 = arith.constant 1 : i32
%51 = arith.extsi %49 : i32 to i64
%50 = arith.subi %arg3, %51 : i64
%52 = arith.andi %48, %50 : i64
llvm.store %52, %40 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%54 = llvm.load %40 : !llvm.ptr -> i64
%55 = llvm.getelementptr %arg2[%54] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%53 = llvm.load %55 : !llvm.ptr -> i8
%56 = arith.constant 0 : i32
%58 = arith.extsi %53 : i8 to i32
%57 = arith.cmpi ne, %58, %56 : i32
%59 = scf.if %57 -> (i1) {
%61 = llvm.load %40 : !llvm.ptr -> i64
%62 = llvm.getelementptr %arg0[%61] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%60 = llvm.load %62 : !llvm.ptr -> i64
%63 = arith.cmpi ne, %60, %arg4 : i64
scf.yield %63 : i1
} else {
%64 = arith.constant false
scf.yield %64 : i1
}
cf.cond_br %59, ^bb13, ^bb14
^bb13:
%65 = llvm.load %40 : !llvm.ptr -> i64
%66 = arith.constant 1 : i32
%68 = arith.extsi %66 : i32 to i64
%67 = arith.addi %65, %68 : i64
%69 = arith.constant 1 : i32
%71 = arith.extsi %69 : i32 to i64
%70 = arith.subi %arg3, %71 : i64
%72 = arith.andi %67, %70 : i64
llvm.store %72, %40 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%73 = arith.constant 1 : i32
%74 = llvm.load %40 : !llvm.ptr -> i64
%75 = arith.trunci %73 : i32 to i8
%76 = llvm.getelementptr %arg2[%74] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %75, %76 : i8, !llvm.ptr
%77 = llvm.load %40 : !llvm.ptr -> i64
%78 = llvm.getelementptr %arg0[%77] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg4, %78 : i64, !llvm.ptr
%79 = llvm.load %40 : !llvm.ptr -> i64
%80 = llvm.getelementptr %arg1[%79] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg5, %80 : i64, !llvm.ptr
func.return
}
func.func @use_cell(%arg0: i32, %arg1: i32) -> i32 {
%81 = arith.constant 1 : i32
%82 = arith.shli %81, %arg0 : i32
%83 = arith.andi %arg1, %82 : i32
%84 = arith.constant 0 : i32
%85 = arith.cmpi ne, %83, %84 : i32
cf.cond_br %85, ^bb15, ^bb16
^bb15:
%86 = arith.constant 1 : i32
%88 = arith.constant 0 : i32
%87 = arith.subi %88, %86 : i32
func.return %87 : i32
^bb16:
cf.br ^bb17
^bb17:
%89 = arith.ori %arg1, %82 : i32
func.return %89 : i32
}
func.func @search(%arg0: i32, %arg1: i32, %arg2: i32, %arg3: i32, %arg4: i32, %arg5: !llvm.ptr, %arg6: !llvm.ptr, %arg7: !llvm.ptr, %arg8: i64) -> i64 {
%90 = arith.constant 0 : i32
%91 = arith.cmpi eq, %arg0, %90 : i32
cf.cond_br %91, ^bb18, ^bb19
^bb18:
%92 = arith.constant 1 : i32
%93 = arith.extsi %92 : i32 to i64
func.return %93 : i64
^bb19:
cf.br ^bb20
^bb20:
%94 = arith.constant 1 : i32
%95 = arith.shli %94, %arg4 : i32
%96 = arith.constant 1 : i32
%97 = arith.subi %95, %96 : i32
%98 = arith.cmpi eq, %arg1, %97 : i32
cf.cond_br %98, ^bb21, ^bb22
^bb21:
%100 = arith.constant 1 : i32
%101 = arith.subi %arg0, %100 : i32
%102 = arith.constant 0 : i32
%99 = func.call @search(%101, %arg2, %arg3, %102, %arg4, %arg5, %arg6, %arg7, %arg8) : (i32, i32, i32, i32, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
func.return %99 : i64
^bb22:
cf.br ^bb23
^bb23:
%103 = arith.constant 0 : i32
%104 = llvm.mlir.constant(1 : i64) : i64
%105 = llvm.alloca %104 x i32 : (i64) -> !llvm.ptr
llvm.store %103, %105 : i32, !llvm.ptr
cf.br ^bb24
^bb24:
%106 = arith.constant 1 : i32
%107 = llvm.load %105 : !llvm.ptr -> i32
%108 = arith.shli %106, %107 : i32
%109 = arith.andi %arg1, %108 : i32
%110 = arith.constant 0 : i32
%111 = arith.cmpi ne, %109, %110 : i32
cf.cond_br %111, ^bb25, ^bb26
^bb25:
%112 = llvm.load %105 : !llvm.ptr -> i32
%113 = arith.constant 1 : i32
%114 = arith.addi %112, %113 : i32
llvm.store %114, %105 : i32, !llvm.ptr
cf.br ^bb24
^bb26:
%115 = arith.extsi %arg0 : i32 to i64
%116 = llvm.mlir.constant(1 : i64) : i64
%117 = llvm.alloca %116 x i64 : (i64) -> !llvm.ptr
llvm.store %115, %117 : i64, !llvm.ptr
%118 = llvm.load %117 : !llvm.ptr -> i64
%120 = arith.extsi %arg4 : i32 to i64
%119 = arith.shli %118, %120 : i64
%121 = arith.extsi %arg1 : i32 to i64
%122 = arith.ori %119, %121 : i64
llvm.store %122, %117 : i64, !llvm.ptr
%123 = llvm.load %117 : !llvm.ptr -> i64
%125 = arith.extsi %arg4 : i32 to i64
%124 = arith.shli %123, %125 : i64
%126 = arith.extsi %arg2 : i32 to i64
%127 = arith.ori %124, %126 : i64
llvm.store %127, %117 : i64, !llvm.ptr
%128 = llvm.load %117 : !llvm.ptr -> i64
%130 = arith.extsi %arg4 : i32 to i64
%129 = arith.shli %128, %130 : i64
%131 = arith.extsi %arg3 : i32 to i64
%132 = arith.ori %129, %131 : i64
llvm.store %132, %117 : i64, !llvm.ptr
%134 = llvm.load %117 : !llvm.ptr -> i64
%133 = func.call @cache_get(%arg5, %arg6, %arg7, %arg8, %134) : (!llvm.ptr, !llvm.ptr, !llvm.ptr, i64, i64) -> i64
%135 = arith.constant 0 : i32
%137 = arith.extsi %135 : i32 to i64
%136 = arith.cmpi sge, %133, %137 : i64
cf.cond_br %136, ^bb27, ^bb28
^bb27:
func.return %133 : i64
^bb28:
cf.br ^bb29
^bb29:
%138 = arith.constant 0 : i32
%139 = arith.extsi %138 : i32 to i64
%140 = llvm.mlir.constant(1 : i64) : i64
%141 = llvm.alloca %140 x i64 : (i64) -> !llvm.ptr
llvm.store %139, %141 : i64, !llvm.ptr
%142 = arith.constant 2 : i32
%143 = arith.cmpi sge, %arg0, %142 : i32
%144 = scf.if %143 -> (i1) {
%145 = llvm.load %105 : !llvm.ptr -> i32
%146 = arith.constant 1 : i32
%147 = arith.subi %arg4, %146 : i32
%148 = arith.cmpi slt, %145, %147 : i32
scf.yield %148 : i1
} else {
%149 = arith.constant false
scf.yield %149 : i1
}
cf.cond_br %144, ^bb30, ^bb31
^bb30:
%151 = llvm.load %105 : !llvm.ptr -> i32
%150 = func.call @use_cell(%151, %arg1) : (i32, i32) -> i32
%152 = llvm.mlir.constant(1 : i64) : i64
%153 = llvm.alloca %152 x i32 : (i64) -> !llvm.ptr
llvm.store %150, %153 : i32, !llvm.ptr
%154 = llvm.load %153 : !llvm.ptr -> i32
%155 = arith.constant 0 : i32
%156 = arith.cmpi sge, %154, %155 : i32
cf.cond_br %156, ^bb33, ^bb34
^bb33:
%158 = llvm.load %105 : !llvm.ptr -> i32
%159 = arith.constant 1 : i32
%160 = arith.addi %158, %159 : i32
%161 = llvm.load %153 : !llvm.ptr -> i32
%157 = func.call @use_cell(%160, %161) : (i32, i32) -> i32
llvm.store %157, %153 : i32, !llvm.ptr
%162 = llvm.load %153 : !llvm.ptr -> i32
%163 = arith.constant 0 : i32
%164 = arith.cmpi sge, %162, %163 : i32
cf.cond_br %164, ^bb36, ^bb37
^bb36:
%166 = llvm.load %105 : !llvm.ptr -> i32
%165 = func.call @use_cell(%166, %arg2) : (i32, i32) -> i32
%167 = arith.constant 0 : i32
%168 = arith.cmpi sge, %165, %167 : i32
cf.cond_br %168, ^bb39, ^bb40
^bb39:
%169 = llvm.load %141 : !llvm.ptr -> i64
%171 = llvm.load %153 : !llvm.ptr -> i32
%170 = func.call @search(%arg0, %171, %165, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8) : (i32, i32, i32, i32, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%172 = arith.addi %169, %170 : i64
llvm.store %172, %141 : i64, !llvm.ptr
cf.br ^bb41
^bb40:
cf.br ^bb41
^bb41:
cf.br ^bb38
^bb37:
cf.br ^bb38
^bb38:
cf.br ^bb35
^bb34:
cf.br ^bb35
^bb35:
cf.br ^bb32
^bb31:
cf.br ^bb32
^bb32:
%173 = arith.constant 2 : i32
%174 = arith.cmpi sge, %arg0, %173 : i32
%175 = scf.if %174 -> (i1) {
%176 = llvm.load %105 : !llvm.ptr -> i32
%177 = arith.constant 1 : i32
%178 = arith.subi %arg4, %177 : i32
%179 = arith.cmpi slt, %176, %178 : i32
scf.yield %179 : i1
} else {
%180 = arith.constant false
scf.yield %180 : i1
}
cf.cond_br %175, ^bb42, ^bb43
^bb42:
%182 = llvm.load %105 : !llvm.ptr -> i32
%181 = func.call @use_cell(%182, %arg1) : (i32, i32) -> i32
%183 = llvm.mlir.constant(1 : i64) : i64
%184 = llvm.alloca %183 x i32 : (i64) -> !llvm.ptr
llvm.store %181, %184 : i32, !llvm.ptr
%185 = llvm.load %184 : !llvm.ptr -> i32
%186 = arith.constant 0 : i32
%187 = arith.cmpi sge, %185, %186 : i32
cf.cond_br %187, ^bb45, ^bb46
^bb45:
%189 = llvm.load %105 : !llvm.ptr -> i32
%190 = arith.constant 1 : i32
%191 = arith.addi %189, %190 : i32
%192 = llvm.load %184 : !llvm.ptr -> i32
%188 = func.call @use_cell(%191, %192) : (i32, i32) -> i32
llvm.store %188, %184 : i32, !llvm.ptr
%193 = llvm.load %184 : !llvm.ptr -> i32
%194 = arith.constant 0 : i32
%195 = arith.cmpi sge, %193, %194 : i32
cf.cond_br %195, ^bb48, ^bb49
^bb48:
%197 = llvm.load %105 : !llvm.ptr -> i32
%198 = arith.constant 1 : i32
%199 = arith.addi %197, %198 : i32
%196 = func.call @use_cell(%199, %arg2) : (i32, i32) -> i32
%200 = arith.constant 0 : i32
%201 = arith.cmpi sge, %196, %200 : i32
cf.cond_br %201, ^bb51, ^bb52
^bb51:
%202 = llvm.load %141 : !llvm.ptr -> i64
%204 = llvm.load %184 : !llvm.ptr -> i32
%203 = func.call @search(%arg0, %204, %196, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8) : (i32, i32, i32, i32, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%205 = arith.addi %202, %203 : i64
llvm.store %205, %141 : i64, !llvm.ptr
cf.br ^bb53
^bb52:
cf.br ^bb53
^bb53:
cf.br ^bb50
^bb49:
cf.br ^bb50
^bb50:
cf.br ^bb47
^bb46:
cf.br ^bb47
^bb47:
cf.br ^bb44
^bb43:
cf.br ^bb44
^bb44:
%206 = arith.constant 2 : i32
%207 = arith.cmpi sge, %arg0, %206 : i32
%208 = scf.if %207 -> (i1) {
%209 = llvm.load %105 : !llvm.ptr -> i32
%210 = arith.constant 1 : i32
%211 = arith.subi %arg4, %210 : i32
%212 = arith.cmpi slt, %209, %211 : i32
scf.yield %212 : i1
} else {
%213 = arith.constant false
scf.yield %213 : i1
}
cf.cond_br %208, ^bb54, ^bb55
^bb54:
%215 = llvm.load %105 : !llvm.ptr -> i32
%214 = func.call @use_cell(%215, %arg1) : (i32, i32) -> i32
%216 = arith.constant 0 : i32
%217 = arith.cmpi sge, %214, %216 : i32
cf.cond_br %217, ^bb57, ^bb58
^bb57:
%219 = llvm.load %105 : !llvm.ptr -> i32
%218 = func.call @use_cell(%219, %arg2) : (i32, i32) -> i32
%220 = llvm.mlir.constant(1 : i64) : i64
%221 = llvm.alloca %220 x i32 : (i64) -> !llvm.ptr
llvm.store %218, %221 : i32, !llvm.ptr
%222 = llvm.load %221 : !llvm.ptr -> i32
%223 = arith.constant 0 : i32
%224 = arith.cmpi sge, %222, %223 : i32
cf.cond_br %224, ^bb60, ^bb61
^bb60:
%226 = llvm.load %105 : !llvm.ptr -> i32
%227 = arith.constant 1 : i32
%228 = arith.addi %226, %227 : i32
%229 = llvm.load %221 : !llvm.ptr -> i32
%225 = func.call @use_cell(%228, %229) : (i32, i32) -> i32
llvm.store %225, %221 : i32, !llvm.ptr
%230 = llvm.load %221 : !llvm.ptr -> i32
%231 = arith.constant 0 : i32
%232 = arith.cmpi sge, %230, %231 : i32
cf.cond_br %232, ^bb63, ^bb64
^bb63:
%233 = llvm.load %141 : !llvm.ptr -> i64
%235 = llvm.load %221 : !llvm.ptr -> i32
%234 = func.call @search(%arg0, %214, %235, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8) : (i32, i32, i32, i32, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%236 = arith.addi %233, %234 : i64
llvm.store %236, %141 : i64, !llvm.ptr
cf.br ^bb65
^bb64:
cf.br ^bb65
^bb65:
cf.br ^bb62
^bb61:
cf.br ^bb62
^bb62:
cf.br ^bb59
^bb58:
cf.br ^bb59
^bb59:
cf.br ^bb56
^bb55:
cf.br ^bb56
^bb56:
%237 = arith.constant 2 : i32
%238 = arith.cmpi sge, %arg0, %237 : i32
%239 = scf.if %238 -> (i1) {
%240 = llvm.load %105 : !llvm.ptr -> i32
%241 = arith.constant 0 : i32
%242 = arith.cmpi sgt, %240, %241 : i32
scf.yield %242 : i1
} else {
%243 = arith.constant false
scf.yield %243 : i1
}
cf.cond_br %239, ^bb66, ^bb67
^bb66:
%245 = llvm.load %105 : !llvm.ptr -> i32
%244 = func.call @use_cell(%245, %arg1) : (i32, i32) -> i32
%246 = arith.constant 0 : i32
%247 = arith.cmpi sge, %244, %246 : i32
cf.cond_br %247, ^bb69, ^bb70
^bb69:
%249 = llvm.load %105 : !llvm.ptr -> i32
%250 = arith.constant 1 : i32
%251 = arith.subi %249, %250 : i32
%248 = func.call @use_cell(%251, %arg2) : (i32, i32) -> i32
%252 = llvm.mlir.constant(1 : i64) : i64
%253 = llvm.alloca %252 x i32 : (i64) -> !llvm.ptr
llvm.store %248, %253 : i32, !llvm.ptr
%254 = llvm.load %253 : !llvm.ptr -> i32
%255 = arith.constant 0 : i32
%256 = arith.cmpi sge, %254, %255 : i32
cf.cond_br %256, ^bb72, ^bb73
^bb72:
%258 = llvm.load %105 : !llvm.ptr -> i32
%259 = llvm.load %253 : !llvm.ptr -> i32
%257 = func.call @use_cell(%258, %259) : (i32, i32) -> i32
llvm.store %257, %253 : i32, !llvm.ptr
%260 = llvm.load %253 : !llvm.ptr -> i32
%261 = arith.constant 0 : i32
%262 = arith.cmpi sge, %260, %261 : i32
cf.cond_br %262, ^bb75, ^bb76
^bb75:
%263 = llvm.load %141 : !llvm.ptr -> i64
%265 = llvm.load %253 : !llvm.ptr -> i32
%264 = func.call @search(%arg0, %244, %265, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8) : (i32, i32, i32, i32, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%266 = arith.addi %263, %264 : i64
llvm.store %266, %141 : i64, !llvm.ptr
cf.br ^bb77
^bb76:
cf.br ^bb77
^bb77:
cf.br ^bb74
^bb73:
cf.br ^bb74
^bb74:
cf.br ^bb71
^bb70:
cf.br ^bb71
^bb71:
cf.br ^bb68
^bb67:
cf.br ^bb68
^bb68:
%267 = arith.constant 3 : i32
%268 = arith.cmpi sge, %arg0, %267 : i32
cf.cond_br %268, ^bb78, ^bb79
^bb78:
%270 = llvm.load %105 : !llvm.ptr -> i32
%269 = func.call @use_cell(%270, %arg1) : (i32, i32) -> i32
%271 = arith.constant 0 : i32
%272 = arith.cmpi sge, %269, %271 : i32
cf.cond_br %272, ^bb81, ^bb82
^bb81:
%274 = llvm.load %105 : !llvm.ptr -> i32
%273 = func.call @use_cell(%274, %arg2) : (i32, i32) -> i32
%275 = arith.constant 0 : i32
%276 = arith.cmpi sge, %273, %275 : i32
cf.cond_br %276, ^bb84, ^bb85
^bb84:
%278 = llvm.load %105 : !llvm.ptr -> i32
%277 = func.call @use_cell(%278, %arg3) : (i32, i32) -> i32
%279 = arith.constant 0 : i32
%280 = arith.cmpi sge, %277, %279 : i32
cf.cond_br %280, ^bb87, ^bb88
^bb87:
%281 = llvm.load %141 : !llvm.ptr -> i64
%282 = func.call @search(%arg0, %269, %273, %277, %arg4, %arg5, %arg6, %arg7, %arg8) : (i32, i32, i32, i32, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%283 = arith.addi %281, %282 : i64
llvm.store %283, %141 : i64, !llvm.ptr
cf.br ^bb89
^bb88:
cf.br ^bb89
^bb89:
cf.br ^bb86
^bb85:
cf.br ^bb86
^bb86:
cf.br ^bb83
^bb82:
cf.br ^bb83
^bb83:
cf.br ^bb80
^bb79:
cf.br ^bb80
^bb80:
%284 = arith.constant 1 : i32
%285 = arith.cmpi sge, %arg0, %284 : i32
%286 = scf.if %285 -> (i1) {
%287 = llvm.load %105 : !llvm.ptr -> i32
%288 = arith.constant 2 : i32
%289 = arith.subi %arg4, %288 : i32
%290 = arith.cmpi slt, %287, %289 : i32
scf.yield %290 : i1
} else {
%291 = arith.constant false
scf.yield %291 : i1
}
cf.cond_br %286, ^bb90, ^bb91
^bb90:
%293 = llvm.load %105 : !llvm.ptr -> i32
%292 = func.call @use_cell(%293, %arg1) : (i32, i32) -> i32
%294 = llvm.mlir.constant(1 : i64) : i64
%295 = llvm.alloca %294 x i32 : (i64) -> !llvm.ptr
llvm.store %292, %295 : i32, !llvm.ptr
%296 = llvm.load %295 : !llvm.ptr -> i32
%297 = arith.constant 0 : i32
%298 = arith.cmpi sge, %296, %297 : i32
cf.cond_br %298, ^bb93, ^bb94
^bb93:
%300 = llvm.load %105 : !llvm.ptr -> i32
%301 = arith.constant 1 : i32
%302 = arith.addi %300, %301 : i32
%303 = llvm.load %295 : !llvm.ptr -> i32
%299 = func.call @use_cell(%302, %303) : (i32, i32) -> i32
llvm.store %299, %295 : i32, !llvm.ptr
%304 = llvm.load %295 : !llvm.ptr -> i32
%305 = arith.constant 0 : i32
%306 = arith.cmpi sge, %304, %305 : i32
cf.cond_br %306, ^bb96, ^bb97
^bb96:
%308 = llvm.load %105 : !llvm.ptr -> i32
%309 = arith.constant 2 : i32
%310 = arith.addi %308, %309 : i32
%311 = llvm.load %295 : !llvm.ptr -> i32
%307 = func.call @use_cell(%310, %311) : (i32, i32) -> i32
llvm.store %307, %295 : i32, !llvm.ptr
%312 = llvm.load %295 : !llvm.ptr -> i32
%313 = arith.constant 0 : i32
%314 = arith.cmpi sge, %312, %313 : i32
cf.cond_br %314, ^bb99, ^bb100
^bb99:
%315 = llvm.load %141 : !llvm.ptr -> i64
%317 = llvm.load %295 : !llvm.ptr -> i32
%316 = func.call @search(%arg0, %317, %arg2, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8) : (i32, i32, i32, i32, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%318 = arith.addi %315, %316 : i64
llvm.store %318, %141 : i64, !llvm.ptr
cf.br ^bb101
^bb100:
cf.br ^bb101
^bb101:
cf.br ^bb98
^bb97:
cf.br ^bb98
^bb98:
cf.br ^bb95
^bb94:
cf.br ^bb95
^bb95:
cf.br ^bb92
^bb91:
cf.br ^bb92
^bb92:
%320 = llvm.load %117 : !llvm.ptr -> i64
%321 = llvm.load %141 : !llvm.ptr -> i64
func.call @cache_put(%arg5, %arg6, %arg7, %arg8, %320, %321) : (!llvm.ptr, !llvm.ptr, !llvm.ptr, i64, i64, i64) -> ()
%322 = llvm.load %141 : !llvm.ptr -> i64
func.return %322 : i64
}
func.func @main() -> i32 {
%323 = arith.constant 2097152 : i32
%324 = arith.extsi %323 : i32 to i64
%326 = arith.constant 8 : i32
%327 = arith.extsi %326 : i32 to i64
%325 = func.call @calloc(%324, %327) : (i64, i64) -> !llvm.ptr
%329 = arith.constant 8 : i32
%330 = arith.extsi %329 : i32 to i64
%328 = func.call @calloc(%324, %330) : (i64, i64) -> !llvm.ptr
%332 = arith.constant 1 : i32
%333 = arith.extsi %332 : i32 to i64
%331 = func.call @calloc(%324, %333) : (i64, i64) -> !llvm.ptr
%334 = llvm.mlir.zero : !llvm.ptr
%335 = llvm.icmp "eq" %325, %334 : !llvm.ptr
%336 = scf.if %335 -> (i1) {
%337 = arith.constant true
scf.yield %337 : i1
} else {
%338 = llvm.mlir.zero : !llvm.ptr
%339 = llvm.icmp "eq" %328, %338 : !llvm.ptr
scf.yield %339 : i1
}
%340 = scf.if %336 -> (i1) {
%341 = arith.constant true
scf.yield %341 : i1
} else {
%342 = llvm.mlir.zero : !llvm.ptr
%343 = llvm.icmp "eq" %331, %342 : !llvm.ptr
scf.yield %343 : i1
}
cf.cond_br %340, ^bb102, ^bb103
^bb102:
%344 = arith.constant 1 : i32
func.return %344 : i32
^bb103:
cf.br ^bb104
^bb104:
%346 = arith.constant 12 : i32
%347 = arith.constant 0 : i32
%348 = arith.constant 0 : i32
%349 = arith.constant 0 : i32
%350 = arith.constant 9 : i32
%345 = func.call @search(%346, %347, %348, %349, %350, %325, %328, %331, %324) : (i32, i32, i32, i32, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> i64
%351 = llvm.mlir.addressof @str_0 : !llvm.ptr
%352 = llvm.call @printf(%351, %345) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%325) : (!llvm.ptr) -> ()
func.call @free(%328) : (!llvm.ptr) -> ()
func.call @free(%331) : (!llvm.ptr) -> ()
%356 = arith.constant 0 : i32
func.return %356 : i32
}
}