#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 exp(float);
double fabsf(float);
float logf(float x) {
  float y, y_old, ey, epsilon;
  y = 0.0;
  y_old = 1.0;
  epsilon = FLT_EPSILON;
  while (y > y_old + epsilon || y < y_old - epsilon) {
    y_old = y;
    ey = exp(y);
    y -= (ey - x) / ey;
    if (y > 700.0) {
      y = 700.0;
    }
    if (y < -700.0) {
      y = -700.0;
    }
    epsilon = (fabsf(y) > 1.0) ? fabsf(y) * FLT_EPSILON : FLT_EPSILON;
  }
  if (y == 700.0) {
    return INFINITY;
  }
  if (y == -700.0) {
    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  0xec3(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    0x2e8f(%rip),%rax
movsd  (%rax),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
addss  -0x18(%rbp),%xmm1
mov    $0x1,%al
ucomiss %xmm1,%xmm0
mov    %al,-0x19(%rbp)
ja     118b <logf+0x6b>
movss  -0xc(%rbp),%xmm1
movss  -0x10(%rbp),%xmm0
subss  -0x18(%rbp),%xmm0
ucomiss %xmm1,%xmm0
seta   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    119b <logf+0x7b>
jmp    127f <logf+0x15f>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
call   1040 <exp@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
cvtss2sd %xmm0,%xmm0
movsd  0xe2e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11f9 <logf+0xd9>
movss  0xe10(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe0e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1221 <logf+0x101>
movss  0xdec(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <fabsf@plt>
movsd  0xded(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    125c <logf+0x13c>
movss  -0xc(%rbp),%xmm0
call   1030 <fabsf@plt>
mov    0x2d8a(%rip),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    126c <logf+0x14c>
mov    0x2d75(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    1156 <logf+0x36>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd80(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    12b5 <logf+0x195>
jp     12b5 <logf+0x195>
mov    0x2d41(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12f5 <logf+0x1d5>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd52(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    12eb <logf+0x1cb>
jp     12eb <logf+0x1cb>
mov    0x2d0b(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12f5 <logf+0x1d5>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logf>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm0,0xc(%rsp)
mov    0x2ea6(%rip),%rbx
movsd  (%rbx),%xmm0
cvtsd2ss %xmm0,%xmm1
movss  0xebe(%rip),%xmm3
movaps %xmm1,%xmm2
addss  %xmm3,%xmm2
xorps  %xmm0,%xmm0
ucomiss %xmm2,%xmm0
ja     1161 <logf+0x41>
subss  %xmm1,%xmm3
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm3
jbe    1225 <logf+0x105>
xorps  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movss  %xmm0,0x8(%rsp)
call   1040 <exp@plt>
movaps %xmm0,%xmm1
subss  0xc(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  0x8(%rsp),%xmm0
subss  %xmm1,%xmm0
movss  0xe6a(%rip),%xmm1
minss  %xmm0,%xmm1
movss  0xe62(%rip),%xmm0
maxss  %xmm1,%xmm0
movss  %xmm0,0x4(%rsp)
call   1030 <fabsf@plt>
ucomisd 0xe53(%rip),%xmm0
jbe    11d0 <logf+0xb0>
movss  0x4(%rsp),%xmm0
call   1030 <fabsf@plt>
mulsd  (%rbx),%xmm0
jmp    11d4 <logf+0xb4>
movsd  (%rbx),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movss  0x8(%rsp),%xmm3
movaps %xmm3,%xmm1
addss  %xmm2,%xmm1
movss  0x4(%rsp),%xmm0
ucomiss %xmm1,%xmm0
ja     1170 <logf+0x50>
subss  %xmm2,%xmm3
ucomiss %xmm0,%xmm3
ja     1170 <logf+0x50>
ucomiss 0xdf9(%rip),%xmm0
jne    120f <logf+0xef>
jnp    121a <logf+0xfa>
ucomiss 0xdf2(%rip),%xmm0
jne    1225 <logf+0x105>
jp     1225 <logf+0x105>
mov    0x2dc7(%rip),%rax
movss  (%rax),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@FLT_EPSILON = global double 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
store float %0, float* %3
store float 0.000000e+00, float* %4
store float 1.000000e+00, float* %5
%8 = load double, double* @FLT_EPSILON
%9 = fptrunc double %8 to float
store float %9, float* %7
br label %10
10: ; preds = %55, %1
%11 = load float, float* %4
%12 = load float, float* %5
%13 = load float, float* %7
%14 = fadd float %12, %13
%15 = fcmp ogt float %11, %14
br i1 %15, label %22, label %16
16: ; preds = %10
%17 = load float, float* %4
%18 = load float, float* %5
%19 = load float, float* %7
%20 = fsub float %18, %19
%21 = fcmp olt float %17, %20
br label %22
22: ; preds = %16, %10
%23 = phi i1 [ true, %10 ], [ %21, %16 ]
br i1 %23, label %24, label %58
24: ; preds = %22
%25 = load float, float* %4
store float %25, float* %5
%26 = load float, float* %4
%27 = call float @exp(float %26)
store float %27, float* %6
%28 = load float, float* %6
%29 = load float, float* %3
%30 = fsub float %28, %29
%31 = load float, float* %6
%32 = fdiv float %30, %31
%33 = load float, float* %4
%34 = fsub float %33, %32
store float %34, float* %4
%35 = load float, float* %4
%36 = fpext float %35 to double
%37 = fcmp ogt double %36, 7.000000e+02
br i1 %37, label %38, label %39
38: ; preds = %24
store float 7.000000e+02, float* %4
br label %39
39: ; preds = %38, %24
%40 = load float, float* %4
%41 = fpext float %40 to double
%42 = fcmp olt double %41, -7.000000e+02
br i1 %42, label %43, label %44
43: ; preds = %39
store float -7.000000e+02, float* %4
br label %44
44: ; preds = %43, %39
%45 = load float, float* %4
%46 = call double @fabsf(float %45)
%47 = fcmp ogt double %46, 1.000000e+00
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = load float, float* %4
%50 = call double @fabsf(float %49)
%51 = load double, double* @FLT_EPSILON
%52 = fmul double %50, %51
br label %55
53: ; preds = %44
%54 = load double, double* @FLT_EPSILON
br label %55
55: ; preds = %53, %48
%56 = phi double [ %52, %48 ], [ %54, %53 ]
%57 = fptrunc double %56 to float
store float %57, float* %7
br label %10
58: ; preds = %22
%59 = load float, float* %4
%60 = fpext float %59 to double
%61 = fcmp oeq double %60, 7.000000e+02
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = load float, float* @INFINITY
store float %63, float* %2
br label %72
64: ; preds = %58
%65 = load float, float* %4
%66 = fpext float %65 to double
%67 = fcmp oeq double %66, -7.000000e+02
br i1 %67, label %68, label %70
68: ; preds = %64
%69 = load float, float* @INFINITY
store float %69, float* %2
br label %72
70: ; preds = %64
%71 = load float, float* %4
store float %71, float* %2
br label %72
72: ; preds = %70, %68, %62
%73 = load float, float* %2
ret float %73
}

LLVM IR (-O2):
@FLT_EPSILON = global double 0.000000e+00
@INFINITY = global float 0.000000e+00
define float @logf(float %0) {
%2 = load double, double* @FLT_EPSILON
%3 = fptrunc double %2 to float
%4 = fadd float %3, 1.000000e+00
%5 = fcmp olt float %4, 0.000000e+00
%6 = fsub float 1.000000e+00, %3
%7 = fcmp ogt float %6, 0.000000e+00
%8 = or i1 %5, %7
br i1 %8, label %9, label %43
9: ; preds = %1, %27
%10 = phi float [ %18, %27 ], [ 0.000000e+00, %1 ]
%11 = tail call float @exp(float %10)
%12 = fsub float %11, %0
%13 = fdiv float %12, %11
%14 = fsub float %10, %13
%15 = fcmp ogt float %14, 7.000000e+02
%16 = select i1 %15, float 7.000000e+02, float %14
%17 = fcmp olt float %16, -7.000000e+02
%18 = select i1 %17, float -7.000000e+02, float %16
%19 = tail call double @fabsf(float %18)
%20 = fcmp ogt double %19, 1.000000e+00
br i1 %20, label %21, label %25
21: ; preds = %9
%22 = tail call double @fabsf(float %18)
%23 = load double, double* @FLT_EPSILON
%24 = fmul double %22, %23
br label %27
25: ; preds = %9
%26 = load double, double* @FLT_EPSILON
br label %27
27: ; preds = %25, %21
%28 = phi double [ %24, %21 ], [ %26, %25 ]
%29 = fptrunc double %28 to float
%30 = fadd float %10, %29
%31 = fcmp ogt float %18, %30
%32 = fsub float %10, %29
%33 = fcmp olt float %18, %32
%34 = or i1 %31, %33
br i1 %34, label %9, label %35
35: ; preds = %27
%36 = fcmp oeq float %18, 7.000000e+02
br i1 %36, label %37, label %39
37: ; preds = %35
%38 = load float, float* @INFINITY
br label %43
39: ; preds = %35
%40 = fcmp oeq float %18, -7.000000e+02
br i1 %40, label %41, label %43
41: ; preds = %39
%42 = load float, float* @INFINITY
br label %43
43: ; preds = %1, %39, %41, %37
%44 = phi float [ %38, %37 ], [ %42, %41 ], [ %18, %39 ], [ 0.000000e+00, %1 ]
ret float %44
}