Problem 102
How many triangles in data/p102.txt contain the origin?
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n) | O(n^2) |
| Space complexity | O(1) | O(n^2) |
| Approach | Flow solution | Bottom-up DP |
| Verdict | Optimal |
Flow source
# Project Euler 102
# How many triangles in data/p102.txt contain the origin?
extern {
function fopen(path: string, mode: string) -> ptr<void>
function fgetc(f: ptr<void>) -> i32
function fclose(f: ptr<void>) -> i32
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
}
# Read next signed integer. Sets ok[0]=0 on EOF/failure.
function read_signed(f: ptr<void>, ok: ptr<i32>) -> i32 {
let mut c: i32 = fgetc(f)
while c >= 0 && c != 45 && (c < 48 || c > 57) {
c = fgetc(f)
}
if c < 0 {
ok[0] = 0
return 0
}
let mut neg: bool = false
if c == 45 {
neg = true
c = fgetc(f)
}
if c < 48 || c > 57 {
ok[0] = 0
return 0
}
let mut v: i32 = 0
while c >= 48 && c <= 57 {
v = v * 10 + (c - 48)
c = fgetc(f)
}
ok[0] = 1
if neg { return -v }
return v
}
function area2(ax: i32, ay: i32, bx: i32, by: i32, cx: i32, cy: i32) -> i64 {
return ((bx - ax) as i64) * ((cy - ay) as i64) - ((cx - ax) as i64) * ((by - ay) as i64)
}
function contains_origin(x1: i32, y1: i32, x2: i32, y2: i32, x3: i32, y3: i32) -> bool {
let A: i64 = area2(x1, y1, x2, y2, x3, y3)
let A1: i64 = area2(0, 0, x2, y2, x3, y3)
let A2: i64 = area2(x1, y1, 0, 0, x3, y3)
let A3: i64 = area2(x1, y1, x2, y2, 0, 0)
if A == 0 { return false }
if A > 0 {
return A1 >= 0 && A2 >= 0 && A3 >= 0 && A1 + A2 + A3 == A
}
return A1 <= 0 && A2 <= 0 && A3 <= 0 && A1 + A2 + A3 == A
}
function main() -> i32 {
let f: ptr<void> = fopen("data/p102.txt", "r")
if f == null {
printf("failed to read data/p102.txt\n")
return 1
}
let ok: ptr<i32> = calloc(1, 4)
if ok == null { fclose(f); return 1 }
ok[0] = 1
let mut count: i64 = 0
while ok[0] == 1 {
let x1: i32 = read_signed(f, ok)
if ok[0] == 0 { break }
let y1: i32 = read_signed(f, ok)
let x2: i32 = read_signed(f, ok)
let y2: i32 = read_signed(f, ok)
let x3: i32 = read_signed(f, ok)
let y3: i32 = read_signed(f, ok)
if contains_origin(x1, y1, x2, y2, x3, y3) {
count = count + 1
}
}
fclose(f)
free(ok)
printf("%lld\n", count)
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; }
int32_t read_signed_ptr_void_ptr_i32(void* f, int32_t* ok);
int64_t area2_i32_i32_i32_i32_i32_i32(int32_t ax, int32_t ay, int32_t bx, int32_t by, int32_t cx, int32_t cy);
bool contains_origin_i32_i32_i32_i32_i32_i32(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3);
int32_t main(void);
int32_t read_signed_ptr_void_ptr_i32(void* f, int32_t* ok) {
int32_t c = fgetc(f);
while (((c >= 0 && c != 45) && (c < 48 || c > 57))) {
c = fgetc(f);
}
if (c < 0) {
ok[0] = 0;
return 0;
}
bool neg = 0;
if (c == 45) {
neg = 1;
c = fgetc(f);
}
if ((c < 48 || c > 57)) {
ok[0] = 0;
return 0;
}
int32_t v = 0;
while ((c >= 48 && c <= 57)) {
v = ((v * 10) + (c - 48));
c = fgetc(f);
}
ok[0] = 1;
if (neg) {
return (-v);
}
return v;
}
int64_t area2_i32_i32_i32_i32_i32_i32(int32_t ax, int32_t ay, int32_t bx, int32_t by, int32_t cx, int32_t cy) {
return ((((int64_t)((bx - ax))) * ((int64_t)((cy - ay)))) - (((int64_t)((cx - ax))) * ((int64_t)((by - ay)))));
}
bool contains_origin_i32_i32_i32_i32_i32_i32(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3) {
int64_t A = area2_i32_i32_i32_i32_i32_i32(x1, y1, x2, y2, x3, y3);
int64_t A1 = area2_i32_i32_i32_i32_i32_i32(0, 0, x2, y2, x3, y3);
int64_t A2 = area2_i32_i32_i32_i32_i32_i32(x1, y1, 0, 0, x3, y3);
int64_t A3 = area2_i32_i32_i32_i32_i32_i32(x1, y1, x2, y2, 0, 0);
if (A == 0) {
return 0;
}
if (A > 0) {
return (((A1 >= 0 && A2 >= 0) && A3 >= 0) && ((A1 + A2) + A3) == A);
}
return (((A1 <= 0 && A2 <= 0) && A3 <= 0) && ((A1 + A2) + A3) == A);
}
int32_t main(void) {
void* f = (void*)(fopen("data/p102.txt", "r"));
if (f == NULL) {
printf("failed to read data/p102.txt\n");
return 1;
}
int32_t* ok = (int32_t*)(calloc(1, 4));
if (ok == NULL) {
fclose(f);
return 1;
}
ok[0] = 1;
int64_t count = 0;
while (ok[0] == 1) {
int32_t x1 = read_signed_ptr_void_ptr_i32(f, ok);
if (ok[0] == 0) {
break;
}
int32_t y1 = read_signed_ptr_void_ptr_i32(f, ok);
int32_t x2 = read_signed_ptr_void_ptr_i32(f, ok);
int32_t y2 = read_signed_ptr_void_ptr_i32(f, ok);
int32_t x3 = read_signed_ptr_void_ptr_i32(f, ok);
int32_t y3 = read_signed_ptr_void_ptr_i32(f, ok);
if (contains_origin_i32_i32_i32_i32_i32_i32(x1, y1, x2, y2, x3, y3)) {
count = (count + 1);
}
}
fclose(f);
free(ok);
printf("%lld\n", count);
return 0;
}
Generated MLIR
module {
llvm.func @printf(!llvm.ptr, ...) -> i32
llvm.mlir.global internal constant @str_0("data/p102.txt\00") {addr_space = 0 : i32} : !llvm.array<14 x i8>
llvm.mlir.global internal constant @str_1("r\00") {addr_space = 0 : i32} : !llvm.array<2 x i8>
llvm.mlir.global internal constant @str_2("failed to read data/p102.txt\n\00") {addr_space = 0 : i32} : !llvm.array<30 x i8>
llvm.mlir.global internal constant @str_3("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
func.func private @fopen(!llvm.ptr, !llvm.ptr) -> !llvm.ptr
func.func private @fgetc(!llvm.ptr) -> i32
func.func private @fclose(!llvm.ptr) -> i32
func.func private @calloc(i64, i64) -> !llvm.ptr
func.func private @free(!llvm.ptr) -> ()
func.func @read_signed(%arg0: !llvm.ptr, %arg1: !llvm.ptr) -> i32 {
%0 = func.call @fgetc(%arg0) : (!llvm.ptr) -> i32
%1 = llvm.mlir.constant(1 : i64) : i64
%2 = llvm.alloca %1 x i32 : (i64) -> !llvm.ptr
llvm.store %0, %2 : i32, !llvm.ptr
cf.br ^bb0
^bb0:
%3 = llvm.load %2 : !llvm.ptr -> i32
%4 = arith.constant 0 : i32
%5 = arith.cmpi sge, %3, %4 : i32
%6 = scf.if %5 -> (i1) {
%7 = llvm.load %2 : !llvm.ptr -> i32
%8 = arith.constant 45 : i32
%9 = arith.cmpi ne, %7, %8 : i32
scf.yield %9 : i1
} else {
%10 = arith.constant false
scf.yield %10 : i1
}
%11 = scf.if %6 -> (i1) {
%12 = llvm.load %2 : !llvm.ptr -> i32
%13 = arith.constant 48 : i32
%14 = arith.cmpi slt, %12, %13 : i32
%15 = scf.if %14 -> (i1) {
%16 = arith.constant true
scf.yield %16 : i1
} else {
%17 = llvm.load %2 : !llvm.ptr -> i32
%18 = arith.constant 57 : i32
%19 = arith.cmpi sgt, %17, %18 : i32
scf.yield %19 : i1
}
scf.yield %15 : i1
} else {
%20 = arith.constant false
scf.yield %20 : i1
}
cf.cond_br %11, ^bb1, ^bb2
^bb1:
%21 = func.call @fgetc(%arg0) : (!llvm.ptr) -> i32
llvm.store %21, %2 : i32, !llvm.ptr
cf.br ^bb0
^bb2:
%22 = llvm.load %2 : !llvm.ptr -> i32
%23 = arith.constant 0 : i32
%24 = arith.cmpi slt, %22, %23 : i32
cf.cond_br %24, ^bb3, ^bb4
^bb3:
%25 = arith.constant 0 : i32
%26 = arith.constant 0 : i32
%27 = arith.extsi %26 : i32 to i64
%28 = llvm.getelementptr %arg1[%27] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %25, %28 : i32, !llvm.ptr
%29 = arith.constant 0 : i32
func.return %29 : i32
^bb4:
cf.br ^bb5
^bb5:
%30 = arith.constant 0 : i1
%31 = llvm.mlir.constant(1 : i64) : i64
%32 = llvm.alloca %31 x i1 : (i64) -> !llvm.ptr
llvm.store %30, %32 : i1, !llvm.ptr
%33 = llvm.load %2 : !llvm.ptr -> i32
%34 = arith.constant 45 : i32
%35 = arith.cmpi eq, %33, %34 : i32
cf.cond_br %35, ^bb6, ^bb7
^bb6:
%36 = arith.constant 1 : i1
llvm.store %36, %32 : i1, !llvm.ptr
%37 = func.call @fgetc(%arg0) : (!llvm.ptr) -> i32
llvm.store %37, %2 : i32, !llvm.ptr
cf.br ^bb8
^bb7:
cf.br ^bb8
^bb8:
%38 = llvm.load %2 : !llvm.ptr -> i32
%39 = arith.constant 48 : i32
%40 = arith.cmpi slt, %38, %39 : i32
%41 = scf.if %40 -> (i1) {
%42 = arith.constant true
scf.yield %42 : i1
} else {
%43 = llvm.load %2 : !llvm.ptr -> i32
%44 = arith.constant 57 : i32
%45 = arith.cmpi sgt, %43, %44 : i32
scf.yield %45 : i1
}
cf.cond_br %41, ^bb9, ^bb10
^bb9:
%46 = arith.constant 0 : i32
%47 = arith.constant 0 : i32
%48 = arith.extsi %47 : i32 to i64
%49 = llvm.getelementptr %arg1[%48] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %46, %49 : i32, !llvm.ptr
%50 = arith.constant 0 : i32
func.return %50 : i32
^bb10:
cf.br ^bb11
^bb11:
%51 = arith.constant 0 : i32
%52 = llvm.mlir.constant(1 : i64) : i64
%53 = llvm.alloca %52 x i32 : (i64) -> !llvm.ptr
llvm.store %51, %53 : i32, !llvm.ptr
cf.br ^bb12
^bb12:
%54 = llvm.load %2 : !llvm.ptr -> i32
%55 = arith.constant 48 : i32
%56 = arith.cmpi sge, %54, %55 : i32
%57 = scf.if %56 -> (i1) {
%58 = llvm.load %2 : !llvm.ptr -> i32
%59 = arith.constant 57 : i32
%60 = arith.cmpi sle, %58, %59 : i32
scf.yield %60 : i1
} else {
%61 = arith.constant false
scf.yield %61 : i1
}
cf.cond_br %57, ^bb13, ^bb14
^bb13:
%62 = llvm.load %53 : !llvm.ptr -> i32
%63 = arith.constant 10 : i32
%64 = arith.muli %62, %63 : i32
%65 = llvm.load %2 : !llvm.ptr -> i32
%66 = arith.constant 48 : i32
%67 = arith.subi %65, %66 : i32
%68 = arith.addi %64, %67 : i32
llvm.store %68, %53 : i32, !llvm.ptr
%69 = func.call @fgetc(%arg0) : (!llvm.ptr) -> i32
llvm.store %69, %2 : i32, !llvm.ptr
cf.br ^bb12
^bb14:
%70 = arith.constant 1 : i32
%71 = arith.constant 0 : i32
%72 = arith.extsi %71 : i32 to i64
%73 = llvm.getelementptr %arg1[%72] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %70, %73 : i32, !llvm.ptr
%74 = llvm.load %32 : !llvm.ptr -> i1
cf.cond_br %74, ^bb15, ^bb16
^bb15:
%75 = llvm.load %53 : !llvm.ptr -> i32
%77 = arith.constant 0 : i32
%76 = arith.subi %77, %75 : i32
func.return %76 : i32
^bb16:
cf.br ^bb17
^bb17:
%78 = llvm.load %53 : !llvm.ptr -> i32
func.return %78 : i32
}
func.func @area2(%arg0: i32, %arg1: i32, %arg2: i32, %arg3: i32, %arg4: i32, %arg5: i32) -> i64 {
%79 = arith.subi %arg2, %arg0 : i32
%80 = arith.extsi %79 : i32 to i64
%81 = arith.subi %arg5, %arg1 : i32
%82 = arith.extsi %81 : i32 to i64
%83 = arith.muli %80, %82 : i64
%84 = arith.subi %arg4, %arg0 : i32
%85 = arith.extsi %84 : i32 to i64
%86 = arith.subi %arg3, %arg1 : i32
%87 = arith.extsi %86 : i32 to i64
%88 = arith.muli %85, %87 : i64
%89 = arith.subi %83, %88 : i64
func.return %89 : i64
}
func.func @contains_origin(%arg0: i32, %arg1: i32, %arg2: i32, %arg3: i32, %arg4: i32, %arg5: i32) -> i1 {
%90 = func.call @area2(%arg0, %arg1, %arg2, %arg3, %arg4, %arg5) : (i32, i32, i32, i32, i32, i32) -> i64
%92 = arith.constant 0 : i32
%93 = arith.constant 0 : i32
%91 = func.call @area2(%92, %93, %arg2, %arg3, %arg4, %arg5) : (i32, i32, i32, i32, i32, i32) -> i64
%95 = arith.constant 0 : i32
%96 = arith.constant 0 : i32
%94 = func.call @area2(%arg0, %arg1, %95, %96, %arg4, %arg5) : (i32, i32, i32, i32, i32, i32) -> i64
%98 = arith.constant 0 : i32
%99 = arith.constant 0 : i32
%97 = func.call @area2(%arg0, %arg1, %arg2, %arg3, %98, %99) : (i32, i32, i32, i32, i32, i32) -> i64
%100 = arith.constant 0 : i32
%102 = arith.extsi %100 : i32 to i64
%101 = arith.cmpi eq, %90, %102 : i64
cf.cond_br %101, ^bb18, ^bb19
^bb18:
%103 = arith.constant 0 : i1
func.return %103 : i1
^bb19:
cf.br ^bb20
^bb20:
%104 = arith.constant 0 : i32
%106 = arith.extsi %104 : i32 to i64
%105 = arith.cmpi sgt, %90, %106 : i64
cf.cond_br %105, ^bb21, ^bb22
^bb21:
%107 = arith.constant 0 : i32
%109 = arith.extsi %107 : i32 to i64
%108 = arith.cmpi sge, %91, %109 : i64
%110 = scf.if %108 -> (i1) {
%111 = arith.constant 0 : i32
%113 = arith.extsi %111 : i32 to i64
%112 = arith.cmpi sge, %94, %113 : i64
scf.yield %112 : i1
} else {
%114 = arith.constant false
scf.yield %114 : i1
}
%115 = scf.if %110 -> (i1) {
%116 = arith.constant 0 : i32
%118 = arith.extsi %116 : i32 to i64
%117 = arith.cmpi sge, %97, %118 : i64
scf.yield %117 : i1
} else {
%119 = arith.constant false
scf.yield %119 : i1
}
%120 = scf.if %115 -> (i1) {
%121 = arith.addi %91, %94 : i64
%122 = arith.addi %121, %97 : i64
%123 = arith.cmpi eq, %122, %90 : i64
scf.yield %123 : i1
} else {
%124 = arith.constant false
scf.yield %124 : i1
}
func.return %120 : i1
^bb22:
cf.br ^bb23
^bb23:
%125 = arith.constant 0 : i32
%127 = arith.extsi %125 : i32 to i64
%126 = arith.cmpi sle, %91, %127 : i64
%128 = scf.if %126 -> (i1) {
%129 = arith.constant 0 : i32
%131 = arith.extsi %129 : i32 to i64
%130 = arith.cmpi sle, %94, %131 : i64
scf.yield %130 : i1
} else {
%132 = arith.constant false
scf.yield %132 : i1
}
%133 = scf.if %128 -> (i1) {
%134 = arith.constant 0 : i32
%136 = arith.extsi %134 : i32 to i64
%135 = arith.cmpi sle, %97, %136 : i64
scf.yield %135 : i1
} else {
%137 = arith.constant false
scf.yield %137 : i1
}
%138 = scf.if %133 -> (i1) {
%139 = arith.addi %91, %94 : i64
%140 = arith.addi %139, %97 : i64
%141 = arith.cmpi eq, %140, %90 : i64
scf.yield %141 : i1
} else {
%142 = arith.constant false
scf.yield %142 : i1
}
func.return %138 : i1
}
func.func @main() -> i32 {
%144 = llvm.mlir.addressof @str_0 : !llvm.ptr
%145 = llvm.mlir.addressof @str_1 : !llvm.ptr
%143 = func.call @fopen(%144, %145) : (!llvm.ptr, !llvm.ptr) -> !llvm.ptr
%146 = llvm.mlir.zero : !llvm.ptr
%147 = llvm.icmp "eq" %143, %146 : !llvm.ptr
cf.cond_br %147, ^bb24, ^bb25
^bb24:
%148 = llvm.mlir.addressof @str_2 : !llvm.ptr
%149 = llvm.call @printf(%148) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr) -> i32
%150 = arith.constant 1 : i32
func.return %150 : i32
^bb25:
cf.br ^bb26
^bb26:
%152 = arith.constant 1 : i32
%153 = arith.constant 4 : i32
%154 = arith.extsi %152 : i32 to i64
%155 = arith.extsi %153 : i32 to i64
%151 = func.call @calloc(%154, %155) : (i64, i64) -> !llvm.ptr
%156 = llvm.mlir.zero : !llvm.ptr
%157 = llvm.icmp "eq" %151, %156 : !llvm.ptr
cf.cond_br %157, ^bb27, ^bb28
^bb27:
%158 = func.call @fclose(%143) : (!llvm.ptr) -> i32
%159 = arith.constant 1 : i32
func.return %159 : i32
^bb28:
cf.br ^bb29
^bb29:
%160 = arith.constant 1 : i32
%161 = arith.constant 0 : i32
%162 = arith.extsi %161 : i32 to i64
%163 = llvm.getelementptr %151[%162] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %160, %163 : i32, !llvm.ptr
%164 = arith.constant 0 : i32
%165 = arith.extsi %164 : i32 to i64
%166 = llvm.mlir.constant(1 : i64) : i64
%167 = llvm.alloca %166 x i64 : (i64) -> !llvm.ptr
llvm.store %165, %167 : i64, !llvm.ptr
cf.br ^bb30
^bb30:
%169 = arith.constant 0 : i32
%170 = arith.extsi %169 : i32 to i64
%171 = llvm.getelementptr %151[%170] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%168 = llvm.load %171 : !llvm.ptr -> i32
%172 = arith.constant 1 : i32
%173 = arith.cmpi eq, %168, %172 : i32
cf.cond_br %173, ^bb31, ^bb32
^bb31:
%174 = func.call @read_signed(%143, %151) : (!llvm.ptr, !llvm.ptr) -> i32
%176 = arith.constant 0 : i32
%177 = arith.extsi %176 : i32 to i64
%178 = llvm.getelementptr %151[%177] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%175 = llvm.load %178 : !llvm.ptr -> i32
%179 = arith.constant 0 : i32
%180 = arith.cmpi eq, %175, %179 : i32
cf.cond_br %180, ^bb33, ^bb34
^bb33:
cf.br ^bb32
^bb34:
cf.br ^bb35
^bb35:
%181 = func.call @read_signed(%143, %151) : (!llvm.ptr, !llvm.ptr) -> i32
%182 = func.call @read_signed(%143, %151) : (!llvm.ptr, !llvm.ptr) -> i32
%183 = func.call @read_signed(%143, %151) : (!llvm.ptr, !llvm.ptr) -> i32
%184 = func.call @read_signed(%143, %151) : (!llvm.ptr, !llvm.ptr) -> i32
%185 = func.call @read_signed(%143, %151) : (!llvm.ptr, !llvm.ptr) -> i32
%186 = func.call @contains_origin(%174, %181, %182, %183, %184, %185) : (i32, i32, i32, i32, i32, i32) -> i1
cf.cond_br %186, ^bb36, ^bb37
^bb36:
%187 = llvm.load %167 : !llvm.ptr -> i64
%188 = arith.constant 1 : i32
%190 = arith.extsi %188 : i32 to i64
%189 = arith.addi %187, %190 : i64
llvm.store %189, %167 : i64, !llvm.ptr
cf.br ^bb38
^bb37:
cf.br ^bb38
^bb38:
cf.br ^bb30
^bb32:
%191 = func.call @fclose(%143) : (!llvm.ptr) -> i32
func.call @free(%151) : (!llvm.ptr) -> ()
%193 = llvm.mlir.addressof @str_3 : !llvm.ptr
%194 = llvm.load %167 : !llvm.ptr -> i64
%195 = llvm.call @printf(%193, %194) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
%196 = arith.constant 0 : i32
func.return %196 : i32
}
}