Problem 623

Lambda-term counts by size up to 2000, mod 1e9+7.

Answer3679796
Output3679796
StatusPASS
Native helperno
Runtime1330 ms
Peak memory1424 KB
Time complexityO(n) (estimated)
Space complexityO(n) (estimated)

Performance comparison

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

Flow source

# Project Euler 623
# Lambda-term counts by size up to 2000, mod 1e9+7.

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

const MOD: i64 = 1000000007
const LIMIT: i64 = 2000

function main() -> i32 {
    let next_layer: ptr<i64> = calloc(LIMIT + 1, 8)
    if next_layer == null { return 1 }
    let dmax: i64 = (LIMIT - 1) / 5
    let mut depth: i64 = dmax
    while depth >= 0 {
        let max_size: i64 = LIMIT - 5 * depth
        let current: ptr<i64> = calloc(max_size + 1, 8)
        let convolution: ptr<i64> = calloc(max_size + 1, 8)
        if current == null || convolution == null { return 1 }
        let max_convolution_index: i64 = max_size - 2
        let mut size: i64 = 1
        while size <= max_size {
            let mut value: i64 = 0
            if size >= 2 { value = convolution[size - 2] }
            if size == 1 { value = value + depth }
            if size >= 5 {
                let shifted: i64 = size - 5
                if shifted <= LIMIT {
                    value = value + next_layer[shifted]
                }
            }
            value = value % MOD
            current[size] = value
            if value != 0 {
                let double_value: i64 = (2 * value) % MOD
                let upper: i64 = size - 1
                if max_convolution_index - size < upper {
                    upper = max_convolution_index - size
                }
                let mut other_size: i64 = 1
                while other_size <= upper {
                    let index: i64 = size + other_size
                    let t: i128 = (convolution[index] as i128) + (double_value as i128) * (current[other_size] as i128)
                    convolution[index] = (t % (MOD as i128)) as i64
                    other_size = other_size + 1
                }
                let diagonal: i64 = 2 * size
                if diagonal <= max_convolution_index {
                    let t2: i128 = (convolution[diagonal] as i128) + (value as i128) * (value as i128)
                    convolution[diagonal] = (t2 % (MOD as i128)) as i64
                }
            }
            size = size + 1
        }
        free(next_layer)
        next_layer = current
        free(convolution)
        depth = depth - 1
    }
    let mut cumulative: i64 = 0
    let mut size: i64 = 0
    while size <= LIMIT {
        cumulative = (cumulative + next_layer[size]) % MOD
        size = size + 1
    }
    free(next_layer)
    printf("%lld\n", cumulative)
    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);

static const int64_t MOD = 1000000007;
static const int64_t LIMIT = 2000;



