Problem 094

Sum of perimeters of almost equilateral triangles with integer sides ≤ 1e9.

Answer518408346
Output518408346
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)O(n^2)
Space complexityO(1)O(n^2)
ApproachFlow solutionBottom-up DP
VerdictOptimal

Flow source

# Project Euler 094
# Sum of perimeters of almost equilateral triangles with integer sides ≤ 1e9.

function is_square(n: i64) -> bool {
    if n < 0 { return false }
    let mut x: i64 = n
    while x > 1 {
        let y: i64 = (x + n / x) / 2
        if y >= x { break }
        x = y
    }
    let mut r: i64 = x
    while r * r > n { r = r - 1 }
    while (r + 1) * (r + 1) <= n { r = r + 1 }
    return r * r == n
}

function main() -> i32 {
    let limit: i64 = 1000000000
    let mut total: i64 = 0
    # solutions of u^2 - 3v^2 = 4 generated by multiplying by 2+√3
    let mut u: i64 = 2
    let mut v: i64 = 0
    for iter in 0..40 {
        let nu: i64 = 2 * u + 3 * v
        let nv: i64 = u + 2 * v
        u = nu
        v = nv
        # u = 3a±1 ⇒ candidate odd a
        if (u - 1) % 3 == 0 {
            let a: i64 = (u - 1) / 3
            if a > 1 {
                for d in (0 - 1)..2 step 2 {
                    if d != 0 {
                        let perim: i64 = 3 * a + d
                        if perim > 0 && perim <= limit {
                            let base: i64 = a + d
                            let h2: i64 = 4 * a * a - base * base
                            if h2 % 4 == 0 && is_square(h2 / 4) {
                                total = total + perim
                            }
                        }
                    }
                }
            }
        }
        if (u + 1) % 3 == 0 {
            let a: i64 = (u + 1) / 3
            if a > 1 {
                for d in (0 - 1)..2 step 2 {
                    if d != 0 {
                        let perim: i64 = 3 * a + d
                        if perim > 0 && perim <= limit {
                            let base: i64 = a + d
                            let h2: i64 = 4 * a * a - base * base
                            if h2 % 4 == 0 && is_square(h2 / 4) {
                                total = total + perim
                            }
                        }
                    }
                }
            }
        }
    }
    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; }

bool is_square_i64(int64_t n);
int32_t main(void);

bool is_square_i64(int64_t n) {
    if (n < 0) {
        return 0;
    }
    int64_t x = n;
    while (x > 1) {
        int64_t y = FLOW_CHECKED_DIV(((x + FLOW_CHECKED_DIV((n), (x)))), (2));
        if (y >= x) {
            break;
        }
        x = y;
    }
    int64_t r = x;
    while ((r * r) > n) {
        r = (r - 1);
    }
    while (((r + 1) * (r + 1)) <= n) {
        r = (r + 1);
    }
    return (r * r) == n;
}

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