Problem 607
Marsh crossing: local search minimizing travel time (Snell).
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n^2) | ? |
| Space complexity | O(1) | ? |
| Approach | Flow solution | Not curated |
| Verdict | Unknown |
Flow source
# Project Euler 607
# Marsh crossing: local search minimizing travel time (Snell).
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
function sqrt(x: f64) -> f64
}
function duration(xs: ptr<f64>, ys: ptr<f64>) -> f64 {
let mut result: f64 = 0.0
let mut i: i64 = 0
while i < 7 {
let dx: f64 = xs[i] - xs[i + 1]
let dy: f64 = ys[i] - ys[i + 1]
let way: f64 = sqrt(dx * dx + dy * dy)
let mut sp: f64 = 10.0
if i == 1 { sp = 9.0 }
elif i == 2 { sp = 8.0 }
elif i == 3 { sp = 7.0 }
elif i == 4 { sp = 6.0 }
elif i == 5 { sp = 5.0 }
elif i == 6 { sp = 10.0 }
result = result + way / sp
i = i + 1
}
return result
}
function main() -> i32 {
let xs: ptr<f64> = calloc(8, 8)
let ys: ptr<f64> = calloc(8, 8)
if xs == null || ys == null { return 1 }
let scaling: f64 = sqrt(2.0)
let direct: f64 = 50.0 * scaling
let current: f64 = ((100.0 - direct) / 2.0) / scaling
xs[0] = 0.0
ys[0] = 0.0
xs[1] = current
ys[1] = current
let mut i: i64 = 1
while i <= 5 {
xs[i + 1] = current + (i as f64) * 10.0
ys[i + 1] = current + (i as f64) * 10.0
i = i + 1
}
xs[7] = 100.0 / scaling
ys[7] = 100.0 / scaling
let mut seed: i64 = 0
let MASK64: i128 = 18446744073709551615
let mut delta: f64 = 0.01
while delta >= 0.00001 {
let mut it: i64 = 0
while it < 10000 {
let t1: i128 = ((6364136223846793005 as i128) * ((seed as i64) as i128) + 1) & MASK64
seed = t1 as i64
let r1: i64 = ((t1 >> 30) & MASK64) as i64
let t2: i128 = ((6364136223846793005 as i128) * ((seed as i64) as i128) + 1) & MASK64
seed = t2 as i64
let r2: i64 = ((t2 >> 30) & MASK64) as i64
let mut dlt: f64 = delta
if (r1 & 1) == 1 { dlt = 0.0 - delta }
let point_id: i64 = ((r2 % 6 + 6) % 6) + 1
let old: f64 = duration(xs, ys)
ys[point_id] = ys[point_id] + dlt
if duration(xs, ys) >= old {
ys[point_id] = ys[point_id] - dlt
}
it = it + 1
}
delta = delta / 10.0
}
printf("%.10f\n", duration(xs, ys))
free(xs)
free(ys)
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; }
double duration_ptr_f64_ptr_f64(double* xs, double* ys);
int32_t main(void);
double duration_ptr_f64_ptr_f64(double* xs, double* ys) {
double result = 0.0;
int64_t i = 0;
while (i < 7) {
double dx = (xs[i] - xs[(i + 1)]);
double dy = (ys[i] - ys[(i + 1)]);
double way = sqrt(((dx * dx) + (dy * dy)));
double sp = 10.0;
if (i == 1) {
sp = 9.0;
} else if (i == 2) {
sp = 8.0;
} else if (i == 3) {
sp = 7.0;
} else if (i == 4) {
sp = 6.0;
} else if (i == 5) {
sp = 5.0;
} else if (i == 6) {
sp = 10.0;
}
result = (result + (way / sp));
i = (i + 1);
}
return result;
}
int32_t main(void) {
double* xs = (double*)(calloc(8, 8));
double* ys = (double*)(calloc(8, 8));
if ((xs == NULL || ys == NULL)) {
return 1;
}
double scaling = sqrt(2.0);
double direct = (50.0 * scaling);
double current = (((100.0 - direct) / 2.0) / scaling);
xs[0] = 0.0;
ys[0] = 0.0;
xs[1] = current;
ys[1] = current;
int64_t i = 1;
while (i <= 5) {
xs[(i + 1)] = (current + (((double)(i)) * 10.0));
ys[(i + 1)] = (current + (((double)(i)) * 10.0));
i = (i + 1);
}
xs[7] = (100.0 / scaling);
ys[7] = (100.0 / scaling);
int64_t seed = 0;
__int128 MASK64 = ((__int128)0xFFFFFFFFFFFFFFFFULL);
double delta = 0.01;
while (delta >= 0.00001) {
int64_t it = 0;
while (it < 10000) {
__int128 t1 = (((((__int128)(6364136223846793005)) * ((__int128)(((int64_t)(seed))))) + 1) & MASK64);
seed = ((int64_t)(t1));
int64_t r1 = ((int64_t)((FLOW_CHECKED_SHR((t1), (30)) & MASK64)));
__int128 t2 = (((((__int128)(6364136223846793005)) * ((__int128)(((int64_t)(seed))))) + 1) & MASK64);
seed = ((int64_t)(t2));
int64_t r2 = ((int64_t)((FLOW_CHECKED_SHR((t2), (30)) & MASK64)));
double dlt = delta;
if ((r1 & 1) == 1) {
dlt = (0.0 - delta);
}
int64_t point_id = (FLOW_CHECKED_MOD(((FLOW_CHECKED_MOD((r2), (6)) + 6)), (6)) + 1);
double old = duration_ptr_f64_ptr_f64(xs, ys);
ys[point_id] = (ys[point_id] + dlt);
if (duration_ptr_f64_ptr_f64(xs, ys) >= old) {
ys[point_id] = (ys[point_id] - dlt);
}
it = (it + 1);
}
delta = (delta / 10.0);
}
printf("%.10f\n", duration_ptr_f64_ptr_f64(xs, ys));
free(xs);
free(ys);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("%.10f\n\00") {addr_space = 0 : i32} : !llvm.array<7 x i8>
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func private @sqrt(f64) -> f64
func.func @duration(%arg0: !llvm.ptr, %arg1: !llvm.ptr) -> f64 {
%0 = arith.constant 0.0 : f32
%1 = arith.extf %0 : f32 to f64
%2 = llvm.mlir.constant(1 : i64) : i64
%3 = llvm.alloca %2 x f64 : (i64) -> !llvm.ptr
llvm.store %1, %3 : f64, !llvm.ptr
%4 = arith.constant 0 : 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.constant 7 : i32
%11 = arith.extsi %9 : i32 to i64
%10 = arith.cmpi slt, %8, %11 : i64
cf.cond_br %10, ^bb1, ^bb2
^bb1:
%13 = llvm.load %7 : !llvm.ptr -> i64
%14 = llvm.getelementptr %arg0[%13] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%12 = llvm.load %14 : !llvm.ptr -> f64
%16 = llvm.load %7 : !llvm.ptr -> i64
%17 = arith.constant 1 : i32
%19 = arith.extsi %17 : i32 to i64
%18 = arith.addi %16, %19 : i64
%20 = llvm.getelementptr %arg0[%18] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%15 = llvm.load %20 : !llvm.ptr -> f64
%21 = arith.subf %12, %15 : f64
%23 = llvm.load %7 : !llvm.ptr -> i64
%24 = llvm.getelementptr %arg1[%23] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%22 = llvm.load %24 : !llvm.ptr -> f64
%26 = llvm.load %7 : !llvm.ptr -> i64
%27 = arith.constant 1 : i32
%29 = arith.extsi %27 : i32 to i64
%28 = arith.addi %26, %29 : i64
%30 = llvm.getelementptr %arg1[%28] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%25 = llvm.load %30 : !llvm.ptr -> f64
%31 = arith.subf %22, %25 : f64
%32 = arith.mulf %21, %21 : f64
%33 = arith.mulf %31, %31 : f64
%34 = arith.addf %32, %33 : f64
%35 = math.sqrt %34 : f64
%36 = arith.constant 10.0 : f32
%37 = arith.extf %36 : f32 to f64
%38 = llvm.mlir.constant(1 : i64) : i64
%39 = llvm.alloca %38 x f64 : (i64) -> !llvm.ptr
llvm.store %37, %39 : f64, !llvm.ptr
%40 = llvm.load %7 : !llvm.ptr -> i64
%41 = arith.constant 1 : i32
%43 = arith.extsi %41 : i32 to i64
%42 = arith.cmpi eq, %40, %43 : i64
cf.cond_br %42, ^bb3, ^bb4
^bb3:
%44 = arith.constant 9.0 : f32
%45 = arith.extf %44 : f32 to f64
llvm.store %45, %39 : f64, !llvm.ptr
cf.br ^bb5
^bb4:
%46 = llvm.load %7 : !llvm.ptr -> i64
%47 = arith.constant 2 : i32
%49 = arith.extsi %47 : i32 to i64
%48 = arith.cmpi eq, %46, %49 : i64
cf.cond_br %48, ^bb7, ^bb6
^bb7:
%50 = arith.constant 8.0 : f32
%51 = arith.extf %50 : f32 to f64
llvm.store %51, %39 : f64, !llvm.ptr
cf.br ^bb5
^bb6:
%52 = llvm.load %7 : !llvm.ptr -> i64
%53 = arith.constant 3 : i32
%55 = arith.extsi %53 : i32 to i64
%54 = arith.cmpi eq, %52, %55 : i64
cf.cond_br %54, ^bb9, ^bb8
^bb9:
%56 = arith.constant 7.0 : f32
%57 = arith.extf %56 : f32 to f64
llvm.store %57, %39 : f64, !llvm.ptr
cf.br ^bb5
^bb8:
%58 = llvm.load %7 : !llvm.ptr -> i64
%59 = arith.constant 4 : i32
%61 = arith.extsi %59 : i32 to i64
%60 = arith.cmpi eq, %58, %61 : i64
cf.cond_br %60, ^bb11, ^bb10
^bb11:
%62 = arith.constant 6.0 : f32
%63 = arith.extf %62 : f32 to f64
llvm.store %63, %39 : f64, !llvm.ptr
cf.br ^bb5
^bb10:
%64 = llvm.load %7 : !llvm.ptr -> i64
%65 = arith.constant 5 : i32
%67 = arith.extsi %65 : i32 to i64
%66 = arith.cmpi eq, %64, %67 : i64
cf.cond_br %66, ^bb13, ^bb12
^bb13:
%68 = arith.constant 5.0 : f32
%69 = arith.extf %68 : f32 to f64
llvm.store %69, %39 : f64, !llvm.ptr
cf.br ^bb5
^bb12:
%70 = llvm.load %7 : !llvm.ptr -> i64
%71 = arith.constant 6 : i32
%73 = arith.extsi %71 : i32 to i64
%72 = arith.cmpi eq, %70, %73 : i64
cf.cond_br %72, ^bb14, ^bb5
^bb14:
%74 = arith.constant 10.0 : f32
%75 = arith.extf %74 : f32 to f64
llvm.store %75, %39 : f64, !llvm.ptr
cf.br ^bb5
^bb5:
%76 = llvm.load %3 : !llvm.ptr -> f64
%77 = llvm.load %39 : !llvm.ptr -> f64
%78 = arith.divf %35, %77 : f64
%79 = arith.addf %76, %78 : f64
llvm.store %79, %3 : f64, !llvm.ptr
%80 = llvm.load %7 : !llvm.ptr -> i64
%81 = arith.constant 1 : i32
%83 = arith.extsi %81 : i32 to i64
%82 = arith.addi %80, %83 : i64
llvm.store %82, %7 : i64, !llvm.ptr
cf.br ^bb0
^bb2:
%84 = llvm.load %3 : !llvm.ptr -> f64
func.return %84 : f64
}
func.func @main() -> i32 {
%86 = arith.constant 8 : i32
%87 = arith.constant 8 : i32
%88 = arith.extsi %86 : i32 to i64
%89 = arith.extsi %87 : i32 to i64
%85 = func.call @calloc(%88, %89) : (i64, i64) -> !llvm.ptr
%91 = arith.constant 8 : i32
%92 = arith.constant 8 : i32
%93 = arith.extsi %91 : i32 to i64
%94 = arith.extsi %92 : i32 to i64
%90 = func.call @calloc(%93, %94) : (i64, i64) -> !llvm.ptr
%95 = llvm.mlir.zero : !llvm.ptr
%96 = llvm.icmp "eq" %85, %95 : !llvm.ptr
%97 = scf.if %96 -> (i1) {
%98 = arith.constant true
scf.yield %98 : i1
} else {
%99 = llvm.mlir.zero : !llvm.ptr
%100 = llvm.icmp "eq" %90, %99 : !llvm.ptr
scf.yield %100 : i1
}
cf.cond_br %97, ^bb15, ^bb16
^bb15:
%101 = arith.constant 1 : i32
func.return %101 : i32
^bb16:
cf.br ^bb17
^bb17:
%102 = arith.constant 2.0 : f32
%103 = math.sqrt %102 : f32
%104 = arith.extf %103 : f32 to f64
%105 = arith.constant 50.0 : f32
%107 = arith.extf %105 : f32 to f64
%106 = arith.mulf %107, %104 : f64
%108 = arith.constant 100.0 : f32
%110 = arith.extf %108 : f32 to f64
%109 = arith.subf %110, %106 : f64
%111 = arith.constant 2.0 : f32
%113 = arith.extf %111 : f32 to f64
%112 = arith.divf %109, %113 : f64
%114 = arith.divf %112, %104 : f64
%115 = arith.constant 0.0 : f32
%116 = arith.constant 0 : i32
%117 = arith.extf %115 : f32 to f64
%118 = arith.extsi %116 : i32 to i64
%119 = llvm.getelementptr %85[%118] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %117, %119 : f64, !llvm.ptr
%120 = arith.constant 0.0 : f32
%121 = arith.constant 0 : i32
%122 = arith.extf %120 : f32 to f64
%123 = arith.extsi %121 : i32 to i64
%124 = llvm.getelementptr %90[%123] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %122, %124 : f64, !llvm.ptr
%125 = arith.constant 1 : i32
%126 = arith.extsi %125 : i32 to i64
%127 = llvm.getelementptr %85[%126] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %114, %127 : f64, !llvm.ptr
%128 = arith.constant 1 : i32
%129 = arith.extsi %128 : i32 to i64
%130 = llvm.getelementptr %90[%129] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %114, %130 : f64, !llvm.ptr
%131 = arith.constant 1 : i32
%132 = arith.extsi %131 : i32 to i64
%133 = llvm.mlir.constant(1 : i64) : i64
%134 = llvm.alloca %133 x i64 : (i64) -> !llvm.ptr
llvm.store %132, %134 : i64, !llvm.ptr
cf.br ^bb18
^bb18:
%135 = llvm.load %134 : !llvm.ptr -> i64
%136 = arith.constant 5 : i32
%138 = arith.extsi %136 : i32 to i64
%137 = arith.cmpi sle, %135, %138 : i64
cf.cond_br %137, ^bb19, ^bb20
^bb19:
%139 = llvm.load %134 : !llvm.ptr -> i64
%140 = arith.sitofp %139 : i64 to f64
%141 = arith.constant 10.0 : f32
%143 = arith.extf %141 : f32 to f64
%142 = arith.mulf %140, %143 : f64
%144 = arith.addf %114, %142 : f64
%145 = llvm.load %134 : !llvm.ptr -> i64
%146 = arith.constant 1 : i32
%148 = arith.extsi %146 : i32 to i64
%147 = arith.addi %145, %148 : i64
%149 = llvm.getelementptr %85[%147] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %144, %149 : f64, !llvm.ptr
%150 = llvm.load %134 : !llvm.ptr -> i64
%151 = arith.sitofp %150 : i64 to f64
%152 = arith.constant 10.0 : f32
%154 = arith.extf %152 : f32 to f64
%153 = arith.mulf %151, %154 : f64
%155 = arith.addf %114, %153 : f64
%156 = llvm.load %134 : !llvm.ptr -> i64
%157 = arith.constant 1 : i32
%159 = arith.extsi %157 : i32 to i64
%158 = arith.addi %156, %159 : i64
%160 = llvm.getelementptr %90[%158] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %155, %160 : f64, !llvm.ptr
%161 = llvm.load %134 : !llvm.ptr -> i64
%162 = arith.constant 1 : i32
%164 = arith.extsi %162 : i32 to i64
%163 = arith.addi %161, %164 : i64
llvm.store %163, %134 : i64, !llvm.ptr
cf.br ^bb18
^bb20:
%165 = arith.constant 100.0 : f32
%167 = arith.extf %165 : f32 to f64
%166 = arith.divf %167, %104 : f64
%168 = arith.constant 7 : i32
%169 = arith.extsi %168 : i32 to i64
%170 = llvm.getelementptr %85[%169] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %166, %170 : f64, !llvm.ptr
%171 = arith.constant 100.0 : f32
%173 = arith.extf %171 : f32 to f64
%172 = arith.divf %173, %104 : f64
%174 = arith.constant 7 : i32
%175 = arith.extsi %174 : i32 to i64
%176 = llvm.getelementptr %90[%175] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %172, %176 : f64, !llvm.ptr
%177 = arith.constant 0 : i32
%178 = arith.extsi %177 : i32 to i64
%179 = llvm.mlir.constant(1 : i64) : i64
%180 = llvm.alloca %179 x i64 : (i64) -> !llvm.ptr
llvm.store %178, %180 : i64, !llvm.ptr
%181 = arith.constant 18446744069414584319 : i32
%182 = arith.extsi %181 : i32 to i128
%183 = arith.constant 0.01 : f32
%184 = arith.extf %183 : f32 to f64
%185 = llvm.mlir.constant(1 : i64) : i64
%186 = llvm.alloca %185 x f64 : (i64) -> !llvm.ptr
llvm.store %184, %186 : f64, !llvm.ptr
cf.br ^bb21
^bb21:
%187 = llvm.load %186 : !llvm.ptr -> f64
%188 = arith.constant 0.00001 : f32
%190 = arith.extf %188 : f32 to f64
%189 = arith.cmpf oge, %187, %190 : f64
cf.cond_br %189, ^bb22, ^bb23
^bb22:
%191 = arith.constant 0 : i32
%192 = arith.extsi %191 : i32 to i64
%193 = llvm.mlir.constant(1 : i64) : i64
%194 = llvm.alloca %193 x i64 : (i64) -> !llvm.ptr
llvm.store %192, %194 : i64, !llvm.ptr
cf.br ^bb24
^bb24:
%195 = llvm.load %194 : !llvm.ptr -> i64
%196 = arith.constant 10000 : i32
%198 = arith.extsi %196 : i32 to i64
%197 = arith.cmpi slt, %195, %198 : i64
cf.cond_br %197, ^bb25, ^bb26
^bb25:
%199 = arith.constant 6364136219551825709 : i32
%200 = arith.extsi %199 : i32 to i128
%201 = llvm.load %180 : !llvm.ptr -> i64
%202 = arith.extsi %201 : i64 to i128
%204 = arith.trunci %200 : i128 to i64
%205 = arith.trunci %202 : i128 to i64
%203 = arith.muli %204, %205 : i64
%206 = arith.constant 1 : i32
%208 = arith.extsi %206 : i32 to i64
%207 = arith.addi %203, %208 : i64
%210 = arith.trunci %182 : i128 to i64
%209 = arith.andi %207, %210 : i64
%211 = arith.extsi %209 : i64 to i128
%212 = arith.trunci %211 : i128 to i64
llvm.store %212, %180 : i64, !llvm.ptr
%213 = arith.constant 30 : i32
%215 = arith.trunci %211 : i128 to i64
%216 = arith.extsi %213 : i32 to i64
%214 = arith.shrsi %215, %216 : i64
%218 = arith.trunci %182 : i128 to i64
%217 = arith.andi %214, %218 : i64
%219 = arith.constant 6364136219551825709 : i32
%220 = arith.extsi %219 : i32 to i128
%221 = llvm.load %180 : !llvm.ptr -> i64
%222 = arith.extsi %221 : i64 to i128
%224 = arith.trunci %220 : i128 to i64
%225 = arith.trunci %222 : i128 to i64
%223 = arith.muli %224, %225 : i64
%226 = arith.constant 1 : i32
%228 = arith.extsi %226 : i32 to i64
%227 = arith.addi %223, %228 : i64
%230 = arith.trunci %182 : i128 to i64
%229 = arith.andi %227, %230 : i64
%231 = arith.extsi %229 : i64 to i128
%232 = arith.trunci %231 : i128 to i64
llvm.store %232, %180 : i64, !llvm.ptr
%233 = arith.constant 30 : i32
%235 = arith.trunci %231 : i128 to i64
%236 = arith.extsi %233 : i32 to i64
%234 = arith.shrsi %235, %236 : i64
%238 = arith.trunci %182 : i128 to i64
%237 = arith.andi %234, %238 : i64
%239 = llvm.load %186 : !llvm.ptr -> f64
%240 = llvm.mlir.constant(1 : i64) : i64
%241 = llvm.alloca %240 x f64 : (i64) -> !llvm.ptr
llvm.store %239, %241 : f64, !llvm.ptr
%242 = arith.constant 1 : i32
%244 = arith.extsi %242 : i32 to i64
%243 = arith.andi %217, %244 : i64
%245 = arith.constant 1 : i32
%247 = arith.extsi %245 : i32 to i64
%246 = arith.cmpi eq, %243, %247 : i64
cf.cond_br %246, ^bb27, ^bb28
^bb27:
%248 = arith.constant 0.0 : f32
%249 = llvm.load %186 : !llvm.ptr -> f64
%251 = arith.extf %248 : f32 to f64
%250 = arith.subf %251, %249 : f64
llvm.store %250, %241 : f64, !llvm.ptr
cf.br ^bb29
^bb28:
cf.br ^bb29
^bb29:
%252 = arith.constant 6 : i32
%254 = arith.extsi %252 : i32 to i64
%253 = arith.remsi %237, %254 : i64
%255 = arith.constant 6 : i32
%257 = arith.extsi %255 : i32 to i64
%256 = arith.addi %253, %257 : i64
%258 = arith.constant 6 : i32
%260 = arith.extsi %258 : i32 to i64
%259 = arith.remsi %256, %260 : i64
%261 = arith.constant 1 : i32
%263 = arith.extsi %261 : i32 to i64
%262 = arith.addi %259, %263 : i64
%264 = func.call @duration(%85, %90) : (!llvm.ptr, !llvm.ptr) -> f64
%266 = llvm.getelementptr %90[%262] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%265 = llvm.load %266 : !llvm.ptr -> f64
%267 = llvm.load %241 : !llvm.ptr -> f64
%268 = arith.addf %265, %267 : f64
%269 = llvm.getelementptr %90[%262] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %268, %269 : f64, !llvm.ptr
%270 = func.call @duration(%85, %90) : (!llvm.ptr, !llvm.ptr) -> f64
%271 = arith.cmpf oge, %270, %264 : f64
cf.cond_br %271, ^bb30, ^bb31
^bb30:
%273 = llvm.getelementptr %90[%262] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%272 = llvm.load %273 : !llvm.ptr -> f64
%274 = llvm.load %241 : !llvm.ptr -> f64
%275 = arith.subf %272, %274 : f64
%276 = llvm.getelementptr %90[%262] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %275, %276 : f64, !llvm.ptr
cf.br ^bb32
^bb31:
cf.br ^bb32
^bb32:
%277 = llvm.load %194 : !llvm.ptr -> i64
%278 = arith.constant 1 : i32
%280 = arith.extsi %278 : i32 to i64
%279 = arith.addi %277, %280 : i64
llvm.store %279, %194 : i64, !llvm.ptr
cf.br ^bb24
^bb26:
%281 = llvm.load %186 : !llvm.ptr -> f64
%282 = arith.constant 10.0 : f32
%284 = arith.extf %282 : f32 to f64
%283 = arith.divf %281, %284 : f64
llvm.store %283, %186 : f64, !llvm.ptr
cf.br ^bb21
^bb23:
%285 = llvm.mlir.addressof @str_0 : !llvm.ptr
%286 = func.call @duration(%85, %90) : (!llvm.ptr, !llvm.ptr) -> f64
%287 = llvm.call @printf(%285, %286) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, f64) -> i32
func.call @free(%85) : (!llvm.ptr) -> ()
func.call @free(%90) : (!llvm.ptr) -> ()
%290 = arith.constant 0 : i32
func.return %290 : i32
}
}