Problem 167

Sum of U(2, 2n+1)_k for n=2..10, k=10^11.

Answer3916160068885
Output3916160068885
StatusPASS
Native helperno
Runtime20 ms
Peak memory22464 KB
Time complexityO(n) (estimated)
Space complexityO(n) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n)O(n log log n)
Space complexityO(n)O(n)
ApproachFlow solutionSieve or enumeration
VerdictOptimal

Flow source

# Project Euler 167
# Sum of U(2, 2n+1)_k for n=2..10, k=10^11.

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

function ulam_2_v_k(v: i64, k: i64) -> i64 {
    if k == 1 { return 2 }
    if k == 2 { return v }

    let target_odd: i64 = k - 2
    let m: i32 = (v + 1) as i32
    let n: i32 = ((v - 1) / 2) as i32

    let init_bits: ptr<i8> = calloc(m as i64, 1)
    if init_bits == null { return 0 }
    for t in n..(2 * n + 2) {
        init_bits[t] = 1
    }

    let mut state: i64 = 0
    for i in 0..m {
        if init_bits[m - 1 - i] != 0 {
            state = state | (1 << i)
        }
    }
    let init_state: i64 = state
    let mask: i64 = (1 << m) - 1

    # Collect bits until period; max period for these v is modest
    let max_bits: i64 = 5000000
    let bits: ptr<i8> = calloc(max_bits, 1)
    if bits == null { free(init_bits); return 0 }
    for i in 0..m {
        bits[i] = init_bits[i]
    }
    let mut period: i32 = 0
    let mut len: i32 = m
    while true {
        let new_bit: i8 = ((state & 1) ^ ((state >> (m - 1)) & 1)) as i8
        state = ((state << 1) & mask) | (new_bit as i64)
        bits[len] = new_bit
        len = len + 1
        period = period + 1
        if state == init_state { break }
        if len as i64 >= max_bits { break }
    }

    # ones positions in one period of f[0..)
    let ones: ptr<i32> = calloc(period as i64, 4)
    if ones == null { free(bits); free(init_bits); return 0 }
    let mut ones_count: i32 = 0
    for i in 0..period {
        if bits[i] != 0 {
            ones[ones_count] = i
            ones_count = ones_count + 1
        }
    }

    let q: i64 = (target_odd - 1) / (ones_count as i64)
    let r: i64 = (target_odd - 1) % (ones_count as i64)
    let t_idx: i64 = q * (period as i64) + (ones[r] as i64)
    let result: i64 = 2 * t_idx + 1

    free(ones)
    free(bits)
    free(init_bits)
    return result
}

function main() -> i32 {
    let k: i64 = 100000000000
    let mut ans: i64 = 0
    for n in 2..11 {
        ans = ans + ulam_2_v_k(2 * n + 1, k)
    }
    printf("%lld\n", ans)
    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 ulam_2_v_k_i64_i64(int64_t v, int64_t k);
int32_t main(void);



int64_t ulam_2_v_k_i64_i64(int64_t v, int64_t k) {
    if (k == 1) {
        return 2;
    }
    if (k == 2) {
        return v;
    }
    int64_t target_odd = (k - 2);
    int32_t m = ((int32_t)((v + 1)));
    int32_t n = ((int32_t)(FLOW_CHECKED_DIV(((v - 1)), (2))));
    int8_t* init_bits = (int8_t*)(calloc(((int64_t)(m)), 1));
    if (init_bits == NULL) {
        return 0;
    }
    int32_t __flow_step_1 = 1;
    for (int32_t t = n; (n <= ((2 * n) + 2)) ? t < ((2 * n) + 2) : t > ((2 * n) + 2); t += (n <= ((2 * n) + 2)) ? 1 : -1) {
        init_bits[t] = 1;
    }
    int64_t state = 0;
    int32_t __flow_step_2 = 1;
    for (int32_t i = 0; (0 <= m) ? i < m : i > m; i += (0 <= m) ? 1 : -1) {
        if (init_bits[((m - 1) - i)] != 0) {
            state = (state | FLOW_CHECKED_SHL((1), (i)));
        }
    }
    int64_t init_state = state;
    int64_t mask = (FLOW_CHECKED_SHL((1), (m)) - 1);
    int64_t max_bits = 5000000;
    int8_t* bits = (int8_t*)(calloc(max_bits, 1));
    if (bits == NULL) {
        free(init_bits);
        return 0;
    }
    int32_t __flow_step_3 = 1;
    for (int32_t i = 0; (0 <= m) ? i < m : i > m; i += (0 <= m) ? 1 : -1) {
        bits[i] = init_bits[i];
    }
    int32_t period = 0;
    int32_t len = m;
    while (1) {
        int8_t new_bit = ((int8_t)(((state & 1) ^ (FLOW_CHECKED_SHR((state), ((m - 1))) & 1))));
        state = ((FLOW_CHECKED_SHL((state), (1)) & mask) | ((int64_t)(new_bit)));
        bits[len] = new_bit;
        len = (len + 1);
        period = (period + 1);
        if (state == init_state) {
            break;
        }
        if (((int64_t)(len)) >= max_bits) {
            break;
        }
    }
    int32_t* ones = (int32_t*)(calloc(((int64_t)(period)), 4));
    if (ones == NULL) {
        free(bits);
        free(init_bits);
        return 0;
    }
    int32_t ones_count = 0;
    int32_t __flow_step_4 = 1;
    for (int32_t i = 0; (0 <= period) ? i < period : i > period; i += (0 <= period) ? 1 : -1) {
        if (bits[i] != 0) {
            ones[ones_count] = i;
            ones_count = (ones_count + 1);
        }
    }
    int64_t q = FLOW_CHECKED_DIV(((target_odd - 1)), (((int64_t)(ones_count))));
    int64_t r = FLOW_CHECKED_MOD(((target_odd - 1)), (((int64_t)(ones_count))));
    int64_t t_idx = ((q * ((int64_t)(period))) + ((int64_t)(ones[r])));
    int64_t result = ((2 * t_idx) + 1);
    free(ones);
    free(bits);
    free(init_bits);
    return result;
}

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