Problem 249

Prime subset sums of primes < 5000; last 16 digits.

Answer9275262564250418
Output9275262564250418
StatusPASS
Native helperno
Runtime230 ms
Peak memory14768 KB
Time complexityO(n^2) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n * sum)
Space complexityO(n)O(sum)
ApproachFlow solutionSubset sum DP
VerdictUnknown

Flow source

# Project Euler 249
# Prime subset sums of primes < 5000; last 16 digits.

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

function main() -> i32 {
    let LIMIT: i64 = 5000
    let MOD: i64 = 10000000000000000
    let sieve: ptr<i8> = calloc(LIMIT, 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
    i = 2
    while i * i < LIMIT {
        if sieve[i] == 1 {
            let mut j: i64 = i * i
            while j < LIMIT {
                sieve[j] = 0
                j = j + i
            }
        }
        i = i + 1
    }
    let mut max_sum: i64 = 0
    i = 2
    while i < LIMIT {
        if sieve[i] == 1 { max_sum = max_sum + i }
        i = i + 1
    }
    let count: ptr<i64> = calloc(max_sum + 1, 8)
    let big_sieve: ptr<i8> = calloc(max_sum + 1, 1)
    if count == null || big_sieve == null { return 1 }
    count[0] = 1
    let mut largest: i64 = 0
    i = 2
    while i < LIMIT {
        if sieve[i] == 1 {
            largest = largest + i
            let mut j: i64 = largest
            while j >= i {
                count[j] = (count[j] + count[j - i]) % MOD
                j = j - 1
            }
        }
        i = i + 1
    }
    i = 0
    while i <= max_sum {
        big_sieve[i] = 1
        i = i + 1
    }
    big_sieve[0] = 0
    big_sieve[1] = 0
    i = 2
    while i * i <= max_sum {
        if big_sieve[i] == 1 {
            let mut j: i64 = i * i
            while j <= max_sum {
                big_sieve[j] = 0
                j = j + i
            }
        }
        i = i + 1
    }
    let mut result: i64 = 0
    i = 2
    while i <= max_sum {
        if big_sieve[i] == 1 {
            result = (result + count[i]) % MOD
        }
        i = i + 1
    }
    printf("%lld\n", result)
    free(sieve); free(count); free(big_sieve)
    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 = 5000;
    int64_t MOD = 10000000000000000;
    int8_t* sieve = (int8_t*)(calloc(LIMIT, 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;
    i = 2;
    while ((i * i) < LIMIT) {
        if (sieve[i] == 1) {
            int64_t j = (i * i);
            while (j < LIMIT) {
                sieve[j] = 0;
                j = (j + i);
            }
        }
        i = (i + 1);
    }
    int64_t max_sum = 0;
    i = 2;
    while (i < LIMIT) {
        if (sieve[i] == 1) {
            max_sum = (max_sum + i);
        }
        i = (i + 1);
    }
    int64_t* count = (int64_t*)(calloc((max_sum + 1), 8));
    int8_t* big_sieve = (int8_t*)(calloc((max_sum + 1), 1));
    if ((count == NULL || big_sieve == NULL)) {
        return 1;
    }
    count[0] = 1;
    int64_t largest = 0;
    i = 2;
    while (i < LIMIT) {
        if (sieve[i] == 1) {
            largest = (largest + i);
            int64_t j = largest;
            while (j >= i) {
                count[j] = FLOW_CHECKED_MOD(((count[j] + count[(j - i)])), (MOD));
                j = (j - 1);
            }
        }
        i = (i + 1);
    }
    i = 0;
    while (i <= max_sum) {
        big_sieve[i] = 1;
        i = (i + 1);
    }
    big_sieve[0] = 0;
    big_sieve[1] = 0;
    i = 2;
    while ((i * i) <= max_sum) {
        if (big_sieve[i] == 1) {
            int64_t j = (i * i);
            while (j <= max_sum) {
                big_sieve[j] = 0;
                j = (j + i);
            }
        }
        i = (i + 1);
    }
    int64_t result = 0;
    i = 2;
    while (i <= max_sum) {
        if (big_sieve[i] == 1) {
            result = FLOW_CHECKED_MOD(((result + count[i])), (MOD));
        }
        i = (i + 1);
    }
    printf("%lld\n", result);
    free(sieve);
    free(count);
    free(big_sieve);
    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 5000 : i32
    %1 = arith.extsi %0 : i32 to i64
    %2 = arith.constant 9999995705032704 : i32
    %3 = arith.extsi %2 : i32 to i64
    %5 = arith.constant 1 : i32
    %6 = arith.extsi %5 : i32 to i64
    %4 = func.call @calloc(%1, %6) : (i64, i64) -> !llvm.ptr
    %7 = llvm.mlir.zero : !llvm.ptr
    %8 = llvm.icmp "eq" %4, %7 : !llvm.ptr
    cf.cond_br %8, ^bb0, ^bb1
    ^bb0:
      %9 = arith.constant 1 : i32
      func.return %9 : i32
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %10 = arith.constant 0 : i32
    %11 = arith.extsi %10 : i32 to i64
    %12 = llvm.mlir.constant(1 : i64) : i64
    %13 = llvm.alloca %12 x i64 : (i64) -> !llvm.ptr
    llvm.store %11, %13 : i64, !llvm.ptr
    cf.br ^bb3
    ^bb3:
    %14 = llvm.load %13 : !llvm.ptr -> i64
    %15 = arith.cmpi slt, %14, %1 : i64
    cf.cond_br %15, ^bb4, ^bb5
    ^bb4:
      %16 = arith.constant 1 : i32
      %17 = llvm.load %13 : !llvm.ptr -> i64
      %18 = arith.trunci %16 : i32 to i8
      %19 = llvm.getelementptr %4[%17] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %18, %19 : i8, !llvm.ptr
      %20 = llvm.load %13 : !llvm.ptr -> i64
      %21 = arith.constant 1 : i32
      %23 = arith.extsi %21 : i32 to i64
      %22 = arith.addi %20, %23 : i64
      llvm.store %22, %13 : i64, !llvm.ptr
      cf.br ^bb3
    ^bb5:
    %24 = arith.constant 0 : i32
    %25 = arith.constant 0 : i32
    %26 = arith.trunci %24 : i32 to i8
    %27 = arith.extsi %25 : i32 to i64
    %28 = llvm.getelementptr %4[%27] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %26, %28 : i8, !llvm.ptr
    %29 = arith.constant 0 : i32
    %30 = arith.constant 1 : i32
    %31 = arith.trunci %29 : i32 to i8
    %32 = arith.extsi %30 : i32 to i64
    %33 = llvm.getelementptr %4[%32] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %31, %33 : i8, !llvm.ptr
    %34 = arith.constant 2 : i32
    %35 = arith.extsi %34 : i32 to i64
    llvm.store %35, %13 : i64, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %36 = llvm.load %13 : !llvm.ptr -> i64
    %37 = llvm.load %13 : !llvm.ptr -> i64
    %38 = arith.muli %36, %37 : i64
    %39 = arith.cmpi slt, %38, %1 : i64
    cf.cond_br %39, ^bb7, ^bb8
    ^bb7:
      %41 = llvm.load %13 : !llvm.ptr -> i64
      %42 = llvm.getelementptr %4[%41] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %40 = llvm.load %42 : !llvm.ptr -> i8
      %43 = arith.constant 1 : i32
      %45 = arith.extsi %40 : i8 to i32
      %44 = arith.cmpi eq, %45, %43 : i32
      cf.cond_br %44, ^bb9, ^bb10
      ^bb9:
        %46 = llvm.load %13 : !llvm.ptr -> i64
        %47 = llvm.load %13 : !llvm.ptr -> i64
        %48 = arith.muli %46, %47 : i64
        %49 = llvm.mlir.constant(1 : i64) : i64
        %50 = llvm.alloca %49 x i64 : (i64) -> !llvm.ptr
        llvm.store %48, %50 : i64, !llvm.ptr
        cf.br ^bb12
        ^bb12:
        %51 = llvm.load %50 : !llvm.ptr -> i64
        %52 = arith.cmpi slt, %51, %1 : i64
        cf.cond_br %52, ^bb13, ^bb14
        ^bb13:
          %53 = arith.constant 0 : i32
          %54 = llvm.load %50 : !llvm.ptr -> i64
          %55 = arith.trunci %53 : i32 to i8
          %56 = llvm.getelementptr %4[%54] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %55, %56 : i8, !llvm.ptr
          %57 = llvm.load %50 : !llvm.ptr -> i64
          %58 = llvm.load %13 : !llvm.ptr -> i64
          %59 = arith.addi %57, %58 : i64
          llvm.store %59, %50 : i64, !llvm.ptr
          cf.br ^bb12
        ^bb14:
        cf.br ^bb11
      ^bb10:
        cf.br ^bb11
      ^bb11:
      %60 = llvm.load %13 : !llvm.ptr -> i64
      %61 = arith.constant 1 : i32
      %63 = arith.extsi %61 : i32 to i64
      %62 = arith.addi %60, %63 : i64
      llvm.store %62, %13 : i64, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    %64 = arith.constant 0 : i32
    %65 = arith.extsi %64 : i32 to i64
    %66 = llvm.mlir.constant(1 : i64) : i64
    %67 = llvm.alloca %66 x i64 : (i64) -> !llvm.ptr
    llvm.store %65, %67 : i64, !llvm.ptr
    %68 = arith.constant 2 : i32
    %69 = arith.extsi %68 : i32 to i64
    llvm.store %69, %13 : i64, !llvm.ptr
    cf.br ^bb15
    ^bb15:
    %70 = llvm.load %13 : !llvm.ptr -> i64
    %71 = arith.cmpi slt, %70, %1 : i64
    cf.cond_br %71, ^bb16, ^bb17
    ^bb16:
      %73 = llvm.load %13 : !llvm.ptr -> i64
      %74 = llvm.getelementptr %4[%73] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %72 = llvm.load %74 : !llvm.ptr -> i8
      %75 = arith.constant 1 : i32
      %77 = arith.extsi %72 : i8 to i32
      %76 = arith.cmpi eq, %77, %75 : i32
      cf.cond_br %76, ^bb18, ^bb19
      ^bb18:
        %78 = llvm.load %67 : !llvm.ptr -> i64
        %79 = llvm.load %13 : !llvm.ptr -> i64
        %80 = arith.addi %78, %79 : i64
        llvm.store %80, %67 : i64, !llvm.ptr
        cf.br ^bb20
      ^bb19:
        cf.br ^bb20
      ^bb20:
      %81 = llvm.load %13 : !llvm.ptr -> i64
      %82 = arith.constant 1 : i32
      %84 = arith.extsi %82 : i32 to i64
      %83 = arith.addi %81, %84 : i64
      llvm.store %83, %13 : i64, !llvm.ptr
      cf.br ^bb15
    ^bb17:
    %86 = llvm.load %67 : !llvm.ptr -> i64
    %87 = arith.constant 1 : i32
    %89 = arith.extsi %87 : i32 to i64
    %88 = arith.addi %86, %89 : i64
    %90 = arith.constant 8 : i32
    %91 = arith.extsi %90 : i32 to i64
    %85 = func.call @calloc(%88, %91) : (i64, i64) -> !llvm.ptr
    %93 = llvm.load %67 : !llvm.ptr -> i64
    %94 = arith.constant 1 : i32
    %96 = arith.extsi %94 : i32 to i64
    %95 = arith.addi %93, %96 : i64
    %97 = arith.constant 1 : i32
    %98 = arith.extsi %97 : i32 to i64
    %92 = func.call @calloc(%95, %98) : (i64, i64) -> !llvm.ptr
    %99 = llvm.mlir.zero : !llvm.ptr
    %100 = llvm.icmp "eq" %85, %99 : !llvm.ptr
    %101 = scf.if %100 -> (i1) {
      %102 = arith.constant true
      scf.yield %102 : i1
    } else {
      %103 = llvm.mlir.zero : !llvm.ptr
      %104 = llvm.icmp "eq" %92, %103 : !llvm.ptr
      scf.yield %104 : i1
    }
    cf.cond_br %101, ^bb21, ^bb22
    ^bb21:
      %105 = arith.constant 1 : i32
      func.return %105 : i32
    ^bb22:
      cf.br ^bb23
    ^bb23:
    %106 = arith.constant 1 : i32
    %107 = arith.constant 0 : i32
    %108 = arith.extsi %106 : i32 to i64
    %109 = arith.extsi %107 : i32 to i64
    %110 = llvm.getelementptr %85[%109] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %108, %110 : i64, !llvm.ptr
    %111 = arith.constant 0 : i32
    %112 = arith.extsi %111 : i32 to i64
    %113 = llvm.mlir.constant(1 : i64) : i64
    %114 = llvm.alloca %113 x i64 : (i64) -> !llvm.ptr
    llvm.store %112, %114 : i64, !llvm.ptr
    %115 = arith.constant 2 : i32
    %116 = arith.extsi %115 : i32 to i64
    llvm.store %116, %13 : i64, !llvm.ptr
    cf.br ^bb24
    ^bb24:
    %117 = llvm.load %13 : !llvm.ptr -> i64
    %118 = arith.cmpi slt, %117, %1 : i64
    cf.cond_br %118, ^bb25, ^bb26
    ^bb25:
      %120 = llvm.load %13 : !llvm.ptr -> i64
      %121 = llvm.getelementptr %4[%120] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %119 = llvm.load %121 : !llvm.ptr -> i8
      %122 = arith.constant 1 : i32
      %124 = arith.extsi %119 : i8 to i32
      %123 = arith.cmpi eq, %124, %122 : i32
      cf.cond_br %123, ^bb27, ^bb28
      ^bb27:
        %125 = llvm.load %114 : !llvm.ptr -> i64
        %126 = llvm.load %13 : !llvm.ptr -> i64
        %127 = arith.addi %125, %126 : i64
        llvm.store %127, %114 : i64, !llvm.ptr
        %128 = llvm.load %114 : !llvm.ptr -> i64
        %129 = llvm.mlir.constant(1 : i64) : i64
        %130 = llvm.alloca %129 x i64 : (i64) -> !llvm.ptr
        llvm.store %128, %130 : i64, !llvm.ptr
        cf.br ^bb30
        ^bb30:
        %131 = llvm.load %130 : !llvm.ptr -> i64
        %132 = llvm.load %13 : !llvm.ptr -> i64
        %133 = arith.cmpi sge, %131, %132 : i64
        cf.cond_br %133, ^bb31, ^bb32
        ^bb31:
          %135 = llvm.load %130 : !llvm.ptr -> i64
          %136 = llvm.getelementptr %85[%135] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %134 = llvm.load %136 : !llvm.ptr -> i64
          %138 = llvm.load %130 : !llvm.ptr -> i64
          %139 = llvm.load %13 : !llvm.ptr -> i64
          %140 = arith.subi %138, %139 : i64
          %141 = llvm.getelementptr %85[%140] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %137 = llvm.load %141 : !llvm.ptr -> i64
          %142 = arith.addi %134, %137 : i64
          %143 = arith.remsi %142, %3 : i64
          %144 = llvm.load %130 : !llvm.ptr -> i64
          %145 = llvm.getelementptr %85[%144] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          llvm.store %143, %145 : i64, !llvm.ptr
          %146 = llvm.load %130 : !llvm.ptr -> i64
          %147 = arith.constant 1 : i32
          %149 = arith.extsi %147 : i32 to i64
          %148 = arith.subi %146, %149 : i64
          llvm.store %148, %130 : i64, !llvm.ptr
          cf.br ^bb30
        ^bb32:
        cf.br ^bb29
      ^bb28:
        cf.br ^bb29
      ^bb29:
      %150 = llvm.load %13 : !llvm.ptr -> i64
      %151 = arith.constant 1 : i32
      %153 = arith.extsi %151 : i32 to i64
      %152 = arith.addi %150, %153 : i64
      llvm.store %152, %13 : i64, !llvm.ptr
      cf.br ^bb24
    ^bb26:
    %154 = arith.constant 0 : i32
    %155 = arith.extsi %154 : i32 to i64
    llvm.store %155, %13 : i64, !llvm.ptr
    cf.br ^bb33
    ^bb33:
    %156 = llvm.load %13 : !llvm.ptr -> i64
    %157 = llvm.load %67 : !llvm.ptr -> i64
    %158 = arith.cmpi sle, %156, %157 : i64
    cf.cond_br %158, ^bb34, ^bb35
    ^bb34:
      %159 = arith.constant 1 : i32
      %160 = llvm.load %13 : !llvm.ptr -> i64
      %161 = arith.trunci %159 : i32 to i8
      %162 = llvm.getelementptr %92[%160] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %161, %162 : i8, !llvm.ptr
      %163 = llvm.load %13 : !llvm.ptr -> i64
      %164 = arith.constant 1 : i32
      %166 = arith.extsi %164 : i32 to i64
      %165 = arith.addi %163, %166 : i64
      llvm.store %165, %13 : i64, !llvm.ptr
      cf.br ^bb33
    ^bb35:
    %167 = arith.constant 0 : i32
    %168 = arith.constant 0 : i32
    %169 = arith.trunci %167 : i32 to i8
    %170 = arith.extsi %168 : i32 to i64
    %171 = llvm.getelementptr %92[%170] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %169, %171 : i8, !llvm.ptr
    %172 = arith.constant 0 : i32
    %173 = arith.constant 1 : i32
    %174 = arith.trunci %172 : i32 to i8
    %175 = arith.extsi %173 : i32 to i64
    %176 = llvm.getelementptr %92[%175] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %174, %176 : i8, !llvm.ptr
    %177 = arith.constant 2 : i32
    %178 = arith.extsi %177 : i32 to i64
    llvm.store %178, %13 : i64, !llvm.ptr
    cf.br ^bb36
    ^bb36:
    %179 = llvm.load %13 : !llvm.ptr -> i64
    %180 = llvm.load %13 : !llvm.ptr -> i64
    %181 = arith.muli %179, %180 : i64
    %182 = llvm.load %67 : !llvm.ptr -> i64
    %183 = arith.cmpi sle, %181, %182 : i64
    cf.cond_br %183, ^bb37, ^bb38
    ^bb37:
      %185 = llvm.load %13 : !llvm.ptr -> i64
      %186 = llvm.getelementptr %92[%185] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %184 = llvm.load %186 : !llvm.ptr -> i8
      %187 = arith.constant 1 : i32
      %189 = arith.extsi %184 : i8 to i32
      %188 = arith.cmpi eq, %189, %187 : i32
      cf.cond_br %188, ^bb39, ^bb40
      ^bb39:
        %190 = llvm.load %13 : !llvm.ptr -> i64
        %191 = llvm.load %13 : !llvm.ptr -> i64
        %192 = arith.muli %190, %191 : i64
        %193 = llvm.mlir.constant(1 : i64) : i64
        %194 = llvm.alloca %193 x i64 : (i64) -> !llvm.ptr
        llvm.store %192, %194 : i64, !llvm.ptr
        cf.br ^bb42
        ^bb42:
        %195 = llvm.load %194 : !llvm.ptr -> i64
        %196 = llvm.load %67 : !llvm.ptr -> i64
        %197 = arith.cmpi sle, %195, %196 : i64
        cf.cond_br %197, ^bb43, ^bb44
        ^bb43:
          %198 = arith.constant 0 : i32
          %199 = llvm.load %194 : !llvm.ptr -> i64
          %200 = arith.trunci %198 : i32 to i8
          %201 = llvm.getelementptr %92[%199] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %200, %201 : i8, !llvm.ptr
          %202 = llvm.load %194 : !llvm.ptr -> i64
          %203 = llvm.load %13 : !llvm.ptr -> i64
          %204 = arith.addi %202, %203 : i64
          llvm.store %204, %194 : i64, !llvm.ptr
          cf.br ^bb42
        ^bb44:
        cf.br ^bb41
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %205 = llvm.load %13 : !llvm.ptr -> i64
      %206 = arith.constant 1 : i32
      %208 = arith.extsi %206 : i32 to i64
      %207 = arith.addi %205, %208 : i64
      llvm.store %207, %13 : i64, !llvm.ptr
      cf.br ^bb36
    ^bb38:
    %209 = arith.constant 0 : i32
    %210 = arith.extsi %209 : i32 to 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 2 : i32
    %214 = arith.extsi %213 : i32 to i64
    llvm.store %214, %13 : i64, !llvm.ptr
    cf.br ^bb45
    ^bb45:
    %215 = llvm.load %13 : !llvm.ptr -> i64
    %216 = llvm.load %67 : !llvm.ptr -> i64
    %217 = arith.cmpi sle, %215, %216 : i64
    cf.cond_br %217, ^bb46, ^bb47
    ^bb46:
      %219 = llvm.load %13 : !llvm.ptr -> i64
      %220 = llvm.getelementptr %92[%219] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %218 = llvm.load %220 : !llvm.ptr -> i8
      %221 = arith.constant 1 : i32
      %223 = arith.extsi %218 : i8 to i32
      %222 = arith.cmpi eq, %223, %221 : i32
      cf.cond_br %222, ^bb48, ^bb49
      ^bb48:
        %224 = llvm.load %212 : !llvm.ptr -> i64
        %226 = llvm.load %13 : !llvm.ptr -> i64
        %227 = llvm.getelementptr %85[%226] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        %225 = llvm.load %227 : !llvm.ptr -> i64
        %228 = arith.addi %224, %225 : i64
        %229 = arith.remsi %228, %3 : i64
        llvm.store %229, %212 : i64, !llvm.ptr
        cf.br ^bb50
      ^bb49:
        cf.br ^bb50
      ^bb50:
      %230 = llvm.load %13 : !llvm.ptr -> i64
      %231 = arith.constant 1 : i32
      %233 = arith.extsi %231 : i32 to i64
      %232 = arith.addi %230, %233 : i64
      llvm.store %232, %13 : i64, !llvm.ptr
      cf.br ^bb45
    ^bb47:
    %234 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %235 = llvm.load %212 : !llvm.ptr -> i64
    %236 = llvm.call @printf(%234, %235) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    func.call @free(%4) : (!llvm.ptr) -> ()
    func.call @free(%85) : (!llvm.ptr) -> ()
    func.call @free(%92) : (!llvm.ptr) -> ()
    %240 = arith.constant 0 : i32
    func.return %240 : i32
  }
}