#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 dabs(double);
double order_of_magnitude(double);
double inv(double n) {
  double x0 = n * 0.283 * order_of_magnitude(n);
  double xp = x0;
  double atol = 1;
  double xn;
  while (dabs(atol) > 1e-10) {
    xn = xp + xp * (1 - n * xp);
    atol = xn - xp;
    xp = xn;
  }
  return xp;
}


x86 assembly (clang, -O0):
<inv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xed3(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <order_of_magnitude@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe94(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <dabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe89(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11f7 <inv+0xd7>
movsd  -0x18(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm3
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm3,%xmm2
movsd  0xe38(%rip),%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1171 <inv+0x51>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inv>:
sub    $0x28,%rsp
movsd  0xed4(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm0,0x10(%rsp)
call   1030 <order_of_magnitude@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xeb3(%rip),%xmm0
call   1040 <dabs@plt>
test   %eax,%eax
jle    11bc <inv+0x9c>
movapd 0x10(%rsp),%xmm0
xorpd  0xea4(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm1
nopl   0x0(%rax,%rax,1)
movapd 0x10(%rsp),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xe76(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
subsd  %xmm1,%xmm0
call   1040 <dabs@plt>
movsd  0x8(%rsp),%xmm0
movapd %xmm0,%xmm1
test   %eax,%eax
jg     1180 <inv+0x60>
add    $0x28,%rsp
ret
movsd  0x8(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @inv(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %2
%7 = load double, double* %2
%8 = fmul double %7, 2.830000e-01
%9 = load double, double* %2
%10 = call double @order_of_magnitude(double %9)
%11 = fmul double %8, %10
store double %11, double* %3
%12 = load double, double* %3
store double %12, double* %4
store double 1.000000e+00, double* %5
br label %13
13: ; preds = %18, %1
%14 = load double, double* %5
%15 = call i32 @dabs(double %14)
%16 = sitofp i32 %15 to double
%17 = fcmp ogt double %16, 1.000000e-10
br i1 %17, label %18, label %30
18: ; preds = %13
%19 = load double, double* %4
%20 = load double, double* %4
%21 = load double, double* %2
%22 = load double, double* %4
%23 = fneg double %21
%24 = call double @llvm.fmuladd.f64(double %23, double %22, double 1.000000e+00)
%25 = call double @llvm.fmuladd.f64(double %20, double %24, double %19)
store double %25, double* %6
%26 = load double, double* %6
%27 = load double, double* %4
%28 = fsub double %26, %27
store double %28, double* %5
%29 = load double, double* %6
store double %29, double* %4
br label %13
30: ; preds = %13
%31 = load double, double* %4
ret double %31
}

LLVM IR (-O2):
define double @inv(double %0) {
%2 = fmul double %0, 2.830000e-01
%3 = tail call double @order_of_magnitude(double %0)
%4 = fmul double %2, %3
%5 = tail call i32 @dabs(double 1.000000e+00)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %1
%8 = fneg double %0
br label %9
9: ; preds = %7, %9
%10 = phi double [ %4, %7 ], [ %12, %9 ]
%11 = tail call double @llvm.fmuladd.f64(double %8, double %10, double 1.000000e+00)
%12 = tail call double @llvm.fmuladd.f64(double %10, double %11, double %10)
%13 = fsub double %12, %10
%14 = tail call i32 @dabs(double %13)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %9, label %16
16: ; preds = %9, %1
%17 = phi double [ %4, %1 ], [ %12, %9 ]
ret double %17
}