Problem 347

Sum of largest n≤10^7 of form p^a q^b for each prime pair {p,q}.

Answer11109800204052
Output11109800204052
StatusPASS
Native helperno
Runtime30 ms
Peak memory13664 KB
Time complexityO(n^2) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n log log n)
Space complexityO(n)O(n)
ApproachFlow solutionSieve of Eratosthenes
VerdictSuboptimal

Flow source

# Project Euler 347
# Sum of largest n≤10^7 of form p^a q^b for each prime pair {p,q}.

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

function main() -> i32 {
    let limit: i64 = 10000000
    let sieve: ptr<i8> = calloc(limit + 1, 1)
    if sieve == null { return 1 }
    let mut i: i64 = 0
    while i <= limit {
        sieve[i] = 1
        i = i + 1
    }
    sieve[0] = 0; sieve[1] = 0
    let mut p: i64 = 2
    while p * p <= limit {
        if sieve[p] == 1 {
            let mut m: i64 = p * p
            while m <= limit {
                sieve[m] = 0
                m = m + p
            }
        }
        p = p + 1
    }
    let mut pc: i64 = 0
    i = 2
    while i <= limit / 2 {
        if sieve[i] == 1 { pc = pc + 1 }
        i = i + 1
    }
    let primes: ptr<i64> = calloc(pc, 8)
    let mut idx: i64 = 0
    i = 2
    while i <= limit / 2 {
        if sieve[i] == 1 {
            primes[idx] = i
            idx = idx + 1
        }
        i = i + 1
    }

    let mut ans: i64 = 0
    # use set via sort+unique of candidates — count each pair once
    let mut ii: i64 = 0
    while ii < pc {
        let pp: i64 = primes[ii]
        if pp * pp > limit { break }
        let mut jj: i64 = ii + 1
        while jj < pc {
            let qq: i64 = primes[jj]
            let lcm: i64 = pp * qq
            if lcm > limit { break }
            let multlimit: i64 = limit / lcm
            let mut multiplier: i64 = 1
            while multiplier <= multlimit / pp {
                multiplier = multiplier * pp
            }
            let mut maxmult: i64 = multiplier
            while multiplier % pp == 0 {
                multiplier = multiplier / pp
                while multiplier <= multlimit / qq {
                    multiplier = multiplier * qq
                }
                if multiplier > maxmult { maxmult = multiplier }
            }
            ans = ans + maxmult * lcm
            jj = jj + 1
        }
        ii = ii + 1
    }
    printf("%lld\n", ans)
    free(sieve); free(primes)
    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 limit = 10000000;
    int8_t* sieve = (int8_t*)(calloc((limit + 1), 1));
    if (sieve == NULL) {
        return 1;
    }
    int64_t i = 0;
    while (i <= limit) {
        sieve[i] = 1;
        i = (i + 1);
    }
    sieve[0] = 0;
    sieve[1] = 0;
    int64_t p = 2;
    while ((p * p) <= limit) {
        if (sieve[p] == 1) {
            int64_t m = (p * p);
            while (m <= limit) {
                sieve[m] = 0;
                m = (m + p);
            }
        }
        p = (p + 1);
    }
    int64_t pc = 0;
    i = 2;
    while (i <= FLOW_CHECKED_DIV((limit), (2))) {
        if (sieve[i] == 1) {
            pc = (pc + 1);
        }
        i = (i + 1);
    }
    int64_t* primes = (int64_t*)(calloc(pc, 8));
    int64_t idx = 0;
    i = 2;
    while (i <= FLOW_CHECKED_DIV((limit), (2))) {
        if (sieve[i] == 1) {
            primes[idx] = i;
            idx = (idx + 1);
        }
        i = (i + 1);
    }
    int64_t ans = 0;
    int64_t ii = 0;
    while (ii < pc) {
        int64_t pp = primes[ii];
        if ((pp * pp) > limit) {
            break;
        }
        int64_t jj = (ii + 1);
        while (jj < pc) {
            int64_t qq = primes[jj];
            int64_t lcm = (pp * qq);
            if (lcm > limit) {
                break;
            }
            int64_t multlimit = FLOW_CHECKED_DIV((limit), (lcm));
            int64_t multiplier = 1;
            while (multiplier <= FLOW_CHECKED_DIV((multlimit), (pp))) {
                multiplier = (multiplier * pp);
            }
            int64_t maxmult = multiplier;
            while (FLOW_CHECKED_MOD((multiplier), (pp)) == 0) {
                multiplier = FLOW_CHECKED_DIV((multiplier), (pp));
                while (multiplier <= FLOW_CHECKED_DIV((multlimit), (qq))) {
                    multiplier = (multiplier * qq);
                }
                if (multiplier > maxmult) {
                    maxmult = multiplier;
                }
            }
            ans = (ans + (maxmult * lcm));
            jj = (jj + 1);
        }
        ii = (ii + 1);
    }
    printf("%lld\n", ans);
    free(sieve);
    free(primes);
    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 1 : i32
    %7 = arith.extsi %6 : i32 to i64
    %2 = func.call @calloc(%4, %7) : (i64, i64) -> !llvm.ptr
    %8 = llvm.mlir.zero : !llvm.ptr
    %9 = llvm.icmp "eq" %2, %8 : !llvm.ptr
    cf.cond_br %9, ^bb0, ^bb1
    ^bb0:
      %10 = arith.constant 1 : i32
      func.return %10 : i32
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %11 = arith.constant 0 : i32
    %12 = arith.extsi %11 : i32 to i64
    %13 = llvm.mlir.constant(1 : i64) : i64
    %14 = llvm.alloca %13 x i64 : (i64) -> !llvm.ptr
    llvm.store %12, %14 : i64, !llvm.ptr
    cf.br ^bb3
    ^bb3:
    %15 = llvm.load %14 : !llvm.ptr -> i64
    %16 = arith.cmpi sle, %15, %1 : i64
    cf.cond_br %16, ^bb4, ^bb5
    ^bb4:
      %17 = arith.constant 1 : i32
      %18 = llvm.load %14 : !llvm.ptr -> i64
      %19 = arith.trunci %17 : i32 to i8
      %20 = llvm.getelementptr %2[%18] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %19, %20 : i8, !llvm.ptr
      %21 = llvm.load %14 : !llvm.ptr -> i64
      %22 = arith.constant 1 : i32
      %24 = arith.extsi %22 : i32 to i64
      %23 = arith.addi %21, %24 : i64
      llvm.store %23, %14 : i64, !llvm.ptr
      cf.br ^bb3
    ^bb5:
    %25 = arith.constant 0 : i32
    %26 = arith.constant 0 : i32
    %27 = arith.trunci %25 : i32 to i8
    %28 = arith.extsi %26 : i32 to i64
    %29 = llvm.getelementptr %2[%28] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %27, %29 : i8, !llvm.ptr
    %30 = arith.constant 0 : i32
    %31 = arith.constant 1 : i32
    %32 = arith.trunci %30 : i32 to i8
    %33 = arith.extsi %31 : i32 to i64
    %34 = llvm.getelementptr %2[%33] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %32, %34 : i8, !llvm.ptr
    %35 = arith.constant 2 : i32
    %36 = arith.extsi %35 : i32 to i64
    %37 = llvm.mlir.constant(1 : i64) : i64
    %38 = llvm.alloca %37 x i64 : (i64) -> !llvm.ptr
    llvm.store %36, %38 : i64, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %39 = llvm.load %38 : !llvm.ptr -> i64
    %40 = llvm.load %38 : !llvm.ptr -> i64
    %41 = arith.muli %39, %40 : i64
    %42 = arith.cmpi sle, %41, %1 : i64
    cf.cond_br %42, ^bb7, ^bb8
    ^bb7:
      %44 = llvm.load %38 : !llvm.ptr -> i64
      %45 = llvm.getelementptr %2[%44] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %43 = llvm.load %45 : !llvm.ptr -> i8
      %46 = arith.constant 1 : i32
      %48 = arith.extsi %43 : i8 to i32
      %47 = arith.cmpi eq, %48, %46 : i32
      cf.cond_br %47, ^bb9, ^bb10
      ^bb9:
        %49 = llvm.load %38 : !llvm.ptr -> i64
        %50 = llvm.load %38 : !llvm.ptr -> i64
        %51 = arith.muli %49, %50 : i64
        %52 = llvm.mlir.constant(1 : i64) : i64
        %53 = llvm.alloca %52 x i64 : (i64) -> !llvm.ptr
        llvm.store %51, %53 : i64, !llvm.ptr
        cf.br ^bb12
        ^bb12:
        %54 = llvm.load %53 : !llvm.ptr -> i64
        %55 = arith.cmpi sle, %54, %1 : i64
        cf.cond_br %55, ^bb13, ^bb14
        ^bb13:
          %56 = arith.constant 0 : i32
          %57 = llvm.load %53 : !llvm.ptr -> i64
          %58 = arith.trunci %56 : i32 to i8
          %59 = llvm.getelementptr %2[%57] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %58, %59 : i8, !llvm.ptr
          %60 = llvm.load %53 : !llvm.ptr -> i64
          %61 = llvm.load %38 : !llvm.ptr -> i64
          %62 = arith.addi %60, %61 : i64
          llvm.store %62, %53 : i64, !llvm.ptr
          cf.br ^bb12
        ^bb14:
        cf.br ^bb11
      ^bb10:
        cf.br ^bb11
      ^bb11:
      %63 = llvm.load %38 : !llvm.ptr -> i64
      %64 = arith.constant 1 : i32
      %66 = arith.extsi %64 : i32 to i64
      %65 = arith.addi %63, %66 : i64
      llvm.store %65, %38 : i64, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    %67 = arith.constant 0 : i32
    %68 = arith.extsi %67 : i32 to i64
    %69 = llvm.mlir.constant(1 : i64) : i64
    %70 = llvm.alloca %69 x i64 : (i64) -> !llvm.ptr
    llvm.store %68, %70 : i64, !llvm.ptr
    %71 = arith.constant 2 : i32
    %72 = arith.extsi %71 : i32 to i64
    llvm.store %72, %14 : i64, !llvm.ptr
    cf.br ^bb15
    ^bb15:
    %73 = llvm.load %14 : !llvm.ptr -> i64
    %74 = arith.constant 2 : i32
    %76 = arith.extsi %74 : i32 to i64
    %75 = arith.divsi %1, %76 : i64
    %77 = arith.cmpi sle, %73, %75 : i64
    cf.cond_br %77, ^bb16, ^bb17
    ^bb16:
      %79 = llvm.load %14 : !llvm.ptr -> i64
      %80 = llvm.getelementptr %2[%79] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %78 = llvm.load %80 : !llvm.ptr -> i8
      %81 = arith.constant 1 : i32
      %83 = arith.extsi %78 : i8 to i32
      %82 = arith.cmpi eq, %83, %81 : i32
      cf.cond_br %82, ^bb18, ^bb19
      ^bb18:
        %84 = llvm.load %70 : !llvm.ptr -> i64
        %85 = arith.constant 1 : i32
        %87 = arith.extsi %85 : i32 to i64
        %86 = arith.addi %84, %87 : i64
        llvm.store %86, %70 : i64, !llvm.ptr
        cf.br ^bb20
      ^bb19:
        cf.br ^bb20
      ^bb20:
      %88 = llvm.load %14 : !llvm.ptr -> i64
      %89 = arith.constant 1 : i32
      %91 = arith.extsi %89 : i32 to i64
      %90 = arith.addi %88, %91 : i64
      llvm.store %90, %14 : i64, !llvm.ptr
      cf.br ^bb15
    ^bb17:
    %93 = llvm.load %70 : !llvm.ptr -> i64
    %94 = arith.constant 8 : i32
    %95 = arith.extsi %94 : i32 to i64
    %92 = func.call @calloc(%93, %95) : (i64, i64) -> !llvm.ptr
    %96 = arith.constant 0 : i32
    %97 = arith.extsi %96 : i32 to i64
    %98 = llvm.mlir.constant(1 : i64) : i64
    %99 = llvm.alloca %98 x i64 : (i64) -> !llvm.ptr
    llvm.store %97, %99 : i64, !llvm.ptr
    %100 = arith.constant 2 : i32
    %101 = arith.extsi %100 : i32 to i64
    llvm.store %101, %14 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %102 = llvm.load %14 : !llvm.ptr -> i64
    %103 = arith.constant 2 : i32
    %105 = arith.extsi %103 : i32 to i64
    %104 = arith.divsi %1, %105 : i64
    %106 = arith.cmpi sle, %102, %104 : i64
    cf.cond_br %106, ^bb22, ^bb23
    ^bb22:
      %108 = llvm.load %14 : !llvm.ptr -> i64
      %109 = llvm.getelementptr %2[%108] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %107 = llvm.load %109 : !llvm.ptr -> i8
      %110 = arith.constant 1 : i32
      %112 = arith.extsi %107 : i8 to i32
      %111 = arith.cmpi eq, %112, %110 : i32
      cf.cond_br %111, ^bb24, ^bb25
      ^bb24:
        %113 = llvm.load %14 : !llvm.ptr -> i64
        %114 = llvm.load %99 : !llvm.ptr -> i64
        %115 = llvm.getelementptr %92[%114] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %113, %115 : i64, !llvm.ptr
        %116 = llvm.load %99 : !llvm.ptr -> i64
        %117 = arith.constant 1 : i32
        %119 = arith.extsi %117 : i32 to i64
        %118 = arith.addi %116, %119 : i64
        llvm.store %118, %99 : i64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %120 = llvm.load %14 : !llvm.ptr -> i64
      %121 = arith.constant 1 : i32
      %123 = arith.extsi %121 : i32 to i64
      %122 = arith.addi %120, %123 : i64
      llvm.store %122, %14 : i64, !llvm.ptr
      cf.br ^bb21
    ^bb23:
    %124 = arith.constant 0 : i32
    %125 = arith.extsi %124 : i32 to i64
    %126 = llvm.mlir.constant(1 : i64) : i64
    %127 = llvm.alloca %126 x i64 : (i64) -> !llvm.ptr
    llvm.store %125, %127 : i64, !llvm.ptr
    %128 = arith.constant 0 : i32
    %129 = arith.extsi %128 : i32 to i64
    %130 = llvm.mlir.constant(1 : i64) : i64
    %131 = llvm.alloca %130 x i64 : (i64) -> !llvm.ptr
    llvm.store %129, %131 : i64, !llvm.ptr
    cf.br ^bb27
    ^bb27:
    %132 = llvm.load %131 : !llvm.ptr -> i64
    %133 = llvm.load %70 : !llvm.ptr -> i64
    %134 = arith.cmpi slt, %132, %133 : i64
    cf.cond_br %134, ^bb28, ^bb29
    ^bb28:
      %136 = llvm.load %131 : !llvm.ptr -> i64
      %137 = llvm.getelementptr %92[%136] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %135 = llvm.load %137 : !llvm.ptr -> i64
      %138 = arith.muli %135, %135 : i64
      %139 = arith.cmpi sgt, %138, %1 : i64
      cf.cond_br %139, ^bb30, ^bb31
      ^bb30:
        cf.br ^bb29
      ^bb31:
        cf.br ^bb32
      ^bb32:
      %140 = llvm.load %131 : !llvm.ptr -> i64
      %141 = arith.constant 1 : i32
      %143 = arith.extsi %141 : i32 to i64
      %142 = arith.addi %140, %143 : i64
      %144 = llvm.mlir.constant(1 : i64) : i64
      %145 = llvm.alloca %144 x i64 : (i64) -> !llvm.ptr
      llvm.store %142, %145 : i64, !llvm.ptr
      cf.br ^bb33
      ^bb33:
      %146 = llvm.load %145 : !llvm.ptr -> i64
      %147 = llvm.load %70 : !llvm.ptr -> i64
      %148 = arith.cmpi slt, %146, %147 : i64
      cf.cond_br %148, ^bb34, ^bb35
      ^bb34:
        %150 = llvm.load %145 : !llvm.ptr -> i64
        %151 = llvm.getelementptr %92[%150] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %149 = llvm.load %151 : !llvm.ptr -> i64
        %152 = arith.muli %135, %149 : i64
        %153 = arith.cmpi sgt, %152, %1 : i64
        cf.cond_br %153, ^bb36, ^bb37
        ^bb36:
          cf.br ^bb35
        ^bb37:
          cf.br ^bb38
        ^bb38:
        %154 = arith.divsi %1, %152 : i64
        %155 = arith.constant 1 : 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
        cf.br ^bb39
        ^bb39:
        %159 = llvm.load %158 : !llvm.ptr -> i64
        %160 = arith.divsi %154, %135 : i64
        %161 = arith.cmpi sle, %159, %160 : i64
        cf.cond_br %161, ^bb40, ^bb41
        ^bb40:
          %162 = llvm.load %158 : !llvm.ptr -> i64
          %163 = arith.muli %162, %135 : i64
          llvm.store %163, %158 : i64, !llvm.ptr
          cf.br ^bb39
        ^bb41:
        %164 = llvm.load %158 : !llvm.ptr -> i64
        %165 = llvm.mlir.constant(1 : i64) : i64
        %166 = llvm.alloca %165 x i64 : (i64) -> !llvm.ptr
        llvm.store %164, %166 : i64, !llvm.ptr
        cf.br ^bb42
        ^bb42:
        %167 = llvm.load %158 : !llvm.ptr -> i64
        %168 = arith.remsi %167, %135 : i64
        %169 = arith.constant 0 : i32
        %171 = arith.extsi %169 : i32 to i64
        %170 = arith.cmpi eq, %168, %171 : i64
        cf.cond_br %170, ^bb43, ^bb44
        ^bb43:
          %172 = llvm.load %158 : !llvm.ptr -> i64
          %173 = arith.divsi %172, %135 : i64
          llvm.store %173, %158 : i64, !llvm.ptr
          cf.br ^bb45
          ^bb45:
          %174 = llvm.load %158 : !llvm.ptr -> i64
          %175 = arith.divsi %154, %149 : i64
          %176 = arith.cmpi sle, %174, %175 : i64
          cf.cond_br %176, ^bb46, ^bb47
          ^bb46:
            %177 = llvm.load %158 : !llvm.ptr -> i64
            %178 = arith.muli %177, %149 : i64
            llvm.store %178, %158 : i64, !llvm.ptr
            cf.br ^bb45
          ^bb47:
          %179 = llvm.load %158 : !llvm.ptr -> i64
          %180 = llvm.load %166 : !llvm.ptr -> i64
          %181 = arith.cmpi sgt, %179, %180 : i64
          cf.cond_br %181, ^bb48, ^bb49
          ^bb48:
            %182 = llvm.load %158 : !llvm.ptr -> i64
            llvm.store %182, %166 : i64, !llvm.ptr
            cf.br ^bb50
          ^bb49:
            cf.br ^bb50
          ^bb50:
          cf.br ^bb42
        ^bb44:
        %183 = llvm.load %127 : !llvm.ptr -> i64
        %184 = llvm.load %166 : !llvm.ptr -> i64
        %185 = arith.muli %184, %152 : i64
        %186 = arith.addi %183, %185 : i64
        llvm.store %186, %127 : i64, !llvm.ptr
        %187 = llvm.load %145 : !llvm.ptr -> i64
        %188 = arith.constant 1 : i32
        %190 = arith.extsi %188 : i32 to i64
        %189 = arith.addi %187, %190 : i64
        llvm.store %189, %145 : i64, !llvm.ptr
        cf.br ^bb33
      ^bb35:
      %191 = llvm.load %131 : !llvm.ptr -> i64
      %192 = arith.constant 1 : i32
      %194 = arith.extsi %192 : i32 to i64
      %193 = arith.addi %191, %194 : i64
      llvm.store %193, %131 : i64, !llvm.ptr
      cf.br ^bb27
    ^bb29:
    %195 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %196 = llvm.load %127 : !llvm.ptr -> i64
    %197 = llvm.call @printf(%195, %196) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%2) : (!llvm.ptr) -> ()
    func.call @free(%92) : (!llvm.ptr) -> ()
    %200 = arith.constant 0 : i32
    func.return %200 : i32
  }
}