#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 kravtsov_f(double);
double inv_ff(double f) {
  double c = 1.0 / 10.0;
  double tc = kravtsov_f(c);
  double new_c;
  while (fabs((f - tc) / f) > 1e-7) {
    double tc2 = kravtsov_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 = kravtsov_f(c);
  }
  return (c);
}


x86 assembly (clang, -O0):
<inv_ff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xecb(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <kravtsov_f@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe9f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1209 <inv_ff+0xe9>
movsd  0xe85(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1040 <kravtsov_f@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xe64(%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    11eb <inv_ff+0xcb>
movsd  -0x10(%rbp),%xmm0
movsd  0xe33(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11f5 <inv_ff+0xd5>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <kravtsov_f@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    1149 <inv_ff+0x29>
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inv_ff>:
sub    $0x38,%rsp
movsd  %xmm0,0x10(%rsp)
movsd  0xece(%rip),%xmm0
movapd %xmm0,(%rsp)
call   1040 <kravtsov_f@plt>
movapd %xmm0,%xmm1
movsd  0x10(%rsp),%xmm2
movapd %xmm2,%xmm0
movsd  %xmm1,0x18(%rsp)
subsd  %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
divsd  %xmm2,%xmm0
call   1030 <fabs@plt>
test   %eax,%eax
jle    121e <inv_ff+0xfe>
movsd  0xe8d(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movapd %xmm0,(%rsp)
movsd  0xe73(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <kravtsov_f@plt>
subsd  0x18(%rsp),%xmm0
divsd  0xe5c(%rip),%xmm0
movapd 0x20(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd (%rsp),%xmm0
addsd  %xmm0,%xmm1
mulsd  0xe49(%rip),%xmm0
movapd %xmm0,%xmm3
movapd %xmm1,%xmm0
cmpltsd 0xe40(%rip),%xmm0
movapd %xmm0,%xmm2
andnpd %xmm1,%xmm2
andpd  %xmm3,%xmm0
orpd   %xmm2,%xmm0
movapd %xmm0,(%rsp)
call   1040 <kravtsov_f@plt>
movapd %xmm0,%xmm2
movsd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
movsd  %xmm2,0x18(%rsp)
subsd  %xmm2,%xmm0
movapd %xmm0,0x20(%rsp)
divsd  %xmm1,%xmm0
call   1030 <fabs@plt>
movapd (%rsp),%xmm0
test   %eax,%eax
jg     1180 <inv_ff+0x60>
movaps (%rsp),%xmm0
add    $0x38,%rsp
ret

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

LLVM IR (-O2):
define double @inv_ff(double %0) {
%2 = tail call double @kravtsov_f(double 1.000000e-01)
%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 ], [ 1.000000e-01, %1 ]
%10 = phi double [ %20, %7 ], [ %2, %1 ]
%11 = fadd double %9, 1.000000e-01
%12 = tail call double @kravtsov_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 @kravtsov_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 [ 1.000000e-01, %1 ], [ %19, %7 ]
ret double %26
}