#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef scalar_t__ int32_t;

/* Variables and functions */
double circle_equation(double);
double fabs(double);
double solve_intersect(int32_t n) {
  double step = 0.05;
  double x;
  for (x = 0.025;; step *= 0.99) {
    double lhs = x / (double)n;
    double rhs = circle_equation(x);
    if (fabs(lhs - rhs) < 0.000000001) {
      break;
    }
    x += (lhs > rhs) ? (step * -1) : step;
  }
  return x;
}


x86 assembly (clang, -O0):
<solve_intersect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  0xee4(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xecf(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsi2sdq -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <circle_equation@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movaps 0xec6(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe9a(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1185 <solve_intersect+0x75>
jmp    11dc <solve_intersect+0xcc>
movsd  -0x20(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11ac <solve_intersect+0x9c>
movsd  0xe7b(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11b6 <solve_intersect+0xa6>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe53(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1136 <solve_intersect+0x26>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve_intersect>:
sub    $0x38,%rsp
cvtsi2sd %rdi,%xmm1
movsd  0xedf(%rip),%xmm0
movapd %xmm0,%xmm2
movsd  %xmm1,0x10(%rsp)
divsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
call   1030 <circle_equation@plt>
movsd  0x8(%rsp),%xmm4
movsd  0xeb8(%rip),%xmm2
movapd %xmm4,%xmm1
subsd  %xmm0,%xmm1
andpd  0xec8(%rip),%xmm1
movsd  0xea8(%rip),%xmm3
ucomisd %xmm1,%xmm3
ja     11fe <solve_intersect+0xee>
movsd  0xe8e(%rip),%xmm2
movsd  0xe96(%rip),%xmm3
nopw   0x0(%rax,%rax,1)
movapd %xmm3,%xmm1
xorpd  0xea4(%rip),%xmm1
cmpltsd %xmm4,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm3,%xmm0
orpd   %xmm1,%xmm0
addsd  %xmm0,%xmm2
movsd  %xmm2,0x18(%rsp)
mulsd  0xe69(%rip),%xmm3
movapd %xmm3,0x20(%rsp)
movapd %xmm2,%xmm0
divsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd %xmm2,%xmm0
call   1030 <circle_equation@plt>
movsd  0x8(%rsp),%xmm4
movsd  0xe2c(%rip),%xmm3
movsd  0x18(%rsp),%xmm2
movapd %xmm4,%xmm1
subsd  %xmm0,%xmm1
andpd  0xe2e(%rip),%xmm1
ucomisd %xmm1,%xmm3
movapd 0x20(%rsp),%xmm3
jbe    1180 <solve_intersect+0x70>
movapd %xmm2,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define double @solve_intersect(i64 %0) {
%2 = alloca i64
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store i64 %0, i64* %2
store double 5.000000e-02, double* %3
store double 2.500000e-02, double* %4
br label %7
7: ; preds = %33, %1
%8 = load double, double* %4
%9 = load i64, i64* %2
%10 = sitofp i64 %9 to double
%11 = fdiv double %8, %10
store double %11, double* %5
%12 = load double, double* %4
%13 = call double @circle_equation(double %12)
store double %13, double* %6
%14 = load double, double* %5
%15 = load double, double* %6
%16 = fsub double %14, %15
%17 = call double @llvm.fabs.f64(double %16)
%18 = fcmp olt double %17, 1.000000e-09
br i1 %18, label %19, label %20
19: ; preds = %7
br label %36
20: ; preds = %7
%21 = load double, double* %5
%22 = load double, double* %6
%23 = fcmp ogt double %21, %22
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load double, double* %3
%26 = fmul double %25, -1.000000e+00
br label %29
27: ; preds = %20
%28 = load double, double* %3
br label %29
29: ; preds = %27, %24
%30 = phi double [ %26, %24 ], [ %28, %27 ]
%31 = load double, double* %4
%32 = fadd double %31, %30
store double %32, double* %4
br label %33
33: ; preds = %29
%34 = load double, double* %3
%35 = fmul double %34, 0x3FEFAE147AE147AE
store double %35, double* %3
br label %7
36: ; preds = %19
%37 = load double, double* %4
ret double %37
}

LLVM IR (-O2):
define double @solve_intersect(i64 %0) {
%2 = sitofp i64 %0 to double
%3 = fdiv double 2.500000e-02, %2
%4 = tail call double @circle_equation(double 2.500000e-02)
%5 = fsub double %3, %4
%6 = tail call double @llvm.fabs.f64(double %5)
%7 = fcmp olt double %6, 1.000000e-09
br i1 %7, label %23, label %8
8: ; preds = %1, %8
%9 = phi double [ %19, %8 ], [ %4, %1 ]
%10 = phi double [ %18, %8 ], [ %3, %1 ]
%11 = phi double [ %17, %8 ], [ 5.000000e-02, %1 ]
%12 = phi double [ %16, %8 ], [ 2.500000e-02, %1 ]
%13 = fcmp ogt double %10, %9
%14 = fneg double %11
%15 = select i1 %13, double %14, double %11
%16 = fadd double %12, %15
%17 = fmul double %11, 0x3FEFAE147AE147AE
%18 = fdiv double %16, %2
%19 = tail call double @circle_equation(double %16)
%20 = fsub double %18, %19
%21 = tail call double @llvm.fabs.f64(double %20)
%22 = fcmp olt double %21, 1.000000e-09
br i1 %22, label %23, label %8
23: ; preds = %8, %1
%24 = phi double [ 2.500000e-02, %1 ], [ %16, %8 ]
ret double %24
}