#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 const fabs(double);
double log(double);
double g(double x) {
  const double eps = 1e-10;
  const double switchlev = 0.1;
  double z, d, di;
  long i;
  if (x == 0)
    z = 1;
  else if (fabs(x - 1.0) < eps)
    z = 0;
  else {
    d = 1.0 - x;
    if (fabs(d) > switchlev)
      z = (1.0 - (x * x) + (2.0 * x * log(x))) / (d * d);
    else {
      z = d / 3.0;
      di = d;
      for (i = 2l; i <= 7l; i++) {
        di *= d;
        z += (2.0 * di) / ((i + 1) * (i + 2));
      }
    }
  }
  return (z);
}


x86 assembly (clang, -O0):
<g>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xed3(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xebe(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1171 <g+0x51>
jp     1171 <g+0x51>
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12ec <g+0x1cc>
movsd  -0x8(%rbp),%xmm0
movsd  0xe92(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1030 <fabs@plt>
movaps %xmm0,%xmm1
movsd  0xe76(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a9 <g+0x89>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12e7 <g+0x1c7>
movsd  0xe5f(%rip),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <fabs@plt>
movsd  0xe33(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1256 <g+0x136>
movsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe0c(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xe0b(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <log@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12e2 <g+0x1c2>
movsd  -0x28(%rbp),%xmm0
movsd  0xdb5(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movq   $0x2,-0x38(%rbp)
cmpq   $0x7,-0x38(%rbp)
jg     12dd <g+0x1bd>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xd80(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    -0x38(%rbp),%rcx
add    $0x2,%rcx
imul   %rcx,%rax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    127e <g+0x15e>
jmp    12e2 <g+0x1c2>
jmp    12e7 <g+0x1c7>
jmp    12ec <g+0x1cc>
movsd  -0x20(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<g>:
sub    $0x28,%rsp
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1131 <g+0x21>
jp     1131 <g+0x21>
movsd  0xed4(%rip),%xmm0
add    $0x28,%rsp
ret
movsd  0xecf(%rip),%xmm2
addsd  %xmm1,%xmm2
andpd  0xeeb(%rip),%xmm2
movsd  0xec3(%rip),%xmm3
ucomisd %xmm2,%xmm3
ja     1255 <g+0x145>
movsd  0xea1(%rip),%xmm2
movapd %xmm2,%xmm4
subsd  %xmm1,%xmm4
movapd 0xec1(%rip),%xmm0
andpd  %xmm4,%xmm0
ucomisd 0xe9d(%rip),%xmm0
jbe    11c9 <g+0xb9>
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
subsd  %xmm0,%xmm2
movsd  %xmm2,(%rsp)
movapd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movapd %xmm1,%xmm0
movapd %xmm4,0x10(%rsp)
call   1030 <log@plt>
mulsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
movapd 0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
divsd  %xmm1,%xmm0
add    $0x28,%rsp
ret
movapd %xmm4,%xmm0
mulsd  %xmm4,%xmm0
movapd %xmm4,%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm0,%xmm0
divsd  0xe3b(%rip),%xmm0
movapd %xmm4,%xmm1
mulsd  %xmm3,%xmm1
addsd  %xmm3,%xmm3
movapd %xmm4,%xmm2
unpcklpd %xmm3,%xmm2
divpd  0xe3f(%rip),%xmm2
addsd  %xmm2,%xmm0
unpckhpd %xmm2,%xmm2
addsd  %xmm0,%xmm2
movapd %xmm4,%xmm0
mulsd  %xmm1,%xmm0
unpcklpd %xmm0,%xmm1
addpd  %xmm1,%xmm1
divpd  0xe2b(%rip),%xmm1
addsd  %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
mulsd  %xmm4,%xmm0
mulsd  %xmm0,%xmm4
unpcklpd %xmm4,%xmm0
addpd  %xmm0,%xmm0
divpd  0xe1b(%rip),%xmm0
addsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @g(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i64
store double %0, double* %2
store double 1.000000e-10, double* %3
store double 1.000000e-01, double* %4
%9 = load double, double* %2
%10 = fcmp oeq double %9, 0.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %1
store double 1.000000e+00, double* %5
br label %66
12: ; preds = %1
%13 = load double, double* %2
%14 = fsub double %13, 1.000000e+00
%15 = call double @fabs(double %14)
%16 = fcmp olt double %15, 1.000000e-10
br i1 %16, label %17, label %18
17: ; preds = %12
store double 0.000000e+00, double* %5
br label %65
18: ; preds = %12
%19 = load double, double* %2
%20 = fsub double 1.000000e+00, %19
store double %20, double* %6
%21 = load double, double* %6
%22 = call double @fabs(double %21)
%23 = fcmp ogt double %22, 1.000000e-01
br i1 %23, label %24, label %38
24: ; preds = %18
%25 = load double, double* %2
%26 = load double, double* %2
%27 = fneg double %25
%28 = call double @llvm.fmuladd.f64(double %27, double %26, double 1.000000e+00)
%29 = load double, double* %2
%30 = fmul double 2.000000e+00, %29
%31 = load double, double* %2
%32 = call double @log(double %31)
%33 = call double @llvm.fmuladd.f64(double %30, double %32, double %28)
%34 = load double, double* %6
%35 = load double, double* %6
%36 = fmul double %34, %35
%37 = fdiv double %33, %36
store double %37, double* %5
br label %64
38: ; preds = %18
%39 = load double, double* %6
%40 = fdiv double %39, 3.000000e+00
store double %40, double* %5
%41 = load double, double* %6
store double %41, double* %7
store i64 2, i64* %8
br label %42
42: ; preds = %60, %38
%43 = load i64, i64* %8
%44 = icmp sle i64 %43, 7
br i1 %44, label %45, label %63
45: ; preds = %42
%46 = load double, double* %6
%47 = load double, double* %7
%48 = fmul double %47, %46
store double %48, double* %7
%49 = load double, double* %7
%50 = fmul double 2.000000e+00, %49
%51 = load i64, i64* %8
%52 = add nsw i64 %51, 1
%53 = load i64, i64* %8
%54 = add nsw i64 %53, 2
%55 = mul nsw i64 %52, %54
%56 = sitofp i64 %55 to double
%57 = fdiv double %50, %56
%58 = load double, double* %5
%59 = fadd double %58, %57
store double %59, double* %5
br label %60
60: ; preds = %45
%61 = load i64, i64* %8
%62 = add nsw i64 %61, 1
store i64 %62, i64* %8
br label %42
63: ; preds = %42
br label %64
64: ; preds = %63, %24
br label %65
65: ; preds = %64, %17
br label %66
66: ; preds = %65, %11
%67 = load double, double* %5
ret double %67
}

LLVM IR (-O2):
define double @g(double %0) {
%2 = fcmp oeq double %0, 0.000000e+00
br i1 %2, label %52, label %3
3: ; preds = %1
%4 = fadd double %0, -1.000000e+00
%5 = tail call double @llvm.fabs.f64(double %4)
%6 = fcmp olt double %5, 1.000000e-10
br i1 %6, label %52, label %7
7: ; preds = %3
%8 = fsub double 1.000000e+00, %0
%9 = tail call double @llvm.fabs.f64(double %8)
%10 = fcmp ogt double %9, 1.000000e-01
br i1 %10, label %11, label %19
11: ; preds = %7
%12 = fneg double %0
%13 = tail call double @llvm.fmuladd.f64(double %12, double %0, double 1.000000e+00)
%14 = fmul double %0, 2.000000e+00
%15 = tail call double @log(double %0)
%16 = tail call double @llvm.fmuladd.f64(double %14, double %15, double %13)
%17 = fmul double %8, %8
%18 = fdiv double %16, %17
br label %52
19: ; preds = %7
%20 = fmul double %8, %8
%21 = fmul double %20, 2.000000e+00
%22 = fdiv double %21, 1.200000e+01
%23 = fmul double %8, %20
%24 = fmul double %23, 2.000000e+00
%25 = insertelement <2 x double> poison, double %8, i64 0
%26 = insertelement <2 x double> %25, double %24, i64 1
%27 = fdiv <2 x double> %26, <double 3.000000e+00, double 2.000000e+01>
%28 = extractelement <2 x double> %27, i64 0
%29 = fadd double %28, %22
%30 = extractelement <2 x double> %27, i64 1
%31 = fadd double %29, %30
%32 = fmul double %8, %23
%33 = fmul double %8, %32
%34 = insertelement <2 x double> poison, double %32, i64 0
%35 = insertelement <2 x double> %34, double %33, i64 1
%36 = fmul <2 x double> %35, <double 2.000000e+00, double 2.000000e+00>
%37 = fdiv <2 x double> %36, <double 3.000000e+01, double 4.200000e+01>
%38 = extractelement <2 x double> %37, i64 0
%39 = fadd double %31, %38
%40 = extractelement <2 x double> %37, i64 1
%41 = fadd double %39, %40
%42 = fmul double %8, %33
%43 = fmul double %8, %42
%44 = insertelement <2 x double> poison, double %42, i64 0
%45 = insertelement <2 x double> %44, double %43, i64 1
%46 = fmul <2 x double> %45, <double 2.000000e+00, double 2.000000e+00>
%47 = fdiv <2 x double> %46, <double 5.600000e+01, double 7.200000e+01>
%48 = extractelement <2 x double> %47, i64 0
%49 = fadd double %41, %48
%50 = extractelement <2 x double> %47, i64 1
%51 = fadd double %49, %50
br label %52
52: ; preds = %19, %3, %1, %11
%53 = phi double [ %18, %11 ], [ 1.000000e+00, %1 ], [ 0.000000e+00, %3 ], [ %51, %19 ]
ret double %53
}