Problem 373

S(10^7) = sum r*N(r) for integer circumradius triangles.

Answer727227472448913
Output727227472448913
StatusPASS
Native helperno
Runtime410 ms
Peak memory42848 KB
Time complexityO(n^3) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^3)O(n^2)
Space complexityO(n^2)O(n^2)
ApproachFlow solutionBottom-up DP
VerdictSuboptimal

Flow source

# Project Euler 373
# S(10^7) = sum r*N(r) for integer circumradius triangles.

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
}

function main() -> i32 {
    let n: i64 = 10000000
    let spf: ptr<i32> = calloc(n + 1, 4)
    let primes: ptr<i32> = calloc(n / 5 + 10, 4)
    if spf == null || primes == null { return 1 }
    let mut pc: i64 = 0
    let mut i: i64 = 2
    while i <= n {
        if spf[i] == 0 {
            spf[i] = i as i32
            primes[pc] = i as i32
            pc = pc + 1
        }
        let si: i64 = spf[i] as i64
        let mut j: i64 = 0
        while j < pc {
            let p: i64 = primes[j] as i64
            let ip: i64 = i * p
            if ip > n { break }
            spf[ip] = p as i32
            if p == si { break }
            j = j + 1
        }
        i = i + 1
    }

    let t1: ptr<i64> = calloc(25, 8)
    let t2: ptr<i64> = calloc(25, 8)
    let t3: ptr<i64> = calloc(25, 8)
    if t1 == null || t2 == null || t3 == null { return 1 }
    let mut e: i64 = 0
    while e <= 24 {
        t1[e] = 3 * e * e + 3 * e + 1
        t2[e] = 2 * e + 1
        t3[e] = 2 * (e / 2) + 1
        e = e + 1
    }

    let mut total: i64 = 0
    let mut r: i64 = 1
    while r <= n {
        let mut x: i64 = r
        let mut prod1: i64 = 1
        let mut prod2: i64 = 1
        let mut prod3: i64 = 1
        while x > 1 {
            let p: i64 = spf[x] as i64
            let mut ee: i64 = 1
            x = x / p
            while x % p == 0 {
                x = x / p
                ee = ee + 1
            }
            if p % 4 == 1 {
                prod1 = prod1 * t1[ee]
                prod2 = prod2 * t2[ee]
                prod3 = prod3 * t3[ee]
            }
        }
        if prod1 != 1 {
            let cnt: i64 = (2 * prod1 - 3 * prod2 + 3 * prod3 - 2) / 6
            if cnt != 0 {
                total = total + r * cnt
            }
        }
        r = r + 1
    }

    printf("%lld\n", total)
    free(t3)
    free(t2)
    free(t1)
    free(primes)
    free(spf)
    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 main(void);



int32_t main(void) {
    int64_t n = 10000000;
    int32_t* spf = (int32_t*)(calloc((n + 1), 4));
    int32_t* primes = (int32_t*)(calloc((FLOW_CHECKED_DIV((n), (5)) + 10), 4));
    if ((spf == NULL || primes == NULL)) {
        return 1;
    }
    int64_t pc = 0;
    int64_t i = 2;
    while (i <= n) {
        if (spf[i] == 0) {
            spf[i] = ((int32_t)(i));
            primes[pc] = ((int32_t)(i));
            pc = (pc + 1);
        }
        int64_t si = ((int64_t)(spf[i]));
        int64_t j = 0;
        while (j < pc) {
            int64_t p = ((int64_t)(primes[j]));
            int64_t ip = (i * p);
            if (ip > n) {
                break;
            }
            spf[ip] = ((int32_t)(p));
            if (p == si) {
                break;
            }
            j = (j + 1);
        }
        i = (i + 1);
    }
    int64_t* t1 = (int64_t*)(calloc(25, 8));
    int64_t* t2 = (int64_t*)(calloc(25, 8));
    int64_t* t3 = (int64_t*)(calloc(25, 8));
    if (((t1 == NULL || t2 == NULL) || t3 == NULL)) {
        return 1;
    }
    int64_t e = 0;
    while (e <= 24) {
        t1[e] = ((((3 * e) * e) + (3 * e)) + 1);
        t2[e] = ((2 * e) + 1);
        t3[e] = ((2 * FLOW_CHECKED_DIV((e), (2))) + 1);
        e = (e + 1);
    }
    int64_t total = 0;
    int64_t r = 1;
    while (r <= n) {
        int64_t x = r;
        int64_t prod1 = 1;
        int64_t prod2 = 1;
        int64_t prod3 = 1;
        while (x > 1) {
            int64_t p = ((int64_t)(spf[x]));
            int64_t ee = 1;
            x = FLOW_CHECKED_DIV((x), (p));
            while (FLOW_CHECKED_MOD((x), (p)) == 0) {
                x = FLOW_CHECKED_DIV((x), (p));
                ee = (ee + 1);
            }
            if (FLOW_CHECKED_MOD((p), (4)) == 1) {
                prod1 = (prod1 * t1[ee]);
                prod2 = (prod2 * t2[ee]);
                prod3 = (prod3 * t3[ee]);
            }
        }
        if (prod1 != 1) {
            int64_t cnt = FLOW_CHECKED_DIV((((((2 * prod1) - (3 * prod2)) + (3 * prod3)) - 2)), (6));
            if (cnt != 0) {
                total = (total + (r * cnt));
            }
        }
        r = (r + 1);
    }
    printf("%lld\n", total);
    free(t3);
    free(t2);
    free(t1);
    free(primes);
    free(spf);
    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 @main() -> i32 {
    %0 = arith.constant 10000000 : i32
    %1 = arith.extsi %0 : i32 to i64
    %3 = arith.constant 1 : i32
    %5 = arith.extsi %3 : i32 to i64
    %4 = arith.addi %1, %5 : i64
    %6 = arith.constant 4 : i32
    %7 = arith.extsi %6 : i32 to i64
    %2 = func.call @calloc(%4, %7) : (i64, i64) -> !llvm.ptr
    %9 = arith.constant 5 : i32
    %11 = arith.extsi %9 : i32 to i64
    %10 = arith.divsi %1, %11 : i64
    %12 = arith.constant 10 : i32
    %14 = arith.extsi %12 : i32 to i64
    %13 = arith.addi %10, %14 : i64
    %15 = arith.constant 4 : i32
    %16 = arith.extsi %15 : i32 to i64
    %8 = func.call @calloc(%13, %16) : (i64, i64) -> !llvm.ptr
    %17 = llvm.mlir.zero : !llvm.ptr
    %18 = llvm.icmp "eq" %2, %17 : !llvm.ptr
    %19 = scf.if %18 -> (i1) {
      %20 = arith.constant true
      scf.yield %20 : i1
    } else {
      %21 = llvm.mlir.zero : !llvm.ptr
      %22 = llvm.icmp "eq" %8, %21 : !llvm.ptr
      scf.yield %22 : i1
    }
    cf.cond_br %19, ^bb0, ^bb1
    ^bb0:
      %23 = arith.constant 1 : i32
      func.return %23 : i32
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %24 = arith.constant 0 : i32
    %25 = arith.extsi %24 : i32 to i64
    %26 = llvm.mlir.constant(1 : i64) : i64
    %27 = llvm.alloca %26 x i64 : (i64) -> !llvm.ptr
    llvm.store %25, %27 : i64, !llvm.ptr
    %28 = arith.constant 2 : i32
    %29 = arith.extsi %28 : i32 to i64
    %30 = llvm.mlir.constant(1 : i64) : i64
    %31 = llvm.alloca %30 x i64 : (i64) -> !llvm.ptr
    llvm.store %29, %31 : i64, !llvm.ptr
    cf.br ^bb3
    ^bb3:
    %32 = llvm.load %31 : !llvm.ptr -> i64
    %33 = arith.cmpi sle, %32, %1 : i64
    cf.cond_br %33, ^bb4, ^bb5
    ^bb4:
      %35 = llvm.load %31 : !llvm.ptr -> i64
      %36 = llvm.getelementptr %2[%35] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %34 = llvm.load %36 : !llvm.ptr -> i32
      %37 = arith.constant 0 : i32
      %38 = arith.cmpi eq, %34, %37 : i32
      cf.cond_br %38, ^bb6, ^bb7
      ^bb6:
        %39 = llvm.load %31 : !llvm.ptr -> i64
        %40 = arith.trunci %39 : i64 to i32
        %41 = llvm.load %31 : !llvm.ptr -> i64
        %42 = llvm.getelementptr %2[%41] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %40, %42 : i32, !llvm.ptr
        %43 = llvm.load %31 : !llvm.ptr -> i64
        %44 = arith.trunci %43 : i64 to i32
        %45 = llvm.load %27 : !llvm.ptr -> i64
        %46 = llvm.getelementptr %8[%45] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %44, %46 : i32, !llvm.ptr
        %47 = llvm.load %27 : !llvm.ptr -> i64
        %48 = arith.constant 1 : i32
        %50 = arith.extsi %48 : i32 to i64
        %49 = arith.addi %47, %50 : i64
        llvm.store %49, %27 : i64, !llvm.ptr
        cf.br ^bb8
      ^bb7:
        cf.br ^bb8
      ^bb8:
      %52 = llvm.load %31 : !llvm.ptr -> i64
      %53 = llvm.getelementptr %2[%52] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %51 = llvm.load %53 : !llvm.ptr -> i32
      %54 = arith.extsi %51 : i32 to i64
      %55 = arith.constant 0 : i32
      %56 = arith.extsi %55 : i32 to i64
      %57 = llvm.mlir.constant(1 : i64) : i64
      %58 = llvm.alloca %57 x i64 : (i64) -> !llvm.ptr
      llvm.store %56, %58 : i64, !llvm.ptr
      cf.br ^bb9
      ^bb9:
      %59 = llvm.load %58 : !llvm.ptr -> i64
      %60 = llvm.load %27 : !llvm.ptr -> i64
      %61 = arith.cmpi slt, %59, %60 : i64
      cf.cond_br %61, ^bb10, ^bb11
      ^bb10:
        %63 = llvm.load %58 : !llvm.ptr -> i64
        %64 = llvm.getelementptr %8[%63] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %62 = llvm.load %64 : !llvm.ptr -> i32
        %65 = arith.extsi %62 : i32 to i64
        %66 = llvm.load %31 : !llvm.ptr -> i64
        %67 = arith.muli %66, %65 : i64
        %68 = arith.cmpi sgt, %67, %1 : i64
        cf.cond_br %68, ^bb12, ^bb13
        ^bb12:
          cf.br ^bb11
        ^bb13:
          cf.br ^bb14
        ^bb14:
        %69 = arith.trunci %65 : i64 to i32
        %70 = llvm.getelementptr %2[%67] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %69, %70 : i32, !llvm.ptr
        %71 = arith.cmpi eq, %65, %54 : i64
        cf.cond_br %71, ^bb15, ^bb16
        ^bb15:
          cf.br ^bb11
        ^bb16:
          cf.br ^bb17
        ^bb17:
        %72 = llvm.load %58 : !llvm.ptr -> i64
        %73 = arith.constant 1 : i32
        %75 = arith.extsi %73 : i32 to i64
        %74 = arith.addi %72, %75 : i64
        llvm.store %74, %58 : i64, !llvm.ptr
        cf.br ^bb9
      ^bb11:
      %76 = llvm.load %31 : !llvm.ptr -> i64
      %77 = arith.constant 1 : i32
      %79 = arith.extsi %77 : i32 to i64
      %78 = arith.addi %76, %79 : i64
      llvm.store %78, %31 : i64, !llvm.ptr
      cf.br ^bb3
    ^bb5:
    %81 = arith.constant 25 : i32
    %82 = arith.constant 8 : i32
    %83 = arith.extsi %81 : i32 to i64
    %84 = arith.extsi %82 : i32 to i64
    %80 = func.call @calloc(%83, %84) : (i64, i64) -> !llvm.ptr
    %86 = arith.constant 25 : 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 25 : 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" %80, %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" %85, %99 : !llvm.ptr
      scf.yield %100 : i1
    }
    %101 = scf.if %97 -> (i1) {
      %102 = arith.constant true
      scf.yield %102 : i1
    } else {
      %103 = llvm.mlir.zero : !llvm.ptr
      %104 = llvm.icmp "eq" %90, %103 : !llvm.ptr
      scf.yield %104 : i1
    }
    cf.cond_br %101, ^bb18, ^bb19
    ^bb18:
      %105 = arith.constant 1 : i32
      func.return %105 : i32
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %106 = arith.constant 0 : i32
    %107 = arith.extsi %106 : i32 to i64
    %108 = llvm.mlir.constant(1 : i64) : i64
    %109 = llvm.alloca %108 x i64 : (i64) -> !llvm.ptr
    llvm.store %107, %109 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %110 = llvm.load %109 : !llvm.ptr -> i64
    %111 = arith.constant 24 : i32
    %113 = arith.extsi %111 : i32 to i64
    %112 = arith.cmpi sle, %110, %113 : i64
    cf.cond_br %112, ^bb22, ^bb23
    ^bb22:
      %114 = arith.constant 3 : i32
      %115 = llvm.load %109 : !llvm.ptr -> i64
      %117 = arith.extsi %114 : i32 to i64
      %116 = arith.muli %117, %115 : i64
      %118 = llvm.load %109 : !llvm.ptr -> i64
      %119 = arith.muli %116, %118 : i64
      %120 = arith.constant 3 : i32
      %121 = llvm.load %109 : !llvm.ptr -> i64
      %123 = arith.extsi %120 : i32 to i64
      %122 = arith.muli %123, %121 : i64
      %124 = arith.addi %119, %122 : i64
      %125 = arith.constant 1 : i32
      %127 = arith.extsi %125 : i32 to i64
      %126 = arith.addi %124, %127 : i64
      %128 = llvm.load %109 : !llvm.ptr -> i64
      %129 = llvm.getelementptr %80[%128] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %126, %129 : i64, !llvm.ptr
      %130 = arith.constant 2 : i32
      %131 = llvm.load %109 : !llvm.ptr -> i64
      %133 = arith.extsi %130 : i32 to i64
      %132 = arith.muli %133, %131 : i64
      %134 = arith.constant 1 : i32
      %136 = arith.extsi %134 : i32 to i64
      %135 = arith.addi %132, %136 : i64
      %137 = llvm.load %109 : !llvm.ptr -> i64
      %138 = llvm.getelementptr %85[%137] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %135, %138 : i64, !llvm.ptr
      %139 = arith.constant 2 : i32
      %140 = llvm.load %109 : !llvm.ptr -> i64
      %141 = arith.constant 2 : i32
      %143 = arith.extsi %141 : i32 to i64
      %142 = arith.divsi %140, %143 : i64
      %145 = arith.extsi %139 : i32 to i64
      %144 = arith.muli %145, %142 : i64
      %146 = arith.constant 1 : i32
      %148 = arith.extsi %146 : i32 to i64
      %147 = arith.addi %144, %148 : i64
      %149 = llvm.load %109 : !llvm.ptr -> i64
      %150 = llvm.getelementptr %90[%149] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      llvm.store %147, %150 : i64, !llvm.ptr
      %151 = llvm.load %109 : !llvm.ptr -> i64
      %152 = arith.constant 1 : i32
      %154 = arith.extsi %152 : i32 to i64
      %153 = arith.addi %151, %154 : i64
      llvm.store %153, %109 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %155 = arith.constant 0 : i32
    %156 = arith.extsi %155 : i32 to i64
    %157 = llvm.mlir.constant(1 : i64) : i64
    %158 = llvm.alloca %157 x i64 : (i64) -> !llvm.ptr
    llvm.store %156, %158 : i64, !llvm.ptr
    %159 = arith.constant 1 : i32
    %160 = arith.extsi %159 : i32 to i64
    %161 = llvm.mlir.constant(1 : i64) : i64
    %162 = llvm.alloca %161 x i64 : (i64) -> !llvm.ptr
    llvm.store %160, %162 : i64, !llvm.ptr
    cf.br ^bb24
    ^bb24:
    %163 = llvm.load %162 : !llvm.ptr -> i64
    %164 = arith.cmpi sle, %163, %1 : i64
    cf.cond_br %164, ^bb25, ^bb26
    ^bb25:
      %165 = llvm.load %162 : !llvm.ptr -> i64
      %166 = llvm.mlir.constant(1 : i64) : i64
      %167 = llvm.alloca %166 x i64 : (i64) -> !llvm.ptr
      llvm.store %165, %167 : i64, !llvm.ptr
      %168 = arith.constant 1 : i32
      %169 = arith.extsi %168 : i32 to i64
      %170 = llvm.mlir.constant(1 : i64) : i64
      %171 = llvm.alloca %170 x i64 : (i64) -> !llvm.ptr
      llvm.store %169, %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 1 : 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 ^bb27
      ^bb27:
      %180 = llvm.load %167 : !llvm.ptr -> i64
      %181 = arith.constant 1 : i32
      %183 = arith.extsi %181 : i32 to i64
      %182 = arith.cmpi sgt, %180, %183 : i64
      cf.cond_br %182, ^bb28, ^bb29
      ^bb28:
        %185 = llvm.load %167 : !llvm.ptr -> i64
        %186 = llvm.getelementptr %2[%185] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %184 = llvm.load %186 : !llvm.ptr -> i32
        %187 = arith.extsi %184 : i32 to i64
        %188 = arith.constant 1 : i32
        %189 = arith.extsi %188 : i32 to i64
        %190 = llvm.mlir.constant(1 : i64) : i64
        %191 = llvm.alloca %190 x i64 : (i64) -> !llvm.ptr
        llvm.store %189, %191 : i64, !llvm.ptr
        %192 = llvm.load %167 : !llvm.ptr -> i64
        %193 = arith.divsi %192, %187 : i64
        llvm.store %193, %167 : i64, !llvm.ptr
        cf.br ^bb30
        ^bb30:
        %194 = llvm.load %167 : !llvm.ptr -> i64
        %195 = arith.remsi %194, %187 : i64
        %196 = arith.constant 0 : i32
        %198 = arith.extsi %196 : i32 to i64
        %197 = arith.cmpi eq, %195, %198 : i64
        cf.cond_br %197, ^bb31, ^bb32
        ^bb31:
          %199 = llvm.load %167 : !llvm.ptr -> i64
          %200 = arith.divsi %199, %187 : i64
          llvm.store %200, %167 : i64, !llvm.ptr
          %201 = llvm.load %191 : !llvm.ptr -> i64
          %202 = arith.constant 1 : i32
          %204 = arith.extsi %202 : i32 to i64
          %203 = arith.addi %201, %204 : i64
          llvm.store %203, %191 : i64, !llvm.ptr
          cf.br ^bb30
        ^bb32:
        %205 = arith.constant 4 : i32
        %207 = arith.extsi %205 : i32 to i64
        %206 = arith.remsi %187, %207 : i64
        %208 = arith.constant 1 : i32
        %210 = arith.extsi %208 : i32 to i64
        %209 = arith.cmpi eq, %206, %210 : i64
        cf.cond_br %209, ^bb33, ^bb34
        ^bb33:
          %211 = llvm.load %171 : !llvm.ptr -> i64
          %213 = llvm.load %191 : !llvm.ptr -> i64
          %214 = llvm.getelementptr %80[%213] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %212 = llvm.load %214 : !llvm.ptr -> i64
          %215 = arith.muli %211, %212 : i64
          llvm.store %215, %171 : i64, !llvm.ptr
          %216 = llvm.load %175 : !llvm.ptr -> i64
          %218 = llvm.load %191 : !llvm.ptr -> i64
          %219 = llvm.getelementptr %85[%218] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %217 = llvm.load %219 : !llvm.ptr -> i64
          %220 = arith.muli %216, %217 : i64
          llvm.store %220, %175 : i64, !llvm.ptr
          %221 = llvm.load %179 : !llvm.ptr -> i64
          %223 = llvm.load %191 : !llvm.ptr -> i64
          %224 = llvm.getelementptr %90[%223] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %222 = llvm.load %224 : !llvm.ptr -> i64
          %225 = arith.muli %221, %222 : i64
          llvm.store %225, %179 : i64, !llvm.ptr
          cf.br ^bb35
        ^bb34:
          cf.br ^bb35
        ^bb35:
        cf.br ^bb27
      ^bb29:
      %226 = llvm.load %171 : !llvm.ptr -> i64
      %227 = arith.constant 1 : i32
      %229 = arith.extsi %227 : i32 to i64
      %228 = arith.cmpi ne, %226, %229 : i64
      cf.cond_br %228, ^bb36, ^bb37
      ^bb36:
        %230 = arith.constant 2 : i32
        %231 = llvm.load %171 : !llvm.ptr -> i64
        %233 = arith.extsi %230 : i32 to i64
        %232 = arith.muli %233, %231 : i64
        %234 = arith.constant 3 : i32
        %235 = llvm.load %175 : !llvm.ptr -> i64
        %237 = arith.extsi %234 : i32 to i64
        %236 = arith.muli %237, %235 : i64
        %238 = arith.subi %232, %236 : i64
        %239 = arith.constant 3 : i32
        %240 = llvm.load %179 : !llvm.ptr -> i64
        %242 = arith.extsi %239 : i32 to i64
        %241 = arith.muli %242, %240 : i64
        %243 = arith.addi %238, %241 : i64
        %244 = arith.constant 2 : i32
        %246 = arith.extsi %244 : i32 to i64
        %245 = arith.subi %243, %246 : i64
        %247 = arith.constant 6 : i32
        %249 = arith.extsi %247 : i32 to i64
        %248 = arith.divsi %245, %249 : i64
        %250 = arith.constant 0 : i32
        %252 = arith.extsi %250 : i32 to i64
        %251 = arith.cmpi ne, %248, %252 : i64
        cf.cond_br %251, ^bb39, ^bb40
        ^bb39:
          %253 = llvm.load %158 : !llvm.ptr -> i64
          %254 = llvm.load %162 : !llvm.ptr -> i64
          %255 = arith.muli %254, %248 : i64
          %256 = arith.addi %253, %255 : i64
          llvm.store %256, %158 : i64, !llvm.ptr
          cf.br ^bb41
        ^bb40:
          cf.br ^bb41
        ^bb41:
        cf.br ^bb38
      ^bb37:
        cf.br ^bb38
      ^bb38:
      %257 = llvm.load %162 : !llvm.ptr -> i64
      %258 = arith.constant 1 : i32
      %260 = arith.extsi %258 : i32 to i64
      %259 = arith.addi %257, %260 : i64
      llvm.store %259, %162 : i64, !llvm.ptr
      cf.br ^bb24
    ^bb26:
    %261 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %262 = llvm.load %158 : !llvm.ptr -> i64
    %263 = llvm.call @printf(%261, %262) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%90) : (!llvm.ptr) -> ()
    func.call @free(%85) : (!llvm.ptr) -> ()
    func.call @free(%80) : (!llvm.ptr) -> ()
    func.call @free(%8) : (!llvm.ptr) -> ()
    func.call @free(%2) : (!llvm.ptr) -> ()
    %269 = arith.constant 0 : i32
    func.return %269 : i32
  }
}