#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 */
scalar_t__ _finite(double);
double i_zero(double x) {
  double n, a, halfx, sum;
  halfx = x / 2.0;
  sum = 1.0;
  a = 1.0;
  n = 1.0;
  do {
    a *= halfx;
    a /= n;
    sum += a * a;
    n += 1.0;
  } while (a != 0.0 && _finite(sum));
  return sum;
}


x86 assembly (clang, -O0):
<i_zero>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xede(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xec5(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeb8(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeab(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe60(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x29(%rbp)
jne    11cc <i_zero+0xbc>
jp     11cc <i_zero+0xbc>
jmp    11e0 <i_zero+0xd0>
movsd  -0x28(%rbp),%xmm0
call   1030 <_finite@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    115a <i_zero+0x4a>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i_zero>:
sub    $0x28,%rsp
mulsd  0xee4(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xede(%rip),%xmm0
movapd %xmm0,%xmm1
movapd %xmm0,%xmm2
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movapd %xmm0,%xmm3
mulsd  0x8(%rsp),%xmm1
divsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm3,%xmm0
ucomisd 0xeae(%rip),%xmm1
jne    1166 <i_zero+0x56>
jnp    119c <i_zero+0x8c>
addsd  0xe9a(%rip),%xmm2
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1030 <_finite@plt>
movsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm2
movsd  0x20(%rsp),%xmm1
test   %rax,%rax
jne    1140 <i_zero+0x30>
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @i_zero(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 = fdiv double %7, 2.000000e+00
store double %8, double* %5
store double 1.000000e+00, double* %6
store double 1.000000e+00, double* %4
store double 1.000000e+00, double* %3
br label %9
9: ; preds = %29, %1
%10 = load double, double* %5
%11 = load double, double* %4
%12 = fmul double %11, %10
store double %12, double* %4
%13 = load double, double* %3
%14 = load double, double* %4
%15 = fdiv double %14, %13
store double %15, double* %4
%16 = load double, double* %4
%17 = load double, double* %4
%18 = load double, double* %6
%19 = call double @llvm.fmuladd.f64(double %16, double %17, double %18)
store double %19, double* %6
%20 = load double, double* %3
%21 = fadd double %20, 1.000000e+00
store double %21, double* %3
br label %22
22: ; preds = %9
%23 = load double, double* %4
%24 = fcmp une double %23, 0.000000e+00
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load double, double* %6
%27 = call i64 @_finite(double %26)
%28 = icmp ne i64 %27, 0
br label %29
29: ; preds = %25, %22
%30 = phi i1 [ false, %22 ], [ %28, %25 ]
br i1 %30, label %9, label %31
31: ; preds = %29
%32 = load double, double* %6
ret double %32
}

LLVM IR (-O2):
define double @i_zero(double %0) {
%2 = fmul double %0, 5.000000e-01
br label %3
3: ; preds = %11, %1
%4 = phi double [ 1.000000e+00, %1 ], [ %8, %11 ]
%5 = phi double [ 1.000000e+00, %1 ], [ %12, %11 ]
%6 = phi double [ 1.000000e+00, %1 ], [ %9, %11 ]
%7 = fmul double %2, %4
%8 = fdiv double %7, %5
%9 = tail call double @llvm.fmuladd.f64(double %8, double %8, double %6)
%10 = fcmp une double %8, 0.000000e+00
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = fadd double %5, 1.000000e+00
%13 = tail call i64 @_finite(double %9)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %3
15: ; preds = %3, %11
ret double %9
}