Problem 308

FRACTRAN PRIMEGAME steps until 2^(p_10001).

Answer1539669807660924
Output1539669807660924
StatusPASS
Native helperno
Runtime30 ms
Peak memory1680 KB
Time complexityO(n^2) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)?
Space complexityO(n)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 308
# FRACTRAN PRIMEGAME steps until 2^(p_10001).

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

function sum_floor_range(n: i64, lo: i64, hi: i64) -> i64 {
    let mut s: i64 = 0
    let mut d: i64 = lo
    while d <= hi {
        let q: i64 = n / d
        let mut dmax: i64 = n / q
        if dmax > hi { dmax = hi }
        s = s + q * (dmax - d + 1)
        d = dmax + 1
    }
    return s
}

function main() -> i32 {
    # 10001st prime via sieve
    let limit: i64 = 120000
    let is_prime: ptr<i8> = calloc(limit + 1, 1)
    let mut i: i64 = 0
    while i <= limit {
        is_prime[i] = 1
        i = i + 1
    }
    is_prime[0] = 0
    is_prime[1] = 0
    i = 2
    while i * i <= limit {
        if is_prime[i] == 1 {
            let mut j: i64 = i * i
            while j <= limit {
                is_prime[j] = 0
                j = j + i
            }
        }
        i = i + 1
    }
    let mut count: i64 = 0
    let mut p: i64 = 0
    i = 2
    while i <= limit {
        if is_prime[i] == 1 {
            count = count + 1
            if count == 10001 {
                p = i
                break
            }
        }
        i = i + 1
    }

    let spf: ptr<i32> = calloc(p + 1, 4)
    i = 0
    while i <= p {
        spf[i] = i as i32
        i = i + 1
    }
    i = 2
    while i * i <= p {
        if spf[i] == i as i32 {
            let mut j: i64 = i * i
            while j <= p {
                if spf[j] == j as i32 {
                    spf[j] = i as i32
                }
                j = j + i
            }
        }
        i = i + 1
    }

    let mut steps: i64 = 0
    let mut prev_b: i64 = 0
    let mut N: i64 = 2
    while N <= p {
        let mut bN: i64 = 1
        if N >= 2 {
            let s: i64 = spf[N] as i64
            if s != N {
                bN = N / s
            } else {
                bN = 1
            }
        }
        let extra: i64 = 0
        if N != 2 {
            extra = prev_b - 1
        }
        let sfloor: i64 = sum_floor_range(N, bN, N - 1)
        let cost: i64 = (N - 1) + (6 * N + 2) * (N - bN) + 2 * sfloor + extra
        steps = steps + cost
        prev_b = bN
        N = N + 1
    }
    printf("%lld\n", steps)
    free(is_prime)
    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; }

int64_t sum_floor_range_i64_i64_i64(int64_t n, int64_t lo, int64_t hi);
int32_t main(void);



int64_t sum_floor_range_i64_i64_i64(int64_t n, int64_t lo, int64_t hi) {
    int64_t s = 0;
    int64_t d = lo;
    while (d <= hi) {
        int64_t q = FLOW_CHECKED_DIV((n), (d));
        int64_t dmax = FLOW_CHECKED_DIV((n), (q));
        if (dmax > hi) {
            dmax = hi;
        }
        s = (s + (q * ((dmax - d) + 1)));
        d = (dmax + 1);
    }
    return s;
}

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