#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 */
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) {
    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     1140 <logf+0x30>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    12b9 <logf+0x1a9>
movss  -0x8(%rbp),%xmm0
lea    -0x28(%rbp),%rdi
call   1030 <frexpf@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea4(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe7e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d1 <logf+0xc1>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe6b(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe4d(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
jmp    11fc <logf+0xec>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe1d(%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  0xdeb(%rip),%xmm3
mulsd  %xmm3,%xmm2
movss  -0x18(%rbp),%xmm3
cvtss2sd %xmm3,%xmm3
movsd  0xdce(%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  0xd89(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd68(%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>:
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
jae    11f0 <logf+0xe0>
push   %rax
lea    0x4(%rsp),%rdi
call   1030 <frexpf@plt>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
addss  0xeca(%rip),%xmm0
ucomisd 0xeca(%rip),%xmm1
jbe    115e <logf+0x4e>
addss  0xeb8(%rip),%xmm0
movsd  0xec0(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm2,%xmm1
mov    0x4(%rsp),%eax
jmp    117c <logf+0x6c>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  0xe9c(%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  0xe7d(%rip),%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe79(%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  0xe57(%rip),%xmm2
mulsd  %xmm0,%xmm2
mulsd  0xe53(%rip),%xmm0
addsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
add    $0x8,%rsp
movaps %xmm1,%xmm0
ret

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

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