Problem 772

LCM product — f(10^8) mod 10^9+7. f(k) = 2 * lcm(1..k) mod MOD. lcm(1..k) = product of p^{floor(log_p k)} over all primes p <= k. Segmented sieve over [3, k] for odd primes, with power handling.

Answer83985379
Output83985379
StatusPASS
Native helperno
Runtime110 ms
Peak memory2096 KB
Time complexityO(n^2) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n)
Space complexityO(n)O(1)
ApproachFlow solutionDirect hand evaluation or enumeration
VerdictSuboptimal

Flow source

# Project Euler 772
# LCM product — f(10^8) mod 10^9+7.
#
# f(k) = 2 * lcm(1..k) mod MOD.
# lcm(1..k) = product of p^{floor(log_p k)} over all primes p <= k.
# Segmented sieve over [3, k] for odd primes, with power handling.

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
    function memset(p: ptr<void>, c: i32, n: i64) -> ptr<void>
    function sqrt(x: f64) -> f64
}

const MOD: i64 = 1000000007

function main() -> i32 {
    let k: i64 = 100000000
    let mod: i64 = MOD

    # handle 2
    let mut p2: i64 = 2
    while p2 * 2 <= k {
        p2 = p2 * 2
    }
    let mut res: i64 = p2 % mod

    let mut sqrt_k: i64 = (sqrt((k as f64)) as i64)
    while (sqrt_k + 1) * (sqrt_k + 1) <= k {
        sqrt_k = sqrt_k + 1
    }

    # sieve small primes up to sqrt_k
    let comp: ptr<i8> = calloc(sqrt_k + 1, 1)
    let mut i: i64 = 2
    while i * i <= sqrt_k {
        if comp[i] == 0 {
            let mut j: i64 = i * i
            while j <= sqrt_k {
                comp[j] = 1
                j = j + i
            }
        }
        i = i + 1
    }

    # segmented sieve over [3, k], odd numbers only
    let mut low: i64 = 3
    let seg_size: i64 = 1000000
    let seg: ptr<i8> = calloc(seg_size, 1)

    while low <= k {
        let mut high: i64 = low + seg_size
        if high > k + 1 {
            high = k + 1
        }
        memset(seg, 0, high - low)

        let mut p: i64 = 3
        while p <= sqrt_k {
            if comp[p] == 0 {
                let mut start: i64 = ((low + p - 1) / p) * p
                if start < p * p {
                    start = p * p
                }
                if (start & 1) == 0 {
                    start = start + p
                }
                let mut m: i64 = start
                while m < high {
                    seg[m - low] = 1
                    m = m + 2 * p
                }
            }
            p = p + 1
        }

        let mut n: i64 = low
        while n < high {
            if seg[n - low] == 0 {
                res = res * n % mod
                if n <= sqrt_k {
                    let mut power: i64 = n * n
                    while power <= k {
                        res = res * n % mod
                        power = power * n
                    }
                }
            }
            n = n + 2
        }

        low = high
        if (low & 1) == 0 {
            low = low + 1
        }
    }

    free(comp)
    free(seg)

    printf("%lld\n", (2 * res) % mod)
    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);

static const int64_t MOD = 1000000007;





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