#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 /*<<< orphan*/ exit(int);
int fabs(double);
double log(double);
int /*<<< orphan*/ printf(char *);
double logOnePlus(double x) {
  if (x <= -1.0) {
    printf("Invalid argument");
    exit(1);
  }
  if (fabs(x) > 1e-4)
    return log(1.0 + x);
  return (-0.5 * x + 1.0) * x;
}


x86 assembly (clang, -O0):
<logOnePlus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xeab(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1176 <logOnePlus+0x36>
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movsd  -0x10(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe7c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b2 <logOnePlus+0x72>
movsd  0xe7a(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11d9 <logOnePlus+0x99>
movsd  -0x10(%rbp),%xmm0
movsd  0xe51(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe4d(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logOnePlus>:
push   %rax
movsd  0xeb7(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    118f <logOnePlus+0x4f>
movsd  %xmm0,(%rsp)
call   1040 <fabs@plt>
test   %eax,%eax
jle    1170 <logOnePlus+0x30>
movsd  (%rsp),%xmm0
addsd  0xea6(%rip),%xmm0
pop    %rax
jmp    1050 <log@plt>
movsd  0xe90(%rip),%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm0
addsd  0xe87(%rip),%xmm0
mulsd  %xmm1,%xmm0
pop    %rax
ret
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Invalid argument\00"
define double @logOnePlus(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %3
%4 = load double, double* %3
%5 = fcmp ole double %4, -1.000000e+00
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = load double, double* %3
%11 = call i32 @fabs(double %10)
%12 = sitofp i32 %11 to double
%13 = fcmp ogt double %12, 1.000000e-04
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load double, double* %3
%16 = fadd double 1.000000e+00, %15
%17 = call double @log(double %16)
store double %17, double* %2
br label %23
18: ; preds = %9
%19 = load double, double* %3
%20 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %19, double 1.000000e+00)
%21 = load double, double* %3
%22 = fmul double %20, %21
store double %22, double* %2
br label %23
23: ; preds = %18, %14
%24 = load double, double* %2
ret double %24
}

LLVM IR (-O2):
@.str = [17 x i8] c"Invalid argument\00"
define double @logOnePlus(double %0) {
%2 = fcmp ugt double %0, -1.000000e+00
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %1
%7 = tail call i32 @fabs(double %0)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = fadd double %0, 1.000000e+00
%11 = tail call double @log(double %10)
br label %15
12: ; preds = %6
%13 = tail call double @llvm.fmuladd.f64(double %0, double -5.000000e-01, double 1.000000e+00)
%14 = fmul double %13, %0
br label %15
15: ; preds = %12, %9
%16 = phi double [ %11, %9 ], [ %14, %12 ]
ret double %16
}