← All problems
Problem 924
B(n) = smallest number larger than n formed by rearranging digits of n, or 0. a_0 = 0, a_n = a_{n-1}^2 + 2. U(N) = sum_{n=1..N} B(a_n). Answer: U(10^16) mod 1_000_000_007.
View problem on Project Euler
Performance comparison
Metric Our solution Best known
Time complexity O(n)O(n log n)
Space complexity O(n^2)O(n)
Approach Flow solution Search with pruning or sieve
Verdict Optimal
Flow source
# Project Euler 924: Larger Digit Permutation II
# B(n) = smallest number larger than n formed by rearranging digits of n, or 0.
# a_0 = 0, a_n = a_{n-1}^2 + 2. U(N) = sum_{n=1..N} B(a_n).
# Answer: U(10^16) mod 1_000_000_007.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
function memset(p: ptr<void>, c: i32, n: i64) -> ptr<void>
}
const MOD: i64 = 1000000007
const HT_SIZE: i64 = 131072
const HT_MASK: i64 = 131071
const HASH_C: i64 = 2654435761
# Hash table
let mut ht_key: ptr<i64> = null
let mut ht_val: ptr<i64> = null
function ht_init() -> void {
memset(ht_key as ptr<void>, 0, HT_SIZE * 8)
memset(ht_val as ptr<void>, 0, HT_SIZE * 8)
}
function ht_put(key: i64, val: i64) -> void {
let mut h: i64 = (key * HASH_C) & HT_MASK
if h < 0 { h = -h }
let mut i: i64 = 0
while i < HT_SIZE {
let idx: i64 = (h + i) & HT_MASK
if ht_val[idx] == 0 {
ht_key[idx] = key
ht_val[idx] = val
return
}
i = i + 1
}
}
# Returns index if found, -1 if not found
function ht_get(key: i64) -> i64 {
let mut h: i64 = (key * HASH_C) & HT_MASK
if h < 0 { h = -h }
let mut i: i64 = 0
while i < HT_SIZE {
let idx: i64 = (h + i) & HT_MASK
if ht_key[idx] == key && ht_val[idx] != 0 {
return ht_val[idx]
}
if ht_val[idx] == 0 && ht_key[idx] == 0 {
return -1
}
i = i + 1
}
return -1
}
# next_perm_inplace on ptr<i8> digit array
# Returns 1 if next perm exists, 0 otherwise
function next_perm_inplace(digs: ptr<i8>, len: i32) -> i32 {
let mut i: i32 = len - 2
while i >= 0 && digs[i] >= digs[i + 1] {
i = i - 1
}
if i < 0 { return 0 }
let mut j: i32 = len - 1
while digs[j] <= digs[i] {
j = j - 1
}
let tmp: i8 = digs[i]
digs[i] = digs[j]
digs[j] = tmp
let mut l: i32 = i + 1
let mut r: i32 = len - 1
while l < r {
let tmp2: i8 = digs[l]
digs[l] = digs[r]
digs[r] = tmp2
l = l + 1
r = r - 1
}
return 1
}
function B_small(n: i64) -> i64 {
let digs: ptr<i8> = calloc(20, 1)
let mut len: i32 = 0
let mut t: i64 = n
if t == 0 {
digs[0] = 0
len = 1
} else {
while t > 0 {
digs[len] = (t % 10) as i8
len = len + 1
t = t / 10
}
# reverse
let mut i: i32 = 0
while i < len / 2 {
let tmp: i8 = digs[i]
digs[i] = digs[len - 1 - i]
digs[len - 1 - i] = tmp
i = i + 1
}
}
let ok: i32 = next_perm_inplace(digs, len)
if ok == 0 {
free(digs)
return 0
}
let mut y: i64 = 0
let mut i2: i32 = 0
while i2 < len {
y = y * 10 + (digs[i2] as i64)
i2 = i2 + 1
}
free(digs)
return y
}
# next_perm_fixed: fixed-width next permutation (leading zeros allowed)
# Returns next perm value, or -1 if no next permutation
function next_perm_fixed(x: i64, k: i32, buf: ptr<i8>) -> i64 {
let mut t: i64 = x
let mut i: i32 = k - 1
while i >= 0 {
buf[i] = (t % 10) as i8
t = t / 10
i = i - 1
}
# Find pivot
let mut ii: i32 = k - 2
while ii >= 0 && buf[ii] >= buf[ii + 1] {
ii = ii - 1
}
if ii < 0 { return -1 }
let mut j: i32 = k - 1
while buf[j] <= buf[ii] {
j = j - 1
}
let tmp: i8 = buf[ii]
buf[ii] = buf[j]
buf[j] = tmp
let mut l: i32 = ii + 1
let mut r: i32 = k - 1
while l < r {
let tmp2: i8 = buf[l]
buf[l] = buf[r]
buf[r] = tmp2
l = l + 1
r = r - 1
}
let mut y: i64 = 0
let mut d: i32 = 0
while d < k {
y = y * 10 + (buf[d] as i64)
d = d + 1
}
return y
}
# sum_a_mod: cycle detection for a_n mod MOD
function sum_a_mod(N: i64) -> i64 {
let states: ptr<i64> = calloc(200000, 8)
let pref: ptr<i64> = calloc(200000, 8)
ht_init()
states[0] = 0
ht_put(0, 0)
let mut n_states: i32 = 1
let mut x: i64 = 0
let mut mu: i64 = 0
let mut lam: i64 = 0
while true {
let nxt: i64 = (x * x + 2) % MOD
let idx: i64 = n_states as i64
let mut found: i64 = -1
if nxt == 0 {
found = 0
} else {
found = ht_get(nxt)
}
if found >= 0 {
mu = found
lam = idx - found
break
}
ht_put(nxt, idx)
states[n_states] = nxt
n_states = n_states + 1
x = nxt
}
# Build prefix sums
pref[0] = 0
let mut i: i32 = 1
while i < n_states {
pref[i] = (pref[i - 1] + states[i]) % MOD
i = i + 1
}
if N < n_states as i64 {
let result: i64 = pref[N as i32]
free(states)
free(pref)
return result
}
let base_before: i64 = if mu > 0 { pref[(mu - 1) as i32] } else { 0 }
let mut cycle_sum: i64 = (pref[(mu + lam - 1) as i32] - base_before) % MOD
if cycle_sum < 0 { cycle_sum = cycle_sum + MOD }
let cycle_terms: i64 = N - mu + 1
let full: i64 = cycle_terms / lam
let rem: i64 = cycle_terms % lam
let mut total: i64 = (base_before + (full % MOD) * cycle_sum) % MOD
if rem != 0 {
let mut extra: i64 = (pref[(mu + rem - 1) as i32] - base_before) % MOD
if extra < 0 { extra = extra + MOD }
total = (total + extra) % MOD
}
free(states)
free(pref)
return total
}
# delta_small: n=1..5
function delta_small(N: i64) -> i64 {
let mut a: i64 = 0
let mut s: i64 = 0
let limit: i32 = if N < 5 { N as i32 } else { 5 }
let mut n: i32 = 1
while n <= limit {
a = a * a + 2
let b: i64 = B_small(a)
let mut d: i64 = (b - a) % MOD
if d < 0 { d = d + MOD }
s = (s + d) % MOD
n = n + 1
}
return s
}
# delta10_and_bad outputs
let mut g_d10_total: i64 = 0
let mut g_d10_first_bad_n: i64 = -1
let mut g_d10_step: i64 = 0
function delta10_and_bad(N: i64) -> void {
g_d10_total = 0
g_d10_first_bad_n = -1
g_d10_step = 0
if N <= 5 { return }
let k: i32 = 10
let mut m: i128 = 1
let mut i: i32 = 0
while i < k {
m = m * 10
i = i + 1
}
let mut step: i64 = 8
let mut i2: i32 = 0
while i2 < k - 2 {
step = step * 5
i2 = i2 + 1
}
g_d10_step = step
# Compute a_6 mod 10^10
let mut x: i128 = 0
let mut i3: i32 = 0
while i3 < 6 {
x = (x * x + 2) % m
i3 = i3 + 1
}
let start: i128 = x
let total_terms: i64 = N - 5
let q: i64 = total_terms / step
let r: i64 = total_terms % step
let buf: ptr<i8> = calloc(16, 1)
let mut cycle_sum: i64 = 0
let mut rem_sum: i64 = 0
let mut bad_step: i64 = -1
let mut ii: i64 = 1
while ii <= step {
let y: i64 = next_perm_fixed(x as i64, k, buf)
if y < 0 {
bad_step = ii
} else {
let d: i64 = y - (x as i64)
cycle_sum = (cycle_sum + d) % MOD
if cycle_sum < 0 { cycle_sum = cycle_sum + MOD }
if ii <= r {
rem_sum = (rem_sum + d) % MOD
if rem_sum < 0 { rem_sum = rem_sum + MOD }
}
}
x = (x * x + 2) % m
ii = ii + 1
}
free(buf)
g_d10_first_bad_n = bad_step + 5
g_d10_total = ((q % MOD) * cycle_sum % MOD + rem_sum) % MOD
if g_d10_total < 0 { g_d10_total = g_d10_total + MOD }
}
# delta_bad_11
function delta_bad_11(N: i64, first_bad_n: i64, step: i64) -> i64 {
if first_bad_n < 0 || N < first_bad_n { return 0 }
let mut m11: i128 = 1
let mut i: i32 = 0
while i < 11 {
m11 = m11 * 10
i = i + 1
}
# targets[0..4] = first_bad_n + t*step for t=0..4
let targets: ptr<i64> = calloc(5, 8)
let mut t: i32 = 0
while t < 5 {
targets[t] = first_bad_n + (t as i64) * step
t = t + 1
}
let max_n: i64 = targets[4]
# Simulate a_n mod 10^11 up to max_n
let mut x: i128 = 0
let vals: ptr<i64> = calloc(5, 8)
let mut idx: i32 = 0
let mut n: i64 = 1
while n <= max_n {
x = (x * x + 2) % m11
if n == targets[idx] {
vals[idx] = x as i64
idx = idx + 1
if idx == 5 { break }
}
n = n + 1
}
let buf: ptr<i8> = calloc(16, 1)
let deltas: ptr<i64> = calloc(5, 8)
let mut i2: i32 = 0
while i2 < 5 {
let y: i64 = next_perm_fixed(vals[i2], 11, buf)
# y should never be -1 for 11-digit
let mut d: i64 = (y - vals[i2]) % MOD
if d < 0 { d = d + MOD }
deltas[i2] = d
i2 = i2 + 1
}
# Count bad indices <= N
let T: i64 = 1 + (N - first_bad_n) / step
let base: i64 = T / 5
let rem: i64 = T % 5
let mut total: i64 = 0
let mut i3: i32 = 0
while i3 < 5 {
let c: i64 = base + (if i3 < rem as i32 { 1 } else { 0 })
total = (total + (c % MOD) * deltas[i3]) % MOD
i3 = i3 + 1
}
free(targets)
free(vals)
free(buf)
free(deltas)
return total
}
function main() -> i32 {
ht_key = calloc(HT_SIZE, 8)
ht_val = calloc(HT_SIZE, 8)
let mut N: i64 = 1
let mut i: i32 = 0
while i < 16 {
N = N * 10
i = i + 1
}
let s_a: i64 = sum_a_mod(N)
let d_small: i64 = delta_small(N)
delta10_and_bad(N)
let d_bad: i64 = delta_bad_11(N, g_d10_first_bad_n, g_d10_step)
let mut result: i64 = (s_a + d_small + g_d10_total + d_bad) % MOD
if result < 0 { result = result + MOD }
printf("%lld\n", result)
return 0
}
Generated C
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
while (flow_temp_head) {
flow_temp_node* n = flow_temp_head;
flow_temp_head = n->next;
free(n);
}
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
if (!node) return NULL;
node->next = flow_temp_head;
flow_temp_head = node;
if (!flow_temp_atexit_set) {
flow_temp_atexit_set = 1;
atexit(flow_temp_free_all);
}
return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
char* r = (char*)flow_temp_alloc(la + lb + 1);
if (!r) return NULL;
if (la) memcpy(r, a, la);
if (lb) memcpy(r + la, b, lb);
r[la + lb] = '\0';
return r;
}
#define __flow_in_arr(arr, val) __extension__ ({ \
int _found = 0; \
size_t _n = sizeof(arr)/sizeof((arr)[0]); \
for (size_t _i = 0; _i < _n; _i++) { \
if ((arr)[_i] == (val)) { _found = 1; break; } \
} _found; })
/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
abort();
#if defined(__GNUC__) || defined(__clang__)
__builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")
#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#include <math.h>
void* _ui_state = NULL;
static inline float i32_to_f32(int32_t v) { return (float)v; }
/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }
void ht_init(void);
void ht_put_i64_i64(int64_t key, int64_t val);
int64_t ht_get_i64(int64_t key);
int32_t next_perm_inplace_ptr_i8_i32(int8_t* digs, int32_t len);
int64_t B_small_i64(int64_t n);
int64_t next_perm_fixed_i64_i32_ptr_i8(int64_t x, int32_t k, int8_t* buf);
int64_t sum_a_mod_i64(int64_t N);
int64_t delta_small_i64(int64_t N);
void delta10_and_bad_i64(int64_t N);
int64_t delta_bad_11_i64_i64_i64(int64_t N, int64_t first_bad_n, int64_t step);
int32_t main(void);
static const int64_t MOD = 1000000007;
static const int64_t HT_SIZE = 131072;
static const int64_t HT_MASK = 131071;
static const int64_t HASH_C = 2654435761;
/* Module statics */
static int64_t* ht_key = NULL;
static int64_t* ht_val = NULL;
static int64_t g_d10_total = 0;
static int64_t g_d10_first_bad_n = (-1);
static int64_t g_d10_step = 0;
void ht_init(void) {
memset(((void*)(ht_key)), 0, (HT_SIZE * 8));
memset(((void*)(ht_val)), 0, (HT_SIZE * 8));
}
void ht_put_i64_i64(int64_t key, int64_t val) {
int64_t h = ((key * HASH_C) & HT_MASK);
if (h < 0) {
h = (-h);
}
int64_t i = 0;
while (i < HT_SIZE) {
int64_t idx = ((h + i) & HT_MASK);
if (ht_val[idx] == 0) {
ht_key[idx] = key;
ht_val[idx] = val;
return;
}
i = (i + 1);
}
}
int64_t ht_get_i64(int64_t key) {
int64_t h = ((key * HASH_C) & HT_MASK);
if (h < 0) {
h = (-h);
}
int64_t i = 0;
while (i < HT_SIZE) {
int64_t idx = ((h + i) & HT_MASK);
if ((ht_key[idx] == key && ht_val[idx] != 0)) {
return ht_val[idx];
}
if ((ht_val[idx] == 0 && ht_key[idx] == 0)) {
return (-1);
}
i = (i + 1);
}
return (-1);
}
int32_t next_perm_inplace_ptr_i8_i32(int8_t* digs, int32_t len) {
int32_t i = (len - 2);
while ((i >= 0 && digs[i] >= digs[(i + 1)])) {
i = (i - 1);
}
if (i < 0) {
return 0;
}
int32_t j = (len - 1);
while (digs[j] <= digs[i]) {
j = (j - 1);
}
int8_t tmp = digs[i];
digs[i] = digs[j];
digs[j] = tmp;
int32_t l = (i + 1);
int32_t r = (len - 1);
while (l < r) {
int8_t tmp2 = digs[l];
digs[l] = digs[r];
digs[r] = tmp2;
l = (l + 1);
r = (r - 1);
}
return 1;
}
int64_t B_small_i64(int64_t n) {
int8_t* digs = (int8_t*)(calloc(20, 1));
int32_t len = 0;
int64_t t = n;
if (t == 0) {
digs[0] = 0;
len = 1;
} else {
while (t > 0) {
digs[len] = ((int8_t)(FLOW_CHECKED_MOD((t), (10))));
len = (len + 1);
t = FLOW_CHECKED_DIV((t), (10));
}
int32_t i = 0;
while (i < FLOW_CHECKED_DIV((len), (2))) {
int8_t tmp = digs[i];
digs[i] = digs[((len - 1) - i)];
digs[((len - 1) - i)] = tmp;
i = (i + 1);
}
}
int32_t ok = next_perm_inplace_ptr_i8_i32(digs, len);
if (ok == 0) {
free(digs);
return 0;
}
int64_t y = 0;
int32_t i2 = 0;
while (i2 < len) {
y = ((y * 10) + ((int64_t)(digs[i2])));
i2 = (i2 + 1);
}
free(digs);
return y;
}
int64_t next_perm_fixed_i64_i32_ptr_i8(int64_t x, int32_t k, int8_t* buf) {
int64_t t = x;
int32_t i = (k - 1);
while (i >= 0) {
buf[i] = ((int8_t)(FLOW_CHECKED_MOD((t), (10))));
t = FLOW_CHECKED_DIV((t), (10));
i = (i - 1);
}
int32_t ii = (k - 2);
while ((ii >= 0 && buf[ii] >= buf[(ii + 1)])) {
ii = (ii - 1);
}
if (ii < 0) {
return (-1);
}
int32_t j = (k - 1);
while (buf[j] <= buf[ii]) {
j = (j - 1);
}
int8_t tmp = buf[ii];
buf[ii] = buf[j];
buf[j] = tmp;
int32_t l = (ii + 1);
int32_t r = (k - 1);
while (l < r) {
int8_t tmp2 = buf[l];
buf[l] = buf[r];
buf[r] = tmp2;
l = (l + 1);
r = (r - 1);
}
int64_t y = 0;
int32_t d = 0;
while (d < k) {
y = ((y * 10) + ((int64_t)(buf[d])));
d = (d + 1);
}
return y;
}
int64_t sum_a_mod_i64(int64_t N) {
int64_t* states = (int64_t*)(calloc(200000, 8));
int64_t* pref = (int64_t*)(calloc(200000, 8));
ht_init();
states[0] = 0;
ht_put_i64_i64(0, 0);
int32_t n_states = 1;
int64_t x = 0;
int64_t mu = 0;
int64_t lam = 0;
while (1) {
int64_t nxt = FLOW_CHECKED_MOD((((x * x) + 2)), (MOD));
int64_t idx = ((int64_t)(n_states));
int64_t found = (-1);
if (nxt == 0) {
found = 0;
} else {
found = ht_get_i64(nxt);
}
if (found >= 0) {
mu = found;
lam = (idx - found);
break;
}
ht_put_i64_i64(nxt, idx);
states[n_states] = nxt;
n_states = (n_states + 1);
x = nxt;
}
pref[0] = 0;
int32_t i = 1;
while (i < n_states) {
pref[i] = FLOW_CHECKED_MOD(((pref[(i - 1)] + states[i])), (MOD));
i = (i + 1);
}
if (N < ((int64_t)(n_states))) {
int64_t result = pref[((int32_t)(N))];
free(states);
free(pref);
return result;
}
int64_t base_before = ((mu > 0) ? (pref[((int32_t)((mu - 1)))]) : (0));
int64_t cycle_sum = FLOW_CHECKED_MOD(((pref[((int32_t)(((mu + lam) - 1)))] - base_before)), (MOD));
if (cycle_sum < 0) {
cycle_sum = (cycle_sum + MOD);
}
int64_t cycle_terms = ((N - mu) + 1);
int64_t full = FLOW_CHECKED_DIV((cycle_terms), (lam));
int64_t rem = FLOW_CHECKED_MOD((cycle_terms), (lam));
int64_t total = FLOW_CHECKED_MOD(((base_before + (FLOW_CHECKED_MOD((full), (MOD)) * cycle_sum))), (MOD));
if (rem != 0) {
int64_t extra = FLOW_CHECKED_MOD(((pref[((int32_t)(((mu + rem) - 1)))] - base_before)), (MOD));
if (extra < 0) {
extra = (extra + MOD);
}
total = FLOW_CHECKED_MOD(((total + extra)), (MOD));
}
free(states);
free(pref);
return total;
}
int64_t delta_small_i64(int64_t N) {
int64_t a = 0;
int64_t s = 0;
int32_t limit = ((N < 5) ? (((int32_t)(N))) : (5));
int32_t n = 1;
while (n <= limit) {
a = ((a * a) + 2);
int64_t b = B_small_i64(a);
int64_t d = FLOW_CHECKED_MOD(((b - a)), (MOD));
if (d < 0) {
d = (d + MOD);
}
s = FLOW_CHECKED_MOD(((s + d)), (MOD));
n = (n + 1);
}
return s;
}
void delta10_and_bad_i64(int64_t N) {
g_d10_total = 0;
g_d10_first_bad_n = (-1);
g_d10_step = 0;
if (N <= 5) {
return;
}
int32_t k = 10;
__int128 m = 1;
int32_t i = 0;
while (i < k) {
m = (m * 10);
i = (i + 1);
}
int64_t step = 8;
int32_t i2 = 0;
while (i2 < (k - 2)) {
step = (step * 5);
i2 = (i2 + 1);
}
g_d10_step = step;
__int128 x = 0;
int32_t i3 = 0;
while (i3 < 6) {
x = FLOW_CHECKED_MOD((((x * x) + 2)), (m));
i3 = (i3 + 1);
}
__int128 start = x;
int64_t total_terms = (N - 5);
int64_t q = FLOW_CHECKED_DIV((total_terms), (step));
int64_t r = FLOW_CHECKED_MOD((total_terms), (step));
int8_t* buf = (int8_t*)(calloc(16, 1));
int64_t cycle_sum = 0;
int64_t rem_sum = 0;
int64_t bad_step = (-1);
int64_t ii = 1;
while (ii <= step) {
int64_t y = next_perm_fixed_i64_i32_ptr_i8(((int64_t)(x)), k, buf);
if (y < 0) {
bad_step = ii;
} else {
int64_t d = (y - ((int64_t)(x)));
cycle_sum = FLOW_CHECKED_MOD(((cycle_sum + d)), (MOD));
if (cycle_sum < 0) {
cycle_sum = (cycle_sum + MOD);
}
if (ii <= r) {
rem_sum = FLOW_CHECKED_MOD(((rem_sum + d)), (MOD));
if (rem_sum < 0) {
rem_sum = (rem_sum + MOD);
}
}
}
x = FLOW_CHECKED_MOD((((x * x) + 2)), (m));
ii = (ii + 1);
}
free(buf);
g_d10_first_bad_n = (bad_step + 5);
g_d10_total = FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((q), (MOD)) * cycle_sum)), (MOD)) + rem_sum)), (MOD));
if (g_d10_total < 0) {
g_d10_total = (g_d10_total + MOD);
}
}
int64_t delta_bad_11_i64_i64_i64(int64_t N, int64_t first_bad_n, int64_t step) {
if ((first_bad_n < 0 || N < first_bad_n)) {
return 0;
}
__int128 m11 = 1;
int32_t i = 0;
while (i < 11) {
m11 = (m11 * 10);
i = (i + 1);
}
int64_t* targets = (int64_t*)(calloc(5, 8));
int32_t t = 0;
while (t < 5) {
targets[t] = (first_bad_n + (((int64_t)(t)) * step));
t = (t + 1);
}
int64_t max_n = targets[4];
__int128 x = 0;
int64_t* vals = (int64_t*)(calloc(5, 8));
int32_t idx = 0;
int64_t n = 1;
while (n <= max_n) {
x = FLOW_CHECKED_MOD((((x * x) + 2)), (m11));
if (n == targets[idx]) {
vals[idx] = ((int64_t)(x));
idx = (idx + 1);
if (idx == 5) {
break;
}
}
n = (n + 1);
}
int8_t* buf = (int8_t*)(calloc(16, 1));
int64_t* deltas = (int64_t*)(calloc(5, 8));
int32_t i2 = 0;
while (i2 < 5) {
int64_t y = next_perm_fixed_i64_i32_ptr_i8(vals[i2], 11, buf);
int64_t d = FLOW_CHECKED_MOD(((y - vals[i2])), (MOD));
if (d < 0) {
d = (d + MOD);
}
deltas[i2] = d;
i2 = (i2 + 1);
}
int64_t T = (1 + FLOW_CHECKED_DIV(((N - first_bad_n)), (step)));
int64_t base = FLOW_CHECKED_DIV((T), (5));
int64_t rem = FLOW_CHECKED_MOD((T), (5));
int64_t total = 0;
int32_t i3 = 0;
while (i3 < 5) {
int64_t c = (base + ((i3 < ((int32_t)(rem))) ? (1) : (0)));
total = FLOW_CHECKED_MOD(((total + (FLOW_CHECKED_MOD((c), (MOD)) * deltas[i3]))), (MOD));
i3 = (i3 + 1);
}
free(targets);
free(vals);
free(buf);
free(deltas);
return total;
}
int32_t main(void) {
ht_key = calloc(HT_SIZE, 8);
ht_val = calloc(HT_SIZE, 8);
int64_t N = 1;
int32_t i = 0;
while (i < 16) {
N = (N * 10);
i = (i + 1);
}
int64_t s_a = sum_a_mod_i64(N);
int64_t d_small = delta_small_i64(N);
delta10_and_bad_i64(N);
int64_t d_bad = delta_bad_11_i64_i64_i64(N, g_d10_first_bad_n, g_d10_step);
int64_t result = FLOW_CHECKED_MOD(((((s_a + d_small) + g_d10_total) + d_bad)), (MOD));
if (result < 0) {
result = (result + MOD);
}
printf("%lld\n", result);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func private @memset(!llvm.ptr, i32, i64) -> !llvm.ptr
// Constant: MOD
llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
// Constant: HT_SIZE
llvm.mlir.global internal constant @HT_SIZE(131072 : i64) : i64
// Constant: HT_MASK
llvm.mlir.global internal constant @HT_MASK(131071 : i64) : i64
// Constant: HASH_C
llvm.mlir.global internal constant @HASH_C(2654435761 : i64) : i64
// Module static: ht_key
llvm.mlir.global internal @ht_key() {addr_space = 0 : i32} : !llvm.ptr {
%0 = llvm.mlir.zero : !llvm.ptr
llvm.return %0 : !llvm.ptr
}
// Module static: ht_val
llvm.mlir.global internal @ht_val() {addr_space = 0 : i32} : !llvm.ptr {
%1 = llvm.mlir.zero : !llvm.ptr
llvm.return %1 : !llvm.ptr
}
func.func @ht_init() -> () {
%3 = llvm.mlir.addressof @ht_key : !llvm.ptr
%4 = llvm.load %3 : !llvm.ptr -> !llvm.ptr
%5 = arith.constant 0 : i32
%6 = llvm.mlir.addressof @HT_SIZE : !llvm.ptr
%7 = llvm.load %6 : !llvm.ptr -> i64
%8 = arith.constant 8 : i32
%10 = arith.extsi %8 : i32 to i64
%9 = arith.muli %7, %10 : i64
%2 = func.call @memset(%4, %5, %9) : (!llvm.ptr, i32, i64) -> !llvm.ptr
%12 = llvm.mlir.addressof @ht_val : !llvm.ptr
%13 = llvm.load %12 : !llvm.ptr -> !llvm.ptr
%14 = arith.constant 0 : i32
%15 = llvm.mlir.addressof @HT_SIZE : !llvm.ptr
%16 = llvm.load %15 : !llvm.ptr -> i64
%17 = arith.constant 8 : i32
%19 = arith.extsi %17 : i32 to i64
%18 = arith.muli %16, %19 : i64
%11 = func.call @memset(%13, %14, %18) : (!llvm.ptr, i32, i64) -> !llvm.ptr
func.return
}
func.func @ht_put(%arg0: i64, %arg1: i64) -> () {
%20 = llvm.mlir.addressof @HASH_C : !llvm.ptr
%21 = llvm.load %20 : !llvm.ptr -> i64
%22 = arith.muli %arg0, %21 : i64
%23 = llvm.mlir.addressof @HT_MASK : !llvm.ptr
%24 = llvm.load %23 : !llvm.ptr -> i64
%25 = arith.andi %22, %24 : i64
%26 = llvm.mlir.constant(1 : i64) : i64
%27 = llvm.alloca %26 x i64 : (i64) -> !llvm.ptr
llvm.store %25, %27 : i64, !llvm.ptr
%28 = llvm.load %27 : !llvm.ptr -> i64
%29 = arith.constant 0 : i32
%31 = arith.extsi %29 : i32 to i64
%30 = arith.cmpi slt, %28, %31 : i64
cf.cond_br %30, ^bb0, ^bb1
^bb0:
%32 = llvm.load %27 : !llvm.ptr -> i64
%34 = arith.constant 0 : i64
%33 = arith.subi %34, %32 : i64
llvm.store %33, %27 : i64, !llvm.ptr
cf.br ^bb2
^bb1:
cf.br ^bb2
^bb2:
%35 = arith.constant 0 : i32
%36 = arith.extsi %35 : i32 to i64
%37 = llvm.mlir.constant(1 : i64) : i64
%38 = llvm.alloca %37 x i64 : (i64) -> !llvm.ptr
llvm.store %36, %38 : i64, !llvm.ptr
cf.br ^bb3
^bb3:
%39 = llvm.load %38 : !llvm.ptr -> i64
%40 = llvm.mlir.addressof @HT_SIZE : !llvm.ptr
%41 = llvm.load %40 : !llvm.ptr -> i64
%42 = arith.cmpi slt, %39, %41 : i64
cf.cond_br %42, ^bb4, ^bb5
^bb4:
%43 = llvm.load %27 : !llvm.ptr -> i64
%44 = llvm.load %38 : !llvm.ptr -> i64
%45 = arith.addi %43, %44 : i64
%46 = llvm.mlir.addressof @HT_MASK : !llvm.ptr
%47 = llvm.load %46 : !llvm.ptr -> i64
%48 = arith.andi %45, %47 : i64
%50 = llvm.mlir.addressof @ht_val : !llvm.ptr
%51 = llvm.load %50 : !llvm.ptr -> !llvm.ptr
%52 = llvm.getelementptr %51[%48] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%49 = llvm.load %52 : !llvm.ptr -> i64
%53 = arith.constant 0 : i32
%55 = arith.extsi %53 : i32 to i64
%54 = arith.cmpi eq, %49, %55 : i64
cf.cond_br %54, ^bb6, ^bb7
^bb6:
%56 = llvm.mlir.addressof @ht_key : !llvm.ptr
%57 = llvm.load %56 : !llvm.ptr -> !llvm.ptr
%58 = llvm.getelementptr %57[%48] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg0, %58 : i64, !llvm.ptr
%59 = llvm.mlir.addressof @ht_val : !llvm.ptr
%60 = llvm.load %59 : !llvm.ptr -> !llvm.ptr
%61 = llvm.getelementptr %60[%48] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %arg1, %61 : i64, !llvm.ptr
func.return
^bb7:
cf.br ^bb8
^bb8:
%62 = llvm.load %38 : !llvm.ptr -> i64
%63 = arith.constant 1 : i32
%65 = arith.extsi %63 : i32 to i64
%64 = arith.addi %62, %65 : i64
llvm.store %64, %38 : i64, !llvm.ptr
cf.br ^bb3
^bb5:
func.return
}
func.func @ht_get(%arg0: i64) -> i64 {
%66 = llvm.mlir.addressof @HASH_C : !llvm.ptr
%67 = llvm.load %66 : !llvm.ptr -> i64
%68 = arith.muli %arg0, %67 : i64
%69 = llvm.mlir.addressof @HT_MASK : !llvm.ptr
%70 = llvm.load %69 : !llvm.ptr -> i64
%71 = arith.andi %68, %70 : i64
%72 = llvm.mlir.constant(1 : i64) : i64
%73 = llvm.alloca %72 x i64 : (i64) -> !llvm.ptr
llvm.store %71, %73 : i64, !llvm.ptr
%74 = llvm.load %73 : !llvm.ptr -> i64
%75 = arith.constant 0 : i32
%77 = arith.extsi %75 : i32 to i64
%76 = arith.cmpi slt, %74, %77 : i64
cf.cond_br %76, ^bb9, ^bb10
^bb9:
%78 = llvm.load %73 : !llvm.ptr -> i64
%80 = arith.constant 0 : i64
%79 = arith.subi %80, %78 : i64
llvm.store %79, %73 : i64, !llvm.ptr
cf.br ^bb11
^bb10:
cf.br ^bb11
^bb11:
%81 = arith.constant 0 : i32
%82 = arith.extsi %81 : i32 to i64
%83 = llvm.mlir.constant(1 : i64) : i64
%84 = llvm.alloca %83 x i64 : (i64) -> !llvm.ptr
llvm.store %82, %84 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%85 = llvm.load %84 : !llvm.ptr -> i64
%86 = llvm.mlir.addressof @HT_SIZE : !llvm.ptr
%87 = llvm.load %86 : !llvm.ptr -> i64
%88 = arith.cmpi slt, %85, %87 : i64
cf.cond_br %88, ^bb13, ^bb14
^bb13:
%89 = llvm.load %73 : !llvm.ptr -> i64
%90 = llvm.load %84 : !llvm.ptr -> i64
%91 = arith.addi %89, %90 : i64
%92 = llvm.mlir.addressof @HT_MASK : !llvm.ptr
%93 = llvm.load %92 : !llvm.ptr -> i64
%94 = arith.andi %91, %93 : i64
%96 = llvm.mlir.addressof @ht_key : !llvm.ptr
%97 = llvm.load %96 : !llvm.ptr -> !llvm.ptr
%98 = llvm.getelementptr %97[%94] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%95 = llvm.load %98 : !llvm.ptr -> i64
%99 = arith.cmpi eq, %95, %arg0 : i64
%100 = scf.if %99 -> (i1) {
%102 = llvm.mlir.addressof @ht_val : !llvm.ptr
%103 = llvm.load %102 : !llvm.ptr -> !llvm.ptr
%104 = llvm.getelementptr %103[%94] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%101 = llvm.load %104 : !llvm.ptr -> i64
%105 = arith.constant 0 : i32
%107 = arith.extsi %105 : i32 to i64
%106 = arith.cmpi ne, %101, %107 : i64
scf.yield %106 : i1
} else {
%108 = arith.constant false
scf.yield %108 : i1
}
cf.cond_br %100, ^bb15, ^bb16
^bb15:
%110 = llvm.mlir.addressof @ht_val : !llvm.ptr
%111 = llvm.load %110 : !llvm.ptr -> !llvm.ptr
%112 = llvm.getelementptr %111[%94] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%109 = llvm.load %112 : !llvm.ptr -> i64
func.return %109 : i64
^bb16:
cf.br ^bb17
^bb17:
%114 = llvm.mlir.addressof @ht_val : !llvm.ptr
%115 = llvm.load %114 : !llvm.ptr -> !llvm.ptr
%116 = llvm.getelementptr %115[%94] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%113 = llvm.load %116 : !llvm.ptr -> i64
%117 = arith.constant 0 : i32
%119 = arith.extsi %117 : i32 to i64
%118 = arith.cmpi eq, %113, %119 : i64
%120 = scf.if %118 -> (i1) {
%122 = llvm.mlir.addressof @ht_key : !llvm.ptr
%123 = llvm.load %122 : !llvm.ptr -> !llvm.ptr
%124 = llvm.getelementptr %123[%94] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%121 = llvm.load %124 : !llvm.ptr -> i64
%125 = arith.constant 0 : i32
%127 = arith.extsi %125 : i32 to i64
%126 = arith.cmpi eq, %121, %127 : i64
scf.yield %126 : i1
} else {
%128 = arith.constant false
scf.yield %128 : i1
}
cf.cond_br %120, ^bb18, ^bb19
^bb18:
%129 = arith.constant 1 : i32
%131 = arith.constant 0 : i32
%130 = arith.subi %131, %129 : i32
%132 = arith.extsi %130 : i32 to i64
func.return %132 : i64
^bb19:
cf.br ^bb20
^bb20:
%133 = llvm.load %84 : !llvm.ptr -> i64
%134 = arith.constant 1 : i32
%136 = arith.extsi %134 : i32 to i64
%135 = arith.addi %133, %136 : i64
llvm.store %135, %84 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%137 = arith.constant 1 : i32
%139 = arith.constant 0 : i32
%138 = arith.subi %139, %137 : i32
%140 = arith.extsi %138 : i32 to i64
func.return %140 : i64
}
func.func @next_perm_inplace(%arg0: !llvm.ptr, %arg1: i32) -> i32 {
%141 = arith.constant 2 : i32
%142 = arith.subi %arg1, %141 : i32
%143 = llvm.mlir.constant(1 : i64) : i64
%144 = llvm.alloca %143 x i32 : (i64) -> !llvm.ptr
llvm.store %142, %144 : i32, !llvm.ptr
cf.br ^bb21
^bb21:
%145 = llvm.load %144 : !llvm.ptr -> i32
%146 = arith.constant 0 : i32
%147 = arith.cmpi sge, %145, %146 : i32
%148 = scf.if %147 -> (i1) {
%150 = llvm.load %144 : !llvm.ptr -> i32
%151 = arith.extsi %150 : i32 to i64
%152 = llvm.getelementptr %arg0[%151] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%149 = llvm.load %152 : !llvm.ptr -> i8
%154 = llvm.load %144 : !llvm.ptr -> i32
%155 = arith.constant 1 : i32
%156 = arith.addi %154, %155 : i32
%157 = arith.extsi %156 : i32 to i64
%158 = llvm.getelementptr %arg0[%157] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%153 = llvm.load %158 : !llvm.ptr -> i8
%160 = arith.extsi %149 : i8 to i32
%161 = arith.extsi %153 : i8 to i32
%159 = arith.cmpi sge, %160, %161 : i32
scf.yield %159 : i1
} else {
%162 = arith.constant false
scf.yield %162 : i1
}
cf.cond_br %148, ^bb22, ^bb23
^bb22:
%163 = llvm.load %144 : !llvm.ptr -> i32
%164 = arith.constant 1 : i32
%165 = arith.subi %163, %164 : i32
llvm.store %165, %144 : i32, !llvm.ptr
cf.br ^bb21
^bb23:
%166 = llvm.load %144 : !llvm.ptr -> i32
%167 = arith.constant 0 : i32
%168 = arith.cmpi slt, %166, %167 : i32
cf.cond_br %168, ^bb24, ^bb25
^bb24:
%169 = arith.constant 0 : i32
func.return %169 : i32
^bb25:
cf.br ^bb26
^bb26:
%170 = arith.constant 1 : i32
%171 = arith.subi %arg1, %170 : i32
%172 = llvm.mlir.constant(1 : i64) : i64
%173 = llvm.alloca %172 x i32 : (i64) -> !llvm.ptr
llvm.store %171, %173 : i32, !llvm.ptr
cf.br ^bb27
^bb27:
%175 = llvm.load %173 : !llvm.ptr -> i32
%176 = arith.extsi %175 : i32 to i64
%177 = llvm.getelementptr %arg0[%176] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%174 = llvm.load %177 : !llvm.ptr -> i8
%179 = llvm.load %144 : !llvm.ptr -> i32
%180 = arith.extsi %179 : i32 to i64
%181 = llvm.getelementptr %arg0[%180] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%178 = llvm.load %181 : !llvm.ptr -> i8
%183 = arith.extsi %174 : i8 to i32
%184 = arith.extsi %178 : i8 to i32
%182 = arith.cmpi sle, %183, %184 : i32
cf.cond_br %182, ^bb28, ^bb29
^bb28:
%185 = llvm.load %173 : !llvm.ptr -> i32
%186 = arith.constant 1 : i32
%187 = arith.subi %185, %186 : i32
llvm.store %187, %173 : i32, !llvm.ptr
cf.br ^bb27
^bb29:
%189 = llvm.load %144 : !llvm.ptr -> i32
%190 = arith.extsi %189 : i32 to i64
%191 = llvm.getelementptr %arg0[%190] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%188 = llvm.load %191 : !llvm.ptr -> i8
%193 = llvm.load %173 : !llvm.ptr -> i32
%194 = arith.extsi %193 : i32 to i64
%195 = llvm.getelementptr %arg0[%194] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%192 = llvm.load %195 : !llvm.ptr -> i8
%196 = llvm.load %144 : !llvm.ptr -> i32
%197 = arith.extsi %196 : i32 to i64
%198 = llvm.getelementptr %arg0[%197] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %192, %198 : i8, !llvm.ptr
%199 = llvm.load %173 : !llvm.ptr -> i32
%200 = arith.extsi %199 : i32 to i64
%201 = llvm.getelementptr %arg0[%200] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %188, %201 : i8, !llvm.ptr
%202 = llvm.load %144 : !llvm.ptr -> i32
%203 = arith.constant 1 : i32
%204 = arith.addi %202, %203 : i32
%205 = llvm.mlir.constant(1 : i64) : i64
%206 = llvm.alloca %205 x i32 : (i64) -> !llvm.ptr
llvm.store %204, %206 : i32, !llvm.ptr
%207 = arith.constant 1 : i32
%208 = arith.subi %arg1, %207 : i32
%209 = llvm.mlir.constant(1 : i64) : i64
%210 = llvm.alloca %209 x i32 : (i64) -> !llvm.ptr
llvm.store %208, %210 : i32, !llvm.ptr
cf.br ^bb30
^bb30:
%211 = llvm.load %206 : !llvm.ptr -> i32
%212 = llvm.load %210 : !llvm.ptr -> i32
%213 = arith.cmpi slt, %211, %212 : i32
cf.cond_br %213, ^bb31, ^bb32
^bb31:
%215 = llvm.load %206 : !llvm.ptr -> i32
%216 = arith.extsi %215 : i32 to i64
%217 = llvm.getelementptr %arg0[%216] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%214 = llvm.load %217 : !llvm.ptr -> i8
%219 = llvm.load %210 : !llvm.ptr -> i32
%220 = arith.extsi %219 : i32 to i64
%221 = llvm.getelementptr %arg0[%220] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%218 = llvm.load %221 : !llvm.ptr -> i8
%222 = llvm.load %206 : !llvm.ptr -> i32
%223 = arith.extsi %222 : i32 to i64
%224 = llvm.getelementptr %arg0[%223] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %218, %224 : i8, !llvm.ptr
%225 = llvm.load %210 : !llvm.ptr -> i32
%226 = arith.extsi %225 : i32 to i64
%227 = llvm.getelementptr %arg0[%226] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %214, %227 : i8, !llvm.ptr
%228 = llvm.load %206 : !llvm.ptr -> i32
%229 = arith.constant 1 : i32
%230 = arith.addi %228, %229 : i32
llvm.store %230, %206 : i32, !llvm.ptr
%231 = llvm.load %210 : !llvm.ptr -> i32
%232 = arith.constant 1 : i32
%233 = arith.subi %231, %232 : i32
llvm.store %233, %210 : i32, !llvm.ptr
cf.br ^bb30
^bb32:
%234 = arith.constant 1 : i32
func.return %234 : i32
}
func.func @B_small(%arg0: i64) -> i64 {
%236 = arith.constant 20 : i32
%237 = arith.constant 1 : i32
%238 = arith.extsi %236 : i32 to i64
%239 = arith.extsi %237 : i32 to i64
%235 = func.call @calloc(%238, %239) : (i64, i64) -> !llvm.ptr
%240 = arith.constant 0 : i32
%241 = llvm.mlir.constant(1 : i64) : i64
%242 = llvm.alloca %241 x i32 : (i64) -> !llvm.ptr
llvm.store %240, %242 : i32, !llvm.ptr
%243 = llvm.mlir.constant(1 : i64) : i64
%244 = llvm.alloca %243 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %244 : i64, !llvm.ptr
%245 = llvm.load %244 : !llvm.ptr -> i64
%246 = arith.constant 0 : i32
%248 = arith.extsi %246 : i32 to i64
%247 = arith.cmpi eq, %245, %248 : i64
cf.cond_br %247, ^bb33, ^bb34
^bb33:
%249 = arith.constant 0 : i32
%250 = arith.constant 0 : i32
%251 = arith.trunci %249 : i32 to i8
%252 = arith.extsi %250 : i32 to i64
%253 = llvm.getelementptr %235[%252] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %251, %253 : i8, !llvm.ptr
%254 = arith.constant 1 : i32
llvm.store %254, %242 : i32, !llvm.ptr
cf.br ^bb35
^bb34:
cf.br ^bb36
^bb36:
%255 = llvm.load %244 : !llvm.ptr -> i64
%256 = arith.constant 0 : i32
%258 = arith.extsi %256 : i32 to i64
%257 = arith.cmpi sgt, %255, %258 : i64
cf.cond_br %257, ^bb37, ^bb38
^bb37:
%259 = llvm.load %244 : !llvm.ptr -> i64
%260 = arith.constant 10 : i32
%262 = arith.extsi %260 : i32 to i64
%261 = arith.remsi %259, %262 : i64
%263 = arith.trunci %261 : i64 to i8
%264 = llvm.load %242 : !llvm.ptr -> i32
%265 = arith.extsi %264 : i32 to i64
%266 = llvm.getelementptr %235[%265] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %263, %266 : i8, !llvm.ptr
%267 = llvm.load %242 : !llvm.ptr -> i32
%268 = arith.constant 1 : i32
%269 = arith.addi %267, %268 : i32
llvm.store %269, %242 : i32, !llvm.ptr
%270 = llvm.load %244 : !llvm.ptr -> i64
%271 = arith.constant 10 : i32
%273 = arith.extsi %271 : i32 to i64
%272 = arith.divsi %270, %273 : i64
llvm.store %272, %244 : i64, !llvm.ptr
cf.br ^bb36
^bb38:
%274 = arith.constant 0 : i32
%275 = llvm.mlir.constant(1 : i64) : i64
%276 = llvm.alloca %275 x i32 : (i64) -> !llvm.ptr
llvm.store %274, %276 : i32, !llvm.ptr
cf.br ^bb39
^bb39:
%277 = llvm.load %276 : !llvm.ptr -> i32
%278 = llvm.load %242 : !llvm.ptr -> i32
%279 = arith.constant 2 : i32
%280 = arith.divsi %278, %279 : i32
%281 = arith.cmpi slt, %277, %280 : i32
cf.cond_br %281, ^bb40, ^bb41
^bb40:
%283 = llvm.load %276 : !llvm.ptr -> i32
%284 = arith.extsi %283 : i32 to i64
%285 = llvm.getelementptr %235[%284] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%282 = llvm.load %285 : !llvm.ptr -> i8
%287 = llvm.load %242 : !llvm.ptr -> i32
%288 = arith.constant 1 : i32
%289 = arith.subi %287, %288 : i32
%290 = llvm.load %276 : !llvm.ptr -> i32
%291 = arith.subi %289, %290 : i32
%292 = arith.extsi %291 : i32 to i64
%293 = llvm.getelementptr %235[%292] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%286 = llvm.load %293 : !llvm.ptr -> i8
%294 = llvm.load %276 : !llvm.ptr -> i32
%295 = arith.extsi %294 : i32 to i64
%296 = llvm.getelementptr %235[%295] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %286, %296 : i8, !llvm.ptr
%297 = llvm.load %242 : !llvm.ptr -> i32
%298 = arith.constant 1 : i32
%299 = arith.subi %297, %298 : i32
%300 = llvm.load %276 : !llvm.ptr -> i32
%301 = arith.subi %299, %300 : i32
%302 = arith.extsi %301 : i32 to i64
%303 = llvm.getelementptr %235[%302] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %282, %303 : i8, !llvm.ptr
%304 = llvm.load %276 : !llvm.ptr -> i32
%305 = arith.constant 1 : i32
%306 = arith.addi %304, %305 : i32
llvm.store %306, %276 : i32, !llvm.ptr
cf.br ^bb39
^bb41:
cf.br ^bb35
^bb35:
%308 = llvm.load %242 : !llvm.ptr -> i32
%307 = func.call @next_perm_inplace(%235, %308) : (!llvm.ptr, i32) -> i32
%309 = arith.constant 0 : i32
%310 = arith.cmpi eq, %307, %309 : i32
cf.cond_br %310, ^bb42, ^bb43
^bb42:
func.call @free(%235) : (!llvm.ptr) -> ()
%312 = arith.constant 0 : i32
%313 = arith.extsi %312 : i32 to i64
func.return %313 : i64
^bb43:
cf.br ^bb44
^bb44:
%314 = arith.constant 0 : i32
%315 = arith.extsi %314 : i32 to i64
%316 = llvm.mlir.constant(1 : i64) : i64
%317 = llvm.alloca %316 x i64 : (i64) -> !llvm.ptr
llvm.store %315, %317 : i64, !llvm.ptr
%318 = arith.constant 0 : i32
%319 = llvm.mlir.constant(1 : i64) : i64
%320 = llvm.alloca %319 x i32 : (i64) -> !llvm.ptr
llvm.store %318, %320 : i32, !llvm.ptr
cf.br ^bb45
^bb45:
%321 = llvm.load %320 : !llvm.ptr -> i32
%322 = llvm.load %242 : !llvm.ptr -> i32
%323 = arith.cmpi slt, %321, %322 : i32
cf.cond_br %323, ^bb46, ^bb47
^bb46:
%324 = llvm.load %317 : !llvm.ptr -> i64
%325 = arith.constant 10 : i32
%327 = arith.extsi %325 : i32 to i64
%326 = arith.muli %324, %327 : i64
%329 = llvm.load %320 : !llvm.ptr -> i32
%330 = arith.extsi %329 : i32 to i64
%331 = llvm.getelementptr %235[%330] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%328 = llvm.load %331 : !llvm.ptr -> i8
%332 = arith.extsi %328 : i8 to i64
%333 = arith.addi %326, %332 : i64
llvm.store %333, %317 : i64, !llvm.ptr
%334 = llvm.load %320 : !llvm.ptr -> i32
%335 = arith.constant 1 : i32
%336 = arith.addi %334, %335 : i32
llvm.store %336, %320 : i32, !llvm.ptr
cf.br ^bb45
^bb47:
func.call @free(%235) : (!llvm.ptr) -> ()
%338 = llvm.load %317 : !llvm.ptr -> i64
func.return %338 : i64
}
func.func @next_perm_fixed(%arg0: i64, %arg1: i32, %arg2: !llvm.ptr) -> i64 {
%339 = llvm.mlir.constant(1 : i64) : i64
%340 = llvm.alloca %339 x i64 : (i64) -> !llvm.ptr
llvm.store %arg0, %340 : i64, !llvm.ptr
%341 = arith.constant 1 : i32
%342 = arith.subi %arg1, %341 : i32
%343 = llvm.mlir.constant(1 : i64) : i64
%344 = llvm.alloca %343 x i32 : (i64) -> !llvm.ptr
llvm.store %342, %344 : i32, !llvm.ptr
cf.br ^bb48
^bb48:
%345 = llvm.load %344 : !llvm.ptr -> i32
%346 = arith.constant 0 : i32
%347 = arith.cmpi sge, %345, %346 : i32
cf.cond_br %347, ^bb49, ^bb50
^bb49:
%348 = llvm.load %340 : !llvm.ptr -> i64
%349 = arith.constant 10 : i32
%351 = arith.extsi %349 : i32 to i64
%350 = arith.remsi %348, %351 : i64
%352 = arith.trunci %350 : i64 to i8
%353 = llvm.load %344 : !llvm.ptr -> i32
%354 = arith.extsi %353 : i32 to i64
%355 = llvm.getelementptr %arg2[%354] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %352, %355 : i8, !llvm.ptr
%356 = llvm.load %340 : !llvm.ptr -> i64
%357 = arith.constant 10 : i32
%359 = arith.extsi %357 : i32 to i64
%358 = arith.divsi %356, %359 : i64
llvm.store %358, %340 : i64, !llvm.ptr
%360 = llvm.load %344 : !llvm.ptr -> i32
%361 = arith.constant 1 : i32
%362 = arith.subi %360, %361 : i32
llvm.store %362, %344 : i32, !llvm.ptr
cf.br ^bb48
^bb50:
%363 = arith.constant 2 : i32
%364 = arith.subi %arg1, %363 : i32
%365 = llvm.mlir.constant(1 : i64) : i64
%366 = llvm.alloca %365 x i32 : (i64) -> !llvm.ptr
llvm.store %364, %366 : i32, !llvm.ptr
cf.br ^bb51
^bb51:
%367 = llvm.load %366 : !llvm.ptr -> i32
%368 = arith.constant 0 : i32
%369 = arith.cmpi sge, %367, %368 : i32
%370 = scf.if %369 -> (i1) {
%372 = llvm.load %366 : !llvm.ptr -> i32
%373 = arith.extsi %372 : i32 to i64
%374 = llvm.getelementptr %arg2[%373] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%371 = llvm.load %374 : !llvm.ptr -> i8
%376 = llvm.load %366 : !llvm.ptr -> i32
%377 = arith.constant 1 : i32
%378 = arith.addi %376, %377 : i32
%379 = arith.extsi %378 : i32 to i64
%380 = llvm.getelementptr %arg2[%379] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%375 = llvm.load %380 : !llvm.ptr -> i8
%382 = arith.extsi %371 : i8 to i32
%383 = arith.extsi %375 : i8 to i32
%381 = arith.cmpi sge, %382, %383 : i32
scf.yield %381 : i1
} else {
%384 = arith.constant false
scf.yield %384 : i1
}
cf.cond_br %370, ^bb52, ^bb53
^bb52:
%385 = llvm.load %366 : !llvm.ptr -> i32
%386 = arith.constant 1 : i32
%387 = arith.subi %385, %386 : i32
llvm.store %387, %366 : i32, !llvm.ptr
cf.br ^bb51
^bb53:
%388 = llvm.load %366 : !llvm.ptr -> i32
%389 = arith.constant 0 : i32
%390 = arith.cmpi slt, %388, %389 : i32
cf.cond_br %390, ^bb54, ^bb55
^bb54:
%391 = arith.constant 1 : i32
%393 = arith.constant 0 : i32
%392 = arith.subi %393, %391 : i32
%394 = arith.extsi %392 : i32 to i64
func.return %394 : i64
^bb55:
cf.br ^bb56
^bb56:
%395 = arith.constant 1 : i32
%396 = arith.subi %arg1, %395 : i32
%397 = llvm.mlir.constant(1 : i64) : i64
%398 = llvm.alloca %397 x i32 : (i64) -> !llvm.ptr
llvm.store %396, %398 : i32, !llvm.ptr
cf.br ^bb57
^bb57:
%400 = llvm.load %398 : !llvm.ptr -> i32
%401 = arith.extsi %400 : i32 to i64
%402 = llvm.getelementptr %arg2[%401] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%399 = llvm.load %402 : !llvm.ptr -> i8
%404 = llvm.load %366 : !llvm.ptr -> i32
%405 = arith.extsi %404 : i32 to i64
%406 = llvm.getelementptr %arg2[%405] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%403 = llvm.load %406 : !llvm.ptr -> i8
%408 = arith.extsi %399 : i8 to i32
%409 = arith.extsi %403 : i8 to i32
%407 = arith.cmpi sle, %408, %409 : i32
cf.cond_br %407, ^bb58, ^bb59
^bb58:
%410 = llvm.load %398 : !llvm.ptr -> i32
%411 = arith.constant 1 : i32
%412 = arith.subi %410, %411 : i32
llvm.store %412, %398 : i32, !llvm.ptr
cf.br ^bb57
^bb59:
%414 = llvm.load %366 : !llvm.ptr -> i32
%415 = arith.extsi %414 : i32 to i64
%416 = llvm.getelementptr %arg2[%415] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%413 = llvm.load %416 : !llvm.ptr -> i8
%418 = llvm.load %398 : !llvm.ptr -> i32
%419 = arith.extsi %418 : i32 to i64
%420 = llvm.getelementptr %arg2[%419] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%417 = llvm.load %420 : !llvm.ptr -> i8
%421 = llvm.load %366 : !llvm.ptr -> i32
%422 = arith.extsi %421 : i32 to i64
%423 = llvm.getelementptr %arg2[%422] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %417, %423 : i8, !llvm.ptr
%424 = llvm.load %398 : !llvm.ptr -> i32
%425 = arith.extsi %424 : i32 to i64
%426 = llvm.getelementptr %arg2[%425] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %413, %426 : i8, !llvm.ptr
%427 = llvm.load %366 : !llvm.ptr -> i32
%428 = arith.constant 1 : i32
%429 = arith.addi %427, %428 : i32
%430 = llvm.mlir.constant(1 : i64) : i64
%431 = llvm.alloca %430 x i32 : (i64) -> !llvm.ptr
llvm.store %429, %431 : i32, !llvm.ptr
%432 = arith.constant 1 : i32
%433 = arith.subi %arg1, %432 : i32
%434 = llvm.mlir.constant(1 : i64) : i64
%435 = llvm.alloca %434 x i32 : (i64) -> !llvm.ptr
llvm.store %433, %435 : i32, !llvm.ptr
cf.br ^bb60
^bb60:
%436 = llvm.load %431 : !llvm.ptr -> i32
%437 = llvm.load %435 : !llvm.ptr -> i32
%438 = arith.cmpi slt, %436, %437 : i32
cf.cond_br %438, ^bb61, ^bb62
^bb61:
%440 = llvm.load %431 : !llvm.ptr -> i32
%441 = arith.extsi %440 : i32 to i64
%442 = llvm.getelementptr %arg2[%441] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%439 = llvm.load %442 : !llvm.ptr -> i8
%444 = llvm.load %435 : !llvm.ptr -> i32
%445 = arith.extsi %444 : i32 to i64
%446 = llvm.getelementptr %arg2[%445] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%443 = llvm.load %446 : !llvm.ptr -> i8
%447 = llvm.load %431 : !llvm.ptr -> i32
%448 = arith.extsi %447 : i32 to i64
%449 = llvm.getelementptr %arg2[%448] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %443, %449 : i8, !llvm.ptr
%450 = llvm.load %435 : !llvm.ptr -> i32
%451 = arith.extsi %450 : i32 to i64
%452 = llvm.getelementptr %arg2[%451] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %439, %452 : i8, !llvm.ptr
%453 = llvm.load %431 : !llvm.ptr -> i32
%454 = arith.constant 1 : i32
%455 = arith.addi %453, %454 : i32
llvm.store %455, %431 : i32, !llvm.ptr
%456 = llvm.load %435 : !llvm.ptr -> i32
%457 = arith.constant 1 : i32
%458 = arith.subi %456, %457 : i32
llvm.store %458, %435 : i32, !llvm.ptr
cf.br ^bb60
^bb62:
%459 = arith.constant 0 : i32
%460 = arith.extsi %459 : i32 to i64
%461 = llvm.mlir.constant(1 : i64) : i64
%462 = llvm.alloca %461 x i64 : (i64) -> !llvm.ptr
llvm.store %460, %462 : i64, !llvm.ptr
%463 = arith.constant 0 : i32
%464 = llvm.mlir.constant(1 : i64) : i64
%465 = llvm.alloca %464 x i32 : (i64) -> !llvm.ptr
llvm.store %463, %465 : i32, !llvm.ptr
cf.br ^bb63
^bb63:
%466 = llvm.load %465 : !llvm.ptr -> i32
%467 = arith.cmpi slt, %466, %arg1 : i32
cf.cond_br %467, ^bb64, ^bb65
^bb64:
%468 = llvm.load %462 : !llvm.ptr -> i64
%469 = arith.constant 10 : i32
%471 = arith.extsi %469 : i32 to i64
%470 = arith.muli %468, %471 : i64
%473 = llvm.load %465 : !llvm.ptr -> i32
%474 = arith.extsi %473 : i32 to i64
%475 = llvm.getelementptr %arg2[%474] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%472 = llvm.load %475 : !llvm.ptr -> i8
%476 = arith.extsi %472 : i8 to i64
%477 = arith.addi %470, %476 : i64
llvm.store %477, %462 : i64, !llvm.ptr
%478 = llvm.load %465 : !llvm.ptr -> i32
%479 = arith.constant 1 : i32
%480 = arith.addi %478, %479 : i32
llvm.store %480, %465 : i32, !llvm.ptr
cf.br ^bb63
^bb65:
%481 = llvm.load %462 : !llvm.ptr -> i64
func.return %481 : i64
}
func.func @sum_a_mod(%arg0: i64) -> i64 {
%483 = arith.constant 200000 : i32
%484 = arith.constant 8 : i32
%485 = arith.extsi %483 : i32 to i64
%486 = arith.extsi %484 : i32 to i64
%482 = func.call @calloc(%485, %486) : (i64, i64) -> !llvm.ptr
%488 = arith.constant 200000 : i32
%489 = arith.constant 8 : i32
%490 = arith.extsi %488 : i32 to i64
%491 = arith.extsi %489 : i32 to i64
%487 = func.call @calloc(%490, %491) : (i64, i64) -> !llvm.ptr
func.call @ht_init() : () -> ()
%493 = arith.constant 0 : i32
%494 = arith.constant 0 : i32
%495 = arith.extsi %493 : i32 to i64
%496 = arith.extsi %494 : i32 to i64
%497 = llvm.getelementptr %482[%496] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %495, %497 : i64, !llvm.ptr
%499 = arith.constant 0 : i32
%500 = arith.constant 0 : i32
%501 = arith.extsi %499 : i32 to i64
%502 = arith.extsi %500 : i32 to i64
func.call @ht_put(%501, %502) : (i64, i64) -> ()
%503 = arith.constant 1 : i32
%504 = llvm.mlir.constant(1 : i64) : i64
%505 = llvm.alloca %504 x i32 : (i64) -> !llvm.ptr
llvm.store %503, %505 : i32, !llvm.ptr
%506 = arith.constant 0 : i32
%507 = arith.extsi %506 : i32 to i64
%508 = llvm.mlir.constant(1 : i64) : i64
%509 = llvm.alloca %508 x i64 : (i64) -> !llvm.ptr
llvm.store %507, %509 : i64, !llvm.ptr
%510 = arith.constant 0 : i32
%511 = arith.extsi %510 : i32 to i64
%512 = llvm.mlir.constant(1 : i64) : i64
%513 = llvm.alloca %512 x i64 : (i64) -> !llvm.ptr
llvm.store %511, %513 : i64, !llvm.ptr
%514 = arith.constant 0 : i32
%515 = arith.extsi %514 : i32 to i64
%516 = llvm.mlir.constant(1 : i64) : i64
%517 = llvm.alloca %516 x i64 : (i64) -> !llvm.ptr
llvm.store %515, %517 : i64, !llvm.ptr
cf.br ^bb66
^bb66:
%518 = arith.constant 1 : i1
cf.cond_br %518, ^bb67, ^bb68
^bb67:
%519 = llvm.load %509 : !llvm.ptr -> i64
%520 = llvm.load %509 : !llvm.ptr -> i64
%521 = arith.muli %519, %520 : i64
%522 = arith.constant 2 : i32
%524 = arith.extsi %522 : i32 to i64
%523 = arith.addi %521, %524 : i64
%525 = llvm.mlir.addressof @MOD : !llvm.ptr
%526 = llvm.load %525 : !llvm.ptr -> i64
%527 = arith.remsi %523, %526 : i64
%528 = llvm.load %505 : !llvm.ptr -> i32
%529 = arith.extsi %528 : i32 to i64
%530 = arith.constant 1 : i32
%532 = arith.constant 0 : i32
%531 = arith.subi %532, %530 : i32
%533 = arith.extsi %531 : i32 to i64
%534 = llvm.mlir.constant(1 : i64) : i64
%535 = llvm.alloca %534 x i64 : (i64) -> !llvm.ptr
llvm.store %533, %535 : i64, !llvm.ptr
%536 = arith.constant 0 : i32
%538 = arith.extsi %536 : i32 to i64
%537 = arith.cmpi eq, %527, %538 : i64
cf.cond_br %537, ^bb69, ^bb70
^bb69:
%539 = arith.constant 0 : i32
%540 = arith.extsi %539 : i32 to i64
llvm.store %540, %535 : i64, !llvm.ptr
cf.br ^bb71
^bb70:
%541 = func.call @ht_get(%527) : (i64) -> i64
llvm.store %541, %535 : i64, !llvm.ptr
cf.br ^bb71
^bb71:
%542 = llvm.load %535 : !llvm.ptr -> i64
%543 = arith.constant 0 : i32
%545 = arith.extsi %543 : i32 to i64
%544 = arith.cmpi sge, %542, %545 : i64
cf.cond_br %544, ^bb72, ^bb73
^bb72:
%546 = llvm.load %535 : !llvm.ptr -> i64
llvm.store %546, %513 : i64, !llvm.ptr
%547 = llvm.load %535 : !llvm.ptr -> i64
%548 = arith.subi %529, %547 : i64
llvm.store %548, %517 : i64, !llvm.ptr
cf.br ^bb68
^bb73:
cf.br ^bb74
^bb74:
func.call @ht_put(%527, %529) : (i64, i64) -> ()
%550 = llvm.load %505 : !llvm.ptr -> i32
%551 = arith.extsi %550 : i32 to i64
%552 = llvm.getelementptr %482[%551] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %527, %552 : i64, !llvm.ptr
%553 = llvm.load %505 : !llvm.ptr -> i32
%554 = arith.constant 1 : i32
%555 = arith.addi %553, %554 : i32
llvm.store %555, %505 : i32, !llvm.ptr
llvm.store %527, %509 : i64, !llvm.ptr
cf.br ^bb66
^bb68:
%556 = arith.constant 0 : i32
%557 = arith.constant 0 : i32
%558 = arith.extsi %556 : i32 to i64
%559 = arith.extsi %557 : i32 to i64
%560 = llvm.getelementptr %487[%559] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %558, %560 : i64, !llvm.ptr
%561 = arith.constant 1 : i32
%562 = llvm.mlir.constant(1 : i64) : i64
%563 = llvm.alloca %562 x i32 : (i64) -> !llvm.ptr
llvm.store %561, %563 : i32, !llvm.ptr
cf.br ^bb75
^bb75:
%564 = llvm.load %563 : !llvm.ptr -> i32
%565 = llvm.load %505 : !llvm.ptr -> i32
%566 = arith.cmpi slt, %564, %565 : i32
cf.cond_br %566, ^bb76, ^bb77
^bb76:
%568 = llvm.load %563 : !llvm.ptr -> i32
%569 = arith.constant 1 : i32
%570 = arith.subi %568, %569 : i32
%571 = arith.extsi %570 : i32 to i64
%572 = llvm.getelementptr %487[%571] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%567 = llvm.load %572 : !llvm.ptr -> i64
%574 = llvm.load %563 : !llvm.ptr -> i32
%575 = arith.extsi %574 : i32 to i64
%576 = llvm.getelementptr %482[%575] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%573 = llvm.load %576 : !llvm.ptr -> i64
%577 = arith.addi %567, %573 : i64
%578 = llvm.mlir.addressof @MOD : !llvm.ptr
%579 = llvm.load %578 : !llvm.ptr -> i64
%580 = arith.remsi %577, %579 : i64
%581 = llvm.load %563 : !llvm.ptr -> i32
%582 = arith.extsi %581 : i32 to i64
%583 = llvm.getelementptr %487[%582] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %580, %583 : i64, !llvm.ptr
%584 = llvm.load %563 : !llvm.ptr -> i32
%585 = arith.constant 1 : i32
%586 = arith.addi %584, %585 : i32
llvm.store %586, %563 : i32, !llvm.ptr
cf.br ^bb75
^bb77:
%587 = llvm.load %505 : !llvm.ptr -> i32
%588 = arith.extsi %587 : i32 to i64
%589 = arith.cmpi slt, %arg0, %588 : i64
cf.cond_br %589, ^bb78, ^bb79
^bb78:
%591 = arith.trunci %arg0 : i64 to i32
%592 = arith.extsi %591 : i32 to i64
%593 = llvm.getelementptr %487[%592] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%590 = llvm.load %593 : !llvm.ptr -> i64
func.call @free(%482) : (!llvm.ptr) -> ()
func.call @free(%487) : (!llvm.ptr) -> ()
func.return %590 : i64
^bb79:
cf.br ^bb80
^bb80:
%596 = llvm.load %513 : !llvm.ptr -> i64
%597 = arith.constant 0 : i32
%599 = arith.extsi %597 : i32 to i64
%598 = arith.cmpi sgt, %596, %599 : i64
%600 = scf.if %598 -> (i64) {
%602 = llvm.load %513 : !llvm.ptr -> i64
%603 = arith.constant 1 : i32
%605 = arith.extsi %603 : i32 to i64
%604 = arith.subi %602, %605 : i64
%606 = arith.trunci %604 : i64 to i32
%607 = arith.extsi %606 : i32 to i64
%608 = llvm.getelementptr %487[%607] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%601 = llvm.load %608 : !llvm.ptr -> i64
scf.yield %601 : i64
} else {
%609 = arith.constant 0 : i32
scf.yield %609 : i32
}
%611 = llvm.load %513 : !llvm.ptr -> i64
%612 = llvm.load %517 : !llvm.ptr -> i64
%613 = arith.addi %611, %612 : i64
%614 = arith.constant 1 : i32
%616 = arith.extsi %614 : i32 to i64
%615 = arith.subi %613, %616 : i64
%617 = arith.trunci %615 : i64 to i32
%618 = arith.extsi %617 : i32 to i64
%619 = llvm.getelementptr %487[%618] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%610 = llvm.load %619 : !llvm.ptr -> i64
%620 = arith.subi %610, %600 : i64
%621 = llvm.mlir.addressof @MOD : !llvm.ptr
%622 = llvm.load %621 : !llvm.ptr -> i64
%623 = arith.remsi %620, %622 : i64
%624 = llvm.mlir.constant(1 : i64) : i64
%625 = llvm.alloca %624 x i64 : (i64) -> !llvm.ptr
llvm.store %623, %625 : i64, !llvm.ptr
%626 = llvm.load %625 : !llvm.ptr -> i64
%627 = arith.constant 0 : i32
%629 = arith.extsi %627 : i32 to i64
%628 = arith.cmpi slt, %626, %629 : i64
cf.cond_br %628, ^bb81, ^bb82
^bb81:
%630 = llvm.load %625 : !llvm.ptr -> i64
%631 = llvm.mlir.addressof @MOD : !llvm.ptr
%632 = llvm.load %631 : !llvm.ptr -> i64
%633 = arith.addi %630, %632 : i64
llvm.store %633, %625 : i64, !llvm.ptr
cf.br ^bb83
^bb82:
cf.br ^bb83
^bb83:
%634 = llvm.load %513 : !llvm.ptr -> i64
%635 = arith.subi %arg0, %634 : i64
%636 = arith.constant 1 : i32
%638 = arith.extsi %636 : i32 to i64
%637 = arith.addi %635, %638 : i64
%639 = llvm.load %517 : !llvm.ptr -> i64
%640 = arith.divsi %637, %639 : i64
%641 = llvm.load %517 : !llvm.ptr -> i64
%642 = arith.remsi %637, %641 : i64
%643 = llvm.mlir.addressof @MOD : !llvm.ptr
%644 = llvm.load %643 : !llvm.ptr -> i64
%645 = arith.remsi %640, %644 : i64
%646 = llvm.load %625 : !llvm.ptr -> i64
%647 = arith.muli %645, %646 : i64
%648 = arith.addi %600, %647 : i64
%649 = llvm.mlir.addressof @MOD : !llvm.ptr
%650 = llvm.load %649 : !llvm.ptr -> i64
%651 = arith.remsi %648, %650 : i64
%652 = llvm.mlir.constant(1 : i64) : i64
%653 = llvm.alloca %652 x i64 : (i64) -> !llvm.ptr
llvm.store %651, %653 : i64, !llvm.ptr
%654 = arith.constant 0 : i32
%656 = arith.extsi %654 : i32 to i64
%655 = arith.cmpi ne, %642, %656 : i64
cf.cond_br %655, ^bb84, ^bb85
^bb84:
%658 = llvm.load %513 : !llvm.ptr -> i64
%659 = arith.addi %658, %642 : i64
%660 = arith.constant 1 : i32
%662 = arith.extsi %660 : i32 to i64
%661 = arith.subi %659, %662 : i64
%663 = arith.trunci %661 : i64 to i32
%664 = arith.extsi %663 : i32 to i64
%665 = llvm.getelementptr %487[%664] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%657 = llvm.load %665 : !llvm.ptr -> i64
%666 = arith.subi %657, %600 : i64
%667 = llvm.mlir.addressof @MOD : !llvm.ptr
%668 = llvm.load %667 : !llvm.ptr -> i64
%669 = arith.remsi %666, %668 : i64
%670 = llvm.mlir.constant(1 : i64) : i64
%671 = llvm.alloca %670 x i64 : (i64) -> !llvm.ptr
llvm.store %669, %671 : i64, !llvm.ptr
%672 = llvm.load %671 : !llvm.ptr -> i64
%673 = arith.constant 0 : i32
%675 = arith.extsi %673 : i32 to i64
%674 = arith.cmpi slt, %672, %675 : i64
cf.cond_br %674, ^bb87, ^bb88
^bb87:
%676 = llvm.load %671 : !llvm.ptr -> i64
%677 = llvm.mlir.addressof @MOD : !llvm.ptr
%678 = llvm.load %677 : !llvm.ptr -> i64
%679 = arith.addi %676, %678 : i64
llvm.store %679, %671 : i64, !llvm.ptr
cf.br ^bb89
^bb88:
cf.br ^bb89
^bb89:
%680 = llvm.load %653 : !llvm.ptr -> i64
%681 = llvm.load %671 : !llvm.ptr -> i64
%682 = arith.addi %680, %681 : i64
%683 = llvm.mlir.addressof @MOD : !llvm.ptr
%684 = llvm.load %683 : !llvm.ptr -> i64
%685 = arith.remsi %682, %684 : i64
llvm.store %685, %653 : i64, !llvm.ptr
cf.br ^bb86
^bb85:
cf.br ^bb86
^bb86:
func.call @free(%482) : (!llvm.ptr) -> ()
func.call @free(%487) : (!llvm.ptr) -> ()
%688 = llvm.load %653 : !llvm.ptr -> i64
func.return %688 : i64
}
func.func @delta_small(%arg0: i64) -> i64 {
%689 = arith.constant 0 : i32
%690 = arith.extsi %689 : i32 to i64
%691 = llvm.mlir.constant(1 : i64) : i64
%692 = llvm.alloca %691 x i64 : (i64) -> !llvm.ptr
llvm.store %690, %692 : i64, !llvm.ptr
%693 = arith.constant 0 : i32
%694 = arith.extsi %693 : i32 to i64
%695 = llvm.mlir.constant(1 : i64) : i64
%696 = llvm.alloca %695 x i64 : (i64) -> !llvm.ptr
llvm.store %694, %696 : i64, !llvm.ptr
%697 = arith.constant 5 : i32
%699 = arith.extsi %697 : i32 to i64
%698 = arith.cmpi slt, %arg0, %699 : i64
%700 = scf.if %698 -> (i32) {
%701 = arith.trunci %arg0 : i64 to i32
scf.yield %701 : i32
} else {
%702 = arith.constant 5 : i32
scf.yield %702 : i32
}
%703 = arith.constant 1 : i32
%704 = llvm.mlir.constant(1 : i64) : i64
%705 = llvm.alloca %704 x i32 : (i64) -> !llvm.ptr
llvm.store %703, %705 : i32, !llvm.ptr
cf.br ^bb90
^bb90:
%706 = llvm.load %705 : !llvm.ptr -> i32
%707 = arith.cmpi sle, %706, %700 : i32
cf.cond_br %707, ^bb91, ^bb92
^bb91:
%708 = llvm.load %692 : !llvm.ptr -> i64
%709 = llvm.load %692 : !llvm.ptr -> i64
%710 = arith.muli %708, %709 : i64
%711 = arith.constant 2 : i32
%713 = arith.extsi %711 : i32 to i64
%712 = arith.addi %710, %713 : i64
llvm.store %712, %692 : i64, !llvm.ptr
%715 = llvm.load %692 : !llvm.ptr -> i64
%714 = func.call @B_small(%715) : (i64) -> i64
%716 = llvm.load %692 : !llvm.ptr -> i64
%717 = arith.subi %714, %716 : i64
%718 = llvm.mlir.addressof @MOD : !llvm.ptr
%719 = llvm.load %718 : !llvm.ptr -> i64
%720 = arith.remsi %717, %719 : i64
%721 = llvm.mlir.constant(1 : i64) : i64
%722 = llvm.alloca %721 x i64 : (i64) -> !llvm.ptr
llvm.store %720, %722 : i64, !llvm.ptr
%723 = llvm.load %722 : !llvm.ptr -> i64
%724 = arith.constant 0 : i32
%726 = arith.extsi %724 : i32 to i64
%725 = arith.cmpi slt, %723, %726 : i64
cf.cond_br %725, ^bb93, ^bb94
^bb93:
%727 = llvm.load %722 : !llvm.ptr -> i64
%728 = llvm.mlir.addressof @MOD : !llvm.ptr
%729 = llvm.load %728 : !llvm.ptr -> i64
%730 = arith.addi %727, %729 : i64
llvm.store %730, %722 : i64, !llvm.ptr
cf.br ^bb95
^bb94:
cf.br ^bb95
^bb95:
%731 = llvm.load %696 : !llvm.ptr -> i64
%732 = llvm.load %722 : !llvm.ptr -> i64
%733 = arith.addi %731, %732 : i64
%734 = llvm.mlir.addressof @MOD : !llvm.ptr
%735 = llvm.load %734 : !llvm.ptr -> i64
%736 = arith.remsi %733, %735 : i64
llvm.store %736, %696 : i64, !llvm.ptr
%737 = llvm.load %705 : !llvm.ptr -> i32
%738 = arith.constant 1 : i32
%739 = arith.addi %737, %738 : i32
llvm.store %739, %705 : i32, !llvm.ptr
cf.br ^bb90
^bb92:
%740 = llvm.load %696 : !llvm.ptr -> i64
func.return %740 : i64
}
// Module static: g_d10_total
llvm.mlir.global internal @g_d10_total(0 : i64) : i64
// Module static: g_d10_first_bad_n
llvm.mlir.global internal @g_d10_first_bad_n(0 : i64) : i64
// Module static: g_d10_step
llvm.mlir.global internal @g_d10_step(0 : i64) : i64
func.func @delta10_and_bad(%arg0: i64) -> () {
%741 = arith.constant 0 : i32
%742 = arith.extsi %741 : i32 to i64
%743 = llvm.mlir.addressof @g_d10_total : !llvm.ptr
llvm.store %742, %743 : i64, !llvm.ptr
%744 = arith.constant 1 : i32
%746 = arith.constant 0 : i32
%745 = arith.subi %746, %744 : i32
%747 = arith.extsi %745 : i32 to i64
%748 = llvm.mlir.addressof @g_d10_first_bad_n : !llvm.ptr
llvm.store %747, %748 : i64, !llvm.ptr
%749 = arith.constant 0 : i32
%750 = arith.extsi %749 : i32 to i64
%751 = llvm.mlir.addressof @g_d10_step : !llvm.ptr
llvm.store %750, %751 : i64, !llvm.ptr
%752 = arith.constant 5 : i32
%754 = arith.extsi %752 : i32 to i64
%753 = arith.cmpi sle, %arg0, %754 : i64
cf.cond_br %753, ^bb96, ^bb97
^bb96:
func.return
^bb97:
cf.br ^bb98
^bb98:
%755 = arith.constant 10 : i32
%756 = arith.constant 1 : i32
%757 = arith.extsi %756 : i32 to i128
%758 = llvm.mlir.constant(1 : i64) : i64
%759 = llvm.alloca %758 x i128 : (i64) -> !llvm.ptr
llvm.store %757, %759 : i128, !llvm.ptr
%760 = arith.constant 0 : i32
%761 = llvm.mlir.constant(1 : i64) : i64
%762 = llvm.alloca %761 x i32 : (i64) -> !llvm.ptr
llvm.store %760, %762 : i32, !llvm.ptr
cf.br ^bb99
^bb99:
%763 = llvm.load %762 : !llvm.ptr -> i32
%764 = arith.cmpi slt, %763, %755 : i32
cf.cond_br %764, ^bb100, ^bb101
^bb100:
%765 = llvm.load %759 : !llvm.ptr -> i128
%766 = arith.constant 10 : i32
%768 = arith.trunci %765 : i128 to i64
%769 = arith.extsi %766 : i32 to i64
%767 = arith.muli %768, %769 : i64
%770 = arith.extsi %767 : i64 to i128
llvm.store %770, %759 : i128, !llvm.ptr
%771 = llvm.load %762 : !llvm.ptr -> i32
%772 = arith.constant 1 : i32
%773 = arith.addi %771, %772 : i32
llvm.store %773, %762 : i32, !llvm.ptr
cf.br ^bb99
^bb101:
%774 = arith.constant 8 : i32
%775 = arith.extsi %774 : i32 to i64
%776 = llvm.mlir.constant(1 : i64) : i64
%777 = llvm.alloca %776 x i64 : (i64) -> !llvm.ptr
llvm.store %775, %777 : i64, !llvm.ptr
%778 = arith.constant 0 : i32
%779 = llvm.mlir.constant(1 : i64) : i64
%780 = llvm.alloca %779 x i32 : (i64) -> !llvm.ptr
llvm.store %778, %780 : i32, !llvm.ptr
cf.br ^bb102
^bb102:
%781 = llvm.load %780 : !llvm.ptr -> i32
%782 = arith.constant 2 : i32
%783 = arith.subi %755, %782 : i32
%784 = arith.cmpi slt, %781, %783 : i32
cf.cond_br %784, ^bb103, ^bb104
^bb103:
%785 = llvm.load %777 : !llvm.ptr -> i64
%786 = arith.constant 5 : i32
%788 = arith.extsi %786 : i32 to i64
%787 = arith.muli %785, %788 : i64
llvm.store %787, %777 : i64, !llvm.ptr
%789 = llvm.load %780 : !llvm.ptr -> i32
%790 = arith.constant 1 : i32
%791 = arith.addi %789, %790 : i32
llvm.store %791, %780 : i32, !llvm.ptr
cf.br ^bb102
^bb104:
%792 = llvm.load %777 : !llvm.ptr -> i64
%793 = llvm.mlir.addressof @g_d10_step : !llvm.ptr
llvm.store %792, %793 : i64, !llvm.ptr
%794 = arith.constant 0 : i32
%795 = arith.extsi %794 : i32 to i128
%796 = llvm.mlir.constant(1 : i64) : i64
%797 = llvm.alloca %796 x i128 : (i64) -> !llvm.ptr
llvm.store %795, %797 : i128, !llvm.ptr
%798 = arith.constant 0 : i32
%799 = llvm.mlir.constant(1 : i64) : i64
%800 = llvm.alloca %799 x i32 : (i64) -> !llvm.ptr
llvm.store %798, %800 : i32, !llvm.ptr
cf.br ^bb105
^bb105:
%801 = llvm.load %800 : !llvm.ptr -> i32
%802 = arith.constant 6 : i32
%803 = arith.cmpi slt, %801, %802 : i32
cf.cond_br %803, ^bb106, ^bb107
^bb106:
%804 = llvm.load %797 : !llvm.ptr -> i128
%805 = llvm.load %797 : !llvm.ptr -> i128
%807 = arith.trunci %804 : i128 to i64
%808 = arith.trunci %805 : i128 to i64
%806 = arith.muli %807, %808 : i64
%809 = arith.constant 2 : i32
%811 = arith.extsi %809 : i32 to i64
%810 = arith.addi %806, %811 : i64
%812 = llvm.load %759 : !llvm.ptr -> i128
%814 = arith.trunci %812 : i128 to i64
%813 = arith.remsi %810, %814 : i64
%815 = arith.extsi %813 : i64 to i128
llvm.store %815, %797 : i128, !llvm.ptr
%816 = llvm.load %800 : !llvm.ptr -> i32
%817 = arith.constant 1 : i32
%818 = arith.addi %816, %817 : i32
llvm.store %818, %800 : i32, !llvm.ptr
cf.br ^bb105
^bb107:
%819 = llvm.load %797 : !llvm.ptr -> i128
%820 = arith.constant 5 : i32
%822 = arith.extsi %820 : i32 to i64
%821 = arith.subi %arg0, %822 : i64
%823 = llvm.load %777 : !llvm.ptr -> i64
%824 = arith.divsi %821, %823 : i64
%825 = llvm.load %777 : !llvm.ptr -> i64
%826 = arith.remsi %821, %825 : i64
%828 = arith.constant 16 : i32
%829 = arith.constant 1 : i32
%830 = arith.extsi %828 : i32 to i64
%831 = arith.extsi %829 : i32 to i64
%827 = func.call @calloc(%830, %831) : (i64, i64) -> !llvm.ptr
%832 = arith.constant 0 : i32
%833 = arith.extsi %832 : i32 to i64
%834 = llvm.mlir.constant(1 : i64) : i64
%835 = llvm.alloca %834 x i64 : (i64) -> !llvm.ptr
llvm.store %833, %835 : i64, !llvm.ptr
%836 = arith.constant 0 : i32
%837 = arith.extsi %836 : i32 to i64
%838 = llvm.mlir.constant(1 : i64) : i64
%839 = llvm.alloca %838 x i64 : (i64) -> !llvm.ptr
llvm.store %837, %839 : i64, !llvm.ptr
%840 = arith.constant 1 : i32
%842 = arith.constant 0 : i32
%841 = arith.subi %842, %840 : i32
%843 = arith.extsi %841 : i32 to i64
%844 = llvm.mlir.constant(1 : i64) : i64
%845 = llvm.alloca %844 x i64 : (i64) -> !llvm.ptr
llvm.store %843, %845 : i64, !llvm.ptr
%846 = arith.constant 1 : i32
%847 = arith.extsi %846 : i32 to i64
%848 = llvm.mlir.constant(1 : i64) : i64
%849 = llvm.alloca %848 x i64 : (i64) -> !llvm.ptr
llvm.store %847, %849 : i64, !llvm.ptr
cf.br ^bb108
^bb108:
%850 = llvm.load %849 : !llvm.ptr -> i64
%851 = llvm.load %777 : !llvm.ptr -> i64
%852 = arith.cmpi sle, %850, %851 : i64
cf.cond_br %852, ^bb109, ^bb110
^bb109:
%854 = llvm.load %797 : !llvm.ptr -> i128
%855 = arith.trunci %854 : i128 to i64
%853 = func.call @next_perm_fixed(%855, %755, %827) : (i64, i32, !llvm.ptr) -> i64
%856 = arith.constant 0 : i32
%858 = arith.extsi %856 : i32 to i64
%857 = arith.cmpi slt, %853, %858 : i64
cf.cond_br %857, ^bb111, ^bb112
^bb111:
%859 = llvm.load %849 : !llvm.ptr -> i64
llvm.store %859, %845 : i64, !llvm.ptr
cf.br ^bb113
^bb112:
%860 = llvm.load %797 : !llvm.ptr -> i128
%861 = arith.trunci %860 : i128 to i64
%862 = arith.subi %853, %861 : i64
%863 = llvm.load %835 : !llvm.ptr -> i64
%864 = arith.addi %863, %862 : i64
%865 = llvm.mlir.addressof @MOD : !llvm.ptr
%866 = llvm.load %865 : !llvm.ptr -> i64
%867 = arith.remsi %864, %866 : i64
llvm.store %867, %835 : i64, !llvm.ptr
%868 = llvm.load %835 : !llvm.ptr -> i64
%869 = arith.constant 0 : i32
%871 = arith.extsi %869 : i32 to i64
%870 = arith.cmpi slt, %868, %871 : i64
cf.cond_br %870, ^bb114, ^bb115
^bb114:
%872 = llvm.load %835 : !llvm.ptr -> i64
%873 = llvm.mlir.addressof @MOD : !llvm.ptr
%874 = llvm.load %873 : !llvm.ptr -> i64
%875 = arith.addi %872, %874 : i64
llvm.store %875, %835 : i64, !llvm.ptr
cf.br ^bb116
^bb115:
cf.br ^bb116
^bb116:
%876 = llvm.load %849 : !llvm.ptr -> i64
%877 = arith.cmpi sle, %876, %826 : i64
cf.cond_br %877, ^bb117, ^bb118
^bb117:
%878 = llvm.load %839 : !llvm.ptr -> i64
%879 = arith.addi %878, %862 : i64
%880 = llvm.mlir.addressof @MOD : !llvm.ptr
%881 = llvm.load %880 : !llvm.ptr -> i64
%882 = arith.remsi %879, %881 : i64
llvm.store %882, %839 : i64, !llvm.ptr
%883 = llvm.load %839 : !llvm.ptr -> i64
%884 = arith.constant 0 : i32
%886 = arith.extsi %884 : i32 to i64
%885 = arith.cmpi slt, %883, %886 : i64
cf.cond_br %885, ^bb120, ^bb121
^bb120:
%887 = llvm.load %839 : !llvm.ptr -> i64
%888 = llvm.mlir.addressof @MOD : !llvm.ptr
%889 = llvm.load %888 : !llvm.ptr -> i64
%890 = arith.addi %887, %889 : i64
llvm.store %890, %839 : i64, !llvm.ptr
cf.br ^bb122
^bb121:
cf.br ^bb122
^bb122:
cf.br ^bb119
^bb118:
cf.br ^bb119
^bb119:
cf.br ^bb113
^bb113:
%891 = llvm.load %797 : !llvm.ptr -> i128
%892 = llvm.load %797 : !llvm.ptr -> i128
%894 = arith.trunci %891 : i128 to i64
%895 = arith.trunci %892 : i128 to i64
%893 = arith.muli %894, %895 : i64
%896 = arith.constant 2 : i32
%898 = arith.extsi %896 : i32 to i64
%897 = arith.addi %893, %898 : i64
%899 = llvm.load %759 : !llvm.ptr -> i128
%901 = arith.trunci %899 : i128 to i64
%900 = arith.remsi %897, %901 : i64
%902 = arith.extsi %900 : i64 to i128
llvm.store %902, %797 : i128, !llvm.ptr
%903 = llvm.load %849 : !llvm.ptr -> i64
%904 = arith.constant 1 : i32
%906 = arith.extsi %904 : i32 to i64
%905 = arith.addi %903, %906 : i64
llvm.store %905, %849 : i64, !llvm.ptr
cf.br ^bb108
^bb110:
func.call @free(%827) : (!llvm.ptr) -> ()
%908 = llvm.load %845 : !llvm.ptr -> i64
%909 = arith.constant 5 : i32
%911 = arith.extsi %909 : i32 to i64
%910 = arith.addi %908, %911 : i64
%912 = llvm.mlir.addressof @g_d10_first_bad_n : !llvm.ptr
llvm.store %910, %912 : i64, !llvm.ptr
%913 = llvm.mlir.addressof @MOD : !llvm.ptr
%914 = llvm.load %913 : !llvm.ptr -> i64
%915 = arith.remsi %824, %914 : i64
%916 = llvm.load %835 : !llvm.ptr -> i64
%917 = arith.muli %915, %916 : i64
%918 = llvm.mlir.addressof @MOD : !llvm.ptr
%919 = llvm.load %918 : !llvm.ptr -> i64
%920 = arith.remsi %917, %919 : i64
%921 = llvm.load %839 : !llvm.ptr -> i64
%922 = arith.addi %920, %921 : i64
%923 = llvm.mlir.addressof @MOD : !llvm.ptr
%924 = llvm.load %923 : !llvm.ptr -> i64
%925 = arith.remsi %922, %924 : i64
%926 = llvm.mlir.addressof @g_d10_total : !llvm.ptr
llvm.store %925, %926 : i64, !llvm.ptr
%927 = llvm.mlir.addressof @g_d10_total : !llvm.ptr
%928 = llvm.load %927 : !llvm.ptr -> i64
%929 = arith.constant 0 : i32
%931 = arith.extsi %929 : i32 to i64
%930 = arith.cmpi slt, %928, %931 : i64
cf.cond_br %930, ^bb123, ^bb124
^bb123:
%932 = llvm.mlir.addressof @g_d10_total : !llvm.ptr
%933 = llvm.load %932 : !llvm.ptr -> i64
%934 = llvm.mlir.addressof @MOD : !llvm.ptr
%935 = llvm.load %934 : !llvm.ptr -> i64
%936 = arith.addi %933, %935 : i64
%937 = llvm.mlir.addressof @g_d10_total : !llvm.ptr
llvm.store %936, %937 : i64, !llvm.ptr
cf.br ^bb125
^bb124:
cf.br ^bb125
^bb125:
func.return
}
func.func @delta_bad_11(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
%938 = arith.constant 0 : i32
%940 = arith.extsi %938 : i32 to i64
%939 = arith.cmpi slt, %arg1, %940 : i64
%941 = scf.if %939 -> (i1) {
%942 = arith.constant true
scf.yield %942 : i1
} else {
%943 = arith.cmpi slt, %arg0, %arg1 : i64
scf.yield %943 : i1
}
cf.cond_br %941, ^bb126, ^bb127
^bb126:
%944 = arith.constant 0 : i32
%945 = arith.extsi %944 : i32 to i64
func.return %945 : i64
^bb127:
cf.br ^bb128
^bb128:
%946 = arith.constant 1 : i32
%947 = arith.extsi %946 : i32 to i128
%948 = llvm.mlir.constant(1 : i64) : i64
%949 = llvm.alloca %948 x i128 : (i64) -> !llvm.ptr
llvm.store %947, %949 : i128, !llvm.ptr
%950 = arith.constant 0 : i32
%951 = llvm.mlir.constant(1 : i64) : i64
%952 = llvm.alloca %951 x i32 : (i64) -> !llvm.ptr
llvm.store %950, %952 : i32, !llvm.ptr
cf.br ^bb129
^bb129:
%953 = llvm.load %952 : !llvm.ptr -> i32
%954 = arith.constant 11 : i32
%955 = arith.cmpi slt, %953, %954 : i32
cf.cond_br %955, ^bb130, ^bb131
^bb130:
%956 = llvm.load %949 : !llvm.ptr -> i128
%957 = arith.constant 10 : i32
%959 = arith.trunci %956 : i128 to i64
%960 = arith.extsi %957 : i32 to i64
%958 = arith.muli %959, %960 : i64
%961 = arith.extsi %958 : i64 to i128
llvm.store %961, %949 : i128, !llvm.ptr
%962 = llvm.load %952 : !llvm.ptr -> i32
%963 = arith.constant 1 : i32
%964 = arith.addi %962, %963 : i32
llvm.store %964, %952 : i32, !llvm.ptr
cf.br ^bb129
^bb131:
%966 = arith.constant 5 : i32
%967 = arith.constant 8 : i32
%968 = arith.extsi %966 : i32 to i64
%969 = arith.extsi %967 : i32 to i64
%965 = func.call @calloc(%968, %969) : (i64, i64) -> !llvm.ptr
%970 = arith.constant 0 : i32
%971 = llvm.mlir.constant(1 : i64) : i64
%972 = llvm.alloca %971 x i32 : (i64) -> !llvm.ptr
llvm.store %970, %972 : i32, !llvm.ptr
cf.br ^bb132
^bb132:
%973 = llvm.load %972 : !llvm.ptr -> i32
%974 = arith.constant 5 : i32
%975 = arith.cmpi slt, %973, %974 : i32
cf.cond_br %975, ^bb133, ^bb134
^bb133:
%976 = llvm.load %972 : !llvm.ptr -> i32
%977 = arith.extsi %976 : i32 to i64
%978 = arith.muli %977, %arg2 : i64
%979 = arith.addi %arg1, %978 : i64
%980 = llvm.load %972 : !llvm.ptr -> i32
%981 = arith.extsi %980 : i32 to i64
%982 = llvm.getelementptr %965[%981] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %979, %982 : i64, !llvm.ptr
%983 = llvm.load %972 : !llvm.ptr -> i32
%984 = arith.constant 1 : i32
%985 = arith.addi %983, %984 : i32
llvm.store %985, %972 : i32, !llvm.ptr
cf.br ^bb132
^bb134:
%987 = arith.constant 4 : i32
%988 = arith.extsi %987 : i32 to i64
%989 = llvm.getelementptr %965[%988] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%986 = llvm.load %989 : !llvm.ptr -> i64
%990 = arith.constant 0 : i32
%991 = arith.extsi %990 : i32 to i128
%992 = llvm.mlir.constant(1 : i64) : i64
%993 = llvm.alloca %992 x i128 : (i64) -> !llvm.ptr
llvm.store %991, %993 : i128, !llvm.ptr
%995 = arith.constant 5 : i32
%996 = arith.constant 8 : i32
%997 = arith.extsi %995 : i32 to i64
%998 = arith.extsi %996 : i32 to i64
%994 = func.call @calloc(%997, %998) : (i64, i64) -> !llvm.ptr
%999 = arith.constant 0 : i32
%1000 = llvm.mlir.constant(1 : i64) : i64
%1001 = llvm.alloca %1000 x i32 : (i64) -> !llvm.ptr
llvm.store %999, %1001 : i32, !llvm.ptr
%1002 = arith.constant 1 : i32
%1003 = arith.extsi %1002 : i32 to i64
%1004 = llvm.mlir.constant(1 : i64) : i64
%1005 = llvm.alloca %1004 x i64 : (i64) -> !llvm.ptr
llvm.store %1003, %1005 : i64, !llvm.ptr
cf.br ^bb135
^bb135:
%1006 = llvm.load %1005 : !llvm.ptr -> i64
%1007 = arith.cmpi sle, %1006, %986 : i64
cf.cond_br %1007, ^bb136, ^bb137
^bb136:
%1008 = llvm.load %993 : !llvm.ptr -> i128
%1009 = llvm.load %993 : !llvm.ptr -> i128
%1011 = arith.trunci %1008 : i128 to i64
%1012 = arith.trunci %1009 : i128 to i64
%1010 = arith.muli %1011, %1012 : i64
%1013 = arith.constant 2 : i32
%1015 = arith.extsi %1013 : i32 to i64
%1014 = arith.addi %1010, %1015 : i64
%1016 = llvm.load %949 : !llvm.ptr -> i128
%1018 = arith.trunci %1016 : i128 to i64
%1017 = arith.remsi %1014, %1018 : i64
%1019 = arith.extsi %1017 : i64 to i128
llvm.store %1019, %993 : i128, !llvm.ptr
%1020 = llvm.load %1005 : !llvm.ptr -> i64
%1022 = llvm.load %1001 : !llvm.ptr -> i32
%1023 = arith.extsi %1022 : i32 to i64
%1024 = llvm.getelementptr %965[%1023] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1021 = llvm.load %1024 : !llvm.ptr -> i64
%1025 = arith.cmpi eq, %1020, %1021 : i64
cf.cond_br %1025, ^bb138, ^bb139
^bb138:
%1026 = llvm.load %993 : !llvm.ptr -> i128
%1027 = arith.trunci %1026 : i128 to i64
%1028 = llvm.load %1001 : !llvm.ptr -> i32
%1029 = arith.extsi %1028 : i32 to i64
%1030 = llvm.getelementptr %994[%1029] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %1027, %1030 : i64, !llvm.ptr
%1031 = llvm.load %1001 : !llvm.ptr -> i32
%1032 = arith.constant 1 : i32
%1033 = arith.addi %1031, %1032 : i32
llvm.store %1033, %1001 : i32, !llvm.ptr
%1034 = llvm.load %1001 : !llvm.ptr -> i32
%1035 = arith.constant 5 : i32
%1036 = arith.cmpi eq, %1034, %1035 : i32
cf.cond_br %1036, ^bb141, ^bb142
^bb141:
cf.br ^bb137
^bb142:
cf.br ^bb143
^bb143:
cf.br ^bb140
^bb139:
cf.br ^bb140
^bb140:
%1037 = llvm.load %1005 : !llvm.ptr -> i64
%1038 = arith.constant 1 : i32
%1040 = arith.extsi %1038 : i32 to i64
%1039 = arith.addi %1037, %1040 : i64
llvm.store %1039, %1005 : i64, !llvm.ptr
cf.br ^bb135
^bb137:
%1042 = arith.constant 16 : i32
%1043 = arith.constant 1 : i32
%1044 = arith.extsi %1042 : i32 to i64
%1045 = arith.extsi %1043 : i32 to i64
%1041 = func.call @calloc(%1044, %1045) : (i64, i64) -> !llvm.ptr
%1047 = arith.constant 5 : i32
%1048 = arith.constant 8 : i32
%1049 = arith.extsi %1047 : i32 to i64
%1050 = arith.extsi %1048 : i32 to i64
%1046 = func.call @calloc(%1049, %1050) : (i64, i64) -> !llvm.ptr
%1051 = arith.constant 0 : i32
%1052 = llvm.mlir.constant(1 : i64) : i64
%1053 = llvm.alloca %1052 x i32 : (i64) -> !llvm.ptr
llvm.store %1051, %1053 : i32, !llvm.ptr
cf.br ^bb144
^bb144:
%1054 = llvm.load %1053 : !llvm.ptr -> i32
%1055 = arith.constant 5 : i32
%1056 = arith.cmpi slt, %1054, %1055 : i32
cf.cond_br %1056, ^bb145, ^bb146
^bb145:
%1059 = llvm.load %1053 : !llvm.ptr -> i32
%1060 = arith.extsi %1059 : i32 to i64
%1061 = llvm.getelementptr %994[%1060] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1058 = llvm.load %1061 : !llvm.ptr -> i64
%1062 = arith.constant 11 : i32
%1057 = func.call @next_perm_fixed(%1058, %1062, %1041) : (i64, i32, !llvm.ptr) -> i64
%1064 = llvm.load %1053 : !llvm.ptr -> i32
%1065 = arith.extsi %1064 : i32 to i64
%1066 = llvm.getelementptr %994[%1065] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1063 = llvm.load %1066 : !llvm.ptr -> i64
%1067 = arith.subi %1057, %1063 : i64
%1068 = llvm.mlir.addressof @MOD : !llvm.ptr
%1069 = llvm.load %1068 : !llvm.ptr -> i64
%1070 = arith.remsi %1067, %1069 : i64
%1071 = llvm.mlir.constant(1 : i64) : i64
%1072 = llvm.alloca %1071 x i64 : (i64) -> !llvm.ptr
llvm.store %1070, %1072 : i64, !llvm.ptr
%1073 = llvm.load %1072 : !llvm.ptr -> i64
%1074 = arith.constant 0 : i32
%1076 = arith.extsi %1074 : i32 to i64
%1075 = arith.cmpi slt, %1073, %1076 : i64
cf.cond_br %1075, ^bb147, ^bb148
^bb147:
%1077 = llvm.load %1072 : !llvm.ptr -> i64
%1078 = llvm.mlir.addressof @MOD : !llvm.ptr
%1079 = llvm.load %1078 : !llvm.ptr -> i64
%1080 = arith.addi %1077, %1079 : i64
llvm.store %1080, %1072 : i64, !llvm.ptr
cf.br ^bb149
^bb148:
cf.br ^bb149
^bb149:
%1081 = llvm.load %1072 : !llvm.ptr -> i64
%1082 = llvm.load %1053 : !llvm.ptr -> i32
%1083 = arith.extsi %1082 : i32 to i64
%1084 = llvm.getelementptr %1046[%1083] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %1081, %1084 : i64, !llvm.ptr
%1085 = llvm.load %1053 : !llvm.ptr -> i32
%1086 = arith.constant 1 : i32
%1087 = arith.addi %1085, %1086 : i32
llvm.store %1087, %1053 : i32, !llvm.ptr
cf.br ^bb144
^bb146:
%1088 = arith.constant 1 : i32
%1089 = arith.subi %arg0, %arg1 : i64
%1090 = arith.divsi %1089, %arg2 : i64
%1092 = arith.extsi %1088 : i32 to i64
%1091 = arith.addi %1092, %1090 : i64
%1093 = arith.constant 5 : i32
%1095 = arith.extsi %1093 : i32 to i64
%1094 = arith.divsi %1091, %1095 : i64
%1096 = arith.constant 5 : i32
%1098 = arith.extsi %1096 : i32 to i64
%1097 = arith.remsi %1091, %1098 : i64
%1099 = arith.constant 0 : i32
%1100 = arith.extsi %1099 : i32 to i64
%1101 = llvm.mlir.constant(1 : i64) : i64
%1102 = llvm.alloca %1101 x i64 : (i64) -> !llvm.ptr
llvm.store %1100, %1102 : i64, !llvm.ptr
%1103 = arith.constant 0 : i32
%1104 = llvm.mlir.constant(1 : i64) : i64
%1105 = llvm.alloca %1104 x i32 : (i64) -> !llvm.ptr
llvm.store %1103, %1105 : i32, !llvm.ptr
cf.br ^bb150
^bb150:
%1106 = llvm.load %1105 : !llvm.ptr -> i32
%1107 = arith.constant 5 : i32
%1108 = arith.cmpi slt, %1106, %1107 : i32
cf.cond_br %1108, ^bb151, ^bb152
^bb151:
%1109 = llvm.load %1105 : !llvm.ptr -> i32
%1110 = arith.trunci %1097 : i64 to i32
%1111 = arith.cmpi slt, %1109, %1110 : i32
%1112 = scf.if %1111 -> (i32) {
%1113 = arith.constant 1 : i32
scf.yield %1113 : i32
} else {
%1114 = arith.constant 0 : i32
scf.yield %1114 : i32
}
%1116 = arith.extsi %1112 : i32 to i64
%1115 = arith.addi %1094, %1116 : i64
%1117 = llvm.load %1102 : !llvm.ptr -> i64
%1118 = llvm.mlir.addressof @MOD : !llvm.ptr
%1119 = llvm.load %1118 : !llvm.ptr -> i64
%1120 = arith.remsi %1115, %1119 : i64
%1122 = llvm.load %1105 : !llvm.ptr -> i32
%1123 = arith.extsi %1122 : i32 to i64
%1124 = llvm.getelementptr %1046[%1123] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%1121 = llvm.load %1124 : !llvm.ptr -> i64
%1125 = arith.muli %1120, %1121 : i64
%1126 = arith.addi %1117, %1125 : i64
%1127 = llvm.mlir.addressof @MOD : !llvm.ptr
%1128 = llvm.load %1127 : !llvm.ptr -> i64
%1129 = arith.remsi %1126, %1128 : i64
llvm.store %1129, %1102 : i64, !llvm.ptr
%1130 = llvm.load %1105 : !llvm.ptr -> i32
%1131 = arith.constant 1 : i32
%1132 = arith.addi %1130, %1131 : i32
llvm.store %1132, %1105 : i32, !llvm.ptr
cf.br ^bb150
^bb152:
func.call @free(%965) : (!llvm.ptr) -> ()
func.call @free(%994) : (!llvm.ptr) -> ()
func.call @free(%1041) : (!llvm.ptr) -> ()
func.call @free(%1046) : (!llvm.ptr) -> ()
%1137 = llvm.load %1102 : !llvm.ptr -> i64
func.return %1137 : i64
}
func.func @main() -> i32 {
%1139 = llvm.mlir.addressof @HT_SIZE : !llvm.ptr
%1140 = llvm.load %1139 : !llvm.ptr -> i64
%1141 = arith.constant 8 : i32
%1142 = arith.extsi %1141 : i32 to i64
%1138 = func.call @calloc(%1140, %1142) : (i64, i64) -> !llvm.ptr
%1143 = llvm.mlir.addressof @ht_key : !llvm.ptr
llvm.store %1138, %1143 : !llvm.ptr, !llvm.ptr
%1145 = llvm.mlir.addressof @HT_SIZE : !llvm.ptr
%1146 = llvm.load %1145 : !llvm.ptr -> i64
%1147 = arith.constant 8 : i32
%1148 = arith.extsi %1147 : i32 to i64
%1144 = func.call @calloc(%1146, %1148) : (i64, i64) -> !llvm.ptr
%1149 = llvm.mlir.addressof @ht_val : !llvm.ptr
llvm.store %1144, %1149 : !llvm.ptr, !llvm.ptr
%1150 = arith.constant 1 : i32
%1151 = arith.extsi %1150 : i32 to i64
%1152 = llvm.mlir.constant(1 : i64) : i64
%1153 = llvm.alloca %1152 x i64 : (i64) -> !llvm.ptr
llvm.store %1151, %1153 : i64, !llvm.ptr
%1154 = arith.constant 0 : i32
%1155 = llvm.mlir.constant(1 : i64) : i64
%1156 = llvm.alloca %1155 x i32 : (i64) -> !llvm.ptr
llvm.store %1154, %1156 : i32, !llvm.ptr
cf.br ^bb153
^bb153:
%1157 = llvm.load %1156 : !llvm.ptr -> i32
%1158 = arith.constant 16 : i32
%1159 = arith.cmpi slt, %1157, %1158 : i32
cf.cond_br %1159, ^bb154, ^bb155
^bb154:
%1160 = llvm.load %1153 : !llvm.ptr -> i64
%1161 = arith.constant 10 : i32
%1163 = arith.extsi %1161 : i32 to i64
%1162 = arith.muli %1160, %1163 : i64
llvm.store %1162, %1153 : i64, !llvm.ptr
%1164 = llvm.load %1156 : !llvm.ptr -> i32
%1165 = arith.constant 1 : i32
%1166 = arith.addi %1164, %1165 : i32
llvm.store %1166, %1156 : i32, !llvm.ptr
cf.br ^bb153
^bb155:
%1168 = llvm.load %1153 : !llvm.ptr -> i64
%1167 = func.call @sum_a_mod(%1168) : (i64) -> i64
%1170 = llvm.load %1153 : !llvm.ptr -> i64
%1169 = func.call @delta_small(%1170) : (i64) -> i64
%1172 = llvm.load %1153 : !llvm.ptr -> i64
func.call @delta10_and_bad(%1172) : (i64) -> ()
%1174 = llvm.load %1153 : !llvm.ptr -> i64
%1175 = llvm.mlir.addressof @g_d10_first_bad_n : !llvm.ptr
%1176 = llvm.load %1175 : !llvm.ptr -> i64
%1177 = llvm.mlir.addressof @g_d10_step : !llvm.ptr
%1178 = llvm.load %1177 : !llvm.ptr -> i64
%1173 = func.call @delta_bad_11(%1174, %1176, %1178) : (i64, i64, i64) -> i64
%1179 = arith.addi %1167, %1169 : i64
%1180 = llvm.mlir.addressof @g_d10_total : !llvm.ptr
%1181 = llvm.load %1180 : !llvm.ptr -> i64
%1182 = arith.addi %1179, %1181 : i64
%1183 = arith.addi %1182, %1173 : i64
%1184 = llvm.mlir.addressof @MOD : !llvm.ptr
%1185 = llvm.load %1184 : !llvm.ptr -> i64
%1186 = arith.remsi %1183, %1185 : i64
%1187 = llvm.mlir.constant(1 : i64) : i64
%1188 = llvm.alloca %1187 x i64 : (i64) -> !llvm.ptr
llvm.store %1186, %1188 : i64, !llvm.ptr
%1189 = llvm.load %1188 : !llvm.ptr -> i64
%1190 = arith.constant 0 : i32
%1192 = arith.extsi %1190 : i32 to i64
%1191 = arith.cmpi slt, %1189, %1192 : i64
cf.cond_br %1191, ^bb156, ^bb157
^bb156:
%1193 = llvm.load %1188 : !llvm.ptr -> i64
%1194 = llvm.mlir.addressof @MOD : !llvm.ptr
%1195 = llvm.load %1194 : !llvm.ptr -> i64
%1196 = arith.addi %1193, %1195 : i64
llvm.store %1196, %1188 : i64, !llvm.ptr
cf.br ^bb158
^bb157:
cf.br ^bb158
^bb158:
%1197 = llvm.mlir.addressof @str_0 : !llvm.ptr
%1198 = llvm.load %1188 : !llvm.ptr -> i64
%1199 = llvm.call @printf(%1197, %1198) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%1200 = arith.constant 0 : i32
func.return %1200 : i32
}
}