#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*/ EDOM;
int /*<<< orphan*/ errno;
float frexpf(float const, int *);
float logf(const float x) {
  float Rz;
  float f, z, w, znum, zden, xn;
  int n;
  if (x <= 0.0) {
    errno = EDOM;
    return 0.0;
  }
  f = frexpf(x, &n);
  znum = f - 0.5;
  if (f > 0.70710678118654752440) {
    znum -= 0.5;
    zden = (f * 0.5) + 0.5;
  } else {
    n--;
    zden = znum * 0.5 + 0.5;
  }
  z = znum / zden;
  w = z * z;
  Rz = z + z * (w * (-0.5527074855E+0) / (w + -0.6632718214E+1));
  xn = n;
  return ((xn * -2.121944400546905827679E-4 + Rz) + xn * 0.693359375);
}


x86 assembly (clang, -O0):
<logf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jb     1152 <logf+0x42>
mov    0x2eae(%rip),%rax
mov    (%rax),%ecx
mov    0x2e95(%rip),%rax
mov    %ecx,(%rax)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12cb <logf+0x1bb>
movss  -0x8(%rbp),%xmm0
lea    -0x28(%rbp),%rdi
call   1030 <frexpf@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe92(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe6c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e3 <logf+0xd3>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe59(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe3b(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
jmp    120e <logf+0xfe>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe0b(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x1c(%rbp),%xmm0
divss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x18(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
movsd  0xdd9(%rip),%xmm3
mulsd  %xmm3,%xmm2
movss  -0x18(%rbp),%xmm3
cvtss2sd %xmm3,%xmm3
movsd  0xdbc(%rip),%xmm4
addsd  %xmm4,%xmm3
divsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
cvtsi2ssl -0x28(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd77(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd56(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logf>:
push   %rax
movaps %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm1,%xmm0
jae    1160 <logf+0x50>
lea    0x4(%rsp),%rdi
movaps %xmm1,%xmm0
call   1030 <frexpf@plt>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
addss  0xec8(%rip),%xmm0
ucomisd 0xec8(%rip),%xmm1
jbe    1174 <logf+0x64>
addss  0xeb6(%rip),%xmm0
movsd  0xebe(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm2,%xmm1
mov    0x4(%rsp),%eax
jmp    1192 <logf+0x82>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    0x2e68(%rip),%rcx
mov    %eax,(%rcx)
pop    %rax
ret
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  0xe86(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm2,%xmm1
cvtsd2ss %xmm1,%xmm1
divss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
mulss  %xmm0,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe67(%rip),%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe63(%rip),%xmm0
divsd  %xmm0,%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm1,%xmm2
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm2,%xmm1
cvtss2sd %xmm0,%xmm0
cvtss2sd %xmm1,%xmm1
movsd  0xe41(%rip),%xmm2
mulsd  %xmm0,%xmm2
mulsd  0xe3d(%rip),%xmm0
addsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
cvtsd2ss %xmm0,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@EDOM = global i32 0
@errno = global i32 0
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 float
%9 = alloca float
%10 = alloca float
%11 = alloca i32
store float %0, float* %3
%12 = load float, float* %3
%13 = fpext float %12 to double
%14 = fcmp ole double %13, 0.000000e+00
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = load i32, i32* @EDOM
store i32 %16, i32* @errno
store float 0.000000e+00, float* %2
br label %74
17: ; preds = %1
%18 = load float, float* %3
%19 = call float @frexpf(float %18, i32* %11)
store float %19, float* %5
%20 = load float, float* %5
%21 = fpext float %20 to double
%22 = fsub double %21, 5.000000e-01
%23 = fptrunc double %22 to float
store float %23, float* %8
%24 = load float, float* %5
%25 = fpext float %24 to double
%26 = fcmp ogt double %25, 0x3FE6A09E667F3BCD
br i1 %26, label %27, label %36
27: ; preds = %17
%28 = load float, float* %8
%29 = fpext float %28 to double
%30 = fsub double %29, 5.000000e-01
%31 = fptrunc double %30 to float
store float %31, float* %8
%32 = load float, float* %5
%33 = fpext float %32 to double
%34 = call double @llvm.fmuladd.f64(double %33, double 5.000000e-01, double 5.000000e-01)
%35 = fptrunc double %34 to float
store float %35, float* %9
br label %43
36: ; preds = %17
%37 = load i32, i32* %11
%38 = add nsw i32 %37, -1
store i32 %38, i32* %11
%39 = load float, float* %8
%40 = fpext float %39 to double
%41 = call double @llvm.fmuladd.f64(double %40, double 5.000000e-01, double 5.000000e-01)
%42 = fptrunc double %41 to float
store float %42, float* %9
br label %43
43: ; preds = %36, %27
%44 = load float, float* %8
%45 = load float, float* %9
%46 = fdiv float %44, %45
store float %46, float* %6
%47 = load float, float* %6
%48 = load float, float* %6
%49 = fmul float %47, %48
store float %49, float* %7
%50 = load float, float* %6
%51 = fpext float %50 to double
%52 = load float, float* %6
%53 = fpext float %52 to double
%54 = load float, float* %7
%55 = fpext float %54 to double
%56 = fmul double %55, 0xBFE1AFC79BCF42B8
%57 = load float, float* %7
%58 = fpext float %57 to double
%59 = fadd double %58, 0xC01A87E74892DAA7
%60 = fdiv double %56, %59
%61 = call double @llvm.fmuladd.f64(double %53, double %60, double %51)
%62 = fptrunc double %61 to float
store float %62, float* %4
%63 = load i32, i32* %11
%64 = sitofp i32 %63 to float
store float %64, float* %10
%65 = load float, float* %10
%66 = fpext float %65 to double
%67 = load float, float* %4
%68 = fpext float %67 to double
%69 = call double @llvm.fmuladd.f64(double %66, double 0xBF2BD0105C610CA8, double %68)
%70 = load float, float* %10
%71 = fpext float %70 to double
%72 = call double @llvm.fmuladd.f64(double %71, double 0x3FE6300000000000, double %69)
%73 = fptrunc double %72 to float
store float %73, float* %2
br label %74
74: ; preds = %43, %15
%75 = load float, float* %2
ret float %75
}

LLVM IR (-O2):
@EDOM = global i32 0
@errno = global i32 0
define float @logf(float %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = fcmp ugt float %0, 0.000000e+00
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = load i32, i32* @EDOM
store i32 %6, i32* @errno
br label %41
7: ; preds = %1
%8 = call float @frexpf(float %0, i32* %2)
%9 = fpext float %8 to double
%10 = fadd float %8, -5.000000e-01
%11 = fcmp ogt double %9, 0x3FE6A09E667F3BCD
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = fadd float %10, -5.000000e-01
%14 = tail call double @llvm.fmuladd.f64(double %9, double 5.000000e-01, double 5.000000e-01)
%15 = load i32, i32* %2
br label %21
16: ; preds = %7
%17 = load i32, i32* %2
%18 = add nsw i32 %17, -1
%19 = fpext float %10 to double
%20 = tail call double @llvm.fmuladd.f64(double %19, double 5.000000e-01, double 5.000000e-01)
br label %21
21: ; preds = %16, %12
%22 = phi i32 [ %15, %12 ], [ %18, %16 ]
%23 = phi float [ %13, %12 ], [ %10, %16 ]
%24 = phi double [ %14, %12 ], [ %20, %16 ]
%25 = fptrunc double %24 to float
%26 = fdiv float %23, %25
%27 = fmul float %26, %26
%28 = fpext float %26 to double
%29 = fpext float %27 to double
%30 = fmul double %29, 0xBFE1AFC79BCF42B8
%31 = fadd double %29, 0xC01A87E74892DAA7
%32 = fdiv double %30, %31
%33 = tail call double @llvm.fmuladd.f64(double %28, double %32, double %28)
%34 = fptrunc double %33 to float
%35 = sitofp i32 %22 to float
%36 = fpext float %35 to double
%37 = fpext float %34 to double
%38 = tail call double @llvm.fmuladd.f64(double %36, double 0xBF2BD0105C610CA8, double %37)
%39 = tail call double @llvm.fmuladd.f64(double %36, double 0x3FE6300000000000, double %38)
%40 = fptrunc double %39 to float
br label %41
41: ; preds = %21, %5
%42 = phi float [ 0.000000e+00, %5 ], [ %40, %21 ]
ret float %42
}