Problem 905

Now I Know — epistemic hat game reduced to accelerated Euclidean process. Sum F(a^b, b^a, a^b+b^a) for a=1..7, b=1..19.

Answer70228218
Output70228218
StatusPASS
Native helperno
Runtime0 ms
Peak memory1072 KB
Time complexityO(n^2) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)?
Space complexityO(1)?
ApproachFlow solutionNot curated
VerdictUnknown

Flow source

# Project Euler 905
# Now I Know — epistemic hat game reduced to accelerated Euclidean process.
# Sum F(a^b, b^a, a^b+b^a) for a=1..7, b=1..19.

function ipow(base: i64, exp: i64) -> i64 {
    let mut r: i64 = 1
    let mut b: i64 = base
    let mut e: i64 = exp
    while e > 0 {
        if (e & 1) == 1 { r = r * b }
        b = b * b
        e = e / 2
    }
    return r
}

function k_fast(state0: i64, a0: i64, b0: i64) -> i64 {
    let mut state: i64 = state0
    let mut a: i64 = a0
    let mut b: i64 = b0
    let mut cost: i64 = 0
    while a != b {
        if state == 2 {
            if a > b {
                let p: i64 = (a - 1) / (2 * b)
                if p > 0 {
                    cost = cost + p
                    a = a - 2 * b * p
                } else {
                    cost = cost + 1
                    state = 0
                    let na: i64 = b
                    let nb: i64 = a - b
                    a = na
                    b = nb
                }
            } else {
                let p2: i64 = (b - 1) / (2 * a)
                if p2 > 0 {
                    cost = cost + p2
                    b = b - 2 * a * p2
                } else {
                    cost = cost + 1
                    state = 1
                    b = b - a
                }
            }
        } else {
            if state == 0 {
                if a > b {
                    let p3: i64 = (a - 1) / (2 * b)
                    if p3 > 0 {
                        cost = cost + p3
                        a = a - 2 * b * p3
                    } else {
                        cost = cost + 1
                        state = 1
                        a = a - b
                    }
                } else {
                    state = 2
                    let na2: i64 = b - a
                    let nb2: i64 = a
                    a = na2
                    b = nb2
                }
            } else {
                if a > b {
                    state = 0
                    a = a - b
                } else {
                    state = 2
                    b = b - a
                }
            }
        }
    }
    if state == 2 {
        return cost + 1
    }
    return cost
}

function F(A: i64, B: i64, C: i64) -> i64 {
    if A == B + C {
        return 3 * k_fast(0, B, C) + 1
    }
    if B == A + C {
        return 3 * k_fast(1, A, C) + 2
    }
    if C == A + B {
        return 3 * k_fast(2, A, B)
    }
    return 0
}

function main() -> i32 {
    let mut total: i64 = 0
    let mut a: i64 = 1
    while a <= 7 {
        let mut b: i64 = 1
        while b <= 19 {
            let A: i64 = ipow(a, b)
            let B: i64 = ipow(b, a)
            total = total + F(A, B, A + B)
            b = b + 1
        }
        a = a + 1
    }
    printf("%lld\n", total)
    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 ipow_i64_i64(int64_t base, int64_t exp);
int64_t k_fast_i64_i64_i64(int64_t state0, int64_t a0, int64_t b0);
int64_t F_i64_i64_i64(int64_t A, int64_t B, int64_t C);
int32_t main(void);

int64_t ipow_i64_i64(int64_t base, int64_t exp) {
    int64_t r = 1;
    int64_t b = base;
    int64_t e = exp;
    while (e > 0) {
        if ((e & 1) == 1) {
            r = (r * b);
        }
        b = (b * b);
        e = FLOW_CHECKED_DIV((e), (2));
    }
    return r;
}

int64_t k_fast_i64_i64_i64(int64_t state0, int64_t a0, int64_t b0) {
    int64_t state = state0;
    int64_t a = a0;
    int64_t b = b0;
    int64_t cost = 0;
    while (a != b) {
        if (state == 2) {
            if (a > b) {
                int64_t p = FLOW_CHECKED_DIV(((a - 1)), ((2 * b)));
                if (p > 0) {
                    cost = (cost + p);
                    a = (a - ((2 * b) * p));
                } else {
                    cost = (cost + 1);
                    state = 0;
                    int64_t na = b;
                    int64_t nb = (a - b);
                    a = na;
                    b = nb;
                }
            } else {
                int64_t p2 = FLOW_CHECKED_DIV(((b - 1)), ((2 * a)));
                if (p2 > 0) {
                    cost = (cost + p2);
                    b = (b - ((2 * a) * p2));
                } else {
                    cost = (cost + 1);
                    state = 1;
                    b = (b - a);
                }
            }
        } else {
            if (state == 0) {
                if (a > b) {
                    int64_t p3 = FLOW_CHECKED_DIV(((a - 1)), ((2 * b)));
                    if (p3 > 0) {
                        cost = (cost + p3);
                        a = (a - ((2 * b) * p3));
                    } else {
                        cost = (cost + 1);
                        state = 1;
                        a = (a - b);
                    }
                } else {
                    state = 2;
                    int64_t na2 = (b - a);
                    int64_t nb2 = a;
                    a = na2;
                    b = nb2;
                }
            } else {
                if (a > b) {
                    state = 0;
                    a = (a - b);
                } else {
                    state = 2;
                    b = (b - a);
                }
            }
        }
    }
    if (state == 2) {
        return (cost + 1);
    }
    return cost;
}

int64_t F_i64_i64_i64(int64_t A, int64_t B, int64_t C) {
    if (A == (B + C)) {
        return ((3 * k_fast_i64_i64_i64(0, B, C)) + 1);
    }
    if (B == (A + C)) {
        return ((3 * k_fast_i64_i64_i64(1, A, C)) + 2);
    }
    if (C == (A + B)) {
        return (3 * k_fast_i64_i64_i64(2, A, B));
    }
    return 0;
}

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