Problem 337

Totient stairstep sequences S(2e7) mod 1e8.

Answer85068035
Output85068035
StatusPASS
Native helperno
Runtime2660 ms
Peak memory162320 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-based totient computation
VerdictOptimal

Flow source

# Project Euler 337
# Totient stairstep sequences S(2e7) mod 1e8.

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

function main() -> i32 {
    let n: i64 = 20000000
    let mod: i64 = 100000000
    let phi: ptr<i32> = calloc(n + 1, 4)
    let primes: ptr<i32> = calloc(n / 5, 4)
    let bit: ptr<i32> = calloc(n + 1, 4)
    if phi == null || primes == null || bit == null { return 1 }
    let mut pc: i64 = 0
    phi[1] = 1
    let mut i: i64 = 2
    while i <= n {
        if phi[i] == 0 {
            phi[i] = (i - 1) as i32
            primes[pc] = i as i32
            pc = pc + 1
        }
        let phi_i: i64 = phi[i] as i64
        let mut j: i64 = 0
        while j < pc {
            let p: i64 = primes[j] as i64
            if i * p > n { break }
            if i % p == 0 {
                phi[i * p] = (phi_i * p) as i32
                break
            } else {
                phi[i * p] = (phi_i * (p - 1)) as i32
            }
            j = j + 1
        }
        i = i + 1
    }

    let mut ans: i64 = 0
    i = 2
    while i <= n {
        let t: i64 = phi[i] as i64
        let mut f: i64 = 0
        if i == 6 {
            f = 1
        } else {
            # query fenwick for sum of diffs at indices 1..t
            let mut idx: i64 = t
            while idx > 0 {
                f = (f + (bit[idx] as i64)) % mod
                idx = idx - (idx & -idx)
            }
        }
        ans = (ans + f) % mod
        if f != 0 {
            let l: i64 = t + 1
            if l <= i - 1 {
                let mut idx: i64 = l
                while idx <= n {
                    bit[idx] = (((bit[idx] as i64) + f) % mod) as i32
                    idx = idx + (idx & -idx)
                }
                idx = i
                while idx <= n {
                    bit[idx] = (((bit[idx] as i64) - f % mod + mod) % mod) as i32
                    idx = idx + (idx & -idx)
                }
            }
        }
        i = i + 1
    }
    printf("%lld\n", ans)
    free(phi); free(primes); free(bit)
    return 0
}

Generated C

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
    while (flow_temp_head) {
        flow_temp_node* n = flow_temp_head;
        flow_temp_head = n->next;
        free(n);
    }
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
    flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
    if (!node) return NULL;
    node->next = flow_temp_head;
    flow_temp_head = node;
    if (!flow_temp_atexit_set) {
        flow_temp_atexit_set = 1;
        atexit(flow_temp_free_all);
    }
    return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
    size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
    char* r = (char*)flow_temp_alloc(la + lb + 1);
    if (!r) return NULL;
    if (la) memcpy(r, a, la);
    if (lb) memcpy(r + la, b, lb);
    r[la + lb] = '\0';
    return r;
}

#define __flow_in_arr(arr, val) __extension__ ({ \
    int _found = 0; \
    size_t _n = sizeof(arr)/sizeof((arr)[0]); \
    for (size_t _i = 0; _i < _n; _i++) { \
        if ((arr)[_i] == (val)) { _found = 1; break; } \
    } _found; })

/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
    fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
    abort();
#if defined(__GNUC__) || defined(__clang__)
    __builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")

#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif

#include <math.h>

void* _ui_state = NULL;

static inline float i32_to_f32(int32_t v) { return (float)v; }

/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }

int32_t main(void);



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