← All problems
Problem 534
Weak Queens — S(14) via sliding-window DP.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n^2)?
Space complexity O(n^2)?
Approach Flow solution Not curated
Verdict Unknown
Flow source
# Project Euler 534
# Weak Queens — S(14) via sliding-window DP.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
const N: i64 = 14
function ipow(base: i64, exp: i64) -> i64 {
let mut r: i128 = 1 as i128
let mut b: i128 = base as i128
let mut e: i64 = exp
while e > 0 {
if (e & 1) != 0 { r = r * b }
b = b * b
e = e >> 1
}
return r as i64
}
function nqueens_rec(cols: i64, d1: i64, d2: i64, all: i64) -> i64
function nqueens_rec(cols: i64, d1: i64, d2: i64, all: i64) -> i64 {
if cols == all { return 1 }
let mut total: i64 = 0
let mut avail: i64 = all & ~(cols | d1 | d2)
while avail != 0 {
let bit: i64 = avail & (-avail)
avail = avail - bit
total = total + nqueens_rec(cols | bit, (d1 | bit) << 1 & all, (d2 | bit) >> 1, all)
}
return total
}
function nqueens_classic(n: i64) -> i64 {
let all: i64 = (1 << n) - 1
let half: i64 = n / 2
let mut total: i64 = 0
let mut col0: i64 = 0
while col0 < half {
let bit: i64 = 1 << col0
total = total + nqueens_rec(bit, (bit << 1) & all, bit >> 1, all)
col0 = col0 + 1
}
total = total * 2
if (n & 1) == 1 {
let col: i64 = half
let bit2: i64 = 1 << col
total = total + nqueens_rec(bit2, (bit2 << 1) & all, bit2 >> 1, all)
}
return total
}
function hslot(key: i64, keys: ptr<i64>, used: ptr<i8>, cap: i64) -> i64 {
let mut h: i64 = key % cap
if h < 0 { h = h + cap }
let mut probes: i64 = 0
while used[h] == 1 && keys[h] != key {
h = h + 1
if h == cap { h = 0 }
probes = probes + 1
if probes > cap { return -1 }
}
return h
}
function count_by_L(n: i64, L: i64, attack: ptr<i64>) -> i64 {
if L <= 0 { return ipow(n, n) }
if L >= n - 1 { return nqueens_classic(n) }
let all: i64 = (1 << n) - 1
let shift: i64 = 4
let keep: i64 = ((1 as i64) << (shift * L)) - 1
let mut cap: i64 = 1048576
if L > 6 { cap = 33554432 }
let keys: ptr<i64> = calloc(cap, 8)
let vals: ptr<i64> = calloc(cap, 8)
let used: ptr<i8> = calloc(cap, 1)
let nkeys: ptr<i64> = calloc(cap, 8)
let nvals: ptr<i64> = calloc(cap, 8)
let nused: ptr<i8> = calloc(cap, 1)
if keys == null || vals == null { return 0 }
let half: i64 = n / 2
let mut c0: i64 = 0
while c0 < half {
let slot: i64 = hslot(c0, keys, used, cap)
used[slot] = 1
keys[slot] = c0
vals[slot] = 1
c0 = c0 + 1
}
let mut r: i64 = 1
let mut ci: i64 = 0
while r < n {
let mut m_prev: i64 = r
if m_prev > L { m_prev = L }
let mut mn: i32 = 0
if r + 1 >= L { mn = 1 }
ci = 0
while ci < cap { nused[ci] = 0; ci = ci + 1 }
ci = 0
while ci < cap {
if used[ci] == 1 {
let state: i64 = keys[ci]
let cnt: i64 = vals[ci]
let mut forbid: i64 = 0
let mut s: i64 = state
let mut dist: i64 = 1
while dist <= m_prev {
let pc: i64 = s & 0xF
s = s >> shift
forbid = forbid | attack[pc * (n + 1) + dist]
dist = dist + 1
}
let mut avail: i64 = all & ~forbid
while avail != 0 {
let bit: i64 = avail & (-avail)
avail = avail - bit
let mut tmp: i64 = bit
let mut cc: i64 = 0
while tmp > 1 { tmp = tmp >> 1; cc = cc + 1 }
let mut ns: i64 = (state << shift) | cc
if mn == 1 { ns = ns & keep }
let sl: i64 = hslot(ns, nkeys, nused, cap)
if nused[sl] == 0 {
nused[sl] = 1
nkeys[sl] = ns
nvals[sl] = cnt
} else {
nvals[sl] = nvals[sl] + cnt
}
}
}
ci = ci + 1
}
ci = 0
while ci < cap {
used[ci] = nused[ci]
keys[ci] = nkeys[ci]
vals[ci] = nvals[ci]
nused[ci] = 0
ci = ci + 1
}
r = r + 1
}
let mut total: i64 = 0
ci = 0
while ci < cap {
if used[ci] == 1 { total = total + vals[ci] }
ci = ci + 1
}
free(keys); free(vals); free(used); free(nkeys); free(nvals); free(nused)
return total * 2
}
function main() -> i32 {
let attack: ptr<i64> = calloc(N * (N + 1), 8)
if attack == null { return 1 }
let mut c: i64 = 0
while c < N {
let mut d: i64 = 1
while d <= N {
let mut m: i64 = 1 << c
let cp: i64 = c + d
if cp < N { m = m | (1 << cp) }
let cm: i64 = c - d
if cm >= 0 { m = m | (1 << cm) }
attack[c * (N + 1) + d] = m
d = d + 1
}
c = c + 1
}
let mut ans: i64 = 0
let mut w: i64 = 0
while w < N {
ans = ans + count_by_L(N, N - 1 - w, attack)
w = w + 1
}
printf("%lld\n", ans)
free(attack)
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 ipow_i64_i64(int64_t base, int64_t exp);
int64_t nqueens_rec_i64_i64_i64_i64(int64_t cols, int64_t d1, int64_t d2, int64_t all);
int64_t nqueens_rec_i64_i64_i64_i64(int64_t cols, int64_t d1, int64_t d2, int64_t all);
int64_t nqueens_classic_i64(int64_t n);
int64_t hslot_i64_ptr_i64_ptr_i8_i64(int64_t key, int64_t* keys, int8_t* used, int64_t cap);
int64_t count_by_L_i64_i64_ptr_i64(int64_t n, int64_t L, int64_t* attack);
int32_t main(void);
static const int64_t N = 14;
int64_t ipow_i64_i64(int64_t base, int64_t exp) {
__int128 r = ((__int128)(1));
__int128 b = ((__int128)(base));
int64_t e = exp;
while (e > 0) {
if ((e & 1) != 0) {
r = (r * b);
}
b = (b * b);
e = FLOW_CHECKED_SHR((e), (1));
}
return ((int64_t)(r));
}
int64_t nqueens_rec_i64_i64_i64_i64(int64_t cols, int64_t d1, int64_t d2, int64_t all) {
if (cols == all) {
return 1;
}
int64_t total = 0;
int64_t avail = (all & (~((cols | d1) | d2)));
while (avail != 0) {
int64_t bit = (avail & (-avail));
avail = (avail - bit);
total = (total + nqueens_rec_i64_i64_i64_i64((cols | bit), (FLOW_CHECKED_SHL(((d1 | bit)), (1)) & all), FLOW_CHECKED_SHR(((d2 | bit)), (1)), all));
}
return total;
}
int64_t nqueens_classic_i64(int64_t n) {
int64_t all = (FLOW_CHECKED_SHL((1), (n)) - 1);
int64_t half = FLOW_CHECKED_DIV((n), (2));
int64_t total = 0;
int64_t col0 = 0;
while (col0 < half) {
int64_t bit = FLOW_CHECKED_SHL((1), (col0));
total = (total + nqueens_rec_i64_i64_i64_i64(bit, (FLOW_CHECKED_SHL((bit), (1)) & all), FLOW_CHECKED_SHR((bit), (1)), all));
col0 = (col0 + 1);
}
total = (total * 2);
if ((n & 1) == 1) {
int64_t col = half;
int64_t bit2 = FLOW_CHECKED_SHL((1), (col));
total = (total + nqueens_rec_i64_i64_i64_i64(bit2, (FLOW_CHECKED_SHL((bit2), (1)) & all), FLOW_CHECKED_SHR((bit2), (1)), all));
}
return total;
}
int64_t hslot_i64_ptr_i64_ptr_i8_i64(int64_t key, int64_t* keys, int8_t* used, int64_t cap) {
int64_t h = FLOW_CHECKED_MOD((key), (cap));
if (h < 0) {
h = (h + cap);
}
int64_t probes = 0;
while ((used[h] == 1 && keys[h] != key)) {
h = (h + 1);
if (h == cap) {
h = 0;
}
probes = (probes + 1);
if (probes > cap) {
return (-1);
}
}
return h;
}
int64_t count_by_L_i64_i64_ptr_i64(int64_t n, int64_t L, int64_t* attack) {
if (L <= 0) {
return ipow_i64_i64(n, n);
}
if (L >= (n - 1)) {
return nqueens_classic_i64(n);
}
int64_t all = (FLOW_CHECKED_SHL((1), (n)) - 1);
int64_t shift = 4;
int64_t keep = (FLOW_CHECKED_SHL((((int64_t)(1))), ((shift * L))) - 1);
int64_t cap = 1048576;
if (L > 6) {
cap = 33554432;
}
int64_t* keys = (int64_t*)(calloc(cap, 8));
int64_t* vals = (int64_t*)(calloc(cap, 8));
int8_t* used = (int8_t*)(calloc(cap, 1));
int64_t* nkeys = (int64_t*)(calloc(cap, 8));
int64_t* nvals = (int64_t*)(calloc(cap, 8));
int8_t* nused = (int8_t*)(calloc(cap, 1));
if ((keys == NULL || vals == NULL)) {
return 0;
}
int64_t half = FLOW_CHECKED_DIV((n), (2));
int64_t c0 = 0;
while (c0 < half) {
int64_t slot = hslot_i64_ptr_i64_ptr_i8_i64(c0, keys, used, cap);
used[slot] = 1;
keys[slot] = c0;
vals[slot] = 1;
c0 = (c0 + 1);
}
int64_t r = 1;
int64_t ci = 0;
while (r < n) {
int64_t m_prev = r;
if (m_prev > L) {
m_prev = L;
}
int32_t mn = 0;
if ((r + 1) >= L) {
mn = 1;
}
ci = 0;
while (ci < cap) {
nused[ci] = 0;
ci = (ci + 1);
}
ci = 0;
while (ci < cap) {
if (used[ci] == 1) {
int64_t state = keys[ci];
int64_t cnt = vals[ci];
int64_t forbid = 0;
int64_t s = state;
int64_t dist = 1;
while (dist <= m_prev) {
int64_t pc = (s & 15);
s = FLOW_CHECKED_SHR((s), (shift));
forbid = (forbid | attack[((pc * (n + 1)) + dist)]);
dist = (dist + 1);
}
int64_t avail = (all & (~forbid));
while (avail != 0) {
int64_t bit = (avail & (-avail));
avail = (avail - bit);
int64_t tmp = bit;
int64_t cc = 0;
while (tmp > 1) {
tmp = FLOW_CHECKED_SHR((tmp), (1));
cc = (cc + 1);
}
int64_t ns = (FLOW_CHECKED_SHL((state), (shift)) | cc);
if (mn == 1) {
ns = (ns & keep);
}
int64_t sl = hslot_i64_ptr_i64_ptr_i8_i64(ns, nkeys, nused, cap);
if (nused[sl] == 0) {
nused[sl] = 1;
nkeys[sl] = ns;
nvals[sl] = cnt;
} else {
nvals[sl] = (nvals[sl] + cnt);
}
}
}
ci = (ci + 1);
}
ci = 0;
while (ci < cap) {
used[ci] = nused[ci];
keys[ci] = nkeys[ci];
vals[ci] = nvals[ci];
nused[ci] = 0;
ci = (ci + 1);
}
r = (r + 1);
}
int64_t total = 0;
ci = 0;
while (ci < cap) {
if (used[ci] == 1) {
total = (total + vals[ci]);
}
ci = (ci + 1);
}
free(keys);
free(vals);
free(used);
free(nkeys);
free(nvals);
free(nused);
return (total * 2);
}
int32_t main(void) {
int64_t* attack = (int64_t*)(calloc((N * (N + 1)), 8));
if (attack == NULL) {
return 1;
}
int64_t c = 0;
while (c < N) {
int64_t d = 1;
while (d <= N) {
int64_t m = FLOW_CHECKED_SHL((1), (c));
int64_t cp = (c + d);
if (cp < N) {
m = (m | FLOW_CHECKED_SHL((1), (cp)));
}
int64_t cm = (c - d);
if (cm >= 0) {
m = (m | FLOW_CHECKED_SHL((1), (cm)));
}
attack[((c * (N + 1)) + d)] = m;
d = (d + 1);
}
c = (c + 1);
}
int64_t ans = 0;
int64_t w = 0;
while (w < N) {
ans = (ans + count_by_L_i64_i64_ptr_i64(N, ((N - 1) - w), attack));
w = (w + 1);
}
printf("%lld\n", ans);
free(attack);
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: N
llvm.mlir.global internal constant @N(14 : i64) : i64
func.func @ipow(%arg0: i64, %arg1: i64) -> i64 {
%0 = arith.constant 1 : i32
%1 = arith.extsi %0 : i32 to i128
%2 = llvm.mlir.constant(1 : i64) : i64
%3 = llvm.alloca %2 x i128 : (i64) -> !llvm.ptr
llvm.store %1, %3 : i128, !llvm.ptr
%4 = arith.extsi %arg0 : i64 to i128
%5 = llvm.mlir.constant(1 : i64) : i64
%6 = llvm.alloca %5 x i128 : (i64) -> !llvm.ptr
llvm.store %4, %6 : i128, !llvm.ptr
%7 = llvm.mlir.constant(1 : i64) : i64
%8 = llvm.alloca %7 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %8 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%9 = llvm.load %8 : !llvm.ptr -> i64
%10 = arith.constant 0 : i32
%12 = arith.extsi %10 : i32 to i64
%11 = arith.cmpi sgt, %9, %12 : i64
cf.cond_br %11, ^bb1, ^bb2
^bb1:
%13 = llvm.load %8 : !llvm.ptr -> i64
%14 = arith.constant 1 : i32
%16 = arith.extsi %14 : i32 to i64
%15 = arith.andi %13, %16 : i64
%17 = arith.constant 0 : i32
%19 = arith.extsi %17 : i32 to i64
%18 = arith.cmpi ne, %15, %19 : i64
cf.cond_br %18, ^bb3, ^bb4
^bb3:
%20 = llvm.load %3 : !llvm.ptr -> i128
%21 = llvm.load %6 : !llvm.ptr -> i128
%23 = arith.trunci %20 : i128 to i64
%24 = arith.trunci %21 : i128 to i64
%22 = arith.muli %23, %24 : i64
%25 = arith.extsi %22 : i64 to i128
llvm.store %25, %3 : i128, !llvm.ptr
cf.br ^bb5
^bb4:
cf.br ^bb5
^bb5:
%26 = llvm.load %6 : !llvm.ptr -> i128
%27 = llvm.load %6 : !llvm.ptr -> i128
%29 = arith.trunci %26 : i128 to i64
%30 = arith.trunci %27 : i128 to i64
%28 = arith.muli %29, %30 : i64
%31 = arith.extsi %28 : i64 to i128
llvm.store %31, %6 : i128, !llvm.ptr
%32 = llvm.load %8 : !llvm.ptr -> i64
%33 = arith.constant 1 : i32
%35 = arith.extsi %33 : i32 to i64
%34 = arith.shrsi %32, %35 : i64
llvm.store %34, %8 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%36 = llvm.load %3 : !llvm.ptr -> i128
%37 = arith.trunci %36 : i128 to i64
func.return %37 : i64
}
func.func @nqueens_rec(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64) -> i64 {
}
func.func @nqueens_rec(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64) -> i64 {
%38 = arith.cmpi eq, %arg0, %arg3 : i64
cf.cond_br %38, ^bb6, ^bb7
^bb6:
%39 = arith.constant 1 : i32
%40 = arith.extsi %39 : i32 to i64
func.return %40 : i64
^bb7:
cf.br ^bb8
^bb8:
%41 = arith.constant 0 : i32
%42 = arith.extsi %41 : i32 to i64
%43 = llvm.mlir.constant(1 : i64) : i64
%44 = llvm.alloca %43 x i64 : (i64) -> !llvm.ptr
llvm.store %42, %44 : i64, !llvm.ptr
%45 = arith.ori %arg0, %arg1 : i64
%46 = arith.ori %45, %arg2 : i64
%48 = arith.constant -1 : i64
%47 = arith.xori %46, %48 : i64
%49 = arith.andi %arg3, %47 : i64
%50 = llvm.mlir.constant(1 : i64) : i64
%51 = llvm.alloca %50 x i64 : (i64) -> !llvm.ptr
llvm.store %49, %51 : i64, !llvm.ptr
cf.br ^bb9
^bb9:
%52 = llvm.load %51 : !llvm.ptr -> i64
%53 = arith.constant 0 : i32
%55 = arith.extsi %53 : i32 to i64
%54 = arith.cmpi ne, %52, %55 : i64
cf.cond_br %54, ^bb10, ^bb11
^bb10:
%56 = llvm.load %51 : !llvm.ptr -> i64
%57 = llvm.load %51 : !llvm.ptr -> i64
%59 = arith.constant 0 : i64
%58 = arith.subi %59, %57 : i64
%60 = arith.andi %56, %58 : i64
%61 = llvm.load %51 : !llvm.ptr -> i64
%62 = arith.subi %61, %60 : i64
llvm.store %62, %51 : i64, !llvm.ptr
%63 = llvm.load %44 : !llvm.ptr -> i64
%65 = arith.ori %arg0, %60 : i64
%66 = arith.ori %arg1, %60 : i64
%67 = arith.constant 1 : i32
%69 = arith.extsi %67 : i32 to i64
%68 = arith.shli %66, %69 : i64
%70 = arith.andi %68, %arg3 : i64
%71 = arith.ori %arg2, %60 : i64
%72 = arith.constant 1 : i32
%74 = arith.extsi %72 : i32 to i64
%73 = arith.shrsi %71, %74 : i64
%64 = func.call @nqueens_rec(%65, %70, %73, %arg3) : (i64, i64, i64, i64) -> i64
%75 = arith.addi %63, %64 : i64
llvm.store %75, %44 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%76 = llvm.load %44 : !llvm.ptr -> i64
func.return %76 : i64
}
func.func @nqueens_classic(%arg0: i64) -> i64 {
%77 = arith.constant 1 : i32
%79 = arith.extsi %77 : i32 to i64
%78 = arith.shli %79, %arg0 : i64
%80 = arith.constant 1 : i32
%82 = arith.extsi %80 : i32 to i64
%81 = arith.subi %78, %82 : i64
%83 = arith.constant 2 : i32
%85 = arith.extsi %83 : i32 to i64
%84 = arith.divsi %arg0, %85 : i64
%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 0 : i32
%91 = arith.extsi %90 : i32 to i64
%92 = llvm.mlir.constant(1 : i64) : i64
%93 = llvm.alloca %92 x i64 : (i64) -> !llvm.ptr
llvm.store %91, %93 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%94 = llvm.load %93 : !llvm.ptr -> i64
%95 = arith.cmpi slt, %94, %84 : i64
cf.cond_br %95, ^bb13, ^bb14
^bb13:
%96 = arith.constant 1 : i32
%97 = llvm.load %93 : !llvm.ptr -> i64
%99 = arith.extsi %96 : i32 to i64
%98 = arith.shli %99, %97 : i64
%100 = llvm.load %89 : !llvm.ptr -> i64
%102 = arith.constant 1 : i32
%104 = arith.extsi %102 : i32 to i64
%103 = arith.shli %98, %104 : i64
%105 = arith.andi %103, %81 : i64
%106 = arith.constant 1 : i32
%108 = arith.extsi %106 : i32 to i64
%107 = arith.shrsi %98, %108 : i64
%101 = func.call @nqueens_rec(%98, %105, %107, %81) : (i64, i64, i64, i64) -> i64
%109 = arith.addi %100, %101 : i64
llvm.store %109, %89 : i64, !llvm.ptr
%110 = llvm.load %93 : !llvm.ptr -> i64
%111 = arith.constant 1 : i32
%113 = arith.extsi %111 : i32 to i64
%112 = arith.addi %110, %113 : i64
llvm.store %112, %93 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%114 = llvm.load %89 : !llvm.ptr -> i64
%115 = arith.constant 2 : i32
%117 = arith.extsi %115 : i32 to i64
%116 = arith.muli %114, %117 : i64
llvm.store %116, %89 : i64, !llvm.ptr
%118 = arith.constant 1 : i32
%120 = arith.extsi %118 : i32 to i64
%119 = arith.andi %arg0, %120 : i64
%121 = arith.constant 1 : i32
%123 = arith.extsi %121 : i32 to i64
%122 = arith.cmpi eq, %119, %123 : i64
cf.cond_br %122, ^bb15, ^bb16
^bb15:
%124 = arith.constant 1 : i32
%126 = arith.extsi %124 : i32 to i64
%125 = arith.shli %126, %84 : i64
%127 = llvm.load %89 : !llvm.ptr -> i64
%129 = arith.constant 1 : i32
%131 = arith.extsi %129 : i32 to i64
%130 = arith.shli %125, %131 : i64
%132 = arith.andi %130, %81 : i64
%133 = arith.constant 1 : i32
%135 = arith.extsi %133 : i32 to i64
%134 = arith.shrsi %125, %135 : i64
%128 = func.call @nqueens_rec(%125, %132, %134, %81) : (i64, i64, i64, i64) -> i64
%136 = arith.addi %127, %128 : i64
llvm.store %136, %89 : i64, !llvm.ptr
cf.br ^bb17
^bb16:
cf.br ^bb17
^bb17:
%137 = llvm.load %89 : !llvm.ptr -> i64
func.return %137 : i64
}
func.func @hslot(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: i64) -> i64 {
%138 = arith.remsi %arg0, %arg3 : i64
%139 = llvm.mlir.constant(1 : i64) : i64
%140 = llvm.alloca %139 x i64 : (i64) -> !llvm.ptr
llvm.store %138, %140 : i64, !llvm.ptr
%141 = llvm.load %140 : !llvm.ptr -> i64
%142 = arith.constant 0 : i32
%144 = arith.extsi %142 : i32 to i64
%143 = arith.cmpi slt, %141, %144 : i64
cf.cond_br %143, ^bb18, ^bb19
^bb18:
%145 = llvm.load %140 : !llvm.ptr -> i64
%146 = arith.addi %145, %arg3 : i64
llvm.store %146, %140 : i64, !llvm.ptr
cf.br ^bb20
^bb19:
cf.br ^bb20
^bb20:
%147 = arith.constant 0 : i32
%148 = arith.extsi %147 : i32 to i64
%149 = llvm.mlir.constant(1 : i64) : i64
%150 = llvm.alloca %149 x i64 : (i64) -> !llvm.ptr
llvm.store %148, %150 : i64, !llvm.ptr
cf.br ^bb21
^bb21:
%152 = llvm.load %140 : !llvm.ptr -> i64
%153 = llvm.getelementptr %arg2[%152] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%151 = llvm.load %153 : !llvm.ptr -> i8
%154 = arith.constant 1 : i32
%156 = arith.extsi %151 : i8 to i32
%155 = arith.cmpi eq, %156, %154 : i32
%157 = scf.if %155 -> (i1) {
%159 = llvm.load %140 : !llvm.ptr -> i64
%160 = llvm.getelementptr %arg1[%159] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%158 = llvm.load %160 : !llvm.ptr -> i64
%161 = arith.cmpi ne, %158, %arg0 : i64
scf.yield %161 : i1
} else {
%162 = arith.constant false
scf.yield %162 : i1
}
cf.cond_br %157, ^bb22, ^bb23
^bb22:
%163 = llvm.load %140 : !llvm.ptr -> i64
%164 = arith.constant 1 : i32
%166 = arith.extsi %164 : i32 to i64
%165 = arith.addi %163, %166 : i64
llvm.store %165, %140 : i64, !llvm.ptr
%167 = llvm.load %140 : !llvm.ptr -> i64
%168 = arith.cmpi eq, %167, %arg3 : i64
cf.cond_br %168, ^bb24, ^bb25
^bb24:
%169 = arith.constant 0 : i32
%170 = arith.extsi %169 : i32 to i64
llvm.store %170, %140 : i64, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%171 = llvm.load %150 : !llvm.ptr -> i64
%172 = arith.constant 1 : i32
%174 = arith.extsi %172 : i32 to i64
%173 = arith.addi %171, %174 : i64
llvm.store %173, %150 : i64, !llvm.ptr
%175 = llvm.load %150 : !llvm.ptr -> i64
%176 = arith.cmpi sgt, %175, %arg3 : i64
cf.cond_br %176, ^bb27, ^bb28
^bb27:
%177 = arith.constant 1 : i32
%179 = arith.constant 0 : i32
%178 = arith.subi %179, %177 : i32
%180 = arith.extsi %178 : i32 to i64
func.return %180 : i64
^bb28:
cf.br ^bb29
^bb29:
cf.br ^bb21
^bb23:
%181 = llvm.load %140 : !llvm.ptr -> i64
func.return %181 : i64
}
func.func @count_by_L(%arg0: i64, %arg1: i64, %arg2: !llvm.ptr) -> i64 {
%182 = arith.constant 0 : i32
%184 = arith.extsi %182 : i32 to i64
%183 = arith.cmpi sle, %arg1, %184 : i64
cf.cond_br %183, ^bb30, ^bb31
^bb30:
%185 = func.call @ipow(%arg0, %arg0) : (i64, i64) -> i64
func.return %185 : i64
^bb31:
cf.br ^bb32
^bb32:
%186 = arith.constant 1 : i32
%188 = arith.extsi %186 : i32 to i64
%187 = arith.subi %arg0, %188 : i64
%189 = arith.cmpi sge, %arg1, %187 : i64
cf.cond_br %189, ^bb33, ^bb34
^bb33:
%190 = func.call @nqueens_classic(%arg0) : (i64) -> i64
func.return %190 : i64
^bb34:
cf.br ^bb35
^bb35:
%191 = arith.constant 1 : i32
%193 = arith.extsi %191 : i32 to i64
%192 = arith.shli %193, %arg0 : i64
%194 = arith.constant 1 : i32
%196 = arith.extsi %194 : i32 to i64
%195 = arith.subi %192, %196 : i64
%197 = arith.constant 4 : i32
%198 = arith.extsi %197 : i32 to i64
%199 = arith.constant 1 : i32
%200 = arith.extsi %199 : i32 to i64
%201 = arith.muli %198, %arg1 : i64
%202 = arith.shli %200, %201 : i64
%203 = arith.constant 1 : i32
%205 = arith.extsi %203 : i32 to i64
%204 = arith.subi %202, %205 : i64
%206 = arith.constant 1048576 : i32
%207 = arith.extsi %206 : i32 to i64
%208 = llvm.mlir.constant(1 : i64) : i64
%209 = llvm.alloca %208 x i64 : (i64) -> !llvm.ptr
llvm.store %207, %209 : i64, !llvm.ptr
%210 = arith.constant 6 : i32
%212 = arith.extsi %210 : i32 to i64
%211 = arith.cmpi sgt, %arg1, %212 : i64
cf.cond_br %211, ^bb36, ^bb37
^bb36:
%213 = arith.constant 33554432 : i32
%214 = arith.extsi %213 : i32 to i64
llvm.store %214, %209 : i64, !llvm.ptr
cf.br ^bb38
^bb37:
cf.br ^bb38
^bb38:
%216 = llvm.load %209 : !llvm.ptr -> i64
%217 = arith.constant 8 : i32
%218 = arith.extsi %217 : i32 to i64
%215 = func.call @calloc(%216, %218) : (i64, i64) -> !llvm.ptr
%220 = llvm.load %209 : !llvm.ptr -> i64
%221 = arith.constant 8 : i32
%222 = arith.extsi %221 : i32 to i64
%219 = func.call @calloc(%220, %222) : (i64, i64) -> !llvm.ptr
%224 = llvm.load %209 : !llvm.ptr -> i64
%225 = arith.constant 1 : i32
%226 = arith.extsi %225 : i32 to i64
%223 = func.call @calloc(%224, %226) : (i64, i64) -> !llvm.ptr
%228 = llvm.load %209 : !llvm.ptr -> i64
%229 = arith.constant 8 : i32
%230 = arith.extsi %229 : i32 to i64
%227 = func.call @calloc(%228, %230) : (i64, i64) -> !llvm.ptr
%232 = llvm.load %209 : !llvm.ptr -> i64
%233 = arith.constant 8 : i32
%234 = arith.extsi %233 : i32 to i64
%231 = func.call @calloc(%232, %234) : (i64, i64) -> !llvm.ptr
%236 = llvm.load %209 : !llvm.ptr -> i64
%237 = arith.constant 1 : i32
%238 = arith.extsi %237 : i32 to i64
%235 = func.call @calloc(%236, %238) : (i64, i64) -> !llvm.ptr
%239 = llvm.mlir.zero : !llvm.ptr
%240 = llvm.icmp "eq" %215, %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" %219, %243 : !llvm.ptr
scf.yield %244 : i1
}
cf.cond_br %241, ^bb39, ^bb40
^bb39:
%245 = arith.constant 0 : i32
%246 = arith.extsi %245 : i32 to i64
func.return %246 : i64
^bb40:
cf.br ^bb41
^bb41:
%247 = arith.constant 2 : i32
%249 = arith.extsi %247 : i32 to i64
%248 = arith.divsi %arg0, %249 : i64
%250 = arith.constant 0 : i32
%251 = arith.extsi %250 : i32 to i64
%252 = llvm.mlir.constant(1 : i64) : i64
%253 = llvm.alloca %252 x i64 : (i64) -> !llvm.ptr
llvm.store %251, %253 : i64, !llvm.ptr
cf.br ^bb42
^bb42:
%254 = llvm.load %253 : !llvm.ptr -> i64
%255 = arith.cmpi slt, %254, %248 : i64
cf.cond_br %255, ^bb43, ^bb44
^bb43:
%257 = llvm.load %253 : !llvm.ptr -> i64
%258 = llvm.load %209 : !llvm.ptr -> i64
%256 = func.call @hslot(%257, %215, %223, %258) : (i64, !llvm.ptr, !llvm.ptr, i64) -> i64
%259 = arith.constant 1 : i32
%260 = arith.trunci %259 : i32 to i8
%261 = llvm.getelementptr %223[%256] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %260, %261 : i8, !llvm.ptr
%262 = llvm.load %253 : !llvm.ptr -> i64
%263 = llvm.getelementptr %215[%256] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %262, %263 : i64, !llvm.ptr
%264 = arith.constant 1 : i32
%265 = arith.extsi %264 : i32 to i64
%266 = llvm.getelementptr %219[%256] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %265, %266 : i64, !llvm.ptr
%267 = llvm.load %253 : !llvm.ptr -> i64
%268 = arith.constant 1 : i32
%270 = arith.extsi %268 : i32 to i64
%269 = arith.addi %267, %270 : i64
llvm.store %269, %253 : i64, !llvm.ptr
cf.br ^bb42
^bb44:
%271 = arith.constant 1 : i32
%272 = arith.extsi %271 : i32 to i64
%273 = llvm.mlir.constant(1 : i64) : i64
%274 = llvm.alloca %273 x i64 : (i64) -> !llvm.ptr
llvm.store %272, %274 : i64, !llvm.ptr
%275 = arith.constant 0 : i32
%276 = arith.extsi %275 : i32 to i64
%277 = llvm.mlir.constant(1 : i64) : i64
%278 = llvm.alloca %277 x i64 : (i64) -> !llvm.ptr
llvm.store %276, %278 : i64, !llvm.ptr
cf.br ^bb45
^bb45:
%279 = llvm.load %274 : !llvm.ptr -> i64
%280 = arith.cmpi slt, %279, %arg0 : i64
cf.cond_br %280, ^bb46, ^bb47
^bb46:
%281 = llvm.load %274 : !llvm.ptr -> i64
%282 = llvm.mlir.constant(1 : i64) : i64
%283 = llvm.alloca %282 x i64 : (i64) -> !llvm.ptr
llvm.store %281, %283 : i64, !llvm.ptr
%284 = llvm.load %283 : !llvm.ptr -> i64
%285 = arith.cmpi sgt, %284, %arg1 : i64
cf.cond_br %285, ^bb48, ^bb49
^bb48:
llvm.store %arg1, %283 : i64, !llvm.ptr
cf.br ^bb50
^bb49:
cf.br ^bb50
^bb50:
%286 = arith.constant 0 : i32
%287 = llvm.mlir.constant(1 : i64) : i64
%288 = llvm.alloca %287 x i32 : (i64) -> !llvm.ptr
llvm.store %286, %288 : i32, !llvm.ptr
%289 = llvm.load %274 : !llvm.ptr -> i64
%290 = arith.constant 1 : i32
%292 = arith.extsi %290 : i32 to i64
%291 = arith.addi %289, %292 : i64
%293 = arith.cmpi sge, %291, %arg1 : i64
cf.cond_br %293, ^bb51, ^bb52
^bb51:
%294 = arith.constant 1 : i32
llvm.store %294, %288 : i32, !llvm.ptr
cf.br ^bb53
^bb52:
cf.br ^bb53
^bb53:
%295 = arith.constant 0 : i32
%296 = arith.extsi %295 : i32 to i64
llvm.store %296, %278 : i64, !llvm.ptr
cf.br ^bb54
^bb54:
%297 = llvm.load %278 : !llvm.ptr -> i64
%298 = llvm.load %209 : !llvm.ptr -> i64
%299 = arith.cmpi slt, %297, %298 : i64
cf.cond_br %299, ^bb55, ^bb56
^bb55:
%300 = arith.constant 0 : i32
%301 = llvm.load %278 : !llvm.ptr -> i64
%302 = arith.trunci %300 : i32 to i8
%303 = llvm.getelementptr %235[%301] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %302, %303 : i8, !llvm.ptr
%304 = llvm.load %278 : !llvm.ptr -> i64
%305 = arith.constant 1 : i32
%307 = arith.extsi %305 : i32 to i64
%306 = arith.addi %304, %307 : i64
llvm.store %306, %278 : i64, !llvm.ptr
cf.br ^bb54
^bb56:
%308 = arith.constant 0 : i32
%309 = arith.extsi %308 : i32 to i64
llvm.store %309, %278 : i64, !llvm.ptr
cf.br ^bb57
^bb57:
%310 = llvm.load %278 : !llvm.ptr -> i64
%311 = llvm.load %209 : !llvm.ptr -> i64
%312 = arith.cmpi slt, %310, %311 : i64
cf.cond_br %312, ^bb58, ^bb59
^bb58:
%314 = llvm.load %278 : !llvm.ptr -> i64
%315 = llvm.getelementptr %223[%314] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%313 = llvm.load %315 : !llvm.ptr -> i8
%316 = arith.constant 1 : i32
%318 = arith.extsi %313 : i8 to i32
%317 = arith.cmpi eq, %318, %316 : i32
cf.cond_br %317, ^bb60, ^bb61
^bb60:
%320 = llvm.load %278 : !llvm.ptr -> i64
%321 = llvm.getelementptr %215[%320] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%319 = llvm.load %321 : !llvm.ptr -> i64
%323 = llvm.load %278 : !llvm.ptr -> i64
%324 = llvm.getelementptr %219[%323] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%322 = llvm.load %324 : !llvm.ptr -> i64
%325 = arith.constant 0 : i32
%326 = arith.extsi %325 : i32 to i64
%327 = llvm.mlir.constant(1 : i64) : i64
%328 = llvm.alloca %327 x i64 : (i64) -> !llvm.ptr
llvm.store %326, %328 : i64, !llvm.ptr
%329 = llvm.mlir.constant(1 : i64) : i64
%330 = llvm.alloca %329 x i64 : (i64) -> !llvm.ptr
llvm.store %319, %330 : i64, !llvm.ptr
%331 = arith.constant 1 : i32
%332 = arith.extsi %331 : i32 to i64
%333 = llvm.mlir.constant(1 : i64) : i64
%334 = llvm.alloca %333 x i64 : (i64) -> !llvm.ptr
llvm.store %332, %334 : i64, !llvm.ptr
cf.br ^bb63
^bb63:
%335 = llvm.load %334 : !llvm.ptr -> i64
%336 = llvm.load %283 : !llvm.ptr -> i64
%337 = arith.cmpi sle, %335, %336 : i64
cf.cond_br %337, ^bb64, ^bb65
^bb64:
%338 = llvm.load %330 : !llvm.ptr -> i64
%339 = arith.constant 15 : i32
%341 = arith.extsi %339 : i32 to i64
%340 = arith.andi %338, %341 : i64
%342 = llvm.load %330 : !llvm.ptr -> i64
%343 = arith.shrsi %342, %198 : i64
llvm.store %343, %330 : i64, !llvm.ptr
%344 = llvm.load %328 : !llvm.ptr -> i64
%346 = arith.constant 1 : i32
%348 = arith.extsi %346 : i32 to i64
%347 = arith.addi %arg0, %348 : i64
%349 = arith.muli %340, %347 : i64
%350 = llvm.load %334 : !llvm.ptr -> i64
%351 = arith.addi %349, %350 : i64
%352 = llvm.getelementptr %arg2[%351] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%345 = llvm.load %352 : !llvm.ptr -> i64
%353 = arith.ori %344, %345 : i64
llvm.store %353, %328 : i64, !llvm.ptr
%354 = llvm.load %334 : !llvm.ptr -> i64
%355 = arith.constant 1 : i32
%357 = arith.extsi %355 : i32 to i64
%356 = arith.addi %354, %357 : i64
llvm.store %356, %334 : i64, !llvm.ptr
cf.br ^bb63
^bb65:
%358 = llvm.load %328 : !llvm.ptr -> i64
%360 = arith.constant -1 : i64
%359 = arith.xori %358, %360 : i64
%361 = arith.andi %195, %359 : i64
%362 = llvm.mlir.constant(1 : i64) : i64
%363 = llvm.alloca %362 x i64 : (i64) -> !llvm.ptr
llvm.store %361, %363 : i64, !llvm.ptr
cf.br ^bb66
^bb66:
%364 = llvm.load %363 : !llvm.ptr -> i64
%365 = arith.constant 0 : i32
%367 = arith.extsi %365 : i32 to i64
%366 = arith.cmpi ne, %364, %367 : i64
cf.cond_br %366, ^bb67, ^bb68
^bb67:
%368 = llvm.load %363 : !llvm.ptr -> i64
%369 = llvm.load %363 : !llvm.ptr -> i64
%371 = arith.constant 0 : i64
%370 = arith.subi %371, %369 : i64
%372 = arith.andi %368, %370 : i64
%373 = llvm.load %363 : !llvm.ptr -> i64
%374 = arith.subi %373, %372 : i64
llvm.store %374, %363 : i64, !llvm.ptr
%375 = llvm.mlir.constant(1 : i64) : i64
%376 = llvm.alloca %375 x i64 : (i64) -> !llvm.ptr
llvm.store %372, %376 : i64, !llvm.ptr
%377 = arith.constant 0 : i32
%378 = arith.extsi %377 : i32 to i64
%379 = llvm.mlir.constant(1 : i64) : i64
%380 = llvm.alloca %379 x i64 : (i64) -> !llvm.ptr
llvm.store %378, %380 : i64, !llvm.ptr
cf.br ^bb69
^bb69:
%381 = llvm.load %376 : !llvm.ptr -> i64
%382 = arith.constant 1 : i32
%384 = arith.extsi %382 : i32 to i64
%383 = arith.cmpi sgt, %381, %384 : i64
cf.cond_br %383, ^bb70, ^bb71
^bb70:
%385 = llvm.load %376 : !llvm.ptr -> i64
%386 = arith.constant 1 : i32
%388 = arith.extsi %386 : i32 to i64
%387 = arith.shrsi %385, %388 : i64
llvm.store %387, %376 : i64, !llvm.ptr
%389 = llvm.load %380 : !llvm.ptr -> i64
%390 = arith.constant 1 : i32
%392 = arith.extsi %390 : i32 to i64
%391 = arith.addi %389, %392 : i64
llvm.store %391, %380 : i64, !llvm.ptr
cf.br ^bb69
^bb71:
%393 = arith.shli %319, %198 : i64
%394 = llvm.load %380 : !llvm.ptr -> i64
%395 = arith.ori %393, %394 : i64
%396 = llvm.mlir.constant(1 : i64) : i64
%397 = llvm.alloca %396 x i64 : (i64) -> !llvm.ptr
llvm.store %395, %397 : i64, !llvm.ptr
%398 = llvm.load %288 : !llvm.ptr -> i32
%399 = arith.constant 1 : i32
%400 = arith.cmpi eq, %398, %399 : i32
cf.cond_br %400, ^bb72, ^bb73
^bb72:
%401 = llvm.load %397 : !llvm.ptr -> i64
%402 = arith.andi %401, %204 : i64
llvm.store %402, %397 : i64, !llvm.ptr
cf.br ^bb74
^bb73:
cf.br ^bb74
^bb74:
%404 = llvm.load %397 : !llvm.ptr -> i64
%405 = llvm.load %209 : !llvm.ptr -> i64
%403 = func.call @hslot(%404, %227, %235, %405) : (i64, !llvm.ptr, !llvm.ptr, i64) -> i64
%407 = llvm.getelementptr %235[%403] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%406 = llvm.load %407 : !llvm.ptr -> i8
%408 = arith.constant 0 : i32
%410 = arith.extsi %406 : i8 to i32
%409 = arith.cmpi eq, %410, %408 : i32
cf.cond_br %409, ^bb75, ^bb76
^bb75:
%411 = arith.constant 1 : i32
%412 = arith.trunci %411 : i32 to i8
%413 = llvm.getelementptr %235[%403] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %412, %413 : i8, !llvm.ptr
%414 = llvm.load %397 : !llvm.ptr -> i64
%415 = llvm.getelementptr %227[%403] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %414, %415 : i64, !llvm.ptr
%416 = llvm.getelementptr %231[%403] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %322, %416 : i64, !llvm.ptr
cf.br ^bb77
^bb76:
%418 = llvm.getelementptr %231[%403] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%417 = llvm.load %418 : !llvm.ptr -> i64
%419 = arith.addi %417, %322 : i64
%420 = llvm.getelementptr %231[%403] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %419, %420 : i64, !llvm.ptr
cf.br ^bb77
^bb77:
cf.br ^bb66
^bb68:
cf.br ^bb62
^bb61:
cf.br ^bb62
^bb62:
%421 = llvm.load %278 : !llvm.ptr -> i64
%422 = arith.constant 1 : i32
%424 = arith.extsi %422 : i32 to i64
%423 = arith.addi %421, %424 : i64
llvm.store %423, %278 : i64, !llvm.ptr
cf.br ^bb57
^bb59:
%425 = arith.constant 0 : i32
%426 = arith.extsi %425 : i32 to i64
llvm.store %426, %278 : i64, !llvm.ptr
cf.br ^bb78
^bb78:
%427 = llvm.load %278 : !llvm.ptr -> i64
%428 = llvm.load %209 : !llvm.ptr -> i64
%429 = arith.cmpi slt, %427, %428 : i64
cf.cond_br %429, ^bb79, ^bb80
^bb79:
%431 = llvm.load %278 : !llvm.ptr -> i64
%432 = llvm.getelementptr %235[%431] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%430 = llvm.load %432 : !llvm.ptr -> i8
%433 = llvm.load %278 : !llvm.ptr -> i64
%434 = llvm.getelementptr %223[%433] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %430, %434 : i8, !llvm.ptr
%436 = llvm.load %278 : !llvm.ptr -> i64
%437 = llvm.getelementptr %227[%436] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%435 = llvm.load %437 : !llvm.ptr -> i64
%438 = llvm.load %278 : !llvm.ptr -> i64
%439 = llvm.getelementptr %215[%438] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %435, %439 : i64, !llvm.ptr
%441 = llvm.load %278 : !llvm.ptr -> i64
%442 = llvm.getelementptr %231[%441] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%440 = llvm.load %442 : !llvm.ptr -> i64
%443 = llvm.load %278 : !llvm.ptr -> i64
%444 = llvm.getelementptr %219[%443] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %440, %444 : i64, !llvm.ptr
%445 = arith.constant 0 : i32
%446 = llvm.load %278 : !llvm.ptr -> i64
%447 = arith.trunci %445 : i32 to i8
%448 = llvm.getelementptr %235[%446] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %447, %448 : i8, !llvm.ptr
%449 = llvm.load %278 : !llvm.ptr -> i64
%450 = arith.constant 1 : i32
%452 = arith.extsi %450 : i32 to i64
%451 = arith.addi %449, %452 : i64
llvm.store %451, %278 : i64, !llvm.ptr
cf.br ^bb78
^bb80:
%453 = llvm.load %274 : !llvm.ptr -> i64
%454 = arith.constant 1 : i32
%456 = arith.extsi %454 : i32 to i64
%455 = arith.addi %453, %456 : i64
llvm.store %455, %274 : i64, !llvm.ptr
cf.br ^bb45
^bb47:
%457 = arith.constant 0 : i32
%458 = arith.extsi %457 : i32 to i64
%459 = llvm.mlir.constant(1 : i64) : i64
%460 = llvm.alloca %459 x i64 : (i64) -> !llvm.ptr
llvm.store %458, %460 : i64, !llvm.ptr
%461 = arith.constant 0 : i32
%462 = arith.extsi %461 : i32 to i64
llvm.store %462, %278 : i64, !llvm.ptr
cf.br ^bb81
^bb81:
%463 = llvm.load %278 : !llvm.ptr -> i64
%464 = llvm.load %209 : !llvm.ptr -> i64
%465 = arith.cmpi slt, %463, %464 : i64
cf.cond_br %465, ^bb82, ^bb83
^bb82:
%467 = llvm.load %278 : !llvm.ptr -> i64
%468 = llvm.getelementptr %223[%467] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%466 = llvm.load %468 : !llvm.ptr -> i8
%469 = arith.constant 1 : i32
%471 = arith.extsi %466 : i8 to i32
%470 = arith.cmpi eq, %471, %469 : i32
cf.cond_br %470, ^bb84, ^bb85
^bb84:
%472 = llvm.load %460 : !llvm.ptr -> i64
%474 = llvm.load %278 : !llvm.ptr -> i64
%475 = llvm.getelementptr %219[%474] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%473 = llvm.load %475 : !llvm.ptr -> i64
%476 = arith.addi %472, %473 : i64
llvm.store %476, %460 : i64, !llvm.ptr
cf.br ^bb86
^bb85:
cf.br ^bb86
^bb86:
%477 = llvm.load %278 : !llvm.ptr -> i64
%478 = arith.constant 1 : i32
%480 = arith.extsi %478 : i32 to i64
%479 = arith.addi %477, %480 : i64
llvm.store %479, %278 : i64, !llvm.ptr
cf.br ^bb81
^bb83:
func.call @free(%215) : (!llvm.ptr) -> ()
func.call @free(%219) : (!llvm.ptr) -> ()
func.call @free(%223) : (!llvm.ptr) -> ()
func.call @free(%227) : (!llvm.ptr) -> ()
func.call @free(%231) : (!llvm.ptr) -> ()
func.call @free(%235) : (!llvm.ptr) -> ()
%487 = llvm.load %460 : !llvm.ptr -> i64
%488 = arith.constant 2 : i32
%490 = arith.extsi %488 : i32 to i64
%489 = arith.muli %487, %490 : i64
func.return %489 : i64
}
func.func @main() -> i32 {
%492 = llvm.mlir.addressof @N : !llvm.ptr
%493 = llvm.load %492 : !llvm.ptr -> i64
%494 = llvm.mlir.addressof @N : !llvm.ptr
%495 = llvm.load %494 : !llvm.ptr -> i64
%496 = arith.constant 1 : i32
%498 = arith.extsi %496 : i32 to i64
%497 = arith.addi %495, %498 : i64
%499 = arith.muli %493, %497 : i64
%500 = arith.constant 8 : i32
%501 = arith.extsi %500 : i32 to i64
%491 = func.call @calloc(%499, %501) : (i64, i64) -> !llvm.ptr
%502 = llvm.mlir.zero : !llvm.ptr
%503 = llvm.icmp "eq" %491, %502 : !llvm.ptr
cf.cond_br %503, ^bb87, ^bb88
^bb87:
%504 = arith.constant 1 : i32
func.return %504 : i32
^bb88:
cf.br ^bb89
^bb89:
%505 = arith.constant 0 : i32
%506 = arith.extsi %505 : i32 to i64
%507 = llvm.mlir.constant(1 : i64) : i64
%508 = llvm.alloca %507 x i64 : (i64) -> !llvm.ptr
llvm.store %506, %508 : i64, !llvm.ptr
cf.br ^bb90
^bb90:
%509 = llvm.load %508 : !llvm.ptr -> i64
%510 = llvm.mlir.addressof @N : !llvm.ptr
%511 = llvm.load %510 : !llvm.ptr -> i64
%512 = arith.cmpi slt, %509, %511 : i64
cf.cond_br %512, ^bb91, ^bb92
^bb91:
%513 = arith.constant 1 : i32
%514 = arith.extsi %513 : i32 to i64
%515 = llvm.mlir.constant(1 : i64) : i64
%516 = llvm.alloca %515 x i64 : (i64) -> !llvm.ptr
llvm.store %514, %516 : i64, !llvm.ptr
cf.br ^bb93
^bb93:
%517 = llvm.load %516 : !llvm.ptr -> i64
%518 = llvm.mlir.addressof @N : !llvm.ptr
%519 = llvm.load %518 : !llvm.ptr -> i64
%520 = arith.cmpi sle, %517, %519 : i64
cf.cond_br %520, ^bb94, ^bb95
^bb94:
%521 = arith.constant 1 : i32
%522 = llvm.load %508 : !llvm.ptr -> i64
%524 = arith.extsi %521 : i32 to i64
%523 = arith.shli %524, %522 : i64
%525 = llvm.mlir.constant(1 : i64) : i64
%526 = llvm.alloca %525 x i64 : (i64) -> !llvm.ptr
llvm.store %523, %526 : i64, !llvm.ptr
%527 = llvm.load %508 : !llvm.ptr -> i64
%528 = llvm.load %516 : !llvm.ptr -> i64
%529 = arith.addi %527, %528 : i64
%530 = llvm.mlir.addressof @N : !llvm.ptr
%531 = llvm.load %530 : !llvm.ptr -> i64
%532 = arith.cmpi slt, %529, %531 : i64
cf.cond_br %532, ^bb96, ^bb97
^bb96:
%533 = llvm.load %526 : !llvm.ptr -> i64
%534 = arith.constant 1 : i32
%536 = arith.extsi %534 : i32 to i64
%535 = arith.shli %536, %529 : i64
%537 = arith.ori %533, %535 : i64
llvm.store %537, %526 : i64, !llvm.ptr
cf.br ^bb98
^bb97:
cf.br ^bb98
^bb98:
%538 = llvm.load %508 : !llvm.ptr -> i64
%539 = llvm.load %516 : !llvm.ptr -> i64
%540 = arith.subi %538, %539 : i64
%541 = arith.constant 0 : i32
%543 = arith.extsi %541 : i32 to i64
%542 = arith.cmpi sge, %540, %543 : i64
cf.cond_br %542, ^bb99, ^bb100
^bb99:
%544 = llvm.load %526 : !llvm.ptr -> i64
%545 = arith.constant 1 : i32
%547 = arith.extsi %545 : i32 to i64
%546 = arith.shli %547, %540 : i64
%548 = arith.ori %544, %546 : i64
llvm.store %548, %526 : i64, !llvm.ptr
cf.br ^bb101
^bb100:
cf.br ^bb101
^bb101:
%549 = llvm.load %526 : !llvm.ptr -> i64
%550 = llvm.load %508 : !llvm.ptr -> i64
%551 = llvm.mlir.addressof @N : !llvm.ptr
%552 = llvm.load %551 : !llvm.ptr -> i64
%553 = arith.constant 1 : i32
%555 = arith.extsi %553 : i32 to i64
%554 = arith.addi %552, %555 : i64
%556 = arith.muli %550, %554 : i64
%557 = llvm.load %516 : !llvm.ptr -> i64
%558 = arith.addi %556, %557 : i64
%559 = llvm.getelementptr %491[%558] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %549, %559 : i64, !llvm.ptr
%560 = llvm.load %516 : !llvm.ptr -> i64
%561 = arith.constant 1 : i32
%563 = arith.extsi %561 : i32 to i64
%562 = arith.addi %560, %563 : i64
llvm.store %562, %516 : i64, !llvm.ptr
cf.br ^bb93
^bb95:
%564 = llvm.load %508 : !llvm.ptr -> i64
%565 = arith.constant 1 : i32
%567 = arith.extsi %565 : i32 to i64
%566 = arith.addi %564, %567 : i64
llvm.store %566, %508 : i64, !llvm.ptr
cf.br ^bb90
^bb92:
%568 = arith.constant 0 : i32
%569 = arith.extsi %568 : i32 to i64
%570 = llvm.mlir.constant(1 : i64) : i64
%571 = llvm.alloca %570 x i64 : (i64) -> !llvm.ptr
llvm.store %569, %571 : i64, !llvm.ptr
%572 = arith.constant 0 : i32
%573 = arith.extsi %572 : i32 to i64
%574 = llvm.mlir.constant(1 : i64) : i64
%575 = llvm.alloca %574 x i64 : (i64) -> !llvm.ptr
llvm.store %573, %575 : i64, !llvm.ptr
cf.br ^bb102
^bb102:
%576 = llvm.load %575 : !llvm.ptr -> i64
%577 = llvm.mlir.addressof @N : !llvm.ptr
%578 = llvm.load %577 : !llvm.ptr -> i64
%579 = arith.cmpi slt, %576, %578 : i64
cf.cond_br %579, ^bb103, ^bb104
^bb103:
%580 = llvm.load %571 : !llvm.ptr -> i64
%582 = llvm.mlir.addressof @N : !llvm.ptr
%583 = llvm.load %582 : !llvm.ptr -> i64
%584 = llvm.mlir.addressof @N : !llvm.ptr
%585 = llvm.load %584 : !llvm.ptr -> i64
%586 = arith.constant 1 : i32
%588 = arith.extsi %586 : i32 to i64
%587 = arith.subi %585, %588 : i64
%589 = llvm.load %575 : !llvm.ptr -> i64
%590 = arith.subi %587, %589 : i64
%581 = func.call @count_by_L(%583, %590, %491) : (i64, i64, !llvm.ptr) -> i64
%591 = arith.addi %580, %581 : i64
llvm.store %591, %571 : i64, !llvm.ptr
%592 = llvm.load %575 : !llvm.ptr -> i64
%593 = arith.constant 1 : i32
%595 = arith.extsi %593 : i32 to i64
%594 = arith.addi %592, %595 : i64
llvm.store %594, %575 : i64, !llvm.ptr
cf.br ^bb102
^bb104:
%596 = llvm.mlir.addressof @str_0 : !llvm.ptr
%597 = llvm.load %571 : !llvm.ptr -> i64
%598 = llvm.call @printf(%596, %597) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%491) : (!llvm.ptr) -> ()
%600 = arith.constant 0 : i32
func.return %600 : i32
}
}