Problem 609

π sequences: P(10^8) mod 10^9+7. A π-sequence u=(u_0,...,u_m) has u_{n+1}=π(u_n), u_n≥1, m≥1. c(u) = count of non-prime elements. P(n) = product of all p(n,k)>0.

Answer172023848
Output172023848
StatusPASS
Native helperno
Runtime2710 ms
Peak memory489408 KB
Time complexityO(n^2) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n * m)
Space complexityO(n)O(n)
ApproachFlow solutionDynamic programming or generating function
VerdictUnknown

Flow source

# Project Euler 609
# π sequences: P(10^8) mod 10^9+7.
# A π-sequence u=(u_0,...,u_m) has u_{n+1}=π(u_n), u_n≥1, m≥1.
# c(u) = count of non-prime elements. P(n) = product of all p(n,k)>0.

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

function main() -> i32 {
    let LIMIT: i64 = 100000000
    let MOD: i64 = 1000000007

    # Sieve of Eratosthenes
    let is_prime: ptr<i8> = calloc(LIMIT + 2, 1)
    if is_prime == null { return 1 }
    for i in 0..(LIMIT + 2) { is_prime[i] = 1 }
    is_prime[0] = 0
    is_prime[1] = 0
    let mut p: i64 = 2
    while p * p <= LIMIT {
        if is_prime[p] == 1 {
            for m in (p * p)..(LIMIT + 1) step p { is_prime[m] = 0 }
        }
        p = p + 1
    }

    # Build pi(x) array: pi_arr[x] = number of primes ≤ x
    let pi_arr: ptr<i32> = calloc(LIMIT + 1, 4)
    if pi_arr == null { return 1 }
    let mut count: i64 = 0
    for i in 1..(LIMIT + 1) {
        if is_prime[i] == 1 { count = count + 1 }
        pi_arr[i] = count as i32
    }

    # For each u_0, follow pi-sequence and count non-primes.
    let MAXK: i64 = 40
    let arr2: ptr<i64> = calloc(MAXK, 8)
    if arr2 == null { return 1 }

    for x in 1..(LIMIT + 1) {
        let mut npc: i64 = 0
        if is_prime[x] == 0 { npc = 1 }
        let mut curr: i64 = x
        while true {
            let temp: i64 = pi_arr[curr] as i64
            if temp == 0 { break }
            if is_prime[temp] == 0 { npc = npc + 1 }
            if npc < MAXK { arr2[npc] = arr2[npc] + 1 }
            curr = temp
        }
    }

    # P(n) = product of all arr2[k] > 0, mod MOD
    let mut total: i64 = 1
    for i in 0..MAXK {
        if arr2[i] > 0 {
            total = ((total as i128) * (arr2[i] as i128) % (MOD as i128)) as i64
        }
    }

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