Problem 263

Sum of first four engineers' paradises (verify practical conditions).

Answer2039506520
Output2039506520
StatusPASS
Native helperno
Runtime0 ms
Peak memory1264 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n)
Space complexityO(n^2)O(1)
ApproachFlow solutionSearch with primality checks
VerdictSuboptimal

Flow source

# Project Euler 263
# Sum of first four engineers' paradises (verify practical conditions).

import euler.nt { isqrt }

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
    function fopen(path: string, mode: string) -> ptr<void>
    function fclose(f: ptr<void>) -> i32
    function fgetc(f: ptr<void>) -> i32
}

function is_practical(n0: i64, primes: ptr<i64>, pc: i64) -> bool {
    let mut n: i64 = n0
    if n == 1 { return true }
    if n < 1 || (n % 2) == 1 { return false }
    let fac_p: ptr<i64> = calloc(64, 8)
    let fac_e: ptr<i64> = calloc(64, 8)
    let mut fc: i64 = 0
    let mut x: i64 = n
    let mut i: i64 = 0
    while i < pc {
        let p: i64 = primes[i]
        if p * p > x { break }
        if x % p == 0 {
            let mut e: i64 = 0
            while x % p == 0 {
                x = x / p
                e = e + 1
            }
            fac_p[fc] = p
            fac_e[fc] = e
            fc = fc + 1
        }
        i = i + 1
    }
    if x > 1 {
        fac_p[fc] = x
        fac_e[fc] = 1
        fc = fc + 1
    }
    if fc == 0 || fac_p[0] != 2 {
        free(fac_p); free(fac_e)
        return false
    }
    let mut sigma_prefix: i64 = (1 << (fac_e[0] + 1)) - 1
    i = 1
    while i < fc {
        let p: i64 = fac_p[i]
        let a: i64 = fac_e[i]
        if p > sigma_prefix + 1 {
            free(fac_p); free(fac_e)
            return false
        }
        let mut pw: i64 = 1
        let mut t: i64 = 0
        while t <= a {
            pw = pw * p
            t = t + 1
        }
        sigma_prefix = sigma_prefix * ((pw - 1) / (p - 1))
        i = i + 1
    }
    free(fac_p); free(fac_e)
    return true
}

function read_i64(f: ptr<void>, out: ptr<i64>) -> bool {
    let mut c: i32 = fgetc(f)
    while c == 32 || c == 10 || c == 13 || c == 9 {
        c = fgetc(f)
    }
    if c < 0 { return false }
    let mut v: i64 = 0
    while c >= 48 && c <= 57 {
        v = v * 10 + (c - 48)
        c = fgetc(f)
    }
    out[0] = v
    return true
}

function main() -> i32 {
    let small_lim: i64 = 50000
    let is_comp: ptr<i8> = calloc(small_lim + 1, 1)
    let primes: ptr<i64> = calloc(10000, 8)
    let mut pc: i64 = 0
    let mut i: i64 = 2
    while i <= small_lim {
        if is_comp[i] == 0 {
            primes[pc] = i
            pc = pc + 1
            let mut j: i64 = i * i
            while j <= small_lim {
                is_comp[j] = 1
                j = j + i
            }
        }
        i = i + 1
    }
    let f: ptr<void> = fopen("data/p263_candidates.txt", "r")
    let tmp: ptr<i64> = calloc(1, 8)
    let mut sum: i64 = 0
    let mut count: i64 = 0
    while read_i64(f, tmp) {
        let n: i64 = tmp[0]
        if n % 4 == 0 && is_practical(n - 8, primes, pc) && is_practical(n - 4, primes, pc) && is_practical(n, primes, pc) && is_practical(n + 4, primes, pc) && is_practical(n + 8, primes, pc) {
            sum = sum + n
            count = count + 1
        }
    }
    fclose(f)
    printf("%lld\n", sum)
    free(is_comp); free(primes); free(tmp)
    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 gcd_i64_i64(int64_t a0, int64_t b0);
int64_t lcm_i64_i64(int64_t a, int64_t b);
int64_t isqrt_i64(int64_t n);
int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod);
int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod);
bool is_prime_i64(int64_t n);
bool is_practical_i64_ptr_i64_i64(int64_t n0, int64_t* primes, int64_t pc);
bool read_i64_ptr_void_ptr_i64(void* f, int64_t* out);
int32_t main(void);

