Problem 795

Alternating GCD Sum — G(12345678). Ported from native C to pure Flow. Uses i128 for prime power calculations.

Answer955892601606483
Output955892601606483
StatusPASS
Native helperno
Runtime80 ms
Peak memory52672 KB
Time complexityO(n^3) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^3)O(n log log n)
Space complexityO(n)O(n)
ApproachFlow solutionSieve of Eratosthenes
VerdictSuboptimal

Flow source

# Project Euler 795
# Alternating GCD Sum — G(12345678).
# Ported from native C to pure Flow. Uses i128 for prime power calculations.

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

function pow_i(p: i64, e: i64) -> i64 {
    let mut r: i64 = 1
    for i in 0..e {
        r = r * p
    }
    return r
}

function a_prime_power(p: i64, e: i64) -> i64 {
    if e == 0 {
        return 1
    }
    if (e & 1) == 1 {
        let k: i64 = e >> 1
        return pow_i(p, e - 1) * (2 * pow_i(p, k + 1) - 1)
    }
    let k: i64 = e >> 1
    return pow_i(p, e - 1) * ((p + 1) * pow_i(p, k) - 1)
}

function main() -> i32 {
    let N: i64 = 12345678
    let limit: i64 = N / 2
    let spf: ptr<i64> = calloc(limit + 1, 8) as ptr<i64>
    let primes: ptr<i64> = malloc((limit + 1) * 8) as ptr<i64>
    let mut pc: i64 = 0
    for i in 2..(limit + 1) {
        if spf[i] == 0 {
            spf[i] = i
            primes[pc] = i
            pc = pc + 1
        }
        for j in 0..pc {
            let p: i64 = primes[j]
            let x: i64 = p * i
            if x > limit || p > spf[i] {
                break
            }
            spf[x] = p
            if p == spf[i] {
                break
            }
        }
    }

    let c2: ptr<i64> = calloc(65, 8) as ptr<i64>
    for a in 1..65 {
        if ((1 as i64) << a) > N {
            break
        }
        c2[a] = a_prime_power(2, a) - ((1 as i64) << a)
    }

    let odd_cnt: i64 = (N + 1) / 2
    let mut total: i64 = -(odd_cnt * odd_cnt)

    let mut m: i64 = 1
    while m <= limit {
        let mut a_m: i64 = 1
        if m != 1 {
            let mut n: i64 = m
            a_m = 1
            while n > 1 {
                let p: i64 = spf[n]
                let mut e: i64 = 0
                while n % p == 0 {
                    n = n / p
                    e = e + 1
                }
                a_m = a_m * a_prime_power(p, e)
            }
        }
        let mut a: i64 = 1
        let mut n: i64 = m << 1
        while n <= N {
            total = total + a_m * c2[a]
            a = a + 1
            n = n << 1
        }
        m = m + 2
    }

    printf("%lld\n", total)
    free(spf as ptr<void>)
    free(primes as ptr<void>)
    free(c2 as ptr<void>)
    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 pow_i_i64_i64(int64_t p, int64_t e);
int64_t a_prime_power_i64_i64(int64_t p, int64_t e);
int32_t main(void);




int64_t pow_i_i64_i64(int64_t p, int64_t e) {
    int64_t r = 1;
    int32_t __flow_step_1 = 1;
    for (int32_t i = 0; (0 <= e) ? i < e : i > e; i += (0 <= e) ? 1 : -1) {
        r = (r * p);
    }
    return r;
}

int64_t a_prime_power_i64_i64(int64_t p, int64_t e) {
    if (e == 0) {
        return 1;
    }
    if ((e & 1) == 1) {
        int64_t k = FLOW_CHECKED_SHR((e), (1));
        return (pow_i_i64_i64(p, (e - 1)) * ((2 * pow_i_i64_i64(p, (k + 1))) - 1));
    }
    int64_t k = FLOW_CHECKED_SHR((e), (1));
    return (pow_i_i64_i64(p, (e - 1)) * (((p + 1) * pow_i_i64_i64(p, k)) - 1));
}

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