#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 FLT_EPSILON;
float INFINITY;
float NAN;
float expf(float);
double fabsf(float);
scalar_t__ isnan(float);
float logf(float x) {
  float y;
  float y_old;
  float ey;
  float epsilon;
  int relax_factor;
  int iter;
  y = 0.0;
  y_old = 1.0;
  epsilon = FLT_EPSILON;
  iter = 0;
  relax_factor = 1;
  if (isnan(x) || x < 0.0) {
    return NAN;
  }
  if (x == 0.0) {
    return -INFINITY;
  }
  while (y > y_old + epsilon || y < y_old - epsilon) {
    y_old = y;
    ey = expf(y);
    y -= (ey - x) / ey;
    if (y > 88.0F) {
      y = 88.0F;
    }
    if (y < -88.0F) {
      y = -88.0F;
    }
    epsilon = (fabsf(y) > 1.0) ? fabsf(y) * FLT_EPSILON : FLT_EPSILON;
    if (++iter >= 10) {
      relax_factor *= 2;
      iter = 0;
    }
    if (relax_factor > 1) {
      epsilon *= relax_factor;
    }
  }
  if (y == 88.0F) {
    return INFINITY;
  }
  if (y == -88.0F) {
    return INFINITY;
  }
  return y;
}


x86 assembly (clang, -O0):
<logf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  0xeb3(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    0x2e77(%rip),%rax
movsd  (%rax),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
movss  -0x8(%rbp),%xmm0
call   1050 <isnan@plt>
cmp    $0x0,%rax
jne    119e <logf+0x6e>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11b3 <logf+0x83>
mov    0x2e53(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    13b8 <logf+0x288>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11f1 <logf+0xc1>
jp     11f1 <logf+0xc1>
mov    0x2e0a(%rip),%rax
movss  (%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    13b8 <logf+0x288>
jmp    11f6 <logf+0xc6>
movss  -0xc(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
addss  -0x18(%rbp),%xmm1
mov    $0x1,%al
ucomiss %xmm1,%xmm0
mov    %al,-0x21(%rbp)
ja     122b <logf+0xfb>
movss  -0xc(%rbp),%xmm1
movss  -0x10(%rbp),%xmm0
subss  -0x18(%rbp),%xmm0
ucomiss %xmm1,%xmm0
seta   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    123b <logf+0x10b>
jmp    134c <logf+0x21c>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
call   1040 <expf@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm1
subss  -0x8(%rbp),%xmm1
divss  -0x14(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xd86(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    1294 <logf+0x164>
movss  0xd75(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  0xd6c(%rip),%xmm0
ucomiss -0xc(%rbp),%xmm0
jbe    12b3 <logf+0x183>
movss  0xd5a(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <fabsf@plt>
movsd  0xd4b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12ee <logf+0x1be>
movss  -0xc(%rbp),%xmm0
call   1030 <fabsf@plt>
mov    0x2cf0(%rip),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    12fe <logf+0x1ce>
mov    0x2cdb(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmp    $0xa,%eax
jl     132e <logf+0x1fe>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jle    1347 <logf+0x217>
cvtsi2ssl -0x1c(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    11f6 <logf+0xc6>
movss  -0xc(%rbp),%xmm0
movss  0xcab(%rip),%xmm1
ucomiss %xmm1,%xmm0
jne    137d <logf+0x24d>
jp     137d <logf+0x24d>
mov    0x2c71(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    13b8 <logf+0x288>
movss  -0xc(%rbp),%xmm0
movss  0xc7e(%rip),%xmm1
ucomiss %xmm1,%xmm0
jne    13ae <logf+0x27e>
jp     13ae <logf+0x27e>
mov    0x2c40(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    13b8 <logf+0x288>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
movaps %xmm0,%xmm1
movss  %xmm0,0x4(%rsp)
mov    0x2e86(%rip),%r15
movsd  (%r15),%xmm0
movsd  %xmm0,0x8(%rsp)
movaps %xmm1,%xmm0
call   1050 <isnan@plt>
movss  0x4(%rsp),%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm1,%xmm0
ja     118e <logf+0x5e>
test   %rax,%rax
jne    118e <logf+0x5e>
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jne    11a4 <logf+0x74>
jp     11a4 <logf+0x74>
mov    0x2e5f(%rip),%rax
movss  (%rax),%xmm0
xorps  0xe94(%rip),%xmm0
jmp    1199 <logf+0x69>
mov    0x2e63(%rip),%rax
movss  (%rax),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
movsd  0x8(%rsp),%xmm1
cvtsd2ss %xmm1,%xmm1
movss  0xe4a(%rip),%xmm4
movaps %xmm1,%xmm2
addss  %xmm4,%xmm2
ucomiss %xmm2,%xmm0
ja     11ce <logf+0x9e>
subss  %xmm1,%xmm4
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm4
jbe    1199 <logf+0x69>
xorps  %xmm0,%xmm0
mov    $0x1,%ebp
xor    %r14d,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movss  %xmm0,0x8(%rsp)
call   1040 <expf@plt>
movaps %xmm0,%xmm1
subss  0x4(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  0x8(%rsp),%xmm0
subss  %xmm1,%xmm0
movss  0xdfa(%rip),%xmm1
minss  %xmm0,%xmm1
movss  0xdf2(%rip),%xmm0
maxss  %xmm1,%xmm0
movaps %xmm0,0x10(%rsp)
call   1030 <fabsf@plt>
ucomisd 0xde4(%rip),%xmm0
jbe    1240 <logf+0x110>
movapd 0x10(%rsp),%xmm0
call   1030 <fabsf@plt>
mulsd  (%r15),%xmm0
jmp    1245 <logf+0x115>
movsd  (%r15),%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
cmp    $0x9,%ebx
lea    0x1(%rbx),%eax
mov    %eax,%ebx
cmovge %r14d,%ebx
setge  %cl
shl    %cl,%ebp
test   %ebp,%ebp
mov    $0x1,%eax
cmovg  %ebp,%eax
xorps  %xmm2,%xmm2
cvtsi2ss %eax,%xmm2
mulss  %xmm1,%xmm2
movss  0x8(%rsp),%xmm3
movaps %xmm3,%xmm1
addss  %xmm2,%xmm1
movaps 0x10(%rsp),%xmm0
ucomiss %xmm1,%xmm0
ja     11e0 <logf+0xb0>
subss  %xmm2,%xmm3
ucomiss %xmm0,%xmm3
ja     11e0 <logf+0xb0>
ucomiss 0xd63(%rip),%xmm0
jne    12a5 <logf+0x175>
jnp    12b8 <logf+0x188>
ucomiss 0xd5c(%rip),%xmm0
jne    1199 <logf+0x69>
jp     1199 <logf+0x69>
mov    0x2d21(%rip),%rax
jmp    1195 <logf+0x65>

LLVM IR (-O0):
@FLT_EPSILON = global double 0.000000e+00
@NAN = global float 0.000000e+00
@INFINITY = global float 0.000000e+00
define float @logf(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca i32
%9 = alloca i32
store float %0, float* %3
store float 0.000000e+00, float* %4
store float 1.000000e+00, float* %5
%10 = load double, double* @FLT_EPSILON
%11 = fptrunc double %10 to float
store float %11, float* %7
store i32 0, i32* %9
store i32 1, i32* %8
%12 = load float, float* %3
%13 = call i64 @isnan(float %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %1
%16 = load float, float* %3
%17 = fpext float %16 to double
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %21
19: ; preds = %15, %1
%20 = load float, float* @NAN
store float %20, float* %2
br label %102
21: ; preds = %15
%22 = load float, float* %3
%23 = fpext float %22 to double
%24 = fcmp oeq double %23, 0.000000e+00
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load float, float* @INFINITY
%27 = fneg float %26
store float %27, float* %2
br label %102
28: ; preds = %21
br label %29
29: ; preds = %89, %28
%30 = load float, float* %4
%31 = load float, float* %5
%32 = load float, float* %7
%33 = fadd float %31, %32
%34 = fcmp ogt float %30, %33
br i1 %34, label %41, label %35
35: ; preds = %29
%36 = load float, float* %4
%37 = load float, float* %5
%38 = load float, float* %7
%39 = fsub float %37, %38
%40 = fcmp olt float %36, %39
br label %41
41: ; preds = %35, %29
%42 = phi i1 [ true, %29 ], [ %40, %35 ]
br i1 %42, label %43, label %90
43: ; preds = %41
%44 = load float, float* %4
store float %44, float* %5
%45 = load float, float* %4
%46 = call float @expf(float %45)
store float %46, float* %6
%47 = load float, float* %6
%48 = load float, float* %3
%49 = fsub float %47, %48
%50 = load float, float* %6
%51 = fdiv float %49, %50
%52 = load float, float* %4
%53 = fsub float %52, %51
store float %53, float* %4
%54 = load float, float* %4
%55 = fcmp ogt float %54, 8.800000e+01
br i1 %55, label %56, label %57
56: ; preds = %43
store float 8.800000e+01, float* %4
br label %57
57: ; preds = %56, %43
%58 = load float, float* %4
%59 = fcmp olt float %58, -8.800000e+01
br i1 %59, label %60, label %61
60: ; preds = %57
store float -8.800000e+01, float* %4
br label %61
61: ; preds = %60, %57
%62 = load float, float* %4
%63 = call double @fabsf(float %62)
%64 = fcmp ogt double %63, 1.000000e+00
br i1 %64, label %65, label %70
65: ; preds = %61
%66 = load float, float* %4
%67 = call double @fabsf(float %66)
%68 = load double, double* @FLT_EPSILON
%69 = fmul double %67, %68
br label %72
70: ; preds = %61
%71 = load double, double* @FLT_EPSILON
br label %72
72: ; preds = %70, %65
%73 = phi double [ %69, %65 ], [ %71, %70 ]
%74 = fptrunc double %73 to float
store float %74, float* %7
%75 = load i32, i32* %9
%76 = add nsw i32 %75, 1
store i32 %76, i32* %9
%77 = icmp sge i32 %76, 10
br i1 %77, label %78, label %81
78: ; preds = %72
%79 = load i32, i32* %8
%80 = mul nsw i32 %79, 2
store i32 %80, i32* %8
store i32 0, i32* %9
br label %81
81: ; preds = %78, %72
%82 = load i32, i32* %8
%83 = icmp sgt i32 %82, 1
br i1 %83, label %84, label %89
84: ; preds = %81
%85 = load i32, i32* %8
%86 = sitofp i32 %85 to float
%87 = load float, float* %7
%88 = fmul float %87, %86
store float %88, float* %7
br label %89
89: ; preds = %84, %81
br label %29
90: ; preds = %41
%91 = load float, float* %4
%92 = fcmp oeq float %91, 8.800000e+01
br i1 %92, label %93, label %95
93: ; preds = %90
%94 = load float, float* @INFINITY
store float %94, float* %2
br label %102
95: ; preds = %90
%96 = load float, float* %4
%97 = fcmp oeq float %96, -8.800000e+01
br i1 %97, label %98, label %100
98: ; preds = %95
%99 = load float, float* @INFINITY
store float %99, float* %2
br label %102
100: ; preds = %95
%101 = load float, float* %4
store float %101, float* %2
br label %102
102: ; preds = %100, %98, %93, %25, %19
%103 = load float, float* %2
ret float %103
}

LLVM IR (-O2):
@FLT_EPSILON = global double 0.000000e+00
@NAN = global float 0.000000e+00
@INFINITY = global float 0.000000e+00
define float @logf(float %0) {
%2 = load double, double* @FLT_EPSILON
%3 = tail call i64 @isnan(float %0)
%4 = icmp ne i64 %3, 0
%5 = fcmp olt float %0, 0.000000e+00
%6 = or i1 %5, %4
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load float, float* @NAN
br label %66
9: ; preds = %1
%10 = fptrunc double %2 to float
%11 = fcmp oeq float %0, 0.000000e+00
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = fadd float %10, 1.000000e+00
%14 = fcmp olt float %13, 0.000000e+00
%15 = fsub float 1.000000e+00, %10
%16 = fcmp ogt float %15, 0.000000e+00
%17 = or i1 %14, %16
br i1 %17, label %21, label %66
18: ; preds = %9
%19 = load float, float* @INFINITY
%20 = fneg float %19
br label %66
21: ; preds = %12, %41
%22 = phi i32 [ %48, %41 ], [ 0, %12 ]
%23 = phi i32 [ %47, %41 ], [ 1, %12 ]
%24 = phi float [ %32, %41 ], [ 0.000000e+00, %12 ]
%25 = tail call float @expf(float %24)
%26 = fsub float %25, %0
%27 = fdiv float %26, %25
%28 = fsub float %24, %27
%29 = fcmp ogt float %28, 8.800000e+01
%30 = select i1 %29, float 8.800000e+01, float %28
%31 = fcmp olt float %30, -8.800000e+01
%32 = select i1 %31, float -8.800000e+01, float %30
%33 = tail call double @fabsf(float %32)
%34 = fcmp ogt double %33, 1.000000e+00
br i1 %34, label %35, label %39
35: ; preds = %21
%36 = tail call double @fabsf(float %32)
%37 = load double, double* @FLT_EPSILON
%38 = fmul double %36, %37
br label %41
39: ; preds = %21
%40 = load double, double* @FLT_EPSILON
br label %41
41: ; preds = %39, %35
%42 = phi double [ %38, %35 ], [ %40, %39 ]
%43 = fptrunc double %42 to float
%44 = add nsw i32 %22, 1
%45 = icmp sgt i32 %22, 8
%46 = zext i1 %45 to i32
%47 = shl nsw i32 %23, %46
%48 = select i1 %45, i32 0, i32 %44
%49 = icmp sgt i32 %47, 1
%50 = select i1 %49, i32 %47, i32 1
%51 = sitofp i32 %50 to float
%52 = fmul float %51, %43
%53 = fadd float %24, %52
%54 = fcmp ogt float %32, %53
%55 = fsub float %24, %52
%56 = fcmp olt float %32, %55
%57 = or i1 %54, %56
br i1 %57, label %21, label %58
58: ; preds = %41
%59 = fcmp oeq float %32, 8.800000e+01
br i1 %59, label %60, label %62
60: ; preds = %58
%61 = load float, float* @INFINITY
br label %66
62: ; preds = %58
%63 = fcmp oeq float %32, -8.800000e+01
br i1 %63, label %64, label %66
64: ; preds = %62
%65 = load float, float* @INFINITY
br label %66
66: ; preds = %12, %62, %64, %60, %18, %7
%67 = phi float [ %8, %7 ], [ %20, %18 ], [ %61, %60 ], [ %65, %64 ], [ %32, %62 ], [ 0.000000e+00, %12 ]
ret float %67
}