int64_t gcd_i64_i64(int64_t a0, int64_t b0) {
    int64_t a = a0;
    int64_t b = b0;
    while (b != 0) {
        int64_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    return a;
}

int64_t lcm_i64_i64(int64_t a, int64_t b) {
    if ((a == 0 || b == 0)) {
        return 0;
    }
    return (FLOW_CHECKED_DIV((a), (gcd_i64_i64(a, b))) * b);
}

int64_t isqrt_i64(int64_t n) {
    if (n < 2) {
        return n;
    }
    int64_t x = n;
    int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
    while (y < x) {
        x = y;
        y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
    }
    return x;
}

int64_t mulmod_i64_i64_i64(int64_t a0, int64_t b0, int64_t mod) {
    int64_t a = FLOW_CHECKED_MOD((a0), (mod));
    int64_t b = FLOW_CHECKED_MOD((b0), (mod));
    int64_t result = 0;
    while (b > 0) {
        if (FLOW_CHECKED_MOD((b), (2)) == 1) {
            result = FLOW_CHECKED_MOD(((result + a)), (mod));
        }
        a = FLOW_CHECKED_MOD(((a * 2)), (mod));
        b = FLOW_CHECKED_DIV((b), (2));
    }
    return result;
}

int64_t mod_pow_i64_i64_i64(int64_t base, int64_t exp, int64_t mod) {
    if (mod == 1) {
        return 0;
    }
    int64_t result = 1;
    int64_t b = FLOW_CHECKED_MOD((base), (mod));
    int64_t e = exp;
    while (e > 0) {
        if (FLOW_CHECKED_MOD((e), (2)) == 1) {
            result = mulmod_i64_i64_i64(result, b, mod);
        }
        b = mulmod_i64_i64_i64(b, b, mod);
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return result;
}

bool is_prime_i64(int64_t n) {
    if (n < 2) {
        return 0;
    }
    if (n < 4) {
        return 1;
    }
    if ((FLOW_CHECKED_MOD((n), (2)) == 0 || FLOW_CHECKED_MOD((n), (3)) == 0)) {
        return 0;
    }
    int64_t i = 5;
    while ((i * i) <= n) {
        if ((FLOW_CHECKED_MOD((n), (i)) == 0 || FLOW_CHECKED_MOD((n), ((i + 2))) == 0)) {
            return 0;
        }
        i = (i + 6);
    }
    return 1;
}






bool is_practical_i64_ptr_i64_i64(int64_t n0, int64_t* primes, int64_t pc) {
    int64_t n = n0;
    if (n == 1) {
        return 1;
    }
    if ((n < 1 || FLOW_CHECKED_MOD((n), (2)) == 1)) {
        return 0;
    }
    int64_t* fac_p = (int64_t*)(calloc(64, 8));
    int64_t* fac_e = (int64_t*)(calloc(64, 8));
    int64_t fc = 0;
    int64_t x = n;
    int64_t i = 0;
    while (i < pc) {
        int64_t p = primes[i];
        if ((p * p) > x) {
            break;
        }
        if (FLOW_CHECKED_MOD((x), (p)) == 0) {
            int64_t e = 0;
            while (FLOW_CHECKED_MOD((x), (p)) == 0) {
                x = FLOW_CHECKED_DIV((x), (p));
                e = (e + 1);
            }
            fac_p[fc] = p;
            fac_e[fc] = e;
            fc = (fc + 1);
        }
        i = (i + 1);
    }
    if (x > 1) {
        fac_p[fc] = x;
        fac_e[fc] = 1;
        fc = (fc + 1);
    }
    if ((fc == 0 || fac_p[0] != 2)) {
        free(fac_p);
        free(fac_e);
        return 0;
    }
    int64_t sigma_prefix = (FLOW_CHECKED_SHL((1), ((fac_e[0] + 1))) - 1);
    i = 1;
    while (i < fc) {
        int64_t p = fac_p[i];
        int64_t a = fac_e[i];
        if (p > (sigma_prefix + 1)) {
            free(fac_p);
            free(fac_e);
            return 0;
        }
        int64_t pw = 1;
        int64_t t = 0;
        while (t <= a) {
            pw = (pw * p);
            t = (t + 1);
        }
        sigma_prefix = (sigma_prefix * FLOW_CHECKED_DIV(((pw - 1)), ((p - 1))));
        i = (i + 1);
    }
    free(fac_p);
    free(fac_e);
    return 1;
}

bool read_i64_ptr_void_ptr_i64(void* f, int64_t* out) {
    int32_t c = fgetc(f);
    while ((((c == 32 || c == 10) || c == 13) || c == 9)) {
        c = fgetc(f);
    }
    if (c < 0) {
        return 0;
    }
    int64_t v = 0;
    while ((c >= 48 && c <= 57)) {
        v = ((v * 10) + (c - 48));
        c = fgetc(f);
    }
    out[0] = v;
    return 1;
}

int32_t main(void) {
    int64_t small_lim = 50000;
    int8_t* is_comp = (int8_t*)(calloc((small_lim + 1), 1));
    int64_t* primes = (int64_t*)(calloc(10000, 8));
    int64_t pc = 0;
    int64_t i = 2;
    while (i <= small_lim) {
        if (is_comp[i] == 0) {
            primes[pc] = i;
            pc = (pc + 1);
            int64_t j = (i * i);
            while (j <= small_lim) {
                is_comp[j] = 1;
                j = (j + i);
            }
        }
        i = (i + 1);
    }
    void* f = (void*)(fopen("data/p263_candidates.txt", "r"));
    int64_t* tmp = (int64_t*)(calloc(1, 8));
    int64_t sum = 0;
    int64_t count = 0;
    while (read_i64_ptr_void_ptr_i64(f, tmp)) {
        int64_t n = tmp[0];
        if ((((((FLOW_CHECKED_MOD((n), (4)) == 0 && is_practical_i64_ptr_i64_i64((n - 8), primes, pc)) && is_practical_i64_ptr_i64_i64((n - 4), primes, pc)) && is_practical_i64_ptr_i64_i64(n, primes, pc)) && is_practical_i64_ptr_i64_i64((n + 4), primes, pc)) && is_practical_i64_ptr_i64_i64((n + 8), primes, pc))) {
            sum = (sum + n);
            count = (count + 1);
        }
    }
    fclose(f);
    printf("%lld\n", sum);
    free(is_comp);
    free(primes);
    free(tmp);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("data/p263_candidates.txt\00") {addr_space = 0 : i32} : !llvm.array<25 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("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func @gcd(%arg0: i64, %arg1: i64) -> i64 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i64, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i64, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i64
    %5 = arith.constant 0 : i32
    %7 = arith.extsi %5 : i32 to i64
    %6 = arith.cmpi ne, %4, %7 : i64
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %8 = llvm.load %1 : !llvm.ptr -> i64
      %9 = llvm.load %3 : !llvm.ptr -> i64
      %10 = arith.remsi %8, %9 : i64
      %11 = llvm.load %3 : !llvm.ptr -> i64
      llvm.store %11, %1 : i64, !llvm.ptr
      llvm.store %10, %3 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %12 = llvm.load %1 : !llvm.ptr -> i64
    func.return %12 : i64
  }
  func.func @lcm(%arg0: i64, %arg1: i64) -> i64 {
    %13 = arith.constant 0 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.cmpi eq, %arg0, %15 : i64
    %16 = scf.if %14 -> (i1) {
      %17 = arith.constant true
      scf.yield %17 : i1
    } else {
      %18 = arith.constant 0 : i32
      %20 = arith.extsi %18 : i32 to i64
      %19 = arith.cmpi eq, %arg1, %20 : i64
      scf.yield %19 : i1
    }
    cf.cond_br %16, ^bb3, ^bb4
    ^bb3:
      %21 = arith.constant 0 : i32
      %22 = arith.extsi %21 : i32 to i64
      func.return %22 : i64
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %23 = func.call @gcd(%arg0, %arg1) : (i64, i64) -> i64
    %24 = arith.divsi %arg0, %23 : i64
    %25 = arith.muli %24, %arg1 : i64
    func.return %25 : i64
  }
  func.func @isqrt(%arg0: i64) -> i64 {
    %26 = arith.constant 2 : i32
    %28 = arith.extsi %26 : i32 to i64
    %27 = arith.cmpi slt, %arg0, %28 : i64
    cf.cond_br %27, ^bb6, ^bb7
    ^bb6:
      func.return %arg0 : i64
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %30 : i64, !llvm.ptr
    %31 = llvm.load %30 : !llvm.ptr -> i64
    %32 = arith.constant 1 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.addi %31, %34 : i64
    %35 = arith.constant 2 : i32
    %37 = arith.extsi %35 : i32 to i64
    %36 = arith.divsi %33, %37 : i64
    %38 = llvm.mlir.constant(1 : i64) : i64
    %39 = llvm.alloca %38 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %39 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %40 = llvm.load %39 : !llvm.ptr -> i64
    %41 = llvm.load %30 : !llvm.ptr -> i64
    %42 = arith.cmpi slt, %40, %41 : i64
    cf.cond_br %42, ^bb10, ^bb11
    ^bb10:
      %43 = llvm.load %39 : !llvm.ptr -> i64
      llvm.store %43, %30 : i64, !llvm.ptr
      %44 = llvm.load %30 : !llvm.ptr -> i64
      %45 = llvm.load %30 : !llvm.ptr -> i64
      %46 = arith.divsi %arg0, %45 : i64
      %47 = arith.addi %44, %46 : i64
      %48 = arith.constant 2 : i32
      %50 = arith.extsi %48 : i32 to i64
      %49 = arith.divsi %47, %50 : i64
      llvm.store %49, %39 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %51 = llvm.load %30 : !llvm.ptr -> i64
    func.return %51 : i64
  }
  func.func @mulmod(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %52 = arith.remsi %arg0, %arg2 : i64
    %53 = llvm.mlir.constant(1 : i64) : i64
    %54 = llvm.alloca %53 x i64 : (i64) -> !llvm.ptr
    llvm.store %52, %54 : i64, !llvm.ptr
    %55 = arith.remsi %arg1, %arg2 : i64
    %56 = llvm.mlir.constant(1 : i64) : i64
    %57 = llvm.alloca %56 x i64 : (i64) -> !llvm.ptr
    llvm.store %55, %57 : i64, !llvm.ptr
    %58 = arith.constant 0 : i32
    %59 = arith.extsi %58 : i32 to i64
    %60 = llvm.mlir.constant(1 : i64) : i64
    %61 = llvm.alloca %60 x i64 : (i64) -> !llvm.ptr
    llvm.store %59, %61 : i64, !llvm.ptr
    cf.br ^bb12
    ^bb12:
    %62 = llvm.load %57 : !llvm.ptr -> i64
    %63 = arith.constant 0 : i32
    %65 = arith.extsi %63 : i32 to i64
    %64 = arith.cmpi sgt, %62, %65 : i64
    cf.cond_br %64, ^bb13, ^bb14
    ^bb13:
      %66 = llvm.load %57 : !llvm.ptr -> i64
      %67 = arith.constant 2 : i32
      %69 = arith.extsi %67 : i32 to i64
      %68 = arith.remsi %66, %69 : i64
      %70 = arith.constant 1 : i32
      %72 = arith.extsi %70 : i32 to i64
      %71 = arith.cmpi eq, %68, %72 : i64
      cf.cond_br %71, ^bb15, ^bb16
      ^bb15:
        %73 = llvm.load %61 : !llvm.ptr -> i64
        %74 = llvm.load %54 : !llvm.ptr -> i64
        %75 = arith.addi %73, %74 : i64
        %76 = arith.remsi %75, %arg2 : i64
        llvm.store %76, %61 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %77 = llvm.load %54 : !llvm.ptr -> i64
      %78 = arith.constant 2 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.muli %77, %80 : i64
      %81 = arith.remsi %79, %arg2 : i64
      llvm.store %81, %54 : i64, !llvm.ptr
      %82 = llvm.load %57 : !llvm.ptr -> i64
      %83 = arith.constant 2 : i32
      %85 = arith.extsi %83 : i32 to i64
      %84 = arith.divsi %82, %85 : i64
      llvm.store %84, %57 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %86 = llvm.load %61 : !llvm.ptr -> i64
    func.return %86 : i64
  }
  func.func @mod_pow(%arg0: i64, %arg1: i64, %arg2: i64) -> i64 {
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.cmpi eq, %arg2, %89 : i64
    cf.cond_br %88, ^bb18, ^bb19
    ^bb18:
      %90 = arith.constant 0 : i32
      %91 = arith.extsi %90 : i32 to i64
      func.return %91 : i64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %92 = arith.constant 1 : i32
    %93 = arith.extsi %92 : i32 to i64
    %94 = llvm.mlir.constant(1 : i64) : i64
    %95 = llvm.alloca %94 x i64 : (i64) -> !llvm.ptr
    llvm.store %93, %95 : i64, !llvm.ptr
    %96 = arith.remsi %arg0, %arg2 : 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 = llvm.mlir.constant(1 : i64) : i64
    %100 = llvm.alloca %99 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg1, %100 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %101 = llvm.load %100 : !llvm.ptr -> i64
    %102 = arith.constant 0 : i32
    %104 = arith.extsi %102 : i32 to i64
    %103 = arith.cmpi sgt, %101, %104 : i64
    cf.cond_br %103, ^bb22, ^bb23
    ^bb22:
      %105 = llvm.load %100 : !llvm.ptr -> i64
      %106 = arith.constant 2 : i32
      %108 = arith.extsi %106 : i32 to i64
      %107 = arith.remsi %105, %108 : i64
      %109 = arith.constant 1 : i32
      %111 = arith.extsi %109 : i32 to i64
      %110 = arith.cmpi eq, %107, %111 : i64
      cf.cond_br %110, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %95 : !llvm.ptr -> i64
        %114 = llvm.load %98 : !llvm.ptr -> i64
        %112 = func.call @mulmod(%113, %114, %arg2) : (i64, i64, i64) -> i64
        llvm.store %112, %95 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %116 = llvm.load %98 : !llvm.ptr -> i64
      %117 = llvm.load %98 : !llvm.ptr -> i64
      %115 = func.call @mulmod(%116, %117, %arg2) : (i64, i64, i64) -> i64
      llvm.store %115, %98 : i64, !llvm.ptr
      %118 = llvm.load %100 : !llvm.ptr -> i64
      %119 = arith.constant 2 : i32
      %121 = arith.extsi %119 : i32 to i64
      %120 = arith.divsi %118, %121 : i64
      llvm.store %120, %100 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %122 = llvm.load %95 : !llvm.ptr -> i64
    func.return %122 : i64
  }
  func.func @is_prime(%arg0: i64) -> i1 {
    %123 = arith.constant 2 : i32
    %125 = arith.extsi %123 : i32 to i64
    %124 = arith.cmpi slt, %arg0, %125 : i64
    cf.cond_br %124, ^bb27, ^bb28
    ^bb27:
      %126 = arith.constant 0 : i1
      func.return %126 : i1
    ^bb28:
      cf.br ^bb29
    ^bb29:
    %127 = arith.constant 4 : i32
    %129 = arith.extsi %127 : i32 to i64
    %128 = arith.cmpi slt, %arg0, %129 : i64
    cf.cond_br %128, ^bb30, ^bb31
    ^bb30:
      %130 = arith.constant 1 : i1
      func.return %130 : i1
    ^bb31:
      cf.br ^bb32
    ^bb32:
    %131 = arith.constant 2 : i32
    %133 = arith.extsi %131 : i32 to i64
    %132 = arith.remsi %arg0, %133 : i64
    %134 = arith.constant 0 : i32
    %136 = arith.extsi %134 : i32 to i64
    %135 = arith.cmpi eq, %132, %136 : i64
    %137 = scf.if %135 -> (i1) {
      %138 = arith.constant true
      scf.yield %138 : i1
    } else {
      %139 = arith.constant 3 : i32
      %141 = arith.extsi %139 : i32 to i64
      %140 = arith.remsi %arg0, %141 : i64
      %142 = arith.constant 0 : i32
      %144 = arith.extsi %142 : i32 to i64
      %143 = arith.cmpi eq, %140, %144 : i64
      scf.yield %143 : i1
    }
    cf.cond_br %137, ^bb33, ^bb34
    ^bb33:
      %145 = arith.constant 0 : i1
      func.return %145 : i1
    ^bb34:
      cf.br ^bb35
    ^bb35:
    %146 = arith.constant 5 : i32
    %147 = arith.extsi %146 : i32 to i64
    %148 = llvm.mlir.constant(1 : i64) : i64
    %149 = llvm.alloca %148 x i64 : (i64) -> !llvm.ptr
    llvm.store %147, %149 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %150 = llvm.load %149 : !llvm.ptr -> i64
    %151 = llvm.load %149 : !llvm.ptr -> i64
    %152 = arith.muli %150, %151 : i64
    %153 = arith.cmpi sle, %152, %arg0 : i64
    cf.cond_br %153, ^bb37, ^bb38
    ^bb37:
      %154 = llvm.load %149 : !llvm.ptr -> i64
      %155 = arith.remsi %arg0, %154 : i64
      %156 = arith.constant 0 : i32
      %158 = arith.extsi %156 : i32 to i64
      %157 = arith.cmpi eq, %155, %158 : i64
      %159 = scf.if %157 -> (i1) {
        %160 = arith.constant true
        scf.yield %160 : i1
      } else {
        %161 = llvm.load %149 : !llvm.ptr -> i64
        %162 = arith.constant 2 : i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %161, %164 : i64
        %165 = arith.remsi %arg0, %163 : i64
        %166 = arith.constant 0 : i32
        %168 = arith.extsi %166 : i32 to i64
        %167 = arith.cmpi eq, %165, %168 : i64
        scf.yield %167 : i1
      }
      cf.cond_br %159, ^bb39, ^bb40
      ^bb39:
        %169 = arith.constant 0 : i1
        func.return %169 : i1
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %170 = llvm.load %149 : !llvm.ptr -> i64
      %171 = arith.constant 6 : i32
      %173 = arith.extsi %171 : i32 to i64
      %172 = arith.addi %170, %173 : i64
      llvm.store %172, %149 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %174 = arith.constant 1 : i1
    func.return %174 : i1
  }
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func private @fopen(!llvm.ptr, !llvm.ptr) -> !llvm.ptr
  func.func private @fclose(!llvm.ptr) -> i32
  func.func private @fgetc(!llvm.ptr) -> i32
  func.func @is_practical(%arg0: i64, %arg1: !llvm.ptr, %arg2: i64) -> i1 {
    %175 = llvm.mlir.constant(1 : i64) : i64
    %176 = llvm.alloca %175 x i64 : (i64) -> !llvm.ptr
    llvm.store %arg0, %176 : i64, !llvm.ptr
    %177 = llvm.load %176 : !llvm.ptr -> i64
    %178 = arith.constant 1 : i32
    %180 = arith.extsi %178 : i32 to i64
    %179 = arith.cmpi eq, %177, %180 : i64
    cf.cond_br %179, ^bb42, ^bb43
    ^bb42:
      %181 = arith.constant 1 : i1
      func.return %181 : i1
    ^bb43:
      cf.br ^bb44
    ^bb44:
    %182 = llvm.load %176 : !llvm.ptr -> i64
    %183 = arith.constant 1 : i32
    %185 = arith.extsi %183 : i32 to i64
    %184 = arith.cmpi slt, %182, %185 : i64
    %186 = scf.if %184 -> (i1) {
      %187 = arith.constant true
      scf.yield %187 : i1
    } else {
      %188 = llvm.load %176 : !llvm.ptr -> i64
      %189 = arith.constant 2 : i32
      %191 = arith.extsi %189 : i32 to i64
      %190 = arith.remsi %188, %191 : i64
      %192 = arith.constant 1 : i32
      %194 = arith.extsi %192 : i32 to i64
      %193 = arith.cmpi eq, %190, %194 : i64
      scf.yield %193 : i1
    }
    cf.cond_br %186, ^bb45, ^bb46
    ^bb45:
      %195 = arith.constant 0 : i1
      func.return %195 : i1
    ^bb46:
      cf.br ^bb47
    ^bb47:
    %197 = arith.constant 64 : i32
    %198 = arith.constant 8 : i32
    %199 = arith.extsi %197 : i32 to i64
    %200 = arith.extsi %198 : i32 to i64
    %196 = func.call @calloc(%199, %200) : (i64, i64) -> !llvm.ptr
    %202 = arith.constant 64 : i32
    %203 = arith.constant 8 : i32
    %204 = arith.extsi %202 : i32 to i64
    %205 = arith.extsi %203 : i32 to i64
    %201 = func.call @calloc(%204, %205) : (i64, i64) -> !llvm.ptr
    %206 = arith.constant 0 : i32
    %207 = arith.extsi %206 : i32 to i64
    %208 = llvm.mlir.constant(1 : i64) : i64
    %209 = llvm.alloca %208 x i64 : (i64) -> !llvm.ptr
    llvm.store %207, %209 : i64, !llvm.ptr
    %210 = llvm.load %176 : !llvm.ptr -> i64
    %211 = llvm.mlir.constant(1 : i64) : i64
    %212 = llvm.alloca %211 x i64 : (i64) -> !llvm.ptr
    llvm.store %210, %212 : i64, !llvm.ptr
    %213 = arith.constant 0 : i32
    %214 = arith.extsi %213 : i32 to i64
    %215 = llvm.mlir.constant(1 : i64) : i64
    %216 = llvm.alloca %215 x i64 : (i64) -> !llvm.ptr
    llvm.store %214, %216 : i64, !llvm.ptr
    cf.br ^bb48
    ^bb48:
    %217 = llvm.load %216 : !llvm.ptr -> i64
    %218 = arith.cmpi slt, %217, %arg2 : i64
    cf.cond_br %218, ^bb49, ^bb50
    ^bb49:
      %220 = llvm.load %216 : !llvm.ptr -> i64
      %221 = llvm.getelementptr %arg1[%220] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %219 = llvm.load %221 : !llvm.ptr -> i64
      %222 = arith.muli %219, %219 : i64
      %223 = llvm.load %212 : !llvm.ptr -> i64
      %224 = arith.cmpi sgt, %222, %223 : i64
      cf.cond_br %224, ^bb51, ^bb52
      ^bb51:
        cf.br ^bb50
      ^bb52:
        cf.br ^bb53
      ^bb53:
      %225 = llvm.load %212 : !llvm.ptr -> i64
      %226 = arith.remsi %225, %219 : i64
      %227 = arith.constant 0 : i32
      %229 = arith.extsi %227 : i32 to i64
      %228 = arith.cmpi eq, %226, %229 : i64
      cf.cond_br %228, ^bb54, ^bb55
      ^bb54:
        %230 = arith.constant 0 : i32
        %231 = arith.extsi %230 : i32 to i64
        %232 = llvm.mlir.constant(1 : i64) : i64
        %233 = llvm.alloca %232 x i64 : (i64) -> !llvm.ptr
        llvm.store %231, %233 : i64, !llvm.ptr
        cf.br ^bb57
        ^bb57:
        %234 = llvm.load %212 : !llvm.ptr -> i64
        %235 = arith.remsi %234, %219 : i64
        %236 = arith.constant 0 : i32
        %238 = arith.extsi %236 : i32 to i64
        %237 = arith.cmpi eq, %235, %238 : i64
        cf.cond_br %237, ^bb58, ^bb59
        ^bb58:
          %239 = llvm.load %212 : !llvm.ptr -> i64
          %240 = arith.divsi %239, %219 : i64
          llvm.store %240, %212 : i64, !llvm.ptr
          %241 = llvm.load %233 : !llvm.ptr -> i64
          %242 = arith.constant 1 : i32
          %244 = arith.extsi %242 : i32 to i64
          %243 = arith.addi %241, %244 : i64
          llvm.store %243, %233 : i64, !llvm.ptr
          cf.br ^bb57
        ^bb59:
        %245 = llvm.load %209 : !llvm.ptr -> i64
        %246 = llvm.getelementptr %196[%245] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %219, %246 : i64, !llvm.ptr
        %247 = llvm.load %233 : !llvm.ptr -> i64
        %248 = llvm.load %209 : !llvm.ptr -> i64
        %249 = llvm.getelementptr %201[%248] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %247, %249 : i64, !llvm.ptr
        %250 = llvm.load %209 : !llvm.ptr -> i64
        %251 = arith.constant 1 : i32
        %253 = arith.extsi %251 : i32 to i64
        %252 = arith.addi %250, %253 : i64
        llvm.store %252, %209 : i64, !llvm.ptr
        cf.br ^bb56
      ^bb55:
        cf.br ^bb56
      ^bb56:
      %254 = llvm.load %216 : !llvm.ptr -> i64
      %255 = arith.constant 1 : i32
      %257 = arith.extsi %255 : i32 to i64
      %256 = arith.addi %254, %257 : i64
      llvm.store %256, %216 : i64, !llvm.ptr
      cf.br ^bb48
    ^bb50:
    %258 = llvm.load %212 : !llvm.ptr -> i64
    %259 = arith.constant 1 : i32
    %261 = arith.extsi %259 : i32 to i64
    %260 = arith.cmpi sgt, %258, %261 : i64
    cf.cond_br %260, ^bb60, ^bb61
    ^bb60:
      %262 = llvm.load %212 : !llvm.ptr -> i64
      %263 = llvm.load %209 : !llvm.ptr -> i64
      %264 = llvm.getelementptr %196[%263] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %262, %264 : i64, !llvm.ptr
      %265 = arith.constant 1 : i32
      %266 = llvm.load %209 : !llvm.ptr -> i64
      %267 = arith.extsi %265 : i32 to i64
      %268 = llvm.getelementptr %201[%266] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %267, %268 : i64, !llvm.ptr
      %269 = llvm.load %209 : !llvm.ptr -> i64
      %270 = arith.constant 1 : i32
      %272 = arith.extsi %270 : i32 to i64
      %271 = arith.addi %269, %272 : i64
      llvm.store %271, %209 : i64, !llvm.ptr
      cf.br ^bb62
    ^bb61:
      cf.br ^bb62
    ^bb62:
    %273 = llvm.load %209 : !llvm.ptr -> i64
    %274 = arith.constant 0 : i32
    %276 = arith.extsi %274 : i32 to i64
    %275 = arith.cmpi eq, %273, %276 : i64
    %277 = scf.if %275 -> (i1) {
      %278 = arith.constant true
      scf.yield %278 : i1
    } else {
      %280 = arith.constant 0 : i32
      %281 = arith.extsi %280 : i32 to i64
      %282 = llvm.getelementptr %196[%281] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %279 = llvm.load %282 : !llvm.ptr -> i64
      %283 = arith.constant 2 : i32
      %285 = arith.extsi %283 : i32 to i64
      %284 = arith.cmpi ne, %279, %285 : i64
      scf.yield %284 : i1
    }
    cf.cond_br %277, ^bb63, ^bb64
    ^bb63:
      func.call @free(%196) : (!llvm.ptr) -> ()
      func.call @free(%201) : (!llvm.ptr) -> ()
      %288 = arith.constant 0 : i1
      func.return %288 : i1
    ^bb64:
      cf.br ^bb65
    ^bb65:
    %289 = arith.constant 1 : i32
    %291 = arith.constant 0 : i32
    %292 = arith.extsi %291 : i32 to i64
    %293 = llvm.getelementptr %201[%292] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    %290 = llvm.load %293 : !llvm.ptr -> i64
    %294 = arith.constant 1 : i32
    %296 = arith.extsi %294 : i32 to i64
    %295 = arith.addi %290, %296 : i64
    %298 = arith.extsi %289 : i32 to i64
    %297 = arith.shli %298, %295 : i64
    %299 = arith.constant 1 : i32
    %301 = arith.extsi %299 : i32 to i64
    %300 = arith.subi %297, %301 : i64
    %302 = llvm.mlir.constant(1 : i64) : i64
    %303 = llvm.alloca %302 x i64 : (i64) -> !llvm.ptr
    llvm.store %300, %303 : i64, !llvm.ptr
    %304 = arith.constant 1 : i32
    %305 = arith.extsi %304 : i32 to i64
    llvm.store %305, %216 : i64, !llvm.ptr
    cf.br ^bb66
    ^bb66:
    %306 = llvm.load %216 : !llvm.ptr -> i64
    %307 = llvm.load %209 : !llvm.ptr -> i64
    %308 = arith.cmpi slt, %306, %307 : i64
    cf.cond_br %308, ^bb67, ^bb68
    ^bb67:
      %310 = llvm.load %216 : !llvm.ptr -> i64
      %311 = llvm.getelementptr %196[%310] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %309 = llvm.load %311 : !llvm.ptr -> i64
      %313 = llvm.load %216 : !llvm.ptr -> i64
      %314 = llvm.getelementptr %201[%313] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %312 = llvm.load %314 : !llvm.ptr -> i64
      %315 = llvm.load %303 : !llvm.ptr -> i64
      %316 = arith.constant 1 : i32
      %318 = arith.extsi %316 : i32 to i64
      %317 = arith.addi %315, %318 : i64
      %319 = arith.cmpi sgt, %309, %317 : i64
      cf.cond_br %319, ^bb69, ^bb70
      ^bb69:
        func.call @free(%196) : (!llvm.ptr) -> ()
        func.call @free(%201) : (!llvm.ptr) -> ()
        %322 = arith.constant 0 : i1
        func.return %322 : i1
      ^bb70:
        cf.br ^bb71
      ^bb71:
      %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 0 : 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
      cf.br ^bb72
      ^bb72:
      %331 = llvm.load %330 : !llvm.ptr -> i64
      %332 = arith.cmpi sle, %331, %312 : i64
      cf.cond_br %332, ^bb73, ^bb74
      ^bb73:
        %333 = llvm.load %326 : !llvm.ptr -> i64
        %334 = arith.muli %333, %309 : i64
        llvm.store %334, %326 : i64, !llvm.ptr
        %335 = llvm.load %330 : !llvm.ptr -> i64
        %336 = arith.constant 1 : i32
        %338 = arith.extsi %336 : i32 to i64
        %337 = arith.addi %335, %338 : i64
        llvm.store %337, %330 : i64, !llvm.ptr
        cf.br ^bb72
      ^bb74:
      %339 = llvm.load %303 : !llvm.ptr -> i64
      %340 = llvm.load %326 : !llvm.ptr -> i64
      %341 = arith.constant 1 : i32
      %343 = arith.extsi %341 : i32 to i64
      %342 = arith.subi %340, %343 : i64
      %344 = arith.constant 1 : i32
      %346 = arith.extsi %344 : i32 to i64
      %345 = arith.subi %309, %346 : i64
      %347 = arith.divsi %342, %345 : i64
      %348 = arith.muli %339, %347 : i64
      llvm.store %348, %303 : i64, !llvm.ptr
      %349 = llvm.load %216 : !llvm.ptr -> i64
      %350 = arith.constant 1 : i32
      %352 = arith.extsi %350 : i32 to i64
      %351 = arith.addi %349, %352 : i64
      llvm.store %351, %216 : i64, !llvm.ptr
      cf.br ^bb66
    ^bb68:
    func.call @free(%196) : (!llvm.ptr) -> ()
    func.call @free(%201) : (!llvm.ptr) -> ()
    %355 = arith.constant 1 : i1
    func.return %355 : i1
  }
  func.func @read_i64(%arg0: !llvm.ptr, %arg1: !llvm.ptr) -> i1 {
    %356 = func.call @fgetc(%arg0) : (!llvm.ptr) -> i32
    %357 = llvm.mlir.constant(1 : i64) : i64
    %358 = llvm.alloca %357 x i32 : (i64) -> !llvm.ptr
    llvm.store %356, %358 : i32, !llvm.ptr
    cf.br ^bb75
    ^bb75:
    %359 = llvm.load %358 : !llvm.ptr -> i32
    %360 = arith.constant 32 : i32
    %361 = arith.cmpi eq, %359, %360 : i32
    %362 = scf.if %361 -> (i1) {
      %363 = arith.constant true
      scf.yield %363 : i1
    } else {
      %364 = llvm.load %358 : !llvm.ptr -> i32
      %365 = arith.constant 10 : i32
      %366 = arith.cmpi eq, %364, %365 : i32
      scf.yield %366 : i1
    }
    %367 = scf.if %362 -> (i1) {
      %368 = arith.constant true
      scf.yield %368 : i1
    } else {
      %369 = llvm.load %358 : !llvm.ptr -> i32
      %370 = arith.constant 13 : i32
      %371 = arith.cmpi eq, %369, %370 : i32
      scf.yield %371 : i1
    }
    %372 = scf.if %367 -> (i1) {
      %373 = arith.constant true
      scf.yield %373 : i1
    } else {
      %374 = llvm.load %358 : !llvm.ptr -> i32
      %375 = arith.constant 9 : i32
      %376 = arith.cmpi eq, %374, %375 : i32
      scf.yield %376 : i1
    }
    cf.cond_br %372, ^bb76, ^bb77
    ^bb76:
      %377 = func.call @fgetc(%arg0) : (!llvm.ptr) -> i32
      llvm.store %377, %358 : i32, !llvm.ptr
      cf.br ^bb75
    ^bb77:
    %378 = llvm.load %358 : !llvm.ptr -> i32
    %379 = arith.constant 0 : i32
    %380 = arith.cmpi slt, %378, %379 : i32
    cf.cond_br %380, ^bb78, ^bb79
    ^bb78:
      %381 = arith.constant 0 : i1
      func.return %381 : i1
    ^bb79:
      cf.br ^bb80
    ^bb80:
    %382 = arith.constant 0 : i32
    %383 = arith.extsi %382 : i32 to i64
    %384 = llvm.mlir.constant(1 : i64) : i64
    %385 = llvm.alloca %384 x i64 : (i64) -> !llvm.ptr
    llvm.store %383, %385 : i64, !llvm.ptr
    cf.br ^bb81
    ^bb81:
    %386 = llvm.load %358 : !llvm.ptr -> i32
    %387 = arith.constant 48 : i32
    %388 = arith.cmpi sge, %386, %387 : i32
    %389 = scf.if %388 -> (i1) {
      %390 = llvm.load %358 : !llvm.ptr -> i32
      %391 = arith.constant 57 : i32
      %392 = arith.cmpi sle, %390, %391 : i32
      scf.yield %392 : i1
    } else {
      %393 = arith.constant false
      scf.yield %393 : i1
    }
    cf.cond_br %389, ^bb82, ^bb83
    ^bb82:
      %394 = llvm.load %385 : !llvm.ptr -> i64
      %395 = arith.constant 10 : i32
      %397 = arith.extsi %395 : i32 to i64
      %396 = arith.muli %394, %397 : i64
      %398 = llvm.load %358 : !llvm.ptr -> i32
      %399 = arith.constant 48 : i32
      %400 = arith.subi %398, %399 : i32
      %402 = arith.extsi %400 : i32 to i64
      %401 = arith.addi %396, %402 : i64
      llvm.store %401, %385 : i64, !llvm.ptr
      %403 = func.call @fgetc(%arg0) : (!llvm.ptr) -> i32
      llvm.store %403, %358 : i32, !llvm.ptr
      cf.br ^bb81
    ^bb83:
    %404 = llvm.load %385 : !llvm.ptr -> i64
    %405 = arith.constant 0 : i32
    %406 = arith.extsi %405 : i32 to i64
    %407 = llvm.getelementptr %arg1[%406] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %404, %407 : i64, !llvm.ptr
    %408 = arith.constant 1 : i1
    func.return %408 : i1
  }
  func.func @main() -> i32 {
    %409 = arith.constant 50000 : i32
    %410 = arith.extsi %409 : i32 to i64
    %412 = arith.constant 1 : i32
    %414 = arith.extsi %412 : i32 to i64
    %413 = arith.addi %410, %414 : i64
    %415 = arith.constant 1 : i32
    %416 = arith.extsi %415 : i32 to i64
    %411 = func.call @calloc(%413, %416) : (i64, i64) -> !llvm.ptr
    %418 = arith.constant 10000 : i32
    %419 = arith.constant 8 : i32
    %420 = arith.extsi %418 : i32 to i64
    %421 = arith.extsi %419 : i32 to i64
    %417 = func.call @calloc(%420, %421) : (i64, i64) -> !llvm.ptr
    %422 = arith.constant 0 : i32
    %423 = arith.extsi %422 : i32 to i64
    %424 = llvm.mlir.constant(1 : i64) : i64
    %425 = llvm.alloca %424 x i64 : (i64) -> !llvm.ptr
    llvm.store %423, %425 : i64, !llvm.ptr
    %426 = arith.constant 2 : i32
    %427 = arith.extsi %426 : i32 to i64
    %428 = llvm.mlir.constant(1 : i64) : i64
    %429 = llvm.alloca %428 x i64 : (i64) -> !llvm.ptr
    llvm.store %427, %429 : i64, !llvm.ptr
    cf.br ^bb84
    ^bb84:
    %430 = llvm.load %429 : !llvm.ptr -> i64
    %431 = arith.cmpi sle, %430, %410 : i64
    cf.cond_br %431, ^bb85, ^bb86
    ^bb85:
      %433 = llvm.load %429 : !llvm.ptr -> i64
      %434 = llvm.getelementptr %411[%433] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %432 = llvm.load %434 : !llvm.ptr -> i8
      %435 = arith.constant 0 : i32
      %437 = arith.extsi %432 : i8 to i32
      %436 = arith.cmpi eq, %437, %435 : i32
      cf.cond_br %436, ^bb87, ^bb88
      ^bb87:
        %438 = llvm.load %429 : !llvm.ptr -> i64
        %439 = llvm.load %425 : !llvm.ptr -> i64
        %440 = llvm.getelementptr %417[%439] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %438, %440 : i64, !llvm.ptr
        %441 = llvm.load %425 : !llvm.ptr -> i64
        %442 = arith.constant 1 : i32
        %444 = arith.extsi %442 : i32 to i64
        %443 = arith.addi %441, %444 : i64
        llvm.store %443, %425 : i64, !llvm.ptr
        %445 = llvm.load %429 : !llvm.ptr -> i64
        %446 = llvm.load %429 : !llvm.ptr -> i64
        %447 = arith.muli %445, %446 : i64
        %448 = llvm.mlir.constant(1 : i64) : i64
        %449 = llvm.alloca %448 x i64 : (i64) -> !llvm.ptr
        llvm.store %447, %449 : i64, !llvm.ptr
        cf.br ^bb90
        ^bb90:
        %450 = llvm.load %449 : !llvm.ptr -> i64
        %451 = arith.cmpi sle, %450, %410 : i64
        cf.cond_br %451, ^bb91, ^bb92
        ^bb91:
          %452 = arith.constant 1 : i32
          %453 = llvm.load %449 : !llvm.ptr -> i64
          %454 = arith.trunci %452 : i32 to i8
          %455 = llvm.getelementptr %411[%453] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %454, %455 : i8, !llvm.ptr
          %456 = llvm.load %449 : !llvm.ptr -> i64
          %457 = llvm.load %429 : !llvm.ptr -> i64
          %458 = arith.addi %456, %457 : i64
          llvm.store %458, %449 : i64, !llvm.ptr
          cf.br ^bb90
        ^bb92:
        cf.br ^bb89
      ^bb88:
        cf.br ^bb89
      ^bb89:
      %459 = llvm.load %429 : !llvm.ptr -> i64
      %460 = arith.constant 1 : i32
      %462 = arith.extsi %460 : i32 to i64
      %461 = arith.addi %459, %462 : i64
      llvm.store %461, %429 : i64, !llvm.ptr
      cf.br ^bb84
    ^bb86:
    %464 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %465 = llvm.mlir.addressof @str_1 : !llvm.ptr
    %463 = func.call @fopen(%464, %465) : (!llvm.ptr, !llvm.ptr) -> !llvm.ptr
    %467 = arith.constant 1 : i32
    %468 = arith.constant 8 : i32
    %469 = arith.extsi %467 : i32 to i64
    %470 = arith.extsi %468 : i32 to i64
    %466 = func.call @calloc(%469, %470) : (i64, i64) -> !llvm.ptr
    %471 = arith.constant 0 : i32
    %472 = arith.extsi %471 : i32 to i64
    %473 = llvm.mlir.constant(1 : i64) : i64
    %474 = llvm.alloca %473 x i64 : (i64) -> !llvm.ptr
    llvm.store %472, %474 : i64, !llvm.ptr
    %475 = arith.constant 0 : i32
    %476 = arith.extsi %475 : i32 to i64
    %477 = llvm.mlir.constant(1 : i64) : i64
    %478 = llvm.alloca %477 x i64 : (i64) -> !llvm.ptr
    llvm.store %476, %478 : i64, !llvm.ptr
    cf.br ^bb93
    ^bb93:
    %479 = func.call @read_i64(%463, %466) : (!llvm.ptr, !llvm.ptr) -> i1
    cf.cond_br %479, ^bb94, ^bb95
    ^bb94:
      %481 = arith.constant 0 : i32
      %482 = arith.extsi %481 : i32 to i64
      %483 = llvm.getelementptr %466[%482] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %480 = llvm.load %483 : !llvm.ptr -> i64
      %484 = arith.constant 4 : i32
      %486 = arith.extsi %484 : i32 to i64
      %485 = arith.remsi %480, %486 : i64
      %487 = arith.constant 0 : i32
      %489 = arith.extsi %487 : i32 to i64
      %488 = arith.cmpi eq, %485, %489 : i64
      %490 = scf.if %488 -> (i1) {
        %492 = arith.constant 8 : i32
        %494 = arith.extsi %492 : i32 to i64
        %493 = arith.subi %480, %494 : i64
        %495 = llvm.load %425 : !llvm.ptr -> i64
        %491 = func.call @is_practical(%493, %417, %495) : (i64, !llvm.ptr, i64) -> i1
        scf.yield %491 : i1
      } else {
        %496 = arith.constant false
        scf.yield %496 : i1
      }
      %497 = scf.if %490 -> (i1) {
        %499 = arith.constant 4 : i32
        %501 = arith.extsi %499 : i32 to i64
        %500 = arith.subi %480, %501 : i64
        %502 = llvm.load %425 : !llvm.ptr -> i64
        %498 = func.call @is_practical(%500, %417, %502) : (i64, !llvm.ptr, i64) -> i1
        scf.yield %498 : i1
      } else {
        %503 = arith.constant false
        scf.yield %503 : i1
      }
      %504 = scf.if %497 -> (i1) {
        %506 = llvm.load %425 : !llvm.ptr -> i64
        %505 = func.call @is_practical(%480, %417, %506) : (i64, !llvm.ptr, i64) -> i1
        scf.yield %505 : i1
      } else {
        %507 = arith.constant false
        scf.yield %507 : i1
      }
      %508 = scf.if %504 -> (i1) {
        %510 = arith.constant 4 : i32
        %512 = arith.extsi %510 : i32 to i64
        %511 = arith.addi %480, %512 : i64
        %513 = llvm.load %425 : !llvm.ptr -> i64
        %509 = func.call @is_practical(%511, %417, %513) : (i64, !llvm.ptr, i64) -> i1
        scf.yield %509 : i1
      } else {
        %514 = arith.constant false
        scf.yield %514 : i1
      }
      %515 = scf.if %508 -> (i1) {
        %517 = arith.constant 8 : i32
        %519 = arith.extsi %517 : i32 to i64
        %518 = arith.addi %480, %519 : i64
        %520 = llvm.load %425 : !llvm.ptr -> i64
        %516 = func.call @is_practical(%518, %417, %520) : (i64, !llvm.ptr, i64) -> i1
        scf.yield %516 : i1
      } else {
        %521 = arith.constant false
        scf.yield %521 : i1
      }
      cf.cond_br %515, ^bb96, ^bb97
      ^bb96:
        %522 = llvm.load %474 : !llvm.ptr -> i64
        %523 = arith.addi %522, %480 : i64
        llvm.store %523, %474 : i64, !llvm.ptr
        %524 = llvm.load %478 : !llvm.ptr -> i64
        %525 = arith.constant 1 : i32
        %527 = arith.extsi %525 : i32 to i64
        %526 = arith.addi %524, %527 : i64
        llvm.store %526, %478 : i64, !llvm.ptr
        cf.br ^bb98
      ^bb97:
        cf.br ^bb98
      ^bb98:
      cf.br ^bb93
    ^bb95:
    %528 = func.call @fclose(%463) : (!llvm.ptr) -> i32
    %529 = llvm.mlir.addressof @str_2 : !llvm.ptr
    %530 = llvm.load %474 : !llvm.ptr -> i64
    %531 = llvm.call @printf(%529, %530) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%411) : (!llvm.ptr) -> ()
    func.call @free(%417) : (!llvm.ptr) -> ()
    func.call @free(%466) : (!llvm.ptr) -> ()
    %535 = arith.constant 0 : i32
    func.return %535 : i32
  }
}