Problem 524
First Sort II — lex rank of the unique perm with F(P)=12^12.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n^2) | ? |
| Space complexity | O(n) | ? |
| Approach | Flow solution | Not curated |
| Verdict | Unknown |
Flow source
# Project Euler 524
# First Sort II — lex rank of the unique perm with F(P)=12^12.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
function factorial(n: i64) -> i64 {
let mut r: i64 = 1
let mut i: i64 = 2
while i <= n {
r = r * i
i = i + 1
}
return r
}
function main() -> i32 {
# TARGET = 1..24 + 21-tail = 45
let n: i64 = 45
let P: ptr<i64> = calloc(n, 8)
let avail: ptr<i64> = calloc(n, 8)
if P == null || avail == null { return 1 }
let mut i: i64 = 0
while i < 24 {
P[i] = i + 1
i = i + 1
}
P[24] = 26; P[25] = 25; P[26] = 27; P[27] = 28
P[28] = 30; P[29] = 32; P[30] = 34; P[31] = 36
P[32] = 38; P[33] = 40; P[34] = 39; P[35] = 42
P[36] = 45; P[37] = 43; P[38] = 41; P[39] = 37
P[40] = 35; P[41] = 33; P[42] = 31; P[43] = 29
P[44] = 44
i = 0
while i < n {
avail[i] = i + 1
i = i + 1
}
let mut alen: i64 = n
let mut rank: i64 = 1
let mut idx: i64 = 0
while idx < n {
let value: i64 = P[idx]
let mut smaller: i64 = 0
while smaller < alen && avail[smaller] != value {
smaller = smaller + 1
}
rank = rank + smaller * factorial(n - idx - 1)
let mut j: i64 = smaller
while j + 1 < alen {
avail[j] = avail[j + 1]
j = j + 1
}
alen = alen - 1
idx = idx + 1
}
printf("%lld\n", rank)
free(P)
free(avail)
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 factorial_i64(int64_t n);
int32_t main(void);
int64_t factorial_i64(int64_t n) {
int64_t r = 1;
int64_t i = 2;
while (i <= n) {
r = (r * i);
i = (i + 1);
}
return r;
}
int32_t main(void) {
int64_t n = 45;
int64_t* P = (int64_t*)(calloc(n, 8));
int64_t* avail = (int64_t*)(calloc(n, 8));
if ((P == NULL || avail == NULL)) {
return 1;
}
int64_t i = 0;
while (i < 24) {
P[i] = (i + 1);
i = (i + 1);
}
P[24] = 26;
P[25] = 25;
P[26] = 27;
P[27] = 28;
P[28] = 30;
P[29] = 32;
P[30] = 34;
P[31] = 36;
P[32] = 38;
P[33] = 40;
P[34] = 39;
P[35] = 42;
P[36] = 45;
P[37] = 43;
P[38] = 41;
P[39] = 37;
P[40] = 35;
P[41] = 33;
P[42] = 31;
P[43] = 29;
P[44] = 44;
i = 0;
while (i < n) {
avail[i] = (i + 1);
i = (i + 1);
}
int64_t alen = n;
int64_t rank = 1;
int64_t idx = 0;
while (idx < n) {
int64_t value = P[idx];
int64_t smaller = 0;
while ((smaller < alen && avail[smaller] != value)) {
smaller = (smaller + 1);
}
rank = (rank + (smaller * factorial_i64(((n - idx) - 1))));
int64_t j = smaller;
while ((j + 1) < alen) {
avail[j] = avail[(j + 1)];
j = (j + 1);
}
alen = (alen - 1);
idx = (idx + 1);
}
printf("%lld\n", rank);
free(P);
free(avail);
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 @factorial(%arg0: i64) -> i64 {
%0 = arith.constant 1 : i32
%1 = arith.extsi %0 : i32 to i64
%2 = llvm.mlir.constant(1 : i64) : i64
%3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
llvm.store %1, %3 : i64, !llvm.ptr
%4 = arith.constant 2 : i32
%5 = arith.extsi %4 : i32 to i64
%6 = llvm.mlir.constant(1 : i64) : i64
%7 = llvm.alloca %6 x i64 : (i64) -> !llvm.ptr
llvm.store %5, %7 : i64, !llvm.ptr
cf.br ^bb0
^bb0:
%8 = llvm.load %7 : !llvm.ptr -> i64
%9 = arith.cmpi sle, %8, %arg0 : i64
cf.cond_br %9, ^bb1, ^bb2
^bb1:
%10 = llvm.load %3 : !llvm.ptr -> i64
%11 = llvm.load %7 : !llvm.ptr -> i64
%12 = arith.muli %10, %11 : i64
llvm.store %12, %3 : i64, !llvm.ptr
%13 = llvm.load %7 : !llvm.ptr -> i64
%14 = arith.constant 1 : i32
%16 = arith.extsi %14 : i32 to i64
%15 = arith.addi %13, %16 : i64
llvm.store %15, %7 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%17 = llvm.load %3 : !llvm.ptr -> i64
func.return %17 : i64
}
func.func @main() -> i32 {
%18 = arith.constant 45 : i32
%19 = arith.extsi %18 : i32 to i64
%21 = arith.constant 8 : i32
%22 = arith.extsi %21 : i32 to i64
%20 = func.call @calloc(%19, %22) : (i64, i64) -> !llvm.ptr
%24 = arith.constant 8 : i32
%25 = arith.extsi %24 : i32 to i64
%23 = func.call @calloc(%19, %25) : (i64, i64) -> !llvm.ptr
%26 = llvm.mlir.zero : !llvm.ptr
%27 = llvm.icmp "eq" %20, %26 : !llvm.ptr
%28 = scf.if %27 -> (i1) {
%29 = arith.constant true
scf.yield %29 : i1
} else {
%30 = llvm.mlir.zero : !llvm.ptr
%31 = llvm.icmp "eq" %23, %30 : !llvm.ptr
scf.yield %31 : i1
}
cf.cond_br %28, ^bb3, ^bb4
^bb3:
%32 = arith.constant 1 : i32
func.return %32 : i32
^bb4:
cf.br ^bb5
^bb5:
%33 = arith.constant 0 : i32
%34 = arith.extsi %33 : i32 to i64
%35 = llvm.mlir.constant(1 : i64) : i64
%36 = llvm.alloca %35 x i64 : (i64) -> !llvm.ptr
llvm.store %34, %36 : i64, !llvm.ptr
cf.br ^bb6
^bb6:
%37 = llvm.load %36 : !llvm.ptr -> i64
%38 = arith.constant 24 : i32
%40 = arith.extsi %38 : i32 to i64
%39 = arith.cmpi slt, %37, %40 : i64
cf.cond_br %39, ^bb7, ^bb8
^bb7:
%41 = llvm.load %36 : !llvm.ptr -> i64
%42 = arith.constant 1 : i32
%44 = arith.extsi %42 : i32 to i64
%43 = arith.addi %41, %44 : i64
%45 = llvm.load %36 : !llvm.ptr -> i64
%46 = llvm.getelementptr %20[%45] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %43, %46 : i64, !llvm.ptr
%47 = llvm.load %36 : !llvm.ptr -> i64
%48 = arith.constant 1 : i32
%50 = arith.extsi %48 : i32 to i64
%49 = arith.addi %47, %50 : i64
llvm.store %49, %36 : i64, !llvm.ptr
cf.br ^bb6
^bb8:
%51 = arith.constant 26 : i32
%52 = arith.constant 24 : i32
%53 = arith.extsi %51 : i32 to i64
%54 = arith.extsi %52 : i32 to i64
%55 = llvm.getelementptr %20[%54] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %53, %55 : i64, !llvm.ptr
%56 = arith.constant 25 : i32
%57 = arith.constant 25 : i32
%58 = arith.extsi %56 : i32 to i64
%59 = arith.extsi %57 : i32 to i64
%60 = llvm.getelementptr %20[%59] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %58, %60 : i64, !llvm.ptr
%61 = arith.constant 27 : i32
%62 = arith.constant 26 : i32
%63 = arith.extsi %61 : i32 to i64
%64 = arith.extsi %62 : i32 to i64
%65 = llvm.getelementptr %20[%64] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %63, %65 : i64, !llvm.ptr
%66 = arith.constant 28 : i32
%67 = arith.constant 27 : i32
%68 = arith.extsi %66 : i32 to i64
%69 = arith.extsi %67 : i32 to i64
%70 = llvm.getelementptr %20[%69] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %68, %70 : i64, !llvm.ptr
%71 = arith.constant 30 : i32
%72 = arith.constant 28 : i32
%73 = arith.extsi %71 : i32 to i64
%74 = arith.extsi %72 : i32 to i64
%75 = llvm.getelementptr %20[%74] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %73, %75 : i64, !llvm.ptr
%76 = arith.constant 32 : i32
%77 = arith.constant 29 : i32
%78 = arith.extsi %76 : i32 to i64
%79 = arith.extsi %77 : i32 to i64
%80 = llvm.getelementptr %20[%79] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %78, %80 : i64, !llvm.ptr
%81 = arith.constant 34 : i32
%82 = arith.constant 30 : i32
%83 = arith.extsi %81 : i32 to i64
%84 = arith.extsi %82 : i32 to i64
%85 = llvm.getelementptr %20[%84] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %83, %85 : i64, !llvm.ptr
%86 = arith.constant 36 : i32
%87 = arith.constant 31 : i32
%88 = arith.extsi %86 : i32 to i64
%89 = arith.extsi %87 : i32 to i64
%90 = llvm.getelementptr %20[%89] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %88, %90 : i64, !llvm.ptr
%91 = arith.constant 38 : i32
%92 = arith.constant 32 : i32
%93 = arith.extsi %91 : i32 to i64
%94 = arith.extsi %92 : i32 to i64
%95 = llvm.getelementptr %20[%94] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %93, %95 : i64, !llvm.ptr
%96 = arith.constant 40 : i32
%97 = arith.constant 33 : i32
%98 = arith.extsi %96 : i32 to i64
%99 = arith.extsi %97 : i32 to i64
%100 = llvm.getelementptr %20[%99] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %98, %100 : i64, !llvm.ptr
%101 = arith.constant 39 : i32
%102 = arith.constant 34 : i32
%103 = arith.extsi %101 : i32 to i64
%104 = arith.extsi %102 : i32 to i64
%105 = llvm.getelementptr %20[%104] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %103, %105 : i64, !llvm.ptr
%106 = arith.constant 42 : i32
%107 = arith.constant 35 : i32
%108 = arith.extsi %106 : i32 to i64
%109 = arith.extsi %107 : i32 to i64
%110 = llvm.getelementptr %20[%109] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %108, %110 : i64, !llvm.ptr
%111 = arith.constant 45 : i32
%112 = arith.constant 36 : i32
%113 = arith.extsi %111 : i32 to i64
%114 = arith.extsi %112 : i32 to i64
%115 = llvm.getelementptr %20[%114] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %113, %115 : i64, !llvm.ptr
%116 = arith.constant 43 : i32
%117 = arith.constant 37 : i32
%118 = arith.extsi %116 : i32 to i64
%119 = arith.extsi %117 : i32 to i64
%120 = llvm.getelementptr %20[%119] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %118, %120 : i64, !llvm.ptr
%121 = arith.constant 41 : i32
%122 = arith.constant 38 : i32
%123 = arith.extsi %121 : i32 to i64
%124 = arith.extsi %122 : i32 to i64
%125 = llvm.getelementptr %20[%124] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %123, %125 : i64, !llvm.ptr
%126 = arith.constant 37 : i32
%127 = arith.constant 39 : i32
%128 = arith.extsi %126 : i32 to i64
%129 = arith.extsi %127 : i32 to i64
%130 = llvm.getelementptr %20[%129] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %128, %130 : i64, !llvm.ptr
%131 = arith.constant 35 : i32
%132 = arith.constant 40 : i32
%133 = arith.extsi %131 : i32 to i64
%134 = arith.extsi %132 : i32 to i64
%135 = llvm.getelementptr %20[%134] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %133, %135 : i64, !llvm.ptr
%136 = arith.constant 33 : i32
%137 = arith.constant 41 : i32
%138 = arith.extsi %136 : i32 to i64
%139 = arith.extsi %137 : i32 to i64
%140 = llvm.getelementptr %20[%139] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %138, %140 : i64, !llvm.ptr
%141 = arith.constant 31 : i32
%142 = arith.constant 42 : i32
%143 = arith.extsi %141 : i32 to i64
%144 = arith.extsi %142 : i32 to i64
%145 = llvm.getelementptr %20[%144] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %143, %145 : i64, !llvm.ptr
%146 = arith.constant 29 : i32
%147 = arith.constant 43 : i32
%148 = arith.extsi %146 : i32 to i64
%149 = arith.extsi %147 : i32 to i64
%150 = llvm.getelementptr %20[%149] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %148, %150 : i64, !llvm.ptr
%151 = arith.constant 44 : i32
%152 = arith.constant 44 : i32
%153 = arith.extsi %151 : i32 to i64
%154 = arith.extsi %152 : i32 to i64
%155 = llvm.getelementptr %20[%154] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %153, %155 : i64, !llvm.ptr
%156 = arith.constant 0 : i32
%157 = arith.extsi %156 : i32 to i64
llvm.store %157, %36 : i64, !llvm.ptr
cf.br ^bb9
^bb9:
%158 = llvm.load %36 : !llvm.ptr -> i64
%159 = arith.cmpi slt, %158, %19 : i64
cf.cond_br %159, ^bb10, ^bb11
^bb10:
%160 = llvm.load %36 : !llvm.ptr -> i64
%161 = arith.constant 1 : i32
%163 = arith.extsi %161 : i32 to i64
%162 = arith.addi %160, %163 : i64
%164 = llvm.load %36 : !llvm.ptr -> i64
%165 = llvm.getelementptr %23[%164] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %162, %165 : i64, !llvm.ptr
%166 = llvm.load %36 : !llvm.ptr -> i64
%167 = arith.constant 1 : i32
%169 = arith.extsi %167 : i32 to i64
%168 = arith.addi %166, %169 : i64
llvm.store %168, %36 : i64, !llvm.ptr
cf.br ^bb9
^bb11:
%170 = llvm.mlir.constant(1 : i64) : i64
%171 = llvm.alloca %170 x i64 : (i64) -> !llvm.ptr
llvm.store %19, %171 : i64, !llvm.ptr
%172 = arith.constant 1 : i32
%173 = arith.extsi %172 : i32 to i64
%174 = llvm.mlir.constant(1 : i64) : i64
%175 = llvm.alloca %174 x i64 : (i64) -> !llvm.ptr
llvm.store %173, %175 : i64, !llvm.ptr
%176 = arith.constant 0 : i32
%177 = arith.extsi %176 : i32 to i64
%178 = llvm.mlir.constant(1 : i64) : i64
%179 = llvm.alloca %178 x i64 : (i64) -> !llvm.ptr
llvm.store %177, %179 : i64, !llvm.ptr
cf.br ^bb12
^bb12:
%180 = llvm.load %179 : !llvm.ptr -> i64
%181 = arith.cmpi slt, %180, %19 : i64
cf.cond_br %181, ^bb13, ^bb14
^bb13:
%183 = llvm.load %179 : !llvm.ptr -> i64
%184 = llvm.getelementptr %20[%183] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%182 = llvm.load %184 : !llvm.ptr -> i64
%185 = arith.constant 0 : i32
%186 = arith.extsi %185 : i32 to i64
%187 = llvm.mlir.constant(1 : i64) : i64
%188 = llvm.alloca %187 x i64 : (i64) -> !llvm.ptr
llvm.store %186, %188 : i64, !llvm.ptr
cf.br ^bb15
^bb15:
%189 = llvm.load %188 : !llvm.ptr -> i64
%190 = llvm.load %171 : !llvm.ptr -> i64
%191 = arith.cmpi slt, %189, %190 : i64
%192 = scf.if %191 -> (i1) {
%194 = llvm.load %188 : !llvm.ptr -> i64
%195 = llvm.getelementptr %23[%194] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%193 = llvm.load %195 : !llvm.ptr -> i64
%196 = arith.cmpi ne, %193, %182 : i64
scf.yield %196 : i1
} else {
%197 = arith.constant false
scf.yield %197 : i1
}
cf.cond_br %192, ^bb16, ^bb17
^bb16:
%198 = llvm.load %188 : !llvm.ptr -> i64
%199 = arith.constant 1 : i32
%201 = arith.extsi %199 : i32 to i64
%200 = arith.addi %198, %201 : i64
llvm.store %200, %188 : i64, !llvm.ptr
cf.br ^bb15
^bb17:
%202 = llvm.load %175 : !llvm.ptr -> i64
%203 = llvm.load %188 : !llvm.ptr -> i64
%205 = llvm.load %179 : !llvm.ptr -> i64
%206 = arith.subi %19, %205 : i64
%207 = arith.constant 1 : i32
%209 = arith.extsi %207 : i32 to i64
%208 = arith.subi %206, %209 : i64
%204 = func.call @factorial(%208) : (i64) -> i64
%210 = arith.muli %203, %204 : i64
%211 = arith.addi %202, %210 : i64
llvm.store %211, %175 : i64, !llvm.ptr
%212 = llvm.load %188 : !llvm.ptr -> i64
%213 = llvm.mlir.constant(1 : i64) : i64
%214 = llvm.alloca %213 x i64 : (i64) -> !llvm.ptr
llvm.store %212, %214 : i64, !llvm.ptr
cf.br ^bb18
^bb18:
%215 = llvm.load %214 : !llvm.ptr -> i64
%216 = arith.constant 1 : i32
%218 = arith.extsi %216 : i32 to i64
%217 = arith.addi %215, %218 : i64
%219 = llvm.load %171 : !llvm.ptr -> i64
%220 = arith.cmpi slt, %217, %219 : i64
cf.cond_br %220, ^bb19, ^bb20
^bb19:
%222 = llvm.load %214 : !llvm.ptr -> i64
%223 = arith.constant 1 : i32
%225 = arith.extsi %223 : i32 to i64
%224 = arith.addi %222, %225 : i64
%226 = llvm.getelementptr %23[%224] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%221 = llvm.load %226 : !llvm.ptr -> i64
%227 = llvm.load %214 : !llvm.ptr -> i64
%228 = llvm.getelementptr %23[%227] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %221, %228 : i64, !llvm.ptr
%229 = llvm.load %214 : !llvm.ptr -> i64
%230 = arith.constant 1 : i32
%232 = arith.extsi %230 : i32 to i64
%231 = arith.addi %229, %232 : i64
llvm.store %231, %214 : i64, !llvm.ptr
cf.br ^bb18
^bb20:
%233 = llvm.load %171 : !llvm.ptr -> i64
%234 = arith.constant 1 : i32
%236 = arith.extsi %234 : i32 to i64
%235 = arith.subi %233, %236 : i64
llvm.store %235, %171 : i64, !llvm.ptr
%237 = llvm.load %179 : !llvm.ptr -> i64
%238 = arith.constant 1 : i32
%240 = arith.extsi %238 : i32 to i64
%239 = arith.addi %237, %240 : i64
llvm.store %239, %179 : i64, !llvm.ptr
cf.br ^bb12
^bb14:
%241 = llvm.mlir.addressof @str_0 : !llvm.ptr
%242 = llvm.load %175 : !llvm.ptr -> i64
%243 = llvm.call @printf(%241, %242) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
func.call @free(%20) : (!llvm.ptr) -> ()
func.call @free(%23) : (!llvm.ptr) -> ()
%246 = arith.constant 0 : i32
func.return %246 : i32
}
}