#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 */
double c_to_f(double);
int fabs(double);
double f_to_c(double f) {
  double c = f;
  double tc = c_to_f(c);
  double new_c;
  while (fabs((f - tc) / f) > 1e-7) {
    double tc2 = c_to_f(c + 0.1);
    double slope = (tc2 - tc) / 0.1;
    new_c = c + (f - tc) / slope;
    if (new_c < 0)
      c /= 2;
    else
      c = new_c;
    tc = c_to_f(c);
  }
  return c;
}


x86 assembly (clang, -O0):
<f_to_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <c_to_f@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe9a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1206 <f_to_c+0xe6>
movsd  0xe90(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1030 <c_to_f@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xe6f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
divsd  -0x30(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11e8 <f_to_c+0xc8>
movsd  -0x10(%rbp),%xmm0
movsd  0xe36(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11f2 <f_to_c+0xd2>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <c_to_f@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    1146 <f_to_c+0x26>
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_to_c>:
sub    $0x38,%rsp
movsd  %xmm0,(%rsp)
call   1030 <c_to_f@plt>
movapd %xmm0,%xmm1
movsd  (%rsp),%xmm2
movapd %xmm2,%xmm0
movsd  %xmm1,0x8(%rsp)
subsd  %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
divsd  %xmm2,%xmm0
call   1040 <fabs@plt>
test   %eax,%eax
jle    121e <f_to_c+0xfe>
movsd  (%rsp),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movapd %xmm1,0x10(%rsp)
movapd %xmm1,%xmm0
movsd  0xe7e(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <c_to_f@plt>
subsd  0x8(%rsp),%xmm0
divsd  0xe67(%rip),%xmm0
movapd 0x20(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd 0x10(%rsp),%xmm0
addsd  %xmm0,%xmm1
mulsd  0xe53(%rip),%xmm0
movapd %xmm0,%xmm3
movapd %xmm1,%xmm0
cmpltsd 0xe4a(%rip),%xmm0
movapd %xmm0,%xmm2
andnpd %xmm1,%xmm2
andpd  %xmm3,%xmm0
orpd   %xmm2,%xmm0
movapd %xmm0,0x10(%rsp)
call   1030 <c_to_f@plt>
movapd %xmm0,%xmm2
movsd  (%rsp),%xmm1
movapd %xmm1,%xmm0
movsd  %xmm2,0x8(%rsp)
subsd  %xmm2,%xmm0
movapd %xmm0,0x20(%rsp)
divsd  %xmm1,%xmm0
call   1040 <fabs@plt>
movapd 0x10(%rsp),%xmm0
movapd %xmm0,%xmm1
test   %eax,%eax
jg     1170 <f_to_c+0x50>
add    $0x38,%rsp
ret
movsd  (%rsp),%xmm0
add    $0x38,%rsp
ret

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

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