Problem 800

Hybrid Integers: C(800800, 800800). Count pairs of primes p < q with p^q * q^p <= 800800^800800.

Answer1412403576
Output1412403576
StatusPASS
Native helperno
Runtime110 ms
Peak memory81872 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 800
# Hybrid Integers: C(800800, 800800).
# Count pairs of primes p < q with p^q * q^p <= 800800^800800.

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function malloc(n: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
    function log10(x: f64) -> f64
    function fabs(x: f64) -> f64
}

function main() -> i32 {
    let a: i64 = 800800
    let b: i64 = 800800
    let limit: f64 = log10(a as f64) * (b as f64)
    let maxn: i64 = (limit / log10(2.0)) as i64 + 10000
    let comp: ptr<i8> = calloc(maxn + 1, 1)
    let mut i: i64 = 2
    while i * i <= maxn {
        if comp[i] == 0 {
            let mut j: i64 = i * i
            while j <= maxn {
                comp[j] = 1
                j = j + i
            }
        }
        i = i + 1
    }
    let primes: ptr<i32> = malloc((maxn / 10) * 4)
    let mut pc: i64 = 0
    for x in 2..(maxn + 1) {
        if comp[x] == 0 {
            primes[pc] = x as i32
            pc = pc + 1
        }
    }
    let pp: ptr<i32> = malloc((maxn + 2) * 4)
    let mut p_index: i64 = 0
    for x in 1..(maxn + 1) {
        while p_index < pc && (primes[p_index] as i64) <= x {
            p_index = p_index + 1
        }
        pp[x] = p_index as i32
    }

    let mut count: i64 = 0
    for pi in 0..pc {
        let p: i64 = primes[pi] as i64
        let p_log: f64 = log10(p as f64)
        if 2.0 * (p as f64) * p_log > limit {
            break
        }
        let mut lo: i64 = if pi + 1 < pc { primes[pi + 1] as i64 } else { p + 1 }
        while lo <= maxn && comp[lo] != 0 {
            lo = lo + 1
        }
        let mut hi: i64 = (limit / p_log) as i64
        if hi > maxn {
            hi = maxn
        }
        while lo < hi {
            let q: i64 = (lo + hi) / 2
            let q_log: f64 = log10(q as f64)
            if (p as f64) * q_log + (q as f64) * p_log > limit {
                hi = q
            } else {
                lo = q + 1
            }
        }
        let mut q: i64 = lo
        if q > maxn || comp[q] != 0 {
            while q <= maxn && comp[q] != 0 {
                q = q + 1
            }
            if q > maxn {
                break
            }
        }
        let q_log: f64 = log10(q as f64)
        let val: f64 = (p as f64) * q_log + (q as f64) * p_log
        if fabs(val - limit) < 1e-9 {
            count = count + (pp[q] as i64) - (pp[p] as i64)
        } else {
            if val > limit {
                count = count + (pp[q] as i64) - (pp[p] as i64) - 1
            } else {
                q = q + 1
                while q <= maxn && comp[q] != 0 {
                    q = q + 1
                }
                if q > maxn {
                    break
                }
                count = count + (pp[q] as i64) - (pp[p] as i64) - 1
            }
        }
    }
    free(comp)
    free(primes)
    free(pp)
    printf("%lld\n", count)
    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 a = 800800;
    int64_t b = 800800;
    double limit = (log10(((double)(a))) * ((double)(b)));
    int64_t maxn = (((int64_t)((limit / log10(2.0)))) + 10000);
    int8_t* comp = (int8_t*)(calloc((maxn + 1), 1));
    int64_t i = 2;
    while ((i * i) <= maxn) {
        if (comp[i] == 0) {
            int64_t j = (i * i);
            while (j <= maxn) {
                comp[j] = 1;
                j = (j + i);
            }
        }
        i = (i + 1);
    }
    int32_t* primes = (int32_t*)(malloc((FLOW_CHECKED_DIV((maxn), (10)) * 4)));
    int64_t pc = 0;
    int32_t __flow_step_1 = 1;
    for (int32_t x = 2; (2 <= (maxn + 1)) ? x < (maxn + 1) : x > (maxn + 1); x += (2 <= (maxn + 1)) ? 1 : -1) {
        if (comp[x] == 0) {
            primes[pc] = ((int32_t)(x));
            pc = (pc + 1);
        }
    }
    int32_t* pp = (int32_t*)(malloc(((maxn + 2) * 4)));
    int64_t p_index = 0;
    int32_t __flow_step_2 = 1;
    for (int32_t x = 1; (1 <= (maxn + 1)) ? x < (maxn + 1) : x > (maxn + 1); x += (1 <= (maxn + 1)) ? 1 : -1) {
        while ((p_index < pc && ((int64_t)(primes[p_index])) <= x)) {
            p_index = (p_index + 1);
        }
        pp[x] = ((int32_t)(p_index));
    }
    int64_t count = 0;
    int32_t __flow_step_3 = 1;
    for (int32_t pi = 0; (0 <= pc) ? pi < pc : pi > pc; pi += (0 <= pc) ? 1 : -1) {
        int64_t p = ((int64_t)(primes[pi]));
        double p_log = log10(((double)(p)));
        if (((2.0 * ((double)(p))) * p_log) > limit) {
            break;
        }
        int64_t lo = (((pi + 1) < pc) ? (((int64_t)(primes[(pi + 1)]))) : ((p + 1)));
        while ((lo <= maxn && comp[lo] != 0)) {
            lo = (lo + 1);
        }
        int64_t hi = ((int64_t)((limit / p_log)));
        if (hi > maxn) {
            hi = maxn;
        }
        while (lo < hi) {
            int64_t q = FLOW_CHECKED_DIV(((lo + hi)), (2));
            double q_log = log10(((double)(q)));
            if (((((double)(p)) * q_log) + (((double)(q)) * p_log)) > limit) {
                hi = q;
            } else {
                lo = (q + 1);
            }
        }
        int64_t q = lo;
        if ((q > maxn || comp[q] != 0)) {
            while ((q <= maxn && comp[q] != 0)) {
                q = (q + 1);
            }
            if (q > maxn) {
                break;
            }
        }
        double q_log = log10(((double)(q)));
        double val = ((((double)(p)) * q_log) + (((double)(q)) * p_log));
        if (fabs((val - limit)) < 1e-9) {
            count = ((count + ((int64_t)(pp[q]))) - ((int64_t)(pp[p])));
        } else {
            if (val > limit) {
                count = (((count + ((int64_t)(pp[q]))) - ((int64_t)(pp[p]))) - 1);
            } else {
                q = (q + 1);
                while ((q <= maxn && comp[q] != 0)) {
                    q = (q + 1);
                }
                if (q > maxn) {
                    break;
                }
                count = (((count + ((int64_t)(pp[q]))) - ((int64_t)(pp[p]))) - 1);
            }
        }
    }
    free(comp);
    free(primes);
    free(pp);
    printf("%lld\n", count);
    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 @malloc(i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func private @log10(f64) -> f64
  func.func private @fabs(f64) -> f64
  func.func @main() -> i32 {
    %0 = arith.constant 800800 : i32
    %1 = arith.extsi %0 : i32 to i64
    %2 = arith.constant 800800 : i32
    %3 = arith.extsi %2 : i32 to i64
    %5 = arith.sitofp %1 : i64 to f64
    %4 = func.call @log10(%5) : (f64) -> f64
    %6 = arith.sitofp %3 : i64 to f64
    %7 = arith.mulf %4, %6 : f64
    %9 = arith.constant 2.0 : f32
    %10 = arith.extf %9 : f32 to f64
    %8 = func.call @log10(%10) : (f64) -> f64
    %11 = arith.divf %7, %8 : f64
    %12 = arith.fptosi %11 : f64 to i64
    %13 = arith.constant 10000 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.addi %12, %15 : i64
    %17 = arith.constant 1 : i32
    %19 = arith.extsi %17 : i32 to i64
    %18 = arith.addi %14, %19 : i64
    %20 = arith.constant 1 : i32
    %21 = arith.extsi %20 : i32 to i64
    %16 = func.call @calloc(%18, %21) : (i64, i64) -> !llvm.ptr
    %22 = arith.constant 2 : i32
    %23 = arith.extsi %22 : i32 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 ^bb0
    ^bb0:
    %26 = llvm.load %25 : !llvm.ptr -> i64
    %27 = llvm.load %25 : !llvm.ptr -> i64
    %28 = arith.muli %26, %27 : i64
    %29 = arith.cmpi sle, %28, %14 : i64
    cf.cond_br %29, ^bb1, ^bb2
    ^bb1:
      %31 = llvm.load %25 : !llvm.ptr -> i64
      %32 = llvm.getelementptr %16[%31] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %30 = llvm.load %32 : !llvm.ptr -> i8
      %33 = arith.constant 0 : i32
      %35 = arith.extsi %30 : i8 to i32
      %34 = arith.cmpi eq, %35, %33 : i32
      cf.cond_br %34, ^bb3, ^bb4
      ^bb3:
        %36 = llvm.load %25 : !llvm.ptr -> i64
        %37 = llvm.load %25 : !llvm.ptr -> i64
        %38 = arith.muli %36, %37 : 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, %14 : 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 %16[%44] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %45, %46 : i8, !llvm.ptr
          %47 = llvm.load %40 : !llvm.ptr -> i64
          %48 = llvm.load %25 : !llvm.ptr -> i64
          %49 = arith.addi %47, %48 : i64
          llvm.store %49, %40 : i64, !llvm.ptr
          cf.br ^bb6
        ^bb8:
        cf.br ^bb5
      ^bb4:
        cf.br ^bb5
      ^bb5:
      %50 = llvm.load %25 : !llvm.ptr -> i64
      %51 = arith.constant 1 : i32
      %53 = arith.extsi %51 : i32 to i64
      %52 = arith.addi %50, %53 : i64
      llvm.store %52, %25 : i64, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %55 = arith.constant 10 : i32
    %57 = arith.extsi %55 : i32 to i64
    %56 = arith.divsi %14, %57 : i64
    %58 = arith.constant 4 : i32
    %60 = arith.extsi %58 : i32 to i64
    %59 = arith.muli %56, %60 : i64
    %54 = func.call @malloc(%59) : (i64) -> !llvm.ptr
    %61 = arith.constant 0 : i32
    %62 = arith.extsi %61 : i32 to i64
    %63 = llvm.mlir.constant(1 : i64) : i64
    %64 = llvm.alloca %63 x i64 : (i64) -> !llvm.ptr
    llvm.store %62, %64 : i64, !llvm.ptr
    %65 = arith.constant 2 : i32
    %66 = arith.constant 1 : i32
    %68 = arith.extsi %66 : i32 to i64
    %67 = arith.addi %14, %68 : i64
    %69 = arith.index_cast %65 : i32 to index
    %70 = arith.index_cast %67 : i32 to index
    %72 = arith.constant 1 : index
    %73 = arith.constant -1 : index
    %74 = arith.cmpi sle, %69, %70 : index
    %71 = arith.select %74, %72, %73 : index
    cf.br ^bb9(%69 : index)
    ^bb9(%75: index):
    %76 = arith.cmpi slt, %75, %70 : index
    %77 = arith.cmpi sgt, %75, %70 : index
    %78 = arith.select %74, %76, %77 : i1
    cf.cond_br %78, ^bb10(%75 : index), ^bb11(%75 : index)
    ^bb10(%79: index):
      %81 = arith.index_cast %79 : index to i64
      %82 = llvm.getelementptr %16[%81] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %80 = llvm.load %82 : !llvm.ptr -> i8
      %83 = arith.constant 0 : i32
      %85 = arith.extsi %80 : i8 to i32
      %84 = arith.cmpi eq, %85, %83 : i32
      cf.cond_br %84, ^bb12, ^bb13
      ^bb12:
        %86 = arith.index_cast %79 : index to i32
        %87 = llvm.load %64 : !llvm.ptr -> i64
        %88 = llvm.getelementptr %54[%87] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        llvm.store %86, %88 : i32, !llvm.ptr
        %89 = llvm.load %64 : !llvm.ptr -> i64
        %90 = arith.constant 1 : i32
        %92 = arith.extsi %90 : i32 to i64
        %91 = arith.addi %89, %92 : i64
        llvm.store %91, %64 : i64, !llvm.ptr
        cf.br ^bb14
      ^bb13:
        cf.br ^bb14
      ^bb14:
      %93 = arith.addi %79, %71 : index
      cf.br ^bb9(%93 : index)
    ^bb11(%94: index):
    %96 = arith.constant 2 : i32
    %98 = arith.extsi %96 : i32 to i64
    %97 = arith.addi %14, %98 : i64
    %99 = arith.constant 4 : i32
    %101 = arith.extsi %99 : i32 to i64
    %100 = arith.muli %97, %101 : i64
    %95 = func.call @malloc(%100) : (i64) -> !llvm.ptr
    %102 = arith.constant 0 : i32
    %103 = arith.extsi %102 : i32 to i64
    %104 = llvm.mlir.constant(1 : i64) : i64
    %105 = llvm.alloca %104 x i64 : (i64) -> !llvm.ptr
    llvm.store %103, %105 : i64, !llvm.ptr
    %106 = arith.constant 1 : i32
    %107 = arith.constant 1 : i32
    %109 = arith.extsi %107 : i32 to i64
    %108 = arith.addi %14, %109 : i64
    %110 = arith.index_cast %106 : i32 to index
    %111 = arith.index_cast %108 : i32 to index
    %113 = arith.constant 1 : index
    %114 = arith.constant -1 : index
    %115 = arith.cmpi sle, %110, %111 : index
    %112 = arith.select %115, %113, %114 : index
    cf.br ^bb15(%110 : index)
    ^bb15(%116: index):
    %117 = arith.cmpi slt, %116, %111 : index
    %118 = arith.cmpi sgt, %116, %111 : index
    %119 = arith.select %115, %117, %118 : i1
    cf.cond_br %119, ^bb16(%116 : index), ^bb17(%116 : index)
    ^bb16(%120: index):
      cf.br ^bb18
      ^bb18:
      %121 = llvm.load %105 : !llvm.ptr -> i64
      %122 = llvm.load %64 : !llvm.ptr -> i64
      %123 = arith.cmpi slt, %121, %122 : i64
      %124 = scf.if %123 -> (i1) {
        %126 = llvm.load %105 : !llvm.ptr -> i64
        %127 = llvm.getelementptr %54[%126] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %125 = llvm.load %127 : !llvm.ptr -> i32
        %128 = arith.extsi %125 : i32 to i64
        %130 = arith.trunci %128 : i64 to i32
        %131 = arith.index_cast %120 : index to i32
        %129 = arith.cmpi sle, %130, %131 : i32
        scf.yield %129 : i1
      } else {
        %132 = arith.constant false
        scf.yield %132 : i1
      }
      cf.cond_br %124, ^bb19, ^bb20
      ^bb19:
        %133 = llvm.load %105 : !llvm.ptr -> i64
        %134 = arith.constant 1 : i32
        %136 = arith.extsi %134 : i32 to i64
        %135 = arith.addi %133, %136 : i64
        llvm.store %135, %105 : i64, !llvm.ptr
        cf.br ^bb18
      ^bb20:
      %137 = llvm.load %105 : !llvm.ptr -> i64
      %138 = arith.trunci %137 : i64 to i32
      %139 = arith.index_cast %120 : index to i64
      %140 = llvm.getelementptr %95[%139] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %138, %140 : i32, !llvm.ptr
      %141 = arith.addi %120, %112 : index
      cf.br ^bb15(%141 : index)
    ^bb17(%142: index):
    %143 = arith.constant 0 : i32
    %144 = arith.extsi %143 : i32 to i64
    %145 = llvm.mlir.constant(1 : i64) : i64
    %146 = llvm.alloca %145 x i64 : (i64) -> !llvm.ptr
    llvm.store %144, %146 : i64, !llvm.ptr
    %147 = arith.constant 0 : i32
    %148 = llvm.load %64 : !llvm.ptr -> i64
    %149 = arith.index_cast %147 : i32 to index
    %150 = arith.index_cast %148 : i32 to index
    %152 = arith.constant 1 : index
    %153 = arith.constant -1 : index
    %154 = arith.cmpi sle, %149, %150 : index
    %151 = arith.select %154, %152, %153 : index
    cf.br ^bb21(%149 : index)
    ^bb21(%155: index):
    %156 = arith.cmpi slt, %155, %150 : index
    %157 = arith.cmpi sgt, %155, %150 : index
    %158 = arith.select %154, %156, %157 : i1
    cf.cond_br %158, ^bb22(%155 : index), ^bb23(%155 : index)
    ^bb22(%159: index):
      %161 = arith.index_cast %159 : index to i64
      %162 = llvm.getelementptr %54[%161] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      %160 = llvm.load %162 : !llvm.ptr -> i32
      %163 = arith.extsi %160 : i32 to i64
      %165 = arith.sitofp %163 : i64 to f64
      %164 = func.call @log10(%165) : (f64) -> f64
      %166 = arith.constant 2.0 : f32
      %167 = arith.sitofp %163 : i64 to f64
      %169 = arith.extf %166 : f32 to f64
      %168 = arith.mulf %169, %167 : f64
      %170 = arith.mulf %168, %164 : f64
      %171 = arith.cmpf ogt, %170, %7 : f64
      cf.cond_br %171, ^bb24, ^bb25
      ^bb24:
        cf.br ^bb23(%159 : index)
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %172 = arith.constant 1 : i32
      %174 = arith.index_cast %159 : index to i32
      %173 = arith.addi %174, %172 : i32
      %175 = llvm.load %64 : !llvm.ptr -> i64
      %177 = arith.extsi %173 : i32 to i64
      %176 = arith.cmpi slt, %177, %175 : i64
      %178 = scf.if %176 -> (i64) {
        %180 = arith.constant 1 : i32
        %182 = arith.index_cast %159 : index to i32
        %181 = arith.addi %182, %180 : i32
        %183 = arith.extsi %181 : i32 to i64
        %184 = llvm.getelementptr %54[%183] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %179 = llvm.load %184 : !llvm.ptr -> i32
        %185 = arith.extsi %179 : i32 to i64
        scf.yield %185 : i64
      } else {
        %186 = arith.constant 1 : i32
        %188 = arith.extsi %186 : i32 to i64
        %187 = arith.addi %163, %188 : i64
        scf.yield %187 : i64
      }
      %189 = llvm.mlir.constant(1 : i64) : i64
      %190 = llvm.alloca %189 x i64 : (i64) -> !llvm.ptr
      llvm.store %178, %190 : i64, !llvm.ptr
      cf.br ^bb27
      ^bb27:
      %191 = llvm.load %190 : !llvm.ptr -> i64
      %192 = arith.cmpi sle, %191, %14 : i64
      %193 = scf.if %192 -> (i1) {
        %195 = llvm.load %190 : !llvm.ptr -> i64
        %196 = llvm.getelementptr %16[%195] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %194 = llvm.load %196 : !llvm.ptr -> i8
        %197 = arith.constant 0 : i32
        %199 = arith.extsi %194 : i8 to i32
        %198 = arith.cmpi ne, %199, %197 : i32
        scf.yield %198 : i1
      } else {
        %200 = arith.constant false
        scf.yield %200 : i1
      }
      cf.cond_br %193, ^bb28, ^bb29
      ^bb28:
        %201 = llvm.load %190 : !llvm.ptr -> i64
        %202 = arith.constant 1 : i32
        %204 = arith.extsi %202 : i32 to i64
        %203 = arith.addi %201, %204 : i64
        llvm.store %203, %190 : i64, !llvm.ptr
        cf.br ^bb27
      ^bb29:
      %205 = arith.divf %7, %164 : f64
      %206 = arith.fptosi %205 : f64 to 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.cmpi sgt, %209, %14 : i64
      cf.cond_br %210, ^bb30, ^bb31
      ^bb30:
        llvm.store %14, %208 : i64, !llvm.ptr
        cf.br ^bb32
      ^bb31:
        cf.br ^bb32
      ^bb32:
      cf.br ^bb33
      ^bb33:
      %211 = llvm.load %190 : !llvm.ptr -> i64
      %212 = llvm.load %208 : !llvm.ptr -> i64
      %213 = arith.cmpi slt, %211, %212 : i64
      cf.cond_br %213, ^bb34, ^bb35
      ^bb34:
        %214 = llvm.load %190 : !llvm.ptr -> i64
        %215 = llvm.load %208 : !llvm.ptr -> i64
        %216 = arith.addi %214, %215 : i64
        %217 = arith.constant 2 : i32
        %219 = arith.extsi %217 : i32 to i64
        %218 = arith.divsi %216, %219 : i64
        %221 = arith.sitofp %218 : i64 to f64
        %220 = func.call @log10(%221) : (f64) -> f64
        %222 = arith.sitofp %163 : i64 to f64
        %223 = arith.mulf %222, %220 : f64
        %224 = arith.sitofp %218 : i64 to f64
        %225 = arith.mulf %224, %164 : f64
        %226 = arith.addf %223, %225 : f64
        %227 = arith.cmpf ogt, %226, %7 : f64
        cf.cond_br %227, ^bb36, ^bb37
        ^bb36:
          llvm.store %218, %208 : i64, !llvm.ptr
          cf.br ^bb38
        ^bb37:
          %228 = arith.constant 1 : i32
          %230 = arith.extsi %228 : i32 to i64
          %229 = arith.addi %218, %230 : i64
          llvm.store %229, %190 : i64, !llvm.ptr
          cf.br ^bb38
        ^bb38:
        cf.br ^bb33
      ^bb35:
      %231 = llvm.load %190 : !llvm.ptr -> i64
      %232 = llvm.mlir.constant(1 : i64) : i64
      %233 = llvm.alloca %232 x i64 : (i64) -> !llvm.ptr
      llvm.store %231, %233 : i64, !llvm.ptr
      %234 = llvm.load %233 : !llvm.ptr -> i64
      %235 = arith.cmpi sgt, %234, %14 : i64
      %236 = scf.if %235 -> (i1) {
        %237 = arith.constant true
        scf.yield %237 : i1
      } else {
        %239 = llvm.load %233 : !llvm.ptr -> i64
        %240 = llvm.getelementptr %16[%239] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %238 = llvm.load %240 : !llvm.ptr -> i8
        %241 = arith.constant 0 : i32
        %243 = arith.extsi %238 : i8 to i32
        %242 = arith.cmpi ne, %243, %241 : i32
        scf.yield %242 : i1
      }
      cf.cond_br %236, ^bb39, ^bb40
      ^bb39:
        cf.br ^bb42
        ^bb42:
        %244 = llvm.load %233 : !llvm.ptr -> i64
        %245 = arith.cmpi sle, %244, %14 : i64
        %246 = scf.if %245 -> (i1) {
          %248 = llvm.load %233 : !llvm.ptr -> i64
          %249 = llvm.getelementptr %16[%248] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          %247 = llvm.load %249 : !llvm.ptr -> i8
          %250 = arith.constant 0 : i32
          %252 = arith.extsi %247 : i8 to i32
          %251 = arith.cmpi ne, %252, %250 : i32
          scf.yield %251 : i1
        } else {
          %253 = arith.constant false
          scf.yield %253 : i1
        }
        cf.cond_br %246, ^bb43, ^bb44
        ^bb43:
          %254 = llvm.load %233 : !llvm.ptr -> i64
          %255 = arith.constant 1 : i32
          %257 = arith.extsi %255 : i32 to i64
          %256 = arith.addi %254, %257 : i64
          llvm.store %256, %233 : i64, !llvm.ptr
          cf.br ^bb42
        ^bb44:
        %258 = llvm.load %233 : !llvm.ptr -> i64
        %259 = arith.cmpi sgt, %258, %14 : i64
        cf.cond_br %259, ^bb45, ^bb46
        ^bb45:
          cf.br ^bb23(%159 : index)
        ^bb46:
          cf.br ^bb47
        ^bb47:
        cf.br ^bb41
      ^bb40:
        cf.br ^bb41
      ^bb41:
      %261 = llvm.load %233 : !llvm.ptr -> i64
      %262 = arith.sitofp %261 : i64 to f64
      %260 = func.call @log10(%262) : (f64) -> f64
      %263 = arith.sitofp %163 : i64 to f64
      %264 = arith.mulf %263, %260 : f64
      %265 = llvm.load %233 : !llvm.ptr -> i64
      %266 = arith.sitofp %265 : i64 to f64
      %267 = arith.mulf %266, %164 : f64
      %268 = arith.addf %264, %267 : f64
      %269 = arith.subf %268, %7 : f64
      %270 = math.absf %269 : f64
      %271 = arith.constant 0.000000001 : f32
      %273 = arith.extf %271 : f32 to f64
      %272 = arith.cmpf olt, %270, %273 : f64
      cf.cond_br %272, ^bb48, ^bb49
      ^bb48:
        %274 = llvm.load %146 : !llvm.ptr -> i64
        %276 = llvm.load %233 : !llvm.ptr -> i64
        %277 = llvm.getelementptr %95[%276] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %275 = llvm.load %277 : !llvm.ptr -> i32
        %278 = arith.extsi %275 : i32 to i64
        %279 = arith.addi %274, %278 : i64
        %281 = llvm.getelementptr %95[%163] : (!llvm.ptr, i64) -> !llvm.ptr, i32
        %280 = llvm.load %281 : !llvm.ptr -> i32
        %282 = arith.extsi %280 : i32 to i64
        %283 = arith.subi %279, %282 : i64
        llvm.store %283, %146 : i64, !llvm.ptr
        cf.br ^bb50
      ^bb49:
        %284 = arith.cmpf ogt, %268, %7 : f64
        cf.cond_br %284, ^bb51, ^bb52
        ^bb51:
          %285 = llvm.load %146 : !llvm.ptr -> i64
          %287 = llvm.load %233 : !llvm.ptr -> i64
          %288 = llvm.getelementptr %95[%287] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %286 = llvm.load %288 : !llvm.ptr -> i32
          %289 = arith.extsi %286 : i32 to i64
          %290 = arith.addi %285, %289 : i64
          %292 = llvm.getelementptr %95[%163] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %291 = llvm.load %292 : !llvm.ptr -> i32
          %293 = arith.extsi %291 : i32 to i64
          %294 = arith.subi %290, %293 : i64
          %295 = arith.constant 1 : i32
          %297 = arith.extsi %295 : i32 to i64
          %296 = arith.subi %294, %297 : i64
          llvm.store %296, %146 : i64, !llvm.ptr
          cf.br ^bb53
        ^bb52:
          %298 = llvm.load %233 : !llvm.ptr -> i64
          %299 = arith.constant 1 : i32
          %301 = arith.extsi %299 : i32 to i64
          %300 = arith.addi %298, %301 : i64
          llvm.store %300, %233 : i64, !llvm.ptr
          cf.br ^bb54
          ^bb54:
          %302 = llvm.load %233 : !llvm.ptr -> i64
          %303 = arith.cmpi sle, %302, %14 : i64
          %304 = scf.if %303 -> (i1) {
            %306 = llvm.load %233 : !llvm.ptr -> i64
            %307 = llvm.getelementptr %16[%306] : (!llvm.ptr, i64) -> !llvm.ptr, i8
            %305 = llvm.load %307 : !llvm.ptr -> i8
            %308 = arith.constant 0 : i32
            %310 = arith.extsi %305 : i8 to i32
            %309 = arith.cmpi ne, %310, %308 : i32
            scf.yield %309 : i1
          } else {
            %311 = arith.constant false
            scf.yield %311 : i1
          }
          cf.cond_br %304, ^bb55, ^bb56
          ^bb55:
            %312 = llvm.load %233 : !llvm.ptr -> i64
            %313 = arith.constant 1 : i32
            %315 = arith.extsi %313 : i32 to i64
            %314 = arith.addi %312, %315 : i64
            llvm.store %314, %233 : i64, !llvm.ptr
            cf.br ^bb54
          ^bb56:
          %316 = llvm.load %233 : !llvm.ptr -> i64
          %317 = arith.cmpi sgt, %316, %14 : i64
          cf.cond_br %317, ^bb57, ^bb58
          ^bb57:
            cf.br ^bb23(%159 : index)
          ^bb58:
            cf.br ^bb59
          ^bb59:
          %318 = llvm.load %146 : !llvm.ptr -> i64
          %320 = llvm.load %233 : !llvm.ptr -> i64
          %321 = llvm.getelementptr %95[%320] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %319 = llvm.load %321 : !llvm.ptr -> i32
          %322 = arith.extsi %319 : i32 to i64
          %323 = arith.addi %318, %322 : i64
          %325 = llvm.getelementptr %95[%163] : (!llvm.ptr, i64) -> !llvm.ptr, i32
          %324 = llvm.load %325 : !llvm.ptr -> i32
          %326 = arith.extsi %324 : i32 to i64
          %327 = arith.subi %323, %326 : i64
          %328 = arith.constant 1 : i32
          %330 = arith.extsi %328 : i32 to i64
          %329 = arith.subi %327, %330 : i64
          llvm.store %329, %146 : i64, !llvm.ptr
          cf.br ^bb53
        ^bb53:
        cf.br ^bb50
      ^bb50:
      %331 = arith.addi %159, %151 : index
      cf.br ^bb21(%331 : index)
    ^bb23(%332: index):
    func.call @free(%16) : (!llvm.ptr) -> ()
    func.call @free(%54) : (!llvm.ptr) -> ()
    func.call @free(%95) : (!llvm.ptr) -> ()
    %336 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %337 = llvm.load %146 : !llvm.ptr -> i64
    %338 = llvm.call @printf(%336, %337) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %339 = arith.constant 0 : i32
    func.return %339 : i32
  }
}