Problem 991

Equation a/(b+c) + b/(c+a) + c/(a+c) = 4 Parameterized number theory search over two branches.

Answer23871972654940
Output23871972654940
StatusPASS
Native helperno
Runtime10 ms
Peak memory1104 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 991
# Equation a/(b+c) + b/(c+a) + c/(a+c) = 4
# Parameterized number theory search over two branches.

extern {
    function sqrt(x: f64) -> f64
}

function gcd(a0: i32, b0: i32) -> i32 {
    let mut a: i32 = a0
    let mut b: i32 = b0
    while b != 0 {
        let t: i32 = a % b
        a = b
        b = t
    }
    if a < 0 {
        return -a
    }
    return a
}

function isqrt_ll(n: i64) -> i32 {
    if n < 0 {
        return 0
    }
    let mut r: i64 = sqrt(n as f64) as i64
    while r * r > n {
        r = r - 1
    }
    while (r + 1) * (r + 1) <= n {
        r = r + 1
    }
    return r as i32
}

function main() -> i32 {
    let limit: i64 = 10000000
    let mut total: i64 = 0

    # Plus branch: s = 6m^2 - n^2 + mn, n < 2m so s > 4m^2, m <= sqrt(limit/4)
    let m_max: i32 = isqrt_ll(limit / 4) + 2
    for m in 1..(m_max + 1) {
        let n_min: i32 = isqrt_ll(3 * m * m) + 1
        let n_max: i32 = 2 * m - 1
        for n in n_min..(n_max + 1) {
            if gcd(m, n) != 1 {
                continue
            }
            let a: i64 = 4 * m * m - (n as i64) * (n as i64)
            let c: i64 = (n as i64) * (n as i64) - 3 * m * m
            let b: i64 = 5 * m * m - (n as i64) * (n as i64) + (m as i64) * (n as i64)
            let s: i64 = a + b + c
            if a <= 0 || b <= 0 || c <= 0 {
                continue
            }
            if s <= limit {
                let count: i64 = limit / s
                total = total + s * count * (count + 1) / 2
            }
        }
    }

    # Minus branch: k = 2m - n, s = k(5m - k)
    let alpha: f64 = 2.0 + sqrt(3.0)
    let beta: f64 = (5.0 + sqrt(21.0)) / 2.0

    let mut k: i32 = 1
    while true {
        let mut low: i32 = (alpha * (k as f64)) as i32 + 1
        while (2 * low - k) * (2 * low - k) <= 3 * low * low {
            low = low + 1
        }

        let mut high_pos: i32 = (beta * (k as f64)) as i32
        while high_pos > 0 {
            if -(high_pos as i64) * (high_pos as i64) + 5 * (high_pos as i64) * (k as i64) - (k as i64) * (k as i64) > 0 {
                break
            }
            high_pos = high_pos - 1
        }

        let high_sum: i64 = (limit + (k as i64) * (k as i64)) / (5 * k)
        let high: i32 = if high_pos < (high_sum as i32) { high_pos } else { high_sum as i32 }

        if low > (high_sum as i32) {
            break
        }

        for m in low..(high + 1) {
            if gcd(m, k) != 1 {
                continue
            }
            let n: i32 = 2 * m - k
            let a: i64 = 4 * m * m - (n as i64) * (n as i64)
            let c: i64 = (n as i64) * (n as i64) - 3 * m * m
            let b: i64 = 5 * m * m - (n as i64) * (n as i64) - (m as i64) * (n as i64)
            let s: i64 = a + b + c
            if a <= 0 || b <= 0 || c <= 0 {
                continue
            }
            if s <= limit {
                let count: i64 = limit / s
                total = total + s * count * (count + 1) / 2
            }
        }
        k = k + 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; }

int32_t gcd_i32_i32(int32_t a0, int32_t b0);
int32_t isqrt_ll_i64(int64_t n);
int32_t main(void);


int32_t gcd_i32_i32(int32_t a0, int32_t b0) {
    int32_t a = a0;
    int32_t b = b0;
    while (b != 0) {
        int32_t t = FLOW_CHECKED_MOD((a), (b));
        a = b;
        b = t;
    }
    if (a < 0) {
        return (-a);
    }
    return a;
}

int32_t isqrt_ll_i64(int64_t n) {
    if (n < 0) {
        return 0;
    }
    int64_t r = ((int64_t)(sqrt(((double)(n)))));
    while ((r * r) > n) {
        r = (r - 1);
    }
    while (((r + 1) * (r + 1)) <= n) {
        r = (r + 1);
    }
    return ((int32_t)(r));
}

int32_t main(void) {
    int64_t limit = 10000000;
    int64_t total = 0;
    int32_t m_max = (isqrt_ll_i64(FLOW_CHECKED_DIV((limit), (4))) + 2);
    int32_t __flow_step_1 = 1;
    for (int32_t m = 1; (1 <= (m_max + 1)) ? m < (m_max + 1) : m > (m_max + 1); m += (1 <= (m_max + 1)) ? 1 : -1) {
        int32_t n_min = (isqrt_ll_i64(((3 * m) * m)) + 1);
        int32_t n_max = ((2 * m) - 1);
        int32_t __flow_step_2 = 1;
        for (int32_t n = n_min; (n_min <= (n_max + 1)) ? n < (n_max + 1) : n > (n_max + 1); n += (n_min <= (n_max + 1)) ? 1 : -1) {
            if (gcd_i32_i32(m, n) != 1) {
                continue;
            }
            int64_t a = (((4 * m) * m) - (((int64_t)(n)) * ((int64_t)(n))));
            int64_t c = ((((int64_t)(n)) * ((int64_t)(n))) - ((3 * m) * m));
            int64_t b = ((((5 * m) * m) - (((int64_t)(n)) * ((int64_t)(n)))) + (((int64_t)(m)) * ((int64_t)(n))));
            int64_t s = ((a + b) + c);
            if (((a <= 0 || b <= 0) || c <= 0)) {
                continue;
            }
            if (s <= limit) {
                int64_t count = FLOW_CHECKED_DIV((limit), (s));
                total = (total + FLOW_CHECKED_DIV((((s * count) * (count + 1))), (2)));
            }
        }
    }
    double alpha = (2.0 + sqrt(3.0));
    double beta = ((5.0 + sqrt(21.0)) / 2.0);
    int32_t k = 1;
    while (1) {
        int32_t low = (((int32_t)((alpha * ((double)(k))))) + 1);
        while ((((2 * low) - k) * ((2 * low) - k)) <= ((3 * low) * low)) {
            low = (low + 1);
        }
        int32_t high_pos = ((int32_t)((beta * ((double)(k)))));
        while (high_pos > 0) {
            if (((((-((int64_t)(high_pos))) * ((int64_t)(high_pos))) + ((5 * ((int64_t)(high_pos))) * ((int64_t)(k)))) - (((int64_t)(k)) * ((int64_t)(k)))) > 0) {
                break;
            }
            high_pos = (high_pos - 1);
        }
        int64_t high_sum = FLOW_CHECKED_DIV(((limit + (((int64_t)(k)) * ((int64_t)(k))))), ((5 * k)));
        int32_t high = ((high_pos < ((int32_t)(high_sum))) ? (high_pos) : (((int32_t)(high_sum))));
        if (low > ((int32_t)(high_sum))) {
            break;
        }
        int32_t __flow_step_3 = 1;
        for (int32_t m = low; (low <= (high + 1)) ? m < (high + 1) : m > (high + 1); m += (low <= (high + 1)) ? 1 : -1) {
            if (gcd_i32_i32(m, k) != 1) {
                continue;
            }
            int32_t n = ((2 * m) - k);
            int64_t a = (((4 * m) * m) - (((int64_t)(n)) * ((int64_t)(n))));
            int64_t c = ((((int64_t)(n)) * ((int64_t)(n))) - ((3 * m) * m));
            int64_t b = ((((5 * m) * m) - (((int64_t)(n)) * ((int64_t)(n)))) - (((int64_t)(m)) * ((int64_t)(n))));
            int64_t s = ((a + b) + c);
            if (((a <= 0 || b <= 0) || c <= 0)) {
                continue;
            }
            if (s <= limit) {
                int64_t count = FLOW_CHECKED_DIV((limit), (s));
                total = (total + FLOW_CHECKED_DIV((((s * count) * (count + 1))), (2)));
            }
        }
        k = (k + 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 private @sqrt(f64) -> f64
  func.func @gcd(%arg0: i32, %arg1: i32) -> i32 {
    %0 = llvm.mlir.constant(1 : i64) : i64
    %1 = llvm.alloca %0 x i32 : (i64) -> !llvm.ptr
    llvm.store %arg0, %1 : i32, !llvm.ptr
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.alloca %2 x i32 : (i64) -> !llvm.ptr
    llvm.store %arg1, %3 : i32, !llvm.ptr
    cf.br ^bb0
    ^bb0:
    %4 = llvm.load %3 : !llvm.ptr -> i32
    %5 = arith.constant 0 : i32
    %6 = arith.cmpi ne, %4, %5 : i32
    cf.cond_br %6, ^bb1, ^bb2
    ^bb1:
      %7 = llvm.load %1 : !llvm.ptr -> i32
      %8 = llvm.load %3 : !llvm.ptr -> i32
      %9 = arith.remsi %7, %8 : i32
      %10 = llvm.load %3 : !llvm.ptr -> i32
      llvm.store %10, %1 : i32, !llvm.ptr
      llvm.store %9, %3 : i32, !llvm.ptr
      cf.br ^bb0
    ^bb2:
    %11 = llvm.load %1 : !llvm.ptr -> i32
    %12 = arith.constant 0 : i32
    %13 = arith.cmpi slt, %11, %12 : i32
    cf.cond_br %13, ^bb3, ^bb4
    ^bb3:
      %14 = llvm.load %1 : !llvm.ptr -> i32
      %16 = arith.constant 0 : i32
      %15 = arith.subi %16, %14 : i32
      func.return %15 : i32
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %17 = llvm.load %1 : !llvm.ptr -> i32
    func.return %17 : i32
  }
  func.func @isqrt_ll(%arg0: i64) -> i32 {
    %18 = arith.constant 0 : i32
    %20 = arith.extsi %18 : i32 to i64
    %19 = arith.cmpi slt, %arg0, %20 : i64
    cf.cond_br %19, ^bb6, ^bb7
    ^bb6:
      %21 = arith.constant 0 : i32
      func.return %21 : i32
    ^bb7:
      cf.br ^bb8
    ^bb8:
    %22 = arith.sitofp %arg0 : i64 to f64
    %23 = math.sqrt %22 : f64
    %24 = arith.fptosi %23 : f64 to i64
    %25 = llvm.mlir.constant(1 : i64) : i64
    %26 = llvm.alloca %25 x i64 : (i64) -> !llvm.ptr
    llvm.store %24, %26 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %27 = llvm.load %26 : !llvm.ptr -> i64
    %28 = llvm.load %26 : !llvm.ptr -> i64
    %29 = arith.muli %27, %28 : i64
    %30 = arith.cmpi sgt, %29, %arg0 : i64
    cf.cond_br %30, ^bb10, ^bb11
    ^bb10:
      %31 = llvm.load %26 : !llvm.ptr -> i64
      %32 = arith.constant 1 : i32
      %34 = arith.extsi %32 : i32 to i64
      %33 = arith.subi %31, %34 : i64
      llvm.store %33, %26 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    cf.br ^bb12
    ^bb12:
    %35 = llvm.load %26 : !llvm.ptr -> i64
    %36 = arith.constant 1 : i32
    %38 = arith.extsi %36 : i32 to i64
    %37 = arith.addi %35, %38 : i64
    %39 = llvm.load %26 : !llvm.ptr -> i64
    %40 = arith.constant 1 : i32
    %42 = arith.extsi %40 : i32 to i64
    %41 = arith.addi %39, %42 : i64
    %43 = arith.muli %37, %41 : i64
    %44 = arith.cmpi sle, %43, %arg0 : i64
    cf.cond_br %44, ^bb13, ^bb14
    ^bb13:
      %45 = llvm.load %26 : !llvm.ptr -> i64
      %46 = arith.constant 1 : i32
      %48 = arith.extsi %46 : i32 to i64
      %47 = arith.addi %45, %48 : i64
      llvm.store %47, %26 : i64, !llvm.ptr
      cf.br ^bb12
    ^bb14:
    %49 = llvm.load %26 : !llvm.ptr -> i64
    %50 = arith.trunci %49 : i64 to i32
    func.return %50 : i32
  }
  func.func @main() -> i32 {
    %51 = arith.constant 10000000 : i32
    %52 = arith.extsi %51 : i32 to i64
    %53 = arith.constant 0 : i32
    %54 = arith.extsi %53 : i32 to i64
    %55 = llvm.mlir.constant(1 : i64) : i64
    %56 = llvm.alloca %55 x i64 : (i64) -> !llvm.ptr
    llvm.store %54, %56 : i64, !llvm.ptr
    %58 = arith.constant 4 : i32
    %60 = arith.extsi %58 : i32 to i64
    %59 = arith.divsi %52, %60 : i64
    %57 = func.call @isqrt_ll(%59) : (i64) -> i32
    %61 = arith.constant 2 : i32
    %62 = arith.addi %57, %61 : i32
    %63 = arith.constant 1 : i32
    %64 = arith.constant 1 : i32
    %65 = arith.addi %62, %64 : i32
    %66 = arith.index_cast %63 : i32 to index
    %67 = arith.index_cast %65 : i32 to index
    %69 = arith.constant 1 : index
    %70 = arith.constant -1 : index
    %71 = arith.cmpi sle, %66, %67 : index
    %68 = arith.select %71, %69, %70 : index
    cf.br ^bb15(%66 : index)
    ^bb15(%72: index):
    %73 = arith.cmpi slt, %72, %67 : index
    %74 = arith.cmpi sgt, %72, %67 : index
    %75 = arith.select %71, %73, %74 : i1
    cf.cond_br %75, ^bb16(%72 : index), ^bb17(%72 : index)
    ^bb16(%76: index):
      %78 = arith.constant 3 : i32
      %80 = arith.index_cast %76 : index to i32
      %79 = arith.muli %78, %80 : i32
      %82 = arith.index_cast %76 : index to i32
      %81 = arith.muli %79, %82 : i32
      %83 = arith.extsi %81 : i32 to i64
      %77 = func.call @isqrt_ll(%83) : (i64) -> i32
      %84 = arith.constant 1 : i32
      %85 = arith.addi %77, %84 : i32
      %86 = arith.constant 2 : i32
      %88 = arith.index_cast %76 : index to i32
      %87 = arith.muli %86, %88 : i32
      %89 = arith.constant 1 : i32
      %90 = arith.subi %87, %89 : i32
      %91 = arith.constant 1 : i32
      %92 = arith.addi %90, %91 : i32
      %93 = arith.index_cast %85 : i32 to index
      %94 = arith.index_cast %92 : i32 to index
      %96 = arith.constant 1 : index
      %97 = arith.constant -1 : index
      %98 = arith.cmpi sle, %93, %94 : index
      %95 = arith.select %98, %96, %97 : index
      cf.br ^bb18(%93 : index)
      ^bb18(%99: index):
      %100 = arith.cmpi slt, %99, %94 : index
      %101 = arith.cmpi sgt, %99, %94 : index
      %102 = arith.select %98, %100, %101 : i1
      cf.cond_br %102, ^bb19(%99 : index), ^bb20(%99 : index)
      ^bb19(%103: index):
        %105 = arith.index_cast %76 : index to i32
        %106 = arith.index_cast %103 : index to i32
        %104 = func.call @gcd(%105, %106) : (i32, i32) -> i32
        %107 = arith.constant 1 : i32
        %108 = arith.cmpi ne, %104, %107 : i32
        cf.cond_br %108, ^bb21, ^bb22
        ^bb21:
          %109 = arith.addi %103, %95 : index
          cf.br ^bb18(%109 : index)
        ^bb22:
          cf.br ^bb23
        ^bb23:
        %110 = arith.constant 4 : i32
        %112 = arith.index_cast %76 : index to i32
        %111 = arith.muli %110, %112 : i32
        %114 = arith.index_cast %76 : index to i32
        %113 = arith.muli %111, %114 : i32
        %115 = arith.index_cast %103 : index to i64
        %116 = arith.index_cast %103 : index to i64
        %117 = arith.muli %115, %116 : i64
        %119 = arith.extsi %113 : i32 to i64
        %118 = arith.subi %119, %117 : i64
        %120 = arith.index_cast %103 : index to i64
        %121 = arith.index_cast %103 : index to i64
        %122 = arith.muli %120, %121 : i64
        %123 = arith.constant 3 : i32
        %125 = arith.index_cast %76 : index to i32
        %124 = arith.muli %123, %125 : i32
        %127 = arith.index_cast %76 : index to i32
        %126 = arith.muli %124, %127 : i32
        %129 = arith.extsi %126 : i32 to i64
        %128 = arith.subi %122, %129 : i64
        %130 = arith.constant 5 : i32
        %132 = arith.index_cast %76 : index to i32
        %131 = arith.muli %130, %132 : i32
        %134 = arith.index_cast %76 : index to i32
        %133 = arith.muli %131, %134 : i32
        %135 = arith.index_cast %103 : index to i64
        %136 = arith.index_cast %103 : index to i64
        %137 = arith.muli %135, %136 : i64
        %139 = arith.extsi %133 : i32 to i64
        %138 = arith.subi %139, %137 : i64
        %140 = arith.index_cast %76 : index to i64
        %141 = arith.index_cast %103 : index to i64
        %142 = arith.muli %140, %141 : i64
        %143 = arith.addi %138, %142 : i64
        %144 = arith.addi %118, %143 : i64
        %145 = arith.addi %144, %128 : i64
        %146 = arith.constant 0 : i32
        %148 = arith.extsi %146 : i32 to i64
        %147 = arith.cmpi sle, %118, %148 : i64
        %149 = scf.if %147 -> (i1) {
          %150 = arith.constant true
          scf.yield %150 : i1
        } else {
          %151 = arith.constant 0 : i32
          %153 = arith.extsi %151 : i32 to i64
          %152 = arith.cmpi sle, %143, %153 : i64
          scf.yield %152 : i1
        }
        %154 = scf.if %149 -> (i1) {
          %155 = arith.constant true
          scf.yield %155 : i1
        } else {
          %156 = arith.constant 0 : i32
          %158 = arith.extsi %156 : i32 to i64
          %157 = arith.cmpi sle, %128, %158 : i64
          scf.yield %157 : i1
        }
        cf.cond_br %154, ^bb24, ^bb25
        ^bb24:
          %159 = arith.addi %103, %95 : index
          cf.br ^bb18(%159 : index)
        ^bb25:
          cf.br ^bb26
        ^bb26:
        %160 = arith.cmpi sle, %145, %52 : i64
        cf.cond_br %160, ^bb27, ^bb28
        ^bb27:
          %161 = arith.divsi %52, %145 : i64
          %162 = llvm.load %56 : !llvm.ptr -> i64
          %163 = arith.muli %145, %161 : i64
          %164 = arith.constant 1 : i32
          %166 = arith.extsi %164 : i32 to i64
          %165 = arith.addi %161, %166 : i64
          %167 = arith.muli %163, %165 : i64
          %168 = arith.constant 2 : i32
          %170 = arith.extsi %168 : i32 to i64
          %169 = arith.divsi %167, %170 : i64
          %171 = arith.addi %162, %169 : i64
          llvm.store %171, %56 : i64, !llvm.ptr
          cf.br ^bb29
        ^bb28:
          cf.br ^bb29
        ^bb29:
        %172 = arith.addi %103, %95 : index
        cf.br ^bb18(%172 : index)
      ^bb20(%173: index):
      %174 = arith.addi %76, %68 : index
      cf.br ^bb15(%174 : index)
    ^bb17(%175: index):
    %176 = arith.constant 2.0 : f32
    %177 = arith.constant 3.0 : f32
    %178 = math.sqrt %177 : f32
    %180 = arith.extf %176 : f32 to f64
    %179 = arith.addf %180, %178 : f64
    %181 = arith.constant 5.0 : f32
    %182 = arith.constant 21.0 : f32
    %183 = math.sqrt %182 : f32
    %185 = arith.extf %181 : f32 to f64
    %184 = arith.addf %185, %183 : f64
    %186 = arith.constant 2.0 : f32
    %188 = arith.extf %186 : f32 to f64
    %187 = arith.divf %184, %188 : f64
    %189 = arith.constant 1 : i32
    %190 = llvm.mlir.constant(1 : i64) : i64
    %191 = llvm.alloca %190 x i32 : (i64) -> !llvm.ptr
    llvm.store %189, %191 : i32, !llvm.ptr
    cf.br ^bb30
    ^bb30:
    %192 = arith.constant 1 : i1
    cf.cond_br %192, ^bb31, ^bb32
    ^bb31:
      %193 = llvm.load %191 : !llvm.ptr -> i32
      %194 = arith.sitofp %193 : i32 to f64
      %195 = arith.mulf %179, %194 : f64
      %196 = arith.fptosi %195 : f64 to i32
      %197 = arith.constant 1 : i32
      %198 = arith.addi %196, %197 : i32
      %199 = llvm.mlir.constant(1 : i64) : i64
      %200 = llvm.alloca %199 x i32 : (i64) -> !llvm.ptr
      llvm.store %198, %200 : i32, !llvm.ptr
      cf.br ^bb33
      ^bb33:
      %201 = arith.constant 2 : i32
      %202 = llvm.load %200 : !llvm.ptr -> i32
      %203 = arith.muli %201, %202 : i32
      %204 = llvm.load %191 : !llvm.ptr -> i32
      %205 = arith.subi %203, %204 : i32
      %206 = arith.constant 2 : i32
      %207 = llvm.load %200 : !llvm.ptr -> i32
      %208 = arith.muli %206, %207 : i32
      %209 = llvm.load %191 : !llvm.ptr -> i32
      %210 = arith.subi %208, %209 : i32
      %211 = arith.muli %205, %210 : i32
      %212 = arith.constant 3 : i32
      %213 = llvm.load %200 : !llvm.ptr -> i32
      %214 = arith.muli %212, %213 : i32
      %215 = llvm.load %200 : !llvm.ptr -> i32
      %216 = arith.muli %214, %215 : i32
      %217 = arith.cmpi sle, %211, %216 : i32
      cf.cond_br %217, ^bb34, ^bb35
      ^bb34:
        %218 = llvm.load %200 : !llvm.ptr -> i32
        %219 = arith.constant 1 : i32
        %220 = arith.addi %218, %219 : i32
        llvm.store %220, %200 : i32, !llvm.ptr
        cf.br ^bb33
      ^bb35:
      %221 = llvm.load %191 : !llvm.ptr -> i32
      %222 = arith.sitofp %221 : i32 to f64
      %223 = arith.mulf %187, %222 : f64
      %224 = arith.fptosi %223 : f64 to i32
      %225 = llvm.mlir.constant(1 : i64) : i64
      %226 = llvm.alloca %225 x i32 : (i64) -> !llvm.ptr
      llvm.store %224, %226 : i32, !llvm.ptr
      cf.br ^bb36
      ^bb36:
      %227 = llvm.load %226 : !llvm.ptr -> i32
      %228 = arith.constant 0 : i32
      %229 = arith.cmpi sgt, %227, %228 : i32
      cf.cond_br %229, ^bb37, ^bb38
      ^bb37:
        %230 = llvm.load %226 : !llvm.ptr -> i32
        %231 = arith.extsi %230 : i32 to i64
        %233 = arith.constant 0 : i64
        %232 = arith.subi %233, %231 : i64
        %234 = llvm.load %226 : !llvm.ptr -> i32
        %235 = arith.extsi %234 : i32 to i64
        %236 = arith.muli %232, %235 : i64
        %237 = arith.constant 5 : i32
        %238 = llvm.load %226 : !llvm.ptr -> i32
        %239 = arith.extsi %238 : i32 to i64
        %241 = arith.extsi %237 : i32 to i64
        %240 = arith.muli %241, %239 : i64
        %242 = llvm.load %191 : !llvm.ptr -> i32
        %243 = arith.extsi %242 : i32 to i64
        %244 = arith.muli %240, %243 : i64
        %245 = arith.addi %236, %244 : i64
        %246 = llvm.load %191 : !llvm.ptr -> i32
        %247 = arith.extsi %246 : i32 to i64
        %248 = llvm.load %191 : !llvm.ptr -> i32
        %249 = arith.extsi %248 : i32 to i64
        %250 = arith.muli %247, %249 : i64
        %251 = arith.subi %245, %250 : i64
        %252 = arith.constant 0 : i32
        %254 = arith.extsi %252 : i32 to i64
        %253 = arith.cmpi sgt, %251, %254 : i64
        cf.cond_br %253, ^bb39, ^bb40
        ^bb39:
          cf.br ^bb38
        ^bb40:
          cf.br ^bb41
        ^bb41:
        %255 = llvm.load %226 : !llvm.ptr -> i32
        %256 = arith.constant 1 : i32
        %257 = arith.subi %255, %256 : i32
        llvm.store %257, %226 : i32, !llvm.ptr
        cf.br ^bb36
      ^bb38:
      %258 = llvm.load %191 : !llvm.ptr -> i32
      %259 = arith.extsi %258 : i32 to i64
      %260 = llvm.load %191 : !llvm.ptr -> i32
      %261 = arith.extsi %260 : i32 to i64
      %262 = arith.muli %259, %261 : i64
      %263 = arith.addi %52, %262 : i64
      %264 = arith.constant 5 : i32
      %265 = llvm.load %191 : !llvm.ptr -> i32
      %266 = arith.muli %264, %265 : i32
      %268 = arith.extsi %266 : i32 to i64
      %267 = arith.divsi %263, %268 : i64
      %269 = llvm.load %226 : !llvm.ptr -> i32
      %270 = arith.trunci %267 : i64 to i32
      %271 = arith.cmpi slt, %269, %270 : i32
      %272 = scf.if %271 -> (i32) {
        %273 = llvm.load %226 : !llvm.ptr -> i32
        scf.yield %273 : i32
      } else {
        %274 = arith.trunci %267 : i64 to i32
        scf.yield %274 : i32
      }
      %275 = llvm.load %200 : !llvm.ptr -> i32
      %276 = arith.trunci %267 : i64 to i32
      %277 = arith.cmpi sgt, %275, %276 : i32
      cf.cond_br %277, ^bb42, ^bb43
      ^bb42:
        cf.br ^bb32
      ^bb43:
        cf.br ^bb44
      ^bb44:
      %278 = llvm.load %200 : !llvm.ptr -> i32
      %279 = arith.constant 1 : i32
      %280 = arith.addi %272, %279 : i32
      %281 = arith.index_cast %278 : i32 to index
      %282 = arith.index_cast %280 : i32 to index
      %284 = arith.constant 1 : index
      %285 = arith.constant -1 : index
      %286 = arith.cmpi sle, %281, %282 : index
      %283 = arith.select %286, %284, %285 : index
      cf.br ^bb45(%281 : index)
      ^bb45(%287: index):
      %288 = arith.cmpi slt, %287, %282 : index
      %289 = arith.cmpi sgt, %287, %282 : index
      %290 = arith.select %286, %288, %289 : i1
      cf.cond_br %290, ^bb46(%287 : index), ^bb47(%287 : index)
      ^bb46(%291: index):
        %293 = llvm.load %191 : !llvm.ptr -> i32
        %294 = arith.index_cast %291 : index to i32
        %292 = func.call @gcd(%294, %293) : (i32, i32) -> i32
        %295 = arith.constant 1 : i32
        %296 = arith.cmpi ne, %292, %295 : i32
        cf.cond_br %296, ^bb48, ^bb49
        ^bb48:
          %297 = arith.addi %291, %283 : index
          cf.br ^bb45(%297 : index)
        ^bb49:
          cf.br ^bb50
        ^bb50:
        %298 = arith.constant 2 : i32
        %300 = arith.index_cast %291 : index to i32
        %299 = arith.muli %298, %300 : i32
        %301 = llvm.load %191 : !llvm.ptr -> i32
        %302 = arith.subi %299, %301 : i32
        %303 = arith.constant 4 : i32
        %305 = arith.index_cast %291 : index to i32
        %304 = arith.muli %303, %305 : i32
        %307 = arith.index_cast %291 : index to i32
        %306 = arith.muli %304, %307 : i32
        %308 = arith.extsi %302 : i32 to i64
        %309 = arith.extsi %302 : i32 to i64
        %310 = arith.muli %308, %309 : i64
        %312 = arith.extsi %306 : i32 to i64
        %311 = arith.subi %312, %310 : i64
        %313 = arith.extsi %302 : i32 to i64
        %314 = arith.extsi %302 : i32 to i64
        %315 = arith.muli %313, %314 : i64
        %316 = arith.constant 3 : i32
        %318 = arith.index_cast %291 : index to i32
        %317 = arith.muli %316, %318 : i32
        %320 = arith.index_cast %291 : index to i32
        %319 = arith.muli %317, %320 : i32
        %322 = arith.extsi %319 : i32 to i64
        %321 = arith.subi %315, %322 : i64
        %323 = arith.constant 5 : i32
        %325 = arith.index_cast %291 : index to i32
        %324 = arith.muli %323, %325 : i32
        %327 = arith.index_cast %291 : index to i32
        %326 = arith.muli %324, %327 : i32
        %328 = arith.extsi %302 : i32 to i64
        %329 = arith.extsi %302 : i32 to i64
        %330 = arith.muli %328, %329 : i64
        %332 = arith.extsi %326 : i32 to i64
        %331 = arith.subi %332, %330 : i64
        %333 = arith.index_cast %291 : index to i64
        %334 = arith.extsi %302 : i32 to i64
        %335 = arith.muli %333, %334 : i64
        %336 = arith.subi %331, %335 : i64
        %337 = arith.addi %311, %336 : i64
        %338 = arith.addi %337, %321 : i64
        %339 = arith.constant 0 : i32
        %341 = arith.extsi %339 : i32 to i64
        %340 = arith.cmpi sle, %311, %341 : i64
        %342 = scf.if %340 -> (i1) {
          %343 = arith.constant true
          scf.yield %343 : i1
        } else {
          %344 = arith.constant 0 : i32
          %346 = arith.extsi %344 : i32 to i64
          %345 = arith.cmpi sle, %336, %346 : i64
          scf.yield %345 : i1
        }
        %347 = scf.if %342 -> (i1) {
          %348 = arith.constant true
          scf.yield %348 : i1
        } else {
          %349 = arith.constant 0 : i32
          %351 = arith.extsi %349 : i32 to i64
          %350 = arith.cmpi sle, %321, %351 : i64
          scf.yield %350 : i1
        }
        cf.cond_br %347, ^bb51, ^bb52
        ^bb51:
          %352 = arith.addi %291, %283 : index
          cf.br ^bb45(%352 : index)
        ^bb52:
          cf.br ^bb53
        ^bb53:
        %353 = arith.cmpi sle, %338, %52 : i64
        cf.cond_br %353, ^bb54, ^bb55
        ^bb54:
          %354 = arith.divsi %52, %338 : i64
          %355 = llvm.load %56 : !llvm.ptr -> i64
          %356 = arith.muli %338, %354 : i64
          %357 = arith.constant 1 : i32
          %359 = arith.extsi %357 : i32 to i64
          %358 = arith.addi %354, %359 : i64
          %360 = arith.muli %356, %358 : i64
          %361 = arith.constant 2 : i32
          %363 = arith.extsi %361 : i32 to i64
          %362 = arith.divsi %360, %363 : i64
          %364 = arith.addi %355, %362 : i64
          llvm.store %364, %56 : i64, !llvm.ptr
          cf.br ^bb56
        ^bb55:
          cf.br ^bb56
        ^bb56:
        %365 = arith.addi %291, %283 : index
        cf.br ^bb45(%365 : index)
      ^bb47(%366: index):
      %367 = llvm.load %191 : !llvm.ptr -> i32
      %368 = arith.constant 1 : i32
      %369 = arith.addi %367, %368 : i32
      llvm.store %369, %191 : i32, !llvm.ptr
      cf.br ^bb30
    ^bb32:
    %370 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %371 = llvm.load %56 : !llvm.ptr -> i64
    %372 = llvm.call @printf(%370, %371) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
    %373 = arith.constant 0 : i32
    func.return %373 : i32
  }
}