#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 */

/* Variables and functions */
int fabs(double);
double math_calc(int, double, double, double);
double newton_approach(int year, double price, double year_rent,
                       double target) {
  double l = 1;
  double h = 10;
  double res = l;
  if (math_calc(year, price, year_rent, h) < target) {
    l = h;
    h *= 2;
  }
  do {
    double temp_val;
    res = (h - l) / 2 + l;
    temp_val = math_calc(year, price, year_rent, res);
    if (fabs(temp_val - target) < 1e-6) {
      break;
    }
    if (temp_val > target) {
      h = res;
    } else {
      l = res;
    }
  } while (1);
  return res;
}


x86 assembly (clang, -O0):
<newton_approach>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  0xec6(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeb1(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x4(%rbp),%edi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
call   1040 <math_calc@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a3 <newton_approach+0x83>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe77(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11a8 <newton_approach+0x88>
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  0xe56(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x4(%rbp),%edi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
call   1040 <math_calc@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe19(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    120e <newton_approach+0xee>
jmp    124b <newton_approach+0x12b>
movsd  -0x40(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    122d <newton_approach+0x10d>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1237 <newton_approach+0x117>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    123c <newton_approach+0x11c>
mov    $0x1,%al
test   $0x1,%al
jne    11a8 <newton_approach+0x88>
jmp    124b <newton_approach+0x12b>
movsd  -0x38(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newton_approach>:
push   %rbx
sub    $0x50,%rsp
movsd  %xmm2,0x8(%rsp)
mov    %edi,%ebx
movsd  0xecb(%rip),%xmm2
movsd  %xmm0,0x18(%rsp)
movsd  %xmm1,0x20(%rsp)
call   1040 <math_calc@plt>
movsd  0x8(%rsp),%xmm2
xor    %eax,%eax
ucomisd %xmm0,%xmm2
seta   %al
lea    0xeb4(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm3
lea    0xeb8(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
movsd  %xmm0,0x10(%rsp)
jmp    119f <newton_approach+0x7f>
cs nopw 0x0(%rax,%rax,1)
nop
movapd %xmm2,%xmm3
cmpltsd %xmm1,%xmm3
movapd %xmm3,%xmm1
andpd  %xmm0,%xmm1
andnpd 0x40(%rsp),%xmm3
orpd   %xmm1,%xmm3
test   %eax,%eax
jle    1210 <newton_approach+0xf0>
movapd %xmm3,0x40(%rsp)
movapd %xmm3,%xmm2
movsd  0x10(%rsp),%xmm0
subsd  %xmm0,%xmm2
mulsd  0xe4d(%rip),%xmm2
addsd  %xmm0,%xmm2
movapd %xmm2,0x30(%rsp)
mov    %ebx,%edi
movsd  0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
call   1040 <math_calc@plt>
movsd  %xmm0,0x28(%rsp)
subsd  0x8(%rsp),%xmm0
call   1030 <fabs@plt>
movsd  0x28(%rsp),%xmm1
movapd 0x30(%rsp),%xmm0
movsd  0x8(%rsp),%xmm2
ucomisd %xmm2,%xmm1
ja     1180 <newton_approach+0x60>
movsd  %xmm0,0x10(%rsp)
jmp    1180 <newton_approach+0x60>
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @newton_approach(i32 %0, double %1, double %2, double %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
store i32 %0, i32* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
store double 1.000000e+00, double* %9
store double 1.000000e+01, double* %10
%13 = load double, double* %9
store double %13, double* %11
%14 = load i32, i32* %5
%15 = load double, double* %6
%16 = load double, double* %7
%17 = load double, double* %10
%18 = call double @math_calc(i32 %14, double %15, double %16, double %17)
%19 = load double, double* %8
%20 = fcmp olt double %18, %19
br i1 %20, label %21, label %25
21: ; preds = %4
%22 = load double, double* %10
store double %22, double* %9
%23 = load double, double* %10
%24 = fmul double %23, 2.000000e+00
store double %24, double* %10
br label %25
25: ; preds = %21, %4
br label %26
26: ; preds = %54, %25
%27 = load double, double* %10
%28 = load double, double* %9
%29 = fsub double %27, %28
%30 = fdiv double %29, 2.000000e+00
%31 = load double, double* %9
%32 = fadd double %30, %31
store double %32, double* %11
%33 = load i32, i32* %5
%34 = load double, double* %6
%35 = load double, double* %7
%36 = load double, double* %11
%37 = call double @math_calc(i32 %33, double %34, double %35, double %36)
store double %37, double* %12
%38 = load double, double* %12
%39 = load double, double* %8
%40 = fsub double %38, %39
%41 = call i32 @fabs(double %40)
%42 = sitofp i32 %41 to double
%43 = fcmp olt double %42, 0x3EB0C6F7A0B5ED8D
br i1 %43, label %44, label %45
44: ; preds = %26
br label %55
45: ; preds = %26
%46 = load double, double* %12
%47 = load double, double* %8
%48 = fcmp ogt double %46, %47
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = load double, double* %11
store double %50, double* %10
br label %53
51: ; preds = %45
%52 = load double, double* %11
store double %52, double* %9
br label %53
53: ; preds = %51, %49
br label %54
54: ; preds = %53
br i1 true, label %26, label %55
55: ; preds = %54, %44
%56 = load double, double* %11
ret double %56
}

LLVM IR (-O2):
define double @newton_approach(i32 %0, double %1, double %2, double %3) {
%5 = tail call double @math_calc(i32 %0, double %1, double %2, double 1.000000e+01)
%6 = fcmp olt double %5, %3
%7 = select i1 %6, double 2.000000e+01, double 1.000000e+01
%8 = select i1 %6, double 1.000000e+01, double 1.000000e+00
br label %9
9: ; preds = %9, %4
%10 = phi double [ %7, %4 ], [ %20, %9 ]
%11 = phi double [ %8, %4 ], [ %21, %9 ]
%12 = fsub double %10, %11
%13 = fmul double %12, 5.000000e-01
%14 = fadd double %11, %13
%15 = tail call double @math_calc(i32 %0, double %1, double %2, double %14)
%16 = fsub double %15, %3
%17 = tail call i32 @fabs(double %16)
%18 = icmp slt i32 %17, 1
%19 = fcmp ogt double %15, %3
%20 = select i1 %19, double %14, double %10
%21 = select i1 %19, double %11, double %14
br i1 %18, label %22, label %9
22: ; preds = %9
ret double %14
}