Problem 741
Binary Grid Colouring: g(7^7) + g(8^8) mod 1e9+7. Pure Flow port of the native C solver.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n) | ? |
| Space complexity | O(1) | ? |
| Approach | Flow solution | Not curated |
| Verdict | Unknown |
Flow source
# Project Euler 741
# Binary Grid Colouring: g(7^7) + g(8^8) mod 1e9+7.
# Pure Flow port of the native C solver.
const MOD: i64 = 1000000007
const INV2: i64 = 500000004
const INV8: i64 = 125000001
function mm(a: i64, b: i64) -> i64 {
let r: i128 = ((a as i128) * (b as i128)) % (MOD as i128)
return r as i64
}
function mpow(a0: i64, e0: i64) -> i64 {
let mut r: i64 = 1
let mut a: i64 = a0 % MOD
if a < 0 { a = a + MOD }
let mut e: i64 = e0
while e > 0 {
if e % 2 == 1 { r = mm(r, a) }
a = mm(a, a)
e = e / 2
}
return r
}
function madd(a: i64, b: i64) -> i64 {
let mut r: i64 = a + b
if r >= MOD { r = r - MOD }
return r
}
function msub(a: i64, b: i64) -> i64 {
let mut r: i64 = a - b
if r < 0 { r = r + MOD }
return r
}
# Returns f(n), diag_fix(n), n! mod MOD via out-parameters.
function f_diag_fact(n: i64, f_out: ptr<i64>, diag_out: ptr<i64>, fact_out: ptr<i64>) -> void {
if n == 0 {
f_out[0] = 1
diag_out[0] = 1
fact_out[0] = 1
return
}
let mut fact: i64 = 1
let mut h_im2: i64 = 1
let mut h_im1: i64 = 0
let mut d0: i64 = 0
let mut d1: i64 = 0
let mut d2: i64 = 0
let mut d3: i64 = 0
if n <= 3 {
d0 = 0
d1 = 0
d2 = 0
d3 = 0
} else {
d0 = 1
d1 = 0
d2 = 1
d3 = 4
}
let mut i: i64 = 1
while i <= n {
fact = mm(fact, i % MOD)
if i >= 2 {
let k: i64 = i - 1
let h_i: i64 = madd(mm(k % MOD, h_im1), mm(mm(k % MOD, INV2), h_im2))
h_im2 = h_im1
h_im1 = h_i
}
if n >= 4 {
if i >= 4 {
let k: i64 = i - 1
let term1: i64 = mm((2 * k) % MOD, d3)
let term2: i64 = mm(mm(k % MOD, (k - 2) % MOD), d2)
let term3: i64 = mm(mm(mm(k % MOD, (k - 1) % MOD), (k - 2) % MOD), d0)
let newv: i64 = msub(msub(term1, term2), mm(term3, INV2))
d0 = d1
d1 = d2
d2 = d3
d3 = newv
}
}
i = i + 1
}
f_out[0] = mm(fact, h_im1)
let mut diag: i64 = 0
if n == 0 {
diag = 1
} else {
if n == 1 {
diag = 0
} else {
if n == 2 {
diag = 1
} else {
if n == 3 {
diag = 4
} else {
diag = d3
}
}
}
}
diag_out[0] = diag
fact_out[0] = fact
}
function fix_axis_reflection(n: i64, fact_n: i64) -> i64 {
if n % 2 == 1 { return 0 }
return mm(fact_n, mpow(INV2, n / 2))
}
function fix_rotation_90(n: i64) -> i64 {
if n % 2 == 1 { return 0 }
let m: i64 = n / 2
if m == 0 { return 1 }
if m == 1 { return 1 }
if m == 2 { return 2 }
let mut b0: i64 = 1
let mut b1: i64 = 1
let mut b2: i64 = 2
let mut i: i64 = 2
while i < m {
let val: i64 = msub(madd(mm((2 * i + 1) % MOD, b2),
mm((2 * i % MOD) * ((i - 1) % MOD) % MOD, b0)),
mm(i % MOD, b1))
b0 = b1
b1 = b2
b2 = val
i = i + 1
}
return b2
}
function fix_rotation_180(n: i64) -> i64 {
if n == 0 { return 1 }
if n % 2 == 0 {
let m: i64 = n / 2
if m == 0 { return 1 }
if m == 1 { return 1 }
let mut j_prev: i64 = 1
let mut j_curr: i64 = 1
let mut fact: i64 = 1
let mut i: i64 = 1
while i < m {
fact = mm(fact, i % MOD)
let j_next: i64 = madd(mm((4 * i + 1) % MOD, j_curr),
mm((4 * i) % MOD, j_prev))
j_prev = j_curr
j_curr = j_next
i = i + 1
}
let fact_m: i64 = mm(fact, m % MOD)
return mm(fact_m, j_curr)
}
# odd n = 2m+1
let m: i64 = (n - 1) / 2
if m == 0 { return 0 }
let mut fact: i64 = 1
let mut t: i64 = 0
let mut j_prev: i64 = 1
let mut j_curr: i64 = 1
let mut i: i64 = 1
while i <= m {
fact = mm(fact, i % MOD)
t = madd(mm((4 * i) % MOD, t), mm((2 * i) % MOD, j_prev))
if i < m {
let j_next: i64 = madd(mm((4 * i + 1) % MOD, j_curr),
mm((4 * i) % MOD, j_prev))
j_prev = j_curr
j_curr = j_next
}
i = i + 1
}
return mm(fact, t)
}
function g(n: i64) -> i64 {
let buf: array<i64, 3> = [0, 0, 0]
f_diag_fact(n, &buf[0], &buf[1], &buf[2])
let f_n: i64 = buf[0]
let diag: i64 = buf[1]
let fact_n: i64 = buf[2]
let axis: i64 = fix_axis_reflection(n, fact_n)
let r180: i64 = fix_rotation_180(n)
let r90: i64 = fix_rotation_90(n)
let mut total: i64 = f_n
total = madd(total, r180)
total = madd(total, mm(2, r90))
total = madd(total, mm(2, axis))
total = madd(total, mm(2, diag))
return mm(total, INV8)
}
function main() -> i32 {
let mut n1: i64 = 1
let mut i: i32 = 0
while i < 7 {
n1 = n1 * 7
i = i + 1
}
let mut n2: i64 = 1
let mut j: i32 = 0
while j < 8 {
n2 = n2 * 8
j = j + 1
}
let ans: i64 = madd(g(n1), g(n2))
printf("%lld\n", ans)
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 mm_i64_i64(int64_t a, int64_t b);
int64_t mpow_i64_i64(int64_t a0, int64_t e0);
int64_t madd_i64_i64(int64_t a, int64_t b);
int64_t msub_i64_i64(int64_t a, int64_t b);
void f_diag_fact_i64_ptr_i64_ptr_i64_ptr_i64(int64_t n, int64_t* f_out, int64_t* diag_out, int64_t* fact_out);
int64_t fix_axis_reflection_i64_i64(int64_t n, int64_t fact_n);
int64_t fix_rotation_90_i64(int64_t n);
int64_t fix_rotation_180_i64(int64_t n);
int64_t g_i64(int64_t n);
int32_t main(void);
static const int64_t MOD = 1000000007;
static const int64_t INV2 = 500000004;
static const int64_t INV8 = 125000001;
int64_t mm_i64_i64(int64_t a, int64_t b) {
__int128 r = FLOW_CHECKED_MOD(((((__int128)(a)) * ((__int128)(b)))), (((__int128)(MOD))));
return ((int64_t)(r));
}
int64_t mpow_i64_i64(int64_t a0, int64_t e0) {
int64_t r = 1;
int64_t a = FLOW_CHECKED_MOD((a0), (MOD));
if (a < 0) {
a = (a + MOD);
}
int64_t e = e0;
while (e > 0) {
if (FLOW_CHECKED_MOD((e), (2)) == 1) {
r = mm_i64_i64(r, a);
}
a = mm_i64_i64(a, a);
e = FLOW_CHECKED_DIV((e), (2));
}
return r;
}
int64_t madd_i64_i64(int64_t a, int64_t b) {
int64_t r = (a + b);
if (r >= MOD) {
r = (r - MOD);
}
return r;
}
int64_t msub_i64_i64(int64_t a, int64_t b) {
int64_t r = (a - b);
if (r < 0) {
r = (r + MOD);
}
return r;
}
void f_diag_fact_i64_ptr_i64_ptr_i64_ptr_i64(int64_t n, int64_t* f_out, int64_t* diag_out, int64_t* fact_out) {
if (n == 0) {
f_out[0] = 1;
diag_out[0] = 1;
fact_out[0] = 1;
return;
}
int64_t fact = 1;
int64_t h_im2 = 1;
int64_t h_im1 = 0;
int64_t d0 = 0;
int64_t d1 = 0;
int64_t d2 = 0;
int64_t d3 = 0;
if (n <= 3) {
d0 = 0;
d1 = 0;
d2 = 0;
d3 = 0;
} else {
d0 = 1;
d1 = 0;
d2 = 1;
d3 = 4;
}
int64_t i = 1;
while (i <= n) {
fact = mm_i64_i64(fact, FLOW_CHECKED_MOD((i), (MOD)));
if (i >= 2) {
int64_t k = (i - 1);
int64_t h_i = madd_i64_i64(mm_i64_i64(FLOW_CHECKED_MOD((k), (MOD)), h_im1), mm_i64_i64(mm_i64_i64(FLOW_CHECKED_MOD((k), (MOD)), INV2), h_im2));
h_im2 = h_im1;
h_im1 = h_i;
}
if (n >= 4) {
if (i >= 4) {
int64_t k = (i - 1);
int64_t term1 = mm_i64_i64(FLOW_CHECKED_MOD(((2 * k)), (MOD)), d3);
int64_t term2 = mm_i64_i64(mm_i64_i64(FLOW_CHECKED_MOD((k), (MOD)), FLOW_CHECKED_MOD(((k - 2)), (MOD))), d2);
int64_t term3 = mm_i64_i64(mm_i64_i64(mm_i64_i64(FLOW_CHECKED_MOD((k), (MOD)), FLOW_CHECKED_MOD(((k - 1)), (MOD))), FLOW_CHECKED_MOD(((k - 2)), (MOD))), d0);
int64_t newv = msub_i64_i64(msub_i64_i64(term1, term2), mm_i64_i64(term3, INV2));
d0 = d1;
d1 = d2;
d2 = d3;
d3 = newv;
}
}
i = (i + 1);
}
f_out[0] = mm_i64_i64(fact, h_im1);
int64_t diag = 0;
if (n == 0) {
diag = 1;
} else {
if (n == 1) {
diag = 0;
} else {
if (n == 2) {
diag = 1;
} else {
if (n == 3) {
diag = 4;
} else {
diag = d3;
}
}
}
}
diag_out[0] = diag;
fact_out[0] = fact;
}
int64_t fix_axis_reflection_i64_i64(int64_t n, int64_t fact_n) {
if (FLOW_CHECKED_MOD((n), (2)) == 1) {
return 0;
}
return mm_i64_i64(fact_n, mpow_i64_i64(INV2, FLOW_CHECKED_DIV((n), (2))));
}
int64_t fix_rotation_90_i64(int64_t n) {
if (FLOW_CHECKED_MOD((n), (2)) == 1) {
return 0;
}
int64_t m = FLOW_CHECKED_DIV((n), (2));
if (m == 0) {
return 1;
}
if (m == 1) {
return 1;
}
if (m == 2) {
return 2;
}
int64_t b0 = 1;
int64_t b1 = 1;
int64_t b2 = 2;
int64_t i = 2;
while (i < m) {
int64_t val = msub_i64_i64(madd_i64_i64(mm_i64_i64(FLOW_CHECKED_MOD((((2 * i) + 1)), (MOD)), b2), mm_i64_i64(FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD(((2 * i)), (MOD)) * FLOW_CHECKED_MOD(((i - 1)), (MOD)))), (MOD)), b0)), mm_i64_i64(FLOW_CHECKED_MOD((i), (MOD)), b1));
b0 = b1;
b1 = b2;
b2 = val;
i = (i + 1);
}
return b2;
}
int64_t fix_rotation_180_i64(int64_t n) {
if (n == 0) {
return 1;
}
if (FLOW_CHECKED_MOD((n), (2)) == 0) {
int64_t m = FLOW_CHECKED_DIV((n), (2));
if (m == 0) {
return 1;
}
if (m == 1) {
return 1;
}
int64_t j_prev = 1;
int64_t j_curr = 1;
int64_t fact = 1;
int64_t i = 1;
while (i < m) {
fact = mm_i64_i64(fact, FLOW_CHECKED_MOD((i), (MOD)));
int64_t j_next = madd_i64_i64(mm_i64_i64(FLOW_CHECKED_MOD((((4 * i) + 1)), (MOD)), j_curr), mm_i64_i64(FLOW_CHECKED_MOD(((4 * i)), (MOD)), j_prev));
j_prev = j_curr;
j_curr = j_next;
i = (i + 1);
}
int64_t fact_m = mm_i64_i64(fact, FLOW_CHECKED_MOD((m), (MOD)));
return mm_i64_i64(fact_m, j_curr);
}
int64_t m = FLOW_CHECKED_DIV(((n - 1)), (2));
if (m == 0) {
return 0;
}
int64_t fact = 1;
int64_t t = 0;
int64_t j_prev = 1;
int64_t j_curr = 1;
int64_t i = 1;
while (i <= m) {
fact = mm_i64_i64(fact, FLOW_CHECKED_MOD((i), (MOD)));
t = madd_i64_i64(mm_i64_i64(FLOW_CHECKED_MOD(((4 * i)), (MOD)), t), mm_i64_i64(FLOW_CHECKED_MOD(((2 * i)), (MOD)), j_prev));
if (i < m) {
int64_t j_next = madd_i64_i64(mm_i64_i64(FLOW_CHECKED_MOD((((4 * i) + 1)), (MOD)), j_curr), mm_i64_i64(FLOW_CHECKED_MOD(((4 * i)), (MOD)), j_prev));
j_prev = j_curr;
j_curr = j_next;
}
i = (i + 1);
}
return mm_i64_i64(fact, t);
}
int64_t g_i64(int64_t n) {
int64_t buf[3] = { 0, 0, 0 };
f_diag_fact_i64_ptr_i64_ptr_i64_ptr_i64(n, (&(buf[0])), (&(buf[1])), (&(buf[2])));
int64_t f_n = (((unsigned)(0) < 3) ? buf[0] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(0), 3), flow_fault_handler("array index out of bounds"), buf[0]));
int64_t diag = (((unsigned)(1) < 3) ? buf[1] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(1), 3), flow_fault_handler("array index out of bounds"), buf[0]));
int64_t fact_n = (((unsigned)(2) < 3) ? buf[2] : (fprintf(stderr, "array index %d out of bounds (size %d)\n", (int)(2), 3), flow_fault_handler("array index out of bounds"), buf[0]));
int64_t axis = fix_axis_reflection_i64_i64(n, fact_n);
int64_t r180 = fix_rotation_180_i64(n);
int64_t r90 = fix_rotation_90_i64(n);
int64_t total = f_n;
total = madd_i64_i64(total, r180);
total = madd_i64_i64(total, mm_i64_i64(2, r90));
total = madd_i64_i64(total, mm_i64_i64(2, axis));
total = madd_i64_i64(total, mm_i64_i64(2, diag));
return mm_i64_i64(total, INV8);
}
int32_t main(void) {
int64_t n1 = 1;
int32_t i = 0;
while (i < 7) {
n1 = (n1 * 7);
i = (i + 1);
}
int64_t n2 = 1;
int32_t j = 0;
while (j < 8) {
n2 = (n2 * 8);
j = (j + 1);
}
int64_t ans = madd_i64_i64(g_i64(n1), g_i64(n2));
printf("%lld\n", ans);
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>
// Constant: MOD
llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
// Constant: INV2
llvm.mlir.global internal constant @INV2(500000004 : i64) : i64
// Constant: INV8
llvm.mlir.global internal constant @INV8(125000001 : i64) : i64
func.func @mm(%arg0: i64, %arg1: i64) -> i64 {
%0 = arith.extsi %arg0 : i64 to i128
%1 = arith.extsi %arg1 : i64 to i128
%3 = arith.trunci %0 : i128 to i64
%4 = arith.trunci %1 : i128 to i64
%2 = arith.muli %3, %4 : i64
%5 = llvm.mlir.addressof @MOD : !llvm.ptr
%6 = llvm.load %5 : !llvm.ptr -> i64
%7 = arith.extsi %6 : i64 to i128
%9 = arith.trunci %7 : i128 to i64
%8 = arith.remsi %2, %9 : i64
%10 = arith.extsi %8 : i64 to i128
%11 = arith.trunci %10 : i128 to i64
func.return %11 : i64
}
func.func @mpow(%arg0: i64, %arg1: i64) -> i64 {
%12 = arith.constant 1 : i32
%13 = arith.extsi %12 : i32 to i64
%14 = llvm.mlir.constant(1 : i64) : i64
%15 = llvm.alloca %14 x i64 : (i64) -> !llvm.ptr
llvm.store %13, %15 : i64, !llvm.ptr
%16 = llvm.mlir.addressof @MOD : !llvm.ptr
%17 = llvm.load %16 : !llvm.ptr -> i64
%18 = arith.remsi %arg0, %17 : i64
%19 = llvm.mlir.constant(1 : i64) : i64
%20 = llvm.alloca %19 x i64 : (i64) -> !llvm.ptr
llvm.store %18, %20 : i64, !llvm.ptr
%21 = llvm.load %20 : !llvm.ptr -> i64
%22 = arith.constant 0 : i32
%24 = arith.extsi %22 : i32 to i64
%23 = arith.cmpi slt, %21, %24 : i64
cf.cond_br %23, ^bb0, ^bb1
^bb0:
%25 = llvm.load %20 : !llvm.ptr -> i64
%26 = llvm.mlir.addressof @MOD : !llvm.ptr
%27 = llvm.load %26 : !llvm.ptr -> i64
%28 = arith.addi %25, %27 : i64
llvm.store %28, %20 : i64, !llvm.ptr
cf.br ^bb2
^bb1:
cf.br ^bb2
^bb2:
%29 = llvm.mlir.constant(1 : i64) : i64
%30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
llvm.store %arg1, %30 : i64, !llvm.ptr
cf.br ^bb3
^bb3:
%31 = llvm.load %30 : !llvm.ptr -> i64
%32 = arith.constant 0 : i32
%34 = arith.extsi %32 : i32 to i64
%33 = arith.cmpi sgt, %31, %34 : i64
cf.cond_br %33, ^bb4, ^bb5
^bb4:
%35 = llvm.load %30 : !llvm.ptr -> i64
%36 = arith.constant 2 : i32
%38 = arith.extsi %36 : i32 to i64
%37 = arith.remsi %35, %38 : i64
%39 = arith.constant 1 : i32
%41 = arith.extsi %39 : i32 to i64
%40 = arith.cmpi eq, %37, %41 : i64
cf.cond_br %40, ^bb6, ^bb7
^bb6:
%43 = llvm.load %15 : !llvm.ptr -> i64
%44 = llvm.load %20 : !llvm.ptr -> i64
%42 = func.call @mm(%43, %44) : (i64, i64) -> i64
llvm.store %42, %15 : i64, !llvm.ptr
cf.br ^bb8
^bb7:
cf.br ^bb8
^bb8:
%46 = llvm.load %20 : !llvm.ptr -> i64
%47 = llvm.load %20 : !llvm.ptr -> i64
%45 = func.call @mm(%46, %47) : (i64, i64) -> i64
llvm.store %45, %20 : i64, !llvm.ptr
%48 = llvm.load %30 : !llvm.ptr -> i64
%49 = arith.constant 2 : i32
%51 = arith.extsi %49 : i32 to i64
%50 = arith.divsi %48, %51 : i64
llvm.store %50, %30 : i64, !llvm.ptr
cf.br ^bb3
^bb5:
%52 = llvm.load %15 : !llvm.ptr -> i64
func.return %52 : i64
}
func.func @madd(%arg0: i64, %arg1: i64) -> i64 {
%53 = arith.addi %arg0, %arg1 : i64
%54 = llvm.mlir.constant(1 : i64) : i64
%55 = llvm.alloca %54 x i64 : (i64) -> !llvm.ptr
llvm.store %53, %55 : i64, !llvm.ptr
%56 = llvm.load %55 : !llvm.ptr -> i64
%57 = llvm.mlir.addressof @MOD : !llvm.ptr
%58 = llvm.load %57 : !llvm.ptr -> i64
%59 = arith.cmpi sge, %56, %58 : i64
cf.cond_br %59, ^bb9, ^bb10
^bb9:
%60 = llvm.load %55 : !llvm.ptr -> i64
%61 = llvm.mlir.addressof @MOD : !llvm.ptr
%62 = llvm.load %61 : !llvm.ptr -> i64
%63 = arith.subi %60, %62 : i64
llvm.store %63, %55 : i64, !llvm.ptr
cf.br ^bb11
^bb10:
cf.br ^bb11
^bb11:
%64 = llvm.load %55 : !llvm.ptr -> i64
func.return %64 : i64
}
func.func @msub(%arg0: i64, %arg1: i64) -> i64 {
%65 = arith.subi %arg0, %arg1 : i64
%66 = llvm.mlir.constant(1 : i64) : i64
%67 = llvm.alloca %66 x i64 : (i64) -> !llvm.ptr
llvm.store %65, %67 : i64, !llvm.ptr
%68 = llvm.load %67 : !llvm.ptr -> i64
%69 = arith.constant 0 : i32
%71 = arith.extsi %69 : i32 to i64
%70 = arith.cmpi slt, %68, %71 : i64
cf.cond_br %70, ^bb12, ^bb13
^bb12:
%72 = llvm.load %67 : !llvm.ptr -> i64
%73 = llvm.mlir.addressof @MOD : !llvm.ptr
%74 = llvm.load %73 : !llvm.ptr -> i64
%75 = arith.addi %72, %74 : i64
llvm.store %75, %67 : i64, !llvm.ptr
cf.br ^bb14
^bb13:
cf.br ^bb14
^bb14:
%76 = llvm.load %67 : !llvm.ptr -> i64
func.return %76 : i64
}
func.func @f_diag_fact(%arg0: i64, %arg1: !llvm.ptr, %arg2: !llvm.ptr, %arg3: !llvm.ptr) -> () {
%77 = arith.constant 0 : i32
%79 = arith.extsi %77 : i32 to i64
%78 = arith.cmpi eq, %arg0, %79 : i64
cf.cond_br %78, ^bb15, ^bb16
^bb15:
%80 = arith.constant 1 : i32
%81 = arith.constant 0 : i32
%82 = arith.extsi %80 : i32 to i64
%83 = arith.extsi %81 : i32 to i64
%84 = llvm.getelementptr %arg1[%83] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %82, %84 : i64, !llvm.ptr
%85 = arith.constant 1 : i32
%86 = arith.constant 0 : i32
%87 = arith.extsi %85 : i32 to i64
%88 = arith.extsi %86 : i32 to i64
%89 = llvm.getelementptr %arg2[%88] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %87, %89 : i64, !llvm.ptr
%90 = arith.constant 1 : i32
%91 = arith.constant 0 : i32
%92 = arith.extsi %90 : i32 to i64
%93 = arith.extsi %91 : i32 to i64
%94 = llvm.getelementptr %arg3[%93] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %92, %94 : i64, !llvm.ptr
func.return
^bb16:
cf.br ^bb17
^bb17:
%95 = arith.constant 1 : i32
%96 = arith.extsi %95 : i32 to i64
%97 = llvm.mlir.constant(1 : i64) : i64
%98 = llvm.alloca %97 x i64 : (i64) -> !llvm.ptr
llvm.store %96, %98 : i64, !llvm.ptr
%99 = arith.constant 1 : i32
%100 = arith.extsi %99 : i32 to i64
%101 = llvm.mlir.constant(1 : i64) : i64
%102 = llvm.alloca %101 x i64 : (i64) -> !llvm.ptr
llvm.store %100, %102 : i64, !llvm.ptr
%103 = arith.constant 0 : i32
%104 = arith.extsi %103 : i32 to i64
%105 = llvm.mlir.constant(1 : i64) : i64
%106 = llvm.alloca %105 x i64 : (i64) -> !llvm.ptr
llvm.store %104, %106 : i64, !llvm.ptr
%107 = arith.constant 0 : i32
%108 = arith.extsi %107 : i32 to i64
%109 = llvm.mlir.constant(1 : i64) : i64
%110 = llvm.alloca %109 x i64 : (i64) -> !llvm.ptr
llvm.store %108, %110 : i64, !llvm.ptr
%111 = arith.constant 0 : i32
%112 = arith.extsi %111 : i32 to i64
%113 = llvm.mlir.constant(1 : i64) : i64
%114 = llvm.alloca %113 x i64 : (i64) -> !llvm.ptr
llvm.store %112, %114 : i64, !llvm.ptr
%115 = arith.constant 0 : i32
%116 = arith.extsi %115 : i32 to i64
%117 = llvm.mlir.constant(1 : i64) : i64
%118 = llvm.alloca %117 x i64 : (i64) -> !llvm.ptr
llvm.store %116, %118 : i64, !llvm.ptr
%119 = arith.constant 0 : i32
%120 = arith.extsi %119 : i32 to i64
%121 = llvm.mlir.constant(1 : i64) : i64
%122 = llvm.alloca %121 x i64 : (i64) -> !llvm.ptr
llvm.store %120, %122 : i64, !llvm.ptr
%123 = arith.constant 3 : i32
%125 = arith.extsi %123 : i32 to i64
%124 = arith.cmpi sle, %arg0, %125 : i64
cf.cond_br %124, ^bb18, ^bb19
^bb18:
%126 = arith.constant 0 : i32
%127 = arith.extsi %126 : i32 to i64
llvm.store %127, %110 : i64, !llvm.ptr
%128 = arith.constant 0 : i32
%129 = arith.extsi %128 : i32 to i64
llvm.store %129, %114 : i64, !llvm.ptr
%130 = arith.constant 0 : i32
%131 = arith.extsi %130 : i32 to i64
llvm.store %131, %118 : i64, !llvm.ptr
%132 = arith.constant 0 : i32
%133 = arith.extsi %132 : i32 to i64
llvm.store %133, %122 : i64, !llvm.ptr
cf.br ^bb20
^bb19:
%134 = arith.constant 1 : i32
%135 = arith.extsi %134 : i32 to i64
llvm.store %135, %110 : i64, !llvm.ptr
%136 = arith.constant 0 : i32
%137 = arith.extsi %136 : i32 to i64
llvm.store %137, %114 : i64, !llvm.ptr
%138 = arith.constant 1 : i32
%139 = arith.extsi %138 : i32 to i64
llvm.store %139, %118 : i64, !llvm.ptr
%140 = arith.constant 4 : i32
%141 = arith.extsi %140 : i32 to i64
llvm.store %141, %122 : i64, !llvm.ptr
cf.br ^bb20
^bb20:
%142 = arith.constant 1 : i32
%143 = arith.extsi %142 : i32 to i64
%144 = llvm.mlir.constant(1 : i64) : i64
%145 = llvm.alloca %144 x i64 : (i64) -> !llvm.ptr
llvm.store %143, %145 : i64, !llvm.ptr
cf.br ^bb21
^bb21:
%146 = llvm.load %145 : !llvm.ptr -> i64
%147 = arith.cmpi sle, %146, %arg0 : i64
cf.cond_br %147, ^bb22, ^bb23
^bb22:
%149 = llvm.load %98 : !llvm.ptr -> i64
%150 = llvm.load %145 : !llvm.ptr -> i64
%151 = llvm.mlir.addressof @MOD : !llvm.ptr
%152 = llvm.load %151 : !llvm.ptr -> i64
%153 = arith.remsi %150, %152 : i64
%148 = func.call @mm(%149, %153) : (i64, i64) -> i64
llvm.store %148, %98 : i64, !llvm.ptr
%154 = llvm.load %145 : !llvm.ptr -> i64
%155 = arith.constant 2 : i32
%157 = arith.extsi %155 : i32 to i64
%156 = arith.cmpi sge, %154, %157 : i64
cf.cond_br %156, ^bb24, ^bb25
^bb24:
%158 = llvm.load %145 : !llvm.ptr -> i64
%159 = arith.constant 1 : i32
%161 = arith.extsi %159 : i32 to i64
%160 = arith.subi %158, %161 : i64
%164 = llvm.mlir.addressof @MOD : !llvm.ptr
%165 = llvm.load %164 : !llvm.ptr -> i64
%166 = arith.remsi %160, %165 : i64
%167 = llvm.load %106 : !llvm.ptr -> i64
%163 = func.call @mm(%166, %167) : (i64, i64) -> i64
%170 = llvm.mlir.addressof @MOD : !llvm.ptr
%171 = llvm.load %170 : !llvm.ptr -> i64
%172 = arith.remsi %160, %171 : i64
%173 = llvm.mlir.addressof @INV2 : !llvm.ptr
%174 = llvm.load %173 : !llvm.ptr -> i64
%169 = func.call @mm(%172, %174) : (i64, i64) -> i64
%175 = llvm.load %102 : !llvm.ptr -> i64
%168 = func.call @mm(%169, %175) : (i64, i64) -> i64
%162 = func.call @madd(%163, %168) : (i64, i64) -> i64
%176 = llvm.load %106 : !llvm.ptr -> i64
llvm.store %176, %102 : i64, !llvm.ptr
llvm.store %162, %106 : i64, !llvm.ptr
cf.br ^bb26
^bb25:
cf.br ^bb26
^bb26:
%177 = arith.constant 4 : i32
%179 = arith.extsi %177 : i32 to i64
%178 = arith.cmpi sge, %arg0, %179 : i64
cf.cond_br %178, ^bb27, ^bb28
^bb27:
%180 = llvm.load %145 : !llvm.ptr -> i64
%181 = arith.constant 4 : i32
%183 = arith.extsi %181 : i32 to i64
%182 = arith.cmpi sge, %180, %183 : i64
cf.cond_br %182, ^bb30, ^bb31
^bb30:
%184 = llvm.load %145 : !llvm.ptr -> i64
%185 = arith.constant 1 : i32
%187 = arith.extsi %185 : i32 to i64
%186 = arith.subi %184, %187 : i64
%189 = arith.constant 2 : i32
%191 = arith.extsi %189 : i32 to i64
%190 = arith.muli %191, %186 : i64
%192 = llvm.mlir.addressof @MOD : !llvm.ptr
%193 = llvm.load %192 : !llvm.ptr -> i64
%194 = arith.remsi %190, %193 : i64
%195 = llvm.load %122 : !llvm.ptr -> i64
%188 = func.call @mm(%194, %195) : (i64, i64) -> i64
%198 = llvm.mlir.addressof @MOD : !llvm.ptr
%199 = llvm.load %198 : !llvm.ptr -> i64
%200 = arith.remsi %186, %199 : i64
%201 = arith.constant 2 : i32
%203 = arith.extsi %201 : i32 to i64
%202 = arith.subi %186, %203 : i64
%204 = llvm.mlir.addressof @MOD : !llvm.ptr
%205 = llvm.load %204 : !llvm.ptr -> i64
%206 = arith.remsi %202, %205 : i64
%197 = func.call @mm(%200, %206) : (i64, i64) -> i64
%207 = llvm.load %118 : !llvm.ptr -> i64
%196 = func.call @mm(%197, %207) : (i64, i64) -> i64
%211 = llvm.mlir.addressof @MOD : !llvm.ptr
%212 = llvm.load %211 : !llvm.ptr -> i64
%213 = arith.remsi %186, %212 : i64
%214 = arith.constant 1 : i32
%216 = arith.extsi %214 : i32 to i64
%215 = arith.subi %186, %216 : i64
%217 = llvm.mlir.addressof @MOD : !llvm.ptr
%218 = llvm.load %217 : !llvm.ptr -> i64
%219 = arith.remsi %215, %218 : i64
%210 = func.call @mm(%213, %219) : (i64, i64) -> i64
%220 = arith.constant 2 : i32
%222 = arith.extsi %220 : i32 to i64
%221 = arith.subi %186, %222 : i64
%223 = llvm.mlir.addressof @MOD : !llvm.ptr
%224 = llvm.load %223 : !llvm.ptr -> i64
%225 = arith.remsi %221, %224 : i64
%209 = func.call @mm(%210, %225) : (i64, i64) -> i64
%226 = llvm.load %110 : !llvm.ptr -> i64
%208 = func.call @mm(%209, %226) : (i64, i64) -> i64
%228 = func.call @msub(%188, %196) : (i64, i64) -> i64
%230 = llvm.mlir.addressof @INV2 : !llvm.ptr
%231 = llvm.load %230 : !llvm.ptr -> i64
%229 = func.call @mm(%208, %231) : (i64, i64) -> i64
%227 = func.call @msub(%228, %229) : (i64, i64) -> i64
%232 = llvm.load %114 : !llvm.ptr -> i64
llvm.store %232, %110 : i64, !llvm.ptr
%233 = llvm.load %118 : !llvm.ptr -> i64
llvm.store %233, %114 : i64, !llvm.ptr
%234 = llvm.load %122 : !llvm.ptr -> i64
llvm.store %234, %118 : i64, !llvm.ptr
llvm.store %227, %122 : i64, !llvm.ptr
cf.br ^bb32
^bb31:
cf.br ^bb32
^bb32:
cf.br ^bb29
^bb28:
cf.br ^bb29
^bb29:
%235 = llvm.load %145 : !llvm.ptr -> i64
%236 = arith.constant 1 : i32
%238 = arith.extsi %236 : i32 to i64
%237 = arith.addi %235, %238 : i64
llvm.store %237, %145 : i64, !llvm.ptr
cf.br ^bb21
^bb23:
%240 = llvm.load %98 : !llvm.ptr -> i64
%241 = llvm.load %106 : !llvm.ptr -> i64
%239 = func.call @mm(%240, %241) : (i64, i64) -> i64
%242 = arith.constant 0 : i32
%243 = arith.extsi %242 : i32 to i64
%244 = llvm.getelementptr %arg1[%243] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %239, %244 : i64, !llvm.ptr
%245 = arith.constant 0 : i32
%246 = arith.extsi %245 : i32 to i64
%247 = llvm.mlir.constant(1 : i64) : i64
%248 = llvm.alloca %247 x i64 : (i64) -> !llvm.ptr
llvm.store %246, %248 : i64, !llvm.ptr
%249 = arith.constant 0 : i32
%251 = arith.extsi %249 : i32 to i64
%250 = arith.cmpi eq, %arg0, %251 : i64
cf.cond_br %250, ^bb33, ^bb34
^bb33:
%252 = arith.constant 1 : i32
%253 = arith.extsi %252 : i32 to i64
llvm.store %253, %248 : i64, !llvm.ptr
cf.br ^bb35
^bb34:
%254 = arith.constant 1 : i32
%256 = arith.extsi %254 : i32 to i64
%255 = arith.cmpi eq, %arg0, %256 : i64
cf.cond_br %255, ^bb36, ^bb37
^bb36:
%257 = arith.constant 0 : i32
%258 = arith.extsi %257 : i32 to i64
llvm.store %258, %248 : i64, !llvm.ptr
cf.br ^bb38
^bb37:
%259 = arith.constant 2 : i32
%261 = arith.extsi %259 : i32 to i64
%260 = arith.cmpi eq, %arg0, %261 : i64
cf.cond_br %260, ^bb39, ^bb40
^bb39:
%262 = arith.constant 1 : i32
%263 = arith.extsi %262 : i32 to i64
llvm.store %263, %248 : i64, !llvm.ptr
cf.br ^bb41
^bb40:
%264 = arith.constant 3 : i32
%266 = arith.extsi %264 : i32 to i64
%265 = arith.cmpi eq, %arg0, %266 : i64
cf.cond_br %265, ^bb42, ^bb43
^bb42:
%267 = arith.constant 4 : i32
%268 = arith.extsi %267 : i32 to i64
llvm.store %268, %248 : i64, !llvm.ptr
cf.br ^bb44
^bb43:
%269 = llvm.load %122 : !llvm.ptr -> i64
llvm.store %269, %248 : i64, !llvm.ptr
cf.br ^bb44
^bb44:
cf.br ^bb41
^bb41:
cf.br ^bb38
^bb38:
cf.br ^bb35
^bb35:
%270 = llvm.load %248 : !llvm.ptr -> i64
%271 = arith.constant 0 : i32
%272 = arith.extsi %271 : i32 to i64
%273 = llvm.getelementptr %arg2[%272] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %270, %273 : i64, !llvm.ptr
%274 = llvm.load %98 : !llvm.ptr -> i64
%275 = arith.constant 0 : i32
%276 = arith.extsi %275 : i32 to i64
%277 = llvm.getelementptr %arg3[%276] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %274, %277 : i64, !llvm.ptr
func.return
}
func.func @fix_axis_reflection(%arg0: i64, %arg1: i64) -> i64 {
%278 = arith.constant 2 : i32
%280 = arith.extsi %278 : i32 to i64
%279 = arith.remsi %arg0, %280 : i64
%281 = arith.constant 1 : i32
%283 = arith.extsi %281 : i32 to i64
%282 = arith.cmpi eq, %279, %283 : i64
cf.cond_br %282, ^bb45, ^bb46
^bb45:
%284 = arith.constant 0 : i32
%285 = arith.extsi %284 : i32 to i64
func.return %285 : i64
^bb46:
cf.br ^bb47
^bb47:
%288 = llvm.mlir.addressof @INV2 : !llvm.ptr
%289 = llvm.load %288 : !llvm.ptr -> i64
%290 = arith.constant 2 : i32
%292 = arith.extsi %290 : i32 to i64
%291 = arith.divsi %arg0, %292 : i64
%287 = func.call @mpow(%289, %291) : (i64, i64) -> i64
%286 = func.call @mm(%arg1, %287) : (i64, i64) -> i64
func.return %286 : i64
}
func.func @fix_rotation_90(%arg0: i64) -> i64 {
%293 = arith.constant 2 : i32
%295 = arith.extsi %293 : i32 to i64
%294 = arith.remsi %arg0, %295 : i64
%296 = arith.constant 1 : i32
%298 = arith.extsi %296 : i32 to i64
%297 = arith.cmpi eq, %294, %298 : i64
cf.cond_br %297, ^bb48, ^bb49
^bb48:
%299 = arith.constant 0 : i32
%300 = arith.extsi %299 : i32 to i64
func.return %300 : i64
^bb49:
cf.br ^bb50
^bb50:
%301 = arith.constant 2 : i32
%303 = arith.extsi %301 : i32 to i64
%302 = arith.divsi %arg0, %303 : i64
%304 = arith.constant 0 : i32
%306 = arith.extsi %304 : i32 to i64
%305 = arith.cmpi eq, %302, %306 : i64
cf.cond_br %305, ^bb51, ^bb52
^bb51:
%307 = arith.constant 1 : i32
%308 = arith.extsi %307 : i32 to i64
func.return %308 : i64
^bb52:
cf.br ^bb53
^bb53:
%309 = arith.constant 1 : i32
%311 = arith.extsi %309 : i32 to i64
%310 = arith.cmpi eq, %302, %311 : i64
cf.cond_br %310, ^bb54, ^bb55
^bb54:
%312 = arith.constant 1 : i32
%313 = arith.extsi %312 : i32 to i64
func.return %313 : i64
^bb55:
cf.br ^bb56
^bb56:
%314 = arith.constant 2 : i32
%316 = arith.extsi %314 : i32 to i64
%315 = arith.cmpi eq, %302, %316 : i64
cf.cond_br %315, ^bb57, ^bb58
^bb57:
%317 = arith.constant 2 : i32
%318 = arith.extsi %317 : i32 to i64
func.return %318 : i64
^bb58:
cf.br ^bb59
^bb59:
%319 = arith.constant 1 : i32
%320 = arith.extsi %319 : i32 to i64
%321 = llvm.mlir.constant(1 : i64) : i64
%322 = llvm.alloca %321 x i64 : (i64) -> !llvm.ptr
llvm.store %320, %322 : i64, !llvm.ptr
%323 = arith.constant 1 : i32
%324 = arith.extsi %323 : i32 to i64
%325 = llvm.mlir.constant(1 : i64) : i64
%326 = llvm.alloca %325 x i64 : (i64) -> !llvm.ptr
llvm.store %324, %326 : i64, !llvm.ptr
%327 = arith.constant 2 : i32
%328 = arith.extsi %327 : i32 to i64
%329 = llvm.mlir.constant(1 : i64) : i64
%330 = llvm.alloca %329 x i64 : (i64) -> !llvm.ptr
llvm.store %328, %330 : i64, !llvm.ptr
%331 = arith.constant 2 : 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 ^bb60
^bb60:
%335 = llvm.load %334 : !llvm.ptr -> i64
%336 = arith.cmpi slt, %335, %302 : i64
cf.cond_br %336, ^bb61, ^bb62
^bb61:
%340 = arith.constant 2 : i32
%341 = llvm.load %334 : !llvm.ptr -> i64
%343 = arith.extsi %340 : i32 to i64
%342 = arith.muli %343, %341 : i64
%344 = arith.constant 1 : i32
%346 = arith.extsi %344 : i32 to i64
%345 = arith.addi %342, %346 : i64
%347 = llvm.mlir.addressof @MOD : !llvm.ptr
%348 = llvm.load %347 : !llvm.ptr -> i64
%349 = arith.remsi %345, %348 : i64
%350 = llvm.load %330 : !llvm.ptr -> i64
%339 = func.call @mm(%349, %350) : (i64, i64) -> i64
%352 = arith.constant 2 : i32
%353 = llvm.load %334 : !llvm.ptr -> i64
%355 = arith.extsi %352 : i32 to i64
%354 = arith.muli %355, %353 : i64
%356 = llvm.mlir.addressof @MOD : !llvm.ptr
%357 = llvm.load %356 : !llvm.ptr -> i64
%358 = arith.remsi %354, %357 : i64
%359 = llvm.load %334 : !llvm.ptr -> i64
%360 = arith.constant 1 : i32
%362 = arith.extsi %360 : i32 to i64
%361 = arith.subi %359, %362 : i64
%363 = llvm.mlir.addressof @MOD : !llvm.ptr
%364 = llvm.load %363 : !llvm.ptr -> i64
%365 = arith.remsi %361, %364 : i64
%366 = arith.muli %358, %365 : i64
%367 = llvm.mlir.addressof @MOD : !llvm.ptr
%368 = llvm.load %367 : !llvm.ptr -> i64
%369 = arith.remsi %366, %368 : i64
%370 = llvm.load %322 : !llvm.ptr -> i64
%351 = func.call @mm(%369, %370) : (i64, i64) -> i64
%338 = func.call @madd(%339, %351) : (i64, i64) -> i64
%372 = llvm.load %334 : !llvm.ptr -> i64
%373 = llvm.mlir.addressof @MOD : !llvm.ptr
%374 = llvm.load %373 : !llvm.ptr -> i64
%375 = arith.remsi %372, %374 : i64
%376 = llvm.load %326 : !llvm.ptr -> i64
%371 = func.call @mm(%375, %376) : (i64, i64) -> i64
%337 = func.call @msub(%338, %371) : (i64, i64) -> i64
%377 = llvm.load %326 : !llvm.ptr -> i64
llvm.store %377, %322 : i64, !llvm.ptr
%378 = llvm.load %330 : !llvm.ptr -> i64
llvm.store %378, %326 : i64, !llvm.ptr
llvm.store %337, %330 : i64, !llvm.ptr
%379 = llvm.load %334 : !llvm.ptr -> i64
%380 = arith.constant 1 : i32
%382 = arith.extsi %380 : i32 to i64
%381 = arith.addi %379, %382 : i64
llvm.store %381, %334 : i64, !llvm.ptr
cf.br ^bb60
^bb62:
%383 = llvm.load %330 : !llvm.ptr -> i64
func.return %383 : i64
}
func.func @fix_rotation_180(%arg0: i64) -> i64 {
%384 = arith.constant 0 : i32
%386 = arith.extsi %384 : i32 to i64
%385 = arith.cmpi eq, %arg0, %386 : i64
cf.cond_br %385, ^bb63, ^bb64
^bb63:
%387 = arith.constant 1 : i32
%388 = arith.extsi %387 : i32 to i64
func.return %388 : i64
^bb64:
cf.br ^bb65
^bb65:
%389 = arith.constant 2 : i32
%391 = arith.extsi %389 : i32 to i64
%390 = arith.remsi %arg0, %391 : i64
%392 = arith.constant 0 : i32
%394 = arith.extsi %392 : i32 to i64
%393 = arith.cmpi eq, %390, %394 : i64
cf.cond_br %393, ^bb66, ^bb67
^bb66:
%395 = arith.constant 2 : i32
%397 = arith.extsi %395 : i32 to i64
%396 = arith.divsi %arg0, %397 : i64
%398 = arith.constant 0 : i32
%400 = arith.extsi %398 : i32 to i64
%399 = arith.cmpi eq, %396, %400 : i64
cf.cond_br %399, ^bb69, ^bb70
^bb69:
%401 = arith.constant 1 : i32
%402 = arith.extsi %401 : i32 to i64
func.return %402 : i64
^bb70:
cf.br ^bb71
^bb71:
%403 = arith.constant 1 : i32
%405 = arith.extsi %403 : i32 to i64
%404 = arith.cmpi eq, %396, %405 : i64
cf.cond_br %404, ^bb72, ^bb73
^bb72:
%406 = arith.constant 1 : i32
%407 = arith.extsi %406 : i32 to i64
func.return %407 : i64
^bb73:
cf.br ^bb74
^bb74:
%408 = arith.constant 1 : i32
%409 = arith.extsi %408 : i32 to i64
%410 = llvm.mlir.constant(1 : i64) : i64
%411 = llvm.alloca %410 x i64 : (i64) -> !llvm.ptr
llvm.store %409, %411 : i64, !llvm.ptr
%412 = arith.constant 1 : i32
%413 = arith.extsi %412 : i32 to i64
%414 = llvm.mlir.constant(1 : i64) : i64
%415 = llvm.alloca %414 x i64 : (i64) -> !llvm.ptr
llvm.store %413, %415 : i64, !llvm.ptr
%416 = arith.constant 1 : i32
%417 = arith.extsi %416 : i32 to i64
%418 = llvm.mlir.constant(1 : i64) : i64
%419 = llvm.alloca %418 x i64 : (i64) -> !llvm.ptr
llvm.store %417, %419 : i64, !llvm.ptr
%420 = arith.constant 1 : i32
%421 = arith.extsi %420 : i32 to i64
%422 = llvm.mlir.constant(1 : i64) : i64
%423 = llvm.alloca %422 x i64 : (i64) -> !llvm.ptr
llvm.store %421, %423 : i64, !llvm.ptr
cf.br ^bb75
^bb75:
%424 = llvm.load %423 : !llvm.ptr -> i64
%425 = arith.cmpi slt, %424, %396 : i64
cf.cond_br %425, ^bb76, ^bb77
^bb76:
%427 = llvm.load %419 : !llvm.ptr -> i64
%428 = llvm.load %423 : !llvm.ptr -> i64
%429 = llvm.mlir.addressof @MOD : !llvm.ptr
%430 = llvm.load %429 : !llvm.ptr -> i64
%431 = arith.remsi %428, %430 : i64
%426 = func.call @mm(%427, %431) : (i64, i64) -> i64
llvm.store %426, %419 : i64, !llvm.ptr
%434 = arith.constant 4 : i32
%435 = llvm.load %423 : !llvm.ptr -> i64
%437 = arith.extsi %434 : i32 to i64
%436 = arith.muli %437, %435 : i64
%438 = arith.constant 1 : i32
%440 = arith.extsi %438 : i32 to i64
%439 = arith.addi %436, %440 : i64
%441 = llvm.mlir.addressof @MOD : !llvm.ptr
%442 = llvm.load %441 : !llvm.ptr -> i64
%443 = arith.remsi %439, %442 : i64
%444 = llvm.load %415 : !llvm.ptr -> i64
%433 = func.call @mm(%443, %444) : (i64, i64) -> i64
%446 = arith.constant 4 : i32
%447 = llvm.load %423 : !llvm.ptr -> i64
%449 = arith.extsi %446 : i32 to i64
%448 = arith.muli %449, %447 : i64
%450 = llvm.mlir.addressof @MOD : !llvm.ptr
%451 = llvm.load %450 : !llvm.ptr -> i64
%452 = arith.remsi %448, %451 : i64
%453 = llvm.load %411 : !llvm.ptr -> i64
%445 = func.call @mm(%452, %453) : (i64, i64) -> i64
%432 = func.call @madd(%433, %445) : (i64, i64) -> i64
%454 = llvm.load %415 : !llvm.ptr -> i64
llvm.store %454, %411 : i64, !llvm.ptr
llvm.store %432, %415 : i64, !llvm.ptr
%455 = llvm.load %423 : !llvm.ptr -> i64
%456 = arith.constant 1 : i32
%458 = arith.extsi %456 : i32 to i64
%457 = arith.addi %455, %458 : i64
llvm.store %457, %423 : i64, !llvm.ptr
cf.br ^bb75
^bb77:
%460 = llvm.load %419 : !llvm.ptr -> i64
%461 = llvm.mlir.addressof @MOD : !llvm.ptr
%462 = llvm.load %461 : !llvm.ptr -> i64
%463 = arith.remsi %396, %462 : i64
%459 = func.call @mm(%460, %463) : (i64, i64) -> i64
%465 = llvm.load %415 : !llvm.ptr -> i64
%464 = func.call @mm(%459, %465) : (i64, i64) -> i64
func.return %464 : i64
^bb67:
cf.br ^bb68
^bb68:
%466 = arith.constant 1 : i32
%468 = arith.extsi %466 : i32 to i64
%467 = arith.subi %arg0, %468 : i64
%469 = arith.constant 2 : i32
%471 = arith.extsi %469 : i32 to i64
%470 = arith.divsi %467, %471 : i64
%472 = arith.constant 0 : i32
%474 = arith.extsi %472 : i32 to i64
%473 = arith.cmpi eq, %470, %474 : i64
cf.cond_br %473, ^bb78, ^bb79
^bb78:
%475 = arith.constant 0 : i32
%476 = arith.extsi %475 : i32 to i64
func.return %476 : i64
^bb79:
cf.br ^bb80
^bb80:
%477 = arith.constant 1 : i32
%478 = arith.extsi %477 : i32 to i64
%479 = llvm.mlir.constant(1 : i64) : i64
%480 = llvm.alloca %479 x i64 : (i64) -> !llvm.ptr
llvm.store %478, %480 : i64, !llvm.ptr
%481 = arith.constant 0 : i32
%482 = arith.extsi %481 : i32 to i64
%483 = llvm.mlir.constant(1 : i64) : i64
%484 = llvm.alloca %483 x i64 : (i64) -> !llvm.ptr
llvm.store %482, %484 : i64, !llvm.ptr
%485 = arith.constant 1 : i32
%486 = arith.extsi %485 : i32 to i64
%487 = llvm.mlir.constant(1 : i64) : i64
%488 = llvm.alloca %487 x i64 : (i64) -> !llvm.ptr
llvm.store %486, %488 : i64, !llvm.ptr
%489 = arith.constant 1 : i32
%490 = arith.extsi %489 : i32 to i64
%491 = llvm.mlir.constant(1 : i64) : i64
%492 = llvm.alloca %491 x i64 : (i64) -> !llvm.ptr
llvm.store %490, %492 : i64, !llvm.ptr
%493 = arith.constant 1 : i32
%494 = arith.extsi %493 : i32 to i64
%495 = llvm.mlir.constant(1 : i64) : i64
%496 = llvm.alloca %495 x i64 : (i64) -> !llvm.ptr
llvm.store %494, %496 : i64, !llvm.ptr
cf.br ^bb81
^bb81:
%497 = llvm.load %496 : !llvm.ptr -> i64
%498 = arith.cmpi sle, %497, %470 : i64
cf.cond_br %498, ^bb82, ^bb83
^bb82:
%500 = llvm.load %480 : !llvm.ptr -> i64
%501 = llvm.load %496 : !llvm.ptr -> i64
%502 = llvm.mlir.addressof @MOD : !llvm.ptr
%503 = llvm.load %502 : !llvm.ptr -> i64
%504 = arith.remsi %501, %503 : i64
%499 = func.call @mm(%500, %504) : (i64, i64) -> i64
llvm.store %499, %480 : i64, !llvm.ptr
%507 = arith.constant 4 : i32
%508 = llvm.load %496 : !llvm.ptr -> i64
%510 = arith.extsi %507 : i32 to i64
%509 = arith.muli %510, %508 : i64
%511 = llvm.mlir.addressof @MOD : !llvm.ptr
%512 = llvm.load %511 : !llvm.ptr -> i64
%513 = arith.remsi %509, %512 : i64
%514 = llvm.load %484 : !llvm.ptr -> i64
%506 = func.call @mm(%513, %514) : (i64, i64) -> i64
%516 = arith.constant 2 : i32
%517 = llvm.load %496 : !llvm.ptr -> i64
%519 = arith.extsi %516 : i32 to i64
%518 = arith.muli %519, %517 : i64
%520 = llvm.mlir.addressof @MOD : !llvm.ptr
%521 = llvm.load %520 : !llvm.ptr -> i64
%522 = arith.remsi %518, %521 : i64
%523 = llvm.load %488 : !llvm.ptr -> i64
%515 = func.call @mm(%522, %523) : (i64, i64) -> i64
%505 = func.call @madd(%506, %515) : (i64, i64) -> i64
llvm.store %505, %484 : i64, !llvm.ptr
%524 = llvm.load %496 : !llvm.ptr -> i64
%525 = arith.cmpi slt, %524, %470 : i64
cf.cond_br %525, ^bb84, ^bb85
^bb84:
%528 = arith.constant 4 : i32
%529 = llvm.load %496 : !llvm.ptr -> i64
%531 = arith.extsi %528 : i32 to i64
%530 = arith.muli %531, %529 : i64
%532 = arith.constant 1 : i32
%534 = arith.extsi %532 : i32 to i64
%533 = arith.addi %530, %534 : i64
%535 = llvm.mlir.addressof @MOD : !llvm.ptr
%536 = llvm.load %535 : !llvm.ptr -> i64
%537 = arith.remsi %533, %536 : i64
%538 = llvm.load %492 : !llvm.ptr -> i64
%527 = func.call @mm(%537, %538) : (i64, i64) -> i64
%540 = arith.constant 4 : i32
%541 = llvm.load %496 : !llvm.ptr -> i64
%543 = arith.extsi %540 : i32 to i64
%542 = arith.muli %543, %541 : i64
%544 = llvm.mlir.addressof @MOD : !llvm.ptr
%545 = llvm.load %544 : !llvm.ptr -> i64
%546 = arith.remsi %542, %545 : i64
%547 = llvm.load %488 : !llvm.ptr -> i64
%539 = func.call @mm(%546, %547) : (i64, i64) -> i64
%526 = func.call @madd(%527, %539) : (i64, i64) -> i64
%548 = llvm.load %492 : !llvm.ptr -> i64
llvm.store %548, %488 : i64, !llvm.ptr
llvm.store %526, %492 : i64, !llvm.ptr
cf.br ^bb86
^bb85:
cf.br ^bb86
^bb86:
%549 = llvm.load %496 : !llvm.ptr -> i64
%550 = arith.constant 1 : i32
%552 = arith.extsi %550 : i32 to i64
%551 = arith.addi %549, %552 : i64
llvm.store %551, %496 : i64, !llvm.ptr
cf.br ^bb81
^bb83:
%554 = llvm.load %480 : !llvm.ptr -> i64
%555 = llvm.load %484 : !llvm.ptr -> i64
%553 = func.call @mm(%554, %555) : (i64, i64) -> i64
func.return %553 : i64
}
func.func @g(%arg0: i64) -> i64 {
%557 = arith.constant 0 : i32
%558 = arith.constant 0 : i32
%559 = arith.constant 0 : i32
%560 = llvm.mlir.constant(1 : i64) : i64
%561 = llvm.alloca %560 x !llvm.array<3 x i64> : (i64) -> !llvm.ptr
%562 = llvm.mlir.zero : !llvm.array<3 x i64>
llvm.store %562, %561 : !llvm.array<3 x i64>, !llvm.ptr
%563 = arith.extsi %557 : i32 to i64
%564 = arith.extsi %558 : i32 to i64
%565 = arith.extsi %559 : i32 to i64
%566 = llvm.mlir.constant(0 : i64) : i64
%567 = llvm.getelementptr %561[0, %566] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<3 x i64>
llvm.store %563, %567 : i64, !llvm.ptr
%568 = llvm.mlir.constant(1 : i64) : i64
%569 = llvm.getelementptr %561[0, %568] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<3 x i64>
llvm.store %564, %569 : i64, !llvm.ptr
%570 = llvm.mlir.constant(2 : i64) : i64
%571 = llvm.getelementptr %561[0, %570] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<3 x i64>
llvm.store %565, %571 : i64, !llvm.ptr
%573 = arith.constant 0 : i32
%574 = arith.extsi %573 : i32 to i64
%575 = llvm.getelementptr %561[0, %574] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<3 x i64>
%576 = arith.constant 1 : i32
%577 = arith.extsi %576 : i32 to i64
%578 = llvm.getelementptr %561[0, %577] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<3 x i64>
%579 = arith.constant 2 : i32
%580 = arith.extsi %579 : i32 to i64
%581 = llvm.getelementptr %561[0, %580] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<3 x i64>
func.call @f_diag_fact(%arg0, %575, %578, %581) : (i64, !llvm.ptr, !llvm.ptr, !llvm.ptr) -> ()
%583 = arith.constant 0 : i32
%584 = arith.extsi %583 : i32 to i64
%585 = llvm.getelementptr %561[0, %584] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<3 x i64>
%582 = llvm.load %585 : !llvm.ptr -> i64
%587 = arith.constant 1 : i32
%588 = arith.extsi %587 : i32 to i64
%589 = llvm.getelementptr %561[0, %588] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<3 x i64>
%586 = llvm.load %589 : !llvm.ptr -> i64
%591 = arith.constant 2 : i32
%592 = arith.extsi %591 : i32 to i64
%593 = llvm.getelementptr %561[0, %592] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<3 x i64>
%590 = llvm.load %593 : !llvm.ptr -> i64
%594 = func.call @fix_axis_reflection(%arg0, %590) : (i64, i64) -> i64
%595 = func.call @fix_rotation_180(%arg0) : (i64) -> i64
%596 = func.call @fix_rotation_90(%arg0) : (i64) -> i64
%597 = llvm.mlir.constant(1 : i64) : i64
%598 = llvm.alloca %597 x i64 : (i64) -> !llvm.ptr
llvm.store %582, %598 : i64, !llvm.ptr
%600 = llvm.load %598 : !llvm.ptr -> i64
%599 = func.call @madd(%600, %595) : (i64, i64) -> i64
llvm.store %599, %598 : i64, !llvm.ptr
%602 = llvm.load %598 : !llvm.ptr -> i64
%604 = arith.constant 2 : i32
%605 = arith.extsi %604 : i32 to i64
%603 = func.call @mm(%605, %596) : (i64, i64) -> i64
%601 = func.call @madd(%602, %603) : (i64, i64) -> i64
llvm.store %601, %598 : i64, !llvm.ptr
%607 = llvm.load %598 : !llvm.ptr -> i64
%609 = arith.constant 2 : i32
%610 = arith.extsi %609 : i32 to i64
%608 = func.call @mm(%610, %594) : (i64, i64) -> i64
%606 = func.call @madd(%607, %608) : (i64, i64) -> i64
llvm.store %606, %598 : i64, !llvm.ptr
%612 = llvm.load %598 : !llvm.ptr -> i64
%614 = arith.constant 2 : i32
%615 = arith.extsi %614 : i32 to i64
%613 = func.call @mm(%615, %586) : (i64, i64) -> i64
%611 = func.call @madd(%612, %613) : (i64, i64) -> i64
llvm.store %611, %598 : i64, !llvm.ptr
%617 = llvm.load %598 : !llvm.ptr -> i64
%618 = llvm.mlir.addressof @INV8 : !llvm.ptr
%619 = llvm.load %618 : !llvm.ptr -> i64
%616 = func.call @mm(%617, %619) : (i64, i64) -> i64
func.return %616 : i64
}
func.func @main() -> i32 {
%620 = arith.constant 1 : i32
%621 = arith.extsi %620 : i32 to i64
%622 = llvm.mlir.constant(1 : i64) : i64
%623 = llvm.alloca %622 x i64 : (i64) -> !llvm.ptr
llvm.store %621, %623 : i64, !llvm.ptr
%624 = arith.constant 0 : i32
%625 = llvm.mlir.constant(1 : i64) : i64
%626 = llvm.alloca %625 x i32 : (i64) -> !llvm.ptr
llvm.store %624, %626 : i32, !llvm.ptr
cf.br ^bb87
^bb87:
%627 = llvm.load %626 : !llvm.ptr -> i32
%628 = arith.constant 7 : i32
%629 = arith.cmpi slt, %627, %628 : i32
cf.cond_br %629, ^bb88, ^bb89
^bb88:
%630 = llvm.load %623 : !llvm.ptr -> i64
%631 = arith.constant 7 : i32
%633 = arith.extsi %631 : i32 to i64
%632 = arith.muli %630, %633 : i64
llvm.store %632, %623 : i64, !llvm.ptr
%634 = llvm.load %626 : !llvm.ptr -> i32
%635 = arith.constant 1 : i32
%636 = arith.addi %634, %635 : i32
llvm.store %636, %626 : i32, !llvm.ptr
cf.br ^bb87
^bb89:
%637 = arith.constant 1 : i32
%638 = arith.extsi %637 : i32 to i64
%639 = llvm.mlir.constant(1 : i64) : i64
%640 = llvm.alloca %639 x i64 : (i64) -> !llvm.ptr
llvm.store %638, %640 : i64, !llvm.ptr
%641 = arith.constant 0 : i32
%642 = llvm.mlir.constant(1 : i64) : i64
%643 = llvm.alloca %642 x i32 : (i64) -> !llvm.ptr
llvm.store %641, %643 : i32, !llvm.ptr
cf.br ^bb90
^bb90:
%644 = llvm.load %643 : !llvm.ptr -> i32
%645 = arith.constant 8 : i32
%646 = arith.cmpi slt, %644, %645 : i32
cf.cond_br %646, ^bb91, ^bb92
^bb91:
%647 = llvm.load %640 : !llvm.ptr -> i64
%648 = arith.constant 8 : i32
%650 = arith.extsi %648 : i32 to i64
%649 = arith.muli %647, %650 : i64
llvm.store %649, %640 : i64, !llvm.ptr
%651 = llvm.load %643 : !llvm.ptr -> i32
%652 = arith.constant 1 : i32
%653 = arith.addi %651, %652 : i32
llvm.store %653, %643 : i32, !llvm.ptr
cf.br ^bb90
^bb92:
%656 = llvm.load %623 : !llvm.ptr -> i64
%655 = func.call @g(%656) : (i64) -> i64
%658 = llvm.load %640 : !llvm.ptr -> i64
%657 = func.call @g(%658) : (i64) -> i64
%654 = func.call @madd(%655, %657) : (i64, i64) -> i64
%659 = llvm.mlir.addressof @str_0 : !llvm.ptr
%660 = llvm.call @printf(%659, %654) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%661 = arith.constant 0 : i32
func.return %661 : i32
}
}