Problem 515

Dissonant Numbers — D(10^9,10^5,10^5) via inv(k-1) mod p.

Answer2422639000800
Output2422639000800
StatusPASS
Native helperno
Runtime0 ms
Peak memory1312 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 515
# Dissonant Numbers — D(10^9,10^5,10^5) via inv(k-1) mod p.

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

function isqrt(n: i64) -> i64 {
    if n < 2 { return n }
    let mut x: i64 = n
    let mut y: i64 = (x + 1) / 2
    while y < x {
        x = y
        y = (x + n / x) / 2
    }
    return x
}

function modpow(base0: i64, exp0: i64, mod: i64) -> i64 {
    let mut r: i64 = 1
    let mut b: i64 = base0 % mod
    let mut e: i64 = exp0
    while e > 0 {
        if (e & 1) == 1 {
            r = ((r as i128) * (b as i128) % (mod as i128)) as i64
        }
        b = ((b as i128) * (b as i128) % (mod as i128)) as i64
        e = e / 2
    }
    return r
}

function main() -> i32 {
    let a: i64 = 1000000000
    let b: i64 = 100000
    let k: i64 = 100000
    let high: i64 = a + b
    let lim: i64 = isqrt(high - 1)
    let sieve: ptr<i8> = calloc(lim + 1, 1)
    let small: ptr<i32> = calloc(lim + 1, 4)
    let seg: ptr<i8> = calloc(b, 1)
    if sieve == null || small == null || seg == null { return 1 }
    let mut i: i64 = 2
    while i <= lim {
        sieve[i] = 1
        i = i + 1
    }
    i = 2
    while i * i <= lim {
        if sieve[i] == 1 {
            let mut j: i64 = i * i
            while j <= lim {
                sieve[j] = 0
                j = j + i
            }
        }
        i = i + 1
    }
    let mut sn: i64 = 0
    i = 2
    while i <= lim {
        if sieve[i] == 1 {
            small[sn] = i as i32
            sn = sn + 1
        }
        i = i + 1
    }
    i = 0
    while i < b {
        seg[i] = 1
        i = i + 1
    }
    let mut si: i64 = 0
    while si < sn {
        let p: i64 = small[si] as i64
        let mut m: i64 = ((a + p - 1) / p) * p
        if m < p * p { m = p * p }
        while m < high {
            seg[m - a] = 0
            m = m + p
        }
        si = si + 1
    }
    let x: i64 = k - 1
    let mut total: i64 = 0
    i = 0
    while i < b {
        if seg[i] == 1 {
            let p: i64 = a + i
            if p >= 2 {
                total = total + modpow(x, p - 2, p)
            }
        }
        i = i + 1
    }
    printf("%lld\n", total)
    free(sieve); free(small); free(seg)
    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 isqrt_i64(int64_t n);
int64_t modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod);
int32_t main(void);



int64_t isqrt_i64(int64_t n) {
    if (n < 2) {
        return n;
    }
    int64_t x = n;
    int64_t y = FLOW_CHECKED_DIV(((x + 1)), (2));
    while (y < x) {
        x = y;
        y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
    }
    return x;
}

int64_t modpow_i64_i64_i64(int64_t base0, int64_t exp0, int64_t mod) {
    int64_t r = 1;
    int64_t b = FLOW_CHECKED_MOD((base0), (mod));
    int64_t e = exp0;
    while (e > 0) {
        if ((e & 1) == 1) {
            r = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(r)) * ((__int128)(b)))), (((__int128)(mod))))));
        }
        b = ((int64_t)(FLOW_CHECKED_MOD(((((__int128)(b)) * ((__int128)(b)))), (((__int128)(mod))))));
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

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