int32_t main(void) {
    int64_t* next_layer = (int64_t*)(calloc((LIMIT + 1), 8));
    if (next_layer == NULL) {
        return 1;
    }
    int64_t dmax = FLOW_CHECKED_DIV(((LIMIT - 1)), (5));
    int64_t depth = dmax;
    while (depth >= 0) {
        int64_t max_size = (LIMIT - (5 * depth));
        int64_t* current = (int64_t*)(calloc((max_size + 1), 8));
        int64_t* convolution = (int64_t*)(calloc((max_size + 1), 8));
        if ((current == NULL || convolution == NULL)) {
            return 1;
        }
        int64_t max_convolution_index = (max_size - 2);
        int64_t size = 1;
        while (size <= max_size) {
            int64_t value = 0;
            if (size >= 2) {
                value = convolution[(size - 2)];
            }
            if (size == 1) {
                value = (value + depth);
            }
            if (size >= 5) {
                int64_t shifted = (size - 5);
                if (shifted <= LIMIT) {
                    value = (value + next_layer[shifted]);
                }
            }
            value = FLOW_CHECKED_MOD((value), (MOD));
            current[size] = value;
            if (value != 0) {
                int64_t double_value = FLOW_CHECKED_MOD(((2 * value)), (MOD));
                int64_t upper = (size - 1);
                if ((max_convolution_index - size) < upper) {
                    upper = (max_convolution_index - size);
                }
                int64_t other_size = 1;
                while (other_size <= upper) {
                    int64_t index = (size + other_size);
                    __int128 t = (((__int128)(convolution[index])) + (((__int128)(double_value)) * ((__int128)(current[other_size]))));
                    convolution[index] = ((int64_t)(FLOW_CHECKED_MOD((t), (((__int128)(MOD))))));
                    other_size = (other_size + 1);
                }
                int64_t diagonal = (2 * size);
                if (diagonal <= max_convolution_index) {
                    __int128 t2 = (((__int128)(convolution[diagonal])) + (((__int128)(value)) * ((__int128)(value))));
                    convolution[diagonal] = ((int64_t)(FLOW_CHECKED_MOD((t2), (((__int128)(MOD))))));
                }
            }
            size = (size + 1);
        }
        free(next_layer);
        next_layer = current;
        free(convolution);
        depth = (depth - 1);
    }
    int64_t cumulative = 0;
    int64_t size = 0;
    while (size <= LIMIT) {
        cumulative = FLOW_CHECKED_MOD(((cumulative + next_layer[size])), (MOD));
        size = (size + 1);
    }
    free(next_layer);
    printf("%lld\n", cumulative);
    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) -> ()
  // Constant: MOD
  llvm.mlir.global internal constant @MOD(1000000007 : i64) : i64
  // Constant: LIMIT
  llvm.mlir.global internal constant @LIMIT(2000 : i64) : i64
  func.func @main() -> i32 {
    %1 = llvm.mlir.addressof @LIMIT : !llvm.ptr
    %2 = llvm.load %1 : !llvm.ptr -> i64
    %3 = arith.constant 1 : i32
    %5 = arith.extsi %3 : i32 to i64
    %4 = arith.addi %2, %5 : i64
    %6 = arith.constant 8 : i32
    %7 = arith.extsi %6 : i32 to i64
    %0 = func.call @calloc(%4, %7) : (i64, i64) -> !llvm.ptr
    %8 = llvm.mlir.zero : !llvm.ptr
    %9 = llvm.icmp "eq" %0, %8 : !llvm.ptr
    cf.cond_br %9, ^bb0, ^bb1
    ^bb0:
      %10 = arith.constant 1 : i32
      func.return %10 : i32
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %11 = llvm.mlir.addressof @LIMIT : !llvm.ptr
    %12 = llvm.load %11 : !llvm.ptr -> i64
    %13 = arith.constant 1 : i32
    %15 = arith.extsi %13 : i32 to i64
    %14 = arith.subi %12, %15 : i64
    %16 = arith.constant 5 : i32
    %18 = arith.extsi %16 : i32 to i64
    %17 = arith.divsi %14, %18 : i64
    %19 = llvm.mlir.constant(1 : i64) : i64
    %20 = llvm.alloca %19 x i64 : (i64) -> !llvm.ptr
    llvm.store %17, %20 : i64, !llvm.ptr
    cf.br ^bb3(%0 : !llvm.ptr)
    ^bb3(%21: !llvm.ptr):
    %22 = llvm.load %20 : !llvm.ptr -> i64
    %23 = arith.constant 0 : i32
    %25 = arith.extsi %23 : i32 to i64
    %24 = arith.cmpi sge, %22, %25 : i64
    cf.cond_br %24, ^bb4(%21 : !llvm.ptr), ^bb5(%21 : !llvm.ptr)
    ^bb4(%26: !llvm.ptr):
      %27 = llvm.mlir.addressof @LIMIT : !llvm.ptr
      %28 = llvm.load %27 : !llvm.ptr -> i64
      %29 = arith.constant 5 : i32
      %30 = llvm.load %20 : !llvm.ptr -> i64
      %32 = arith.extsi %29 : i32 to i64
      %31 = arith.muli %32, %30 : i64
      %33 = arith.subi %28, %31 : i64
      %35 = arith.constant 1 : i32
      %37 = arith.extsi %35 : i32 to i64
      %36 = arith.addi %33, %37 : i64
      %38 = arith.constant 8 : i32
      %39 = arith.extsi %38 : i32 to i64
      %34 = func.call @calloc(%36, %39) : (i64, i64) -> !llvm.ptr
      %41 = arith.constant 1 : i32
      %43 = arith.extsi %41 : i32 to i64
      %42 = arith.addi %33, %43 : i64
      %44 = arith.constant 8 : i32
      %45 = arith.extsi %44 : i32 to i64
      %40 = func.call @calloc(%42, %45) : (i64, i64) -> !llvm.ptr
      %46 = llvm.mlir.zero : !llvm.ptr
      %47 = llvm.icmp "eq" %34, %46 : !llvm.ptr
      %48 = scf.if %47 -> (i1) {
        %49 = arith.constant true
        scf.yield %49 : i1
      } else {
        %50 = llvm.mlir.zero : !llvm.ptr
        %51 = llvm.icmp "eq" %40, %50 : !llvm.ptr
        scf.yield %51 : i1
      }
      cf.cond_br %48, ^bb6, ^bb7
      ^bb6:
        %52 = arith.constant 1 : i32
        func.return %52 : i32
      ^bb7:
        cf.br ^bb8
      ^bb8:
      %53 = arith.constant 2 : i32
      %55 = arith.extsi %53 : i32 to i64
      %54 = arith.subi %33, %55 : i64
      %56 = arith.constant 1 : i32
      %57 = arith.extsi %56 : i32 to i64
      %58 = llvm.mlir.constant(1 : i64) : i64
      %59 = llvm.alloca %58 x i64 : (i64) -> !llvm.ptr
      llvm.store %57, %59 : i64, !llvm.ptr
      cf.br ^bb9
      ^bb9:
      %60 = llvm.load %59 : !llvm.ptr -> i64
      %61 = arith.cmpi sle, %60, %33 : i64
      cf.cond_br %61, ^bb10, ^bb11
      ^bb10:
        %62 = arith.constant 0 : i32
        %63 = arith.extsi %62 : i32 to i64
        %64 = llvm.mlir.constant(1 : i64) : i64
        %65 = llvm.alloca %64 x i64 : (i64) -> !llvm.ptr
        llvm.store %63, %65 : i64, !llvm.ptr
        %66 = llvm.load %59 : !llvm.ptr -> i64
        %67 = arith.constant 2 : i32
        %69 = arith.extsi %67 : i32 to i64
        %68 = arith.cmpi sge, %66, %69 : i64
        cf.cond_br %68, ^bb12, ^bb13
        ^bb12:
          %71 = llvm.load %59 : !llvm.ptr -> i64
          %72 = arith.constant 2 : i32
          %74 = arith.extsi %72 : i32 to i64
          %73 = arith.subi %71, %74 : i64
          %75 = llvm.getelementptr %40[%73] : (!llvm.ptr, i64) -> !llvm.ptr, i64
          %70 = llvm.load %75 : !llvm.ptr -> i64
          llvm.store %70, %65 : i64, !llvm.ptr
          cf.br ^bb14
        ^bb13:
          cf.br ^bb14
        ^bb14:
        %76 = llvm.load %59 : !llvm.ptr -> i64
        %77 = arith.constant 1 : i32
        %79 = arith.extsi %77 : i32 to i64
        %78 = arith.cmpi eq, %76, %79 : i64
        cf.cond_br %78, ^bb15, ^bb16
        ^bb15:
          %80 = llvm.load %65 : !llvm.ptr -> i64
          %81 = llvm.load %20 : !llvm.ptr -> i64
          %82 = arith.addi %80, %81 : i64
          llvm.store %82, %65 : i64, !llvm.ptr
          cf.br ^bb17
        ^bb16:
          cf.br ^bb17
        ^bb17:
        %83 = llvm.load %59 : !llvm.ptr -> i64
        %84 = arith.constant 5 : i32
        %86 = arith.extsi %84 : i32 to i64
        %85 = arith.cmpi sge, %83, %86 : i64
        cf.cond_br %85, ^bb18, ^bb19
        ^bb18:
          %87 = llvm.load %59 : !llvm.ptr -> i64
          %88 = arith.constant 5 : i32
          %90 = arith.extsi %88 : i32 to i64
          %89 = arith.subi %87, %90 : i64
          %91 = llvm.mlir.addressof @LIMIT : !llvm.ptr
          %92 = llvm.load %91 : !llvm.ptr -> i64
          %93 = arith.cmpi sle, %89, %92 : i64
          cf.cond_br %93, ^bb21, ^bb22
          ^bb21:
            %94 = llvm.load %65 : !llvm.ptr -> i64
            %96 = llvm.getelementptr %26[%89] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %95 = llvm.load %96 : !llvm.ptr -> i64
            %97 = arith.addi %94, %95 : i64
            llvm.store %97, %65 : i64, !llvm.ptr
            cf.br ^bb23
          ^bb22:
            cf.br ^bb23
          ^bb23:
          cf.br ^bb20
        ^bb19:
          cf.br ^bb20
        ^bb20:
        %98 = llvm.load %65 : !llvm.ptr -> i64
        %99 = llvm.mlir.addressof @MOD : !llvm.ptr
        %100 = llvm.load %99 : !llvm.ptr -> i64
        %101 = arith.remsi %98, %100 : i64
        llvm.store %101, %65 : i64, !llvm.ptr
        %102 = llvm.load %65 : !llvm.ptr -> i64
        %103 = llvm.load %59 : !llvm.ptr -> i64
        %104 = llvm.getelementptr %34[%103] : (!llvm.ptr, i64) -> !llvm.ptr, i64
        llvm.store %102, %104 : i64, !llvm.ptr
        %105 = llvm.load %65 : !llvm.ptr -> i64
        %106 = arith.constant 0 : i32
        %108 = arith.extsi %106 : i32 to i64
        %107 = arith.cmpi ne, %105, %108 : i64
        cf.cond_br %107, ^bb24, ^bb25
        ^bb24:
          %109 = arith.constant 2 : i32
          %110 = llvm.load %65 : !llvm.ptr -> i64
          %112 = arith.extsi %109 : i32 to i64
          %111 = arith.muli %112, %110 : i64
          %113 = llvm.mlir.addressof @MOD : !llvm.ptr
          %114 = llvm.load %113 : !llvm.ptr -> i64
          %115 = arith.remsi %111, %114 : i64
          %116 = llvm.load %59 : !llvm.ptr -> i64
          %117 = arith.constant 1 : i32
          %119 = arith.extsi %117 : i32 to i64
          %118 = arith.subi %116, %119 : i64
          %120 = llvm.load %59 : !llvm.ptr -> i64
          %121 = arith.subi %54, %120 : i64
          %122 = arith.cmpi slt, %121, %118 : i64
          %123 = scf.if %122 -> (i64) {
            %124 = llvm.load %59 : !llvm.ptr -> i64
            %125 = arith.subi %54, %124 : i64
            scf.yield %125 : i64
          } else {
            scf.yield %118 : i64
          }
          %126 = arith.constant 1 : i32
          %127 = arith.extsi %126 : i32 to i64
          %128 = llvm.mlir.constant(1 : i64) : i64
          %129 = llvm.alloca %128 x i64 : (i64) -> !llvm.ptr
          llvm.store %127, %129 : i64, !llvm.ptr
          cf.br ^bb27
          ^bb27:
          %130 = llvm.load %129 : !llvm.ptr -> i64
          %131 = arith.cmpi sle, %130, %123 : i64
          cf.cond_br %131, ^bb28, ^bb29
          ^bb28:
            %132 = llvm.load %59 : !llvm.ptr -> i64
            %133 = llvm.load %129 : !llvm.ptr -> i64
            %134 = arith.addi %132, %133 : i64
            %136 = llvm.getelementptr %40[%134] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %135 = llvm.load %136 : !llvm.ptr -> i64
            %137 = arith.extsi %135 : i64 to i128
            %138 = arith.extsi %115 : i64 to i128
            %140 = llvm.load %129 : !llvm.ptr -> i64
            %141 = llvm.getelementptr %34[%140] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %139 = llvm.load %141 : !llvm.ptr -> i64
            %142 = arith.extsi %139 : i64 to i128
            %144 = arith.trunci %138 : i128 to i64
            %145 = arith.trunci %142 : i128 to i64
            %143 = arith.muli %144, %145 : i64
            %147 = arith.trunci %137 : i128 to i64
            %146 = arith.addi %147, %143 : i64
            %148 = arith.extsi %146 : i64 to i128
            %149 = llvm.mlir.addressof @MOD : !llvm.ptr
            %150 = llvm.load %149 : !llvm.ptr -> i64
            %151 = arith.extsi %150 : i64 to i128
            %153 = arith.trunci %148 : i128 to i64
            %154 = arith.trunci %151 : i128 to i64
            %152 = arith.remsi %153, %154 : i64
            %155 = llvm.getelementptr %40[%134] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            llvm.store %152, %155 : i64, !llvm.ptr
            %156 = llvm.load %129 : !llvm.ptr -> i64
            %157 = arith.constant 1 : i32
            %159 = arith.extsi %157 : i32 to i64
            %158 = arith.addi %156, %159 : i64
            llvm.store %158, %129 : i64, !llvm.ptr
            cf.br ^bb27
          ^bb29:
          %160 = arith.constant 2 : i32
          %161 = llvm.load %59 : !llvm.ptr -> i64
          %163 = arith.extsi %160 : i32 to i64
          %162 = arith.muli %163, %161 : i64
          %164 = arith.cmpi sle, %162, %54 : i64
          cf.cond_br %164, ^bb30, ^bb31
          ^bb30:
            %166 = llvm.getelementptr %40[%162] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            %165 = llvm.load %166 : !llvm.ptr -> i64
            %167 = arith.extsi %165 : i64 to i128
            %168 = llvm.load %65 : !llvm.ptr -> i64
            %169 = arith.extsi %168 : i64 to i128
            %170 = llvm.load %65 : !llvm.ptr -> i64
            %171 = arith.extsi %170 : i64 to i128
            %173 = arith.trunci %169 : i128 to i64
            %174 = arith.trunci %171 : i128 to i64
            %172 = arith.muli %173, %174 : i64
            %176 = arith.trunci %167 : i128 to i64
            %175 = arith.addi %176, %172 : i64
            %177 = arith.extsi %175 : i64 to i128
            %178 = llvm.mlir.addressof @MOD : !llvm.ptr
            %179 = llvm.load %178 : !llvm.ptr -> i64
            %180 = arith.extsi %179 : i64 to i128
            %182 = arith.trunci %177 : i128 to i64
            %183 = arith.trunci %180 : i128 to i64
            %181 = arith.remsi %182, %183 : i64
            %184 = llvm.getelementptr %40[%162] : (!llvm.ptr, i64) -> !llvm.ptr, i64
            llvm.store %181, %184 : i64, !llvm.ptr
            cf.br ^bb32
          ^bb31:
            cf.br ^bb32
          ^bb32:
          cf.br ^bb26
        ^bb25:
          cf.br ^bb26
        ^bb26:
        %185 = llvm.load %59 : !llvm.ptr -> i64
        %186 = arith.constant 1 : i32
        %188 = arith.extsi %186 : i32 to i64
        %187 = arith.addi %185, %188 : i64
        llvm.store %187, %59 : i64, !llvm.ptr
        cf.br ^bb9
      ^bb11:
      func.call @free(%26) : (!llvm.ptr) -> ()
      func.call @free(%40) : (!llvm.ptr) -> ()
      %191 = llvm.load %20 : !llvm.ptr -> i64
      %192 = arith.constant 1 : i32
      %194 = arith.extsi %192 : i32 to i64
      %193 = arith.subi %191, %194 : i64
      llvm.store %193, %20 : i64, !llvm.ptr
      cf.br ^bb3(%34 : !llvm.ptr)
    ^bb5(%195: !llvm.ptr):
    %196 = arith.constant 0 : i32
    %197 = arith.extsi %196 : i32 to i64
    %198 = llvm.mlir.constant(1 : i64) : i64
    %199 = llvm.alloca %198 x i64 : (i64) -> !llvm.ptr
    llvm.store %197, %199 : i64, !llvm.ptr
    %200 = arith.constant 0 : i32
    %201 = arith.extsi %200 : i32 to i64
    %202 = llvm.mlir.constant(1 : i64) : i64
    %203 = llvm.alloca %202 x i64 : (i64) -> !llvm.ptr
    llvm.store %201, %203 : i64, !llvm.ptr
    cf.br ^bb33
    ^bb33:
    %204 = llvm.load %203 : !llvm.ptr -> i64
    %205 = llvm.mlir.addressof @LIMIT : !llvm.ptr
    %206 = llvm.load %205 : !llvm.ptr -> i64
    %207 = arith.cmpi sle, %204, %206 : i64
    cf.cond_br %207, ^bb34, ^bb35
    ^bb34:
      %208 = llvm.load %199 : !llvm.ptr -> i64
      %210 = llvm.load %203 : !llvm.ptr -> i64
      %211 = llvm.getelementptr %195[%210] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %209 = llvm.load %211 : !llvm.ptr -> i64
      %212 = arith.addi %208, %209 : i64
      %213 = llvm.mlir.addressof @MOD : !llvm.ptr
      %214 = llvm.load %213 : !llvm.ptr -> i64
      %215 = arith.remsi %212, %214 : i64
      llvm.store %215, %199 : i64, !llvm.ptr
      %216 = llvm.load %203 : !llvm.ptr -> i64
      %217 = arith.constant 1 : i32
      %219 = arith.extsi %217 : i32 to i64
      %218 = arith.addi %216, %219 : i64
      llvm.store %218, %203 : i64, !llvm.ptr
      cf.br ^bb33
    ^bb35:
    func.call @free(%195) : (!llvm.ptr) -> ()
    %221 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %222 = llvm.load %199 : !llvm.ptr -> i64
    %223 = llvm.call @printf(%221, %222) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %224 = arith.constant 0 : i32
    func.return %224 : i32
  }
}