#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 fasterexp(float);
float fasterlog(float);
float fasterlambertw(float x) {
  static const float threshold = 2.26445f;
  float c = (x < threshold) ? 1.546865557f : 1.0f;
  float d = (x < threshold) ? 2.250366841f : 0.0f;
  float a = (x < threshold) ? -0.737769969f : 0.0f;
  float logterm = fasterlog(c * x + d);
  float loglogterm = fasterlog(logterm);
  float w = a + logterm - loglogterm + loglogterm / logterm;
  float expw = fasterexp(-w);
  return (w * w + expw * x) / (1.0f + w);
}


x86 assembly (clang, -O0):
<fasterlambertw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
movss  0xed6(%rip),%xmm3
movss  0xebe(%rip),%xmm2
movss  0xebe(%rip),%xmm1
cmpltss %xmm1,%xmm0
movaps %xmm0,%xmm1
andps  %xmm3,%xmm1
andnps %xmm2,%xmm0
orps   %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
movss  0xe9f(%rip),%xmm3
xorps  %xmm2,%xmm2
movss  0xe90(%rip),%xmm1
cmpltss %xmm1,%xmm0
movaps %xmm0,%xmm1
andps  %xmm3,%xmm1
andnps %xmm2,%xmm0
orps   %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x4(%rbp),%xmm0
movss  0xe69(%rip),%xmm3
xorps  %xmm2,%xmm2
movss  0xe62(%rip),%xmm1
cmpltss %xmm1,%xmm0
movaps %xmm0,%xmm1
andps  %xmm3,%xmm1
andnps %xmm2,%xmm0
orps   %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x4(%rbp),%xmm2
movss  -0xc(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1030 <fasterlog@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
call   1030 <fasterlog@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
subss  -0x18(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
divss  -0x14(%rbp),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
call   1040 <fasterexp@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm2
movss  -0x20(%rbp),%xmm1
mulss  -0x4(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  0xdb2(%rip),%xmm1
addss  -0x1c(%rbp),%xmm1
divss  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fasterlambertw>:
sub    $0x28,%rsp
movaps %xmm0,%xmm2
movss  0xed1(%rip),%xmm0
xor    %eax,%eax
ucomiss %xmm2,%xmm0
seta   %cl
ja     1148 <fasterlambertw+0x28>
xorps  %xmm1,%xmm1
jbe    1152 <fasterlambertw+0x32>
movss  0xec2(%rip),%xmm0
jmp    1155 <fasterlambertw+0x35>
movss  0xeb4(%rip),%xmm1
ja     113e <fasterlambertw+0x1e>
xorps  %xmm0,%xmm0
movss  %xmm0,0x10(%rsp)
mov    %cl,%al
lea    0xeac(%rip),%rcx
movss  (%rcx,%rax,4),%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm2,0xc(%rsp)
call   1030 <fasterlog@plt>
movss  %xmm0,0x8(%rsp)
call   1030 <fasterlog@plt>
movaps %xmm0,%xmm1
movss  0x10(%rsp),%xmm0
movss  0x8(%rsp),%xmm2
addss  %xmm2,%xmm0
subss  %xmm1,%xmm0
divss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movaps %xmm1,0x10(%rsp)
movaps 0xe6e(%rip),%xmm0
xorps  %xmm1,%xmm0
call   1040 <fasterexp@plt>
mulss  0xc(%rsp),%xmm0
movaps 0x10(%rsp),%xmm2
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
addss  %xmm1,%xmm0
addss  0xe34(%rip),%xmm2
divss  %xmm2,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@fasterlambertw.threshold = internal constant float 0x40021D9800000000
define float @fasterlambertw(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
store float %0, float* %2
%10 = load float, float* %2
%11 = fcmp olt float %10, 0x40021D9800000000
%12 = zext i1 %11 to i64
%13 = select i1 %11, float 0x3FF8BFF620000000, float 1.000000e+00
store float %13, float* %3
%14 = load float, float* %2
%15 = fcmp olt float %14, 0x40021D9800000000
%16 = zext i1 %15 to i64
%17 = select i1 %15, float 0x400200C060000000, float 0.000000e+00
store float %17, float* %4
%18 = load float, float* %2
%19 = fcmp olt float %18, 0x40021D9800000000
%20 = zext i1 %19 to i64
%21 = select i1 %19, float 0xBFE79BCFC0000000, float 0.000000e+00
store float %21, float* %5
%22 = load float, float* %3
%23 = load float, float* %2
%24 = load float, float* %4
%25 = call float @llvm.fmuladd.f32(float %22, float %23, float %24)
%26 = call float @fasterlog(float %25)
store float %26, float* %6
%27 = load float, float* %6
%28 = call float @fasterlog(float %27)
store float %28, float* %7
%29 = load float, float* %5
%30 = load float, float* %6
%31 = fadd float %29, %30
%32 = load float, float* %7
%33 = fsub float %31, %32
%34 = load float, float* %7
%35 = load float, float* %6
%36 = fdiv float %34, %35
%37 = fadd float %33, %36
store float %37, float* %8
%38 = load float, float* %8
%39 = fneg float %38
%40 = call float @fasterexp(float %39)
store float %40, float* %9
%41 = load float, float* %8
%42 = load float, float* %8
%43 = load float, float* %9
%44 = load float, float* %2
%45 = fmul float %43, %44
%46 = call float @llvm.fmuladd.f32(float %41, float %42, float %45)
%47 = load float, float* %8
%48 = fadd float 1.000000e+00, %47
%49 = fdiv float %46, %48
ret float %49
}

LLVM IR (-O2):
define float @fasterlambertw(float %0) {
%2 = fcmp olt float %0, 0x40021D9800000000
%3 = select i1 %2, float 0x3FF8BFF620000000, float 1.000000e+00
%4 = select i1 %2, float 0x400200C060000000, float 0.000000e+00
%5 = select i1 %2, float 0xBFE79BCFC0000000, float 0.000000e+00
%6 = tail call float @llvm.fmuladd.f32(float %3, float %0, float %4)
%7 = tail call float @fasterlog(float %6)
%8 = tail call float @fasterlog(float %7)
%9 = fadd float %5, %7
%10 = fsub float %9, %8
%11 = fdiv float %8, %7
%12 = fadd float %10, %11
%13 = fneg float %12
%14 = tail call float @fasterexp(float %13)
%15 = fmul float %14, %0
%16 = tail call float @llvm.fmuladd.f32(float %12, float %12, float %15)
%17 = fadd float %12, 1.000000e+00
%18 = fdiv float %16, %17
ret float %18
}