#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 exp(double);
double fabs(double);
double gp_exp(double);
double log(double);
double sqrt(double);
double lambertw(double x) {
  double p, e, t, w, eps;
  int i;
  eps = 1.0E-08;
  if (x < -exp(-1))
    return -1;
  if (fabs(x) <= eps)
    return x;
  if (x < 1) {
    p = sqrt(2.0 * (exp(1.0) * x + 1.0));
    w = -1.0 + p - p * p / 3.0 + 11.0 / 72.0 * p * p * p;
  } else {
    w = log(x);
  }
  if (x > 3) {
    w = w - log(w);
  }
  for (i = 0; i < 20; i++) {
    e = gp_exp(w);
    t = w * e - x;
    t = t / (e * (w + 1.0) - 0.5 * (w + 2.0) * t / (w + 1.0));
    w = w - t;
    if (fabs(t) < eps * (1.0 + fabs(w)))
      return w;
  }
  return -1;
}


x86 assembly (clang, -O0):
<lambertw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xeb3(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xe94(%rip),%xmm0
call   1040 <exp@plt>
movsd  -0x48(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
ucomisd %xmm1,%xmm0
jbe    11a9 <lambertw+0x69>
movsd  0xe61(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13fe <lambertw+0x2be>
movsd  -0x10(%rbp),%xmm1
movaps 0xe8b(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11d7 <lambertw+0x97>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13fe <lambertw+0x2be>
movsd  0xe31(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1275 <lambertw+0x135>
movsd  0xe1e(%rip),%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe05(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe11(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xdd3(%rip),%xmm1
addsd  -0x18(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  0xddc(%rip),%xmm2
divsd  %xmm2,%xmm0
subsd  %xmm0,%xmm1
movsd  0xdc4(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1284 <lambertw+0x144>
movsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xd8f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12c0 <lambertw+0x180>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x14,-0x3c(%rbp)
jge    13f1 <lambertw+0x2b1>
movsd  -0x30(%rbp),%xmm0
call   1030 <gp_exp@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xceb(%rip),%xmm3
addsd  -0x30(%rbp),%xmm3
movsd  0xcf6(%rip),%xmm4
addsd  -0x30(%rbp),%xmm4
movsd  0xcf1(%rip),%xmm2
mulsd  %xmm4,%xmm2
mulsd  -0x28(%rbp),%xmm2
movsd  0xcc0(%rip),%xmm4
addsd  -0x30(%rbp),%xmm4
divsd  %xmm4,%xmm2
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm1
movaps 0xca4(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm3
movaps 0xc8f(%rip),%xmm2
pand   %xmm2,%xmm3
movsd  0xc53(%rip),%xmm2
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    13de <lambertw+0x29e>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13fe <lambertw+0x2be>
jmp    13e3 <lambertw+0x2a3>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12c7 <lambertw+0x187>
movsd  0xc07(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lambertw>:
push   %rbx
sub    $0x20,%rsp
movapd %xmm0,%xmm4
movsd  0xebf(%rip),%xmm0
movsd  0xebf(%rip),%xmm1
ucomisd %xmm4,%xmm1
ja     12f1 <lambertw+0x1c1>
movapd 0xef5(%rip),%xmm0
andpd  %xmm4,%xmm0
movsd  0xea9(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    11a9 <lambertw+0x79>
movsd  0xea3(%rip),%xmm0
ucomisd %xmm4,%xmm0
movapd %xmm4,0x10(%rsp)
jbe    11b2 <lambertw+0x82>
movsd  0xe97(%rip),%xmm0
mulsd  %xmm4,%xmm0
addsd  0xe83(%rip),%xmm0
addsd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11d1 <lambertw+0xa1>
sqrtsd %xmm0,%xmm0
jmp    11dc <lambertw+0xac>
movapd %xmm4,%xmm0
jmp    12f1 <lambertw+0x1c1>
movapd %xmm4,%xmm0
call   1040 <log@plt>
movapd 0x10(%rsp),%xmm4
movapd %xmm0,%xmm3
ucomisd 0xe6b(%rip),%xmm4
ja     121e <lambertw+0xee>
jmp    123b <lambertw+0x10b>
call   1050 <sqrt@plt>
movapd 0x10(%rsp),%xmm4
movsd  0xe1c(%rip),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
divsd  0xe30(%rip),%xmm2
addsd  %xmm1,%xmm2
movsd  0xe2c(%rip),%xmm3
mulsd  %xmm0,%xmm3
mulsd  %xmm0,%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm2,%xmm3
ucomisd 0xe1c(%rip),%xmm4
jbe    123b <lambertw+0x10b>
movapd %xmm3,%xmm0
movapd %xmm3,(%rsp)
call   1040 <log@plt>
movapd (%rsp),%xmm3
movapd 0x10(%rsp),%xmm4
subsd  %xmm0,%xmm3
xorpd  0xe1d(%rip),%xmm4
mov    $0x14,%ebx
movapd %xmm4,0x10(%rsp)
xchg   %ax,%ax
movapd %xmm3,(%rsp)
movapd %xmm3,%xmm0
call   1030 <gp_exp@plt>
movapd 0x10(%rsp),%xmm4
movapd (%rsp),%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm4,%xmm1
movapd (%rsp),%xmm2
movsd  0xd9a(%rip),%xmm5
addsd  %xmm5,%xmm2
movapd (%rsp),%xmm3
addsd  0xdb1(%rip),%xmm3
mulsd  0xdb1(%rip),%xmm3
mulsd  %xmm1,%xmm3
divsd  %xmm2,%xmm3
mulsd  %xmm0,%xmm2
addsd  %xmm3,%xmm2
movapd (%rsp),%xmm3
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm3
movapd 0xd94(%rip),%xmm2
andpd  %xmm2,%xmm1
movapd %xmm3,%xmm0
andpd  %xmm2,%xmm0
addsd  %xmm5,%xmm0
mulsd  0xd3c(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     12ed <lambertw+0x1bd>
add    $0xffffffff,%ebx
jne    1250 <lambertw+0x120>
movsd  0xd15(%rip),%xmm0
jmp    12f1 <lambertw+0x1c1>
movapd %xmm3,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @lambertw(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
store double %0, double* %3
store double 1.000000e-08, double* %8
%10 = load double, double* %3
%11 = call double @exp(double -1.000000e+00)
%12 = fneg double %11
%13 = fcmp olt double %10, %12
br i1 %13, label %14, label %15
14: ; preds = %1
store double -1.000000e+00, double* %2
br label %100
15: ; preds = %1
%16 = load double, double* %3
%17 = call double @llvm.fabs.f64(double %16)
%18 = load double, double* %8
%19 = fcmp ole double %17, %18
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load double, double* %3
store double %21, double* %2
br label %100
22: ; preds = %15
%23 = load double, double* %3
%24 = fcmp olt double %23, 1.000000e+00
br i1 %24, label %25, label %44
25: ; preds = %22
%26 = call double @exp(double 1.000000e+00)
%27 = load double, double* %3
%28 = call double @llvm.fmuladd.f64(double %26, double %27, double 1.000000e+00)
%29 = fmul double 2.000000e+00, %28
%30 = call double @sqrt(double %29)
store double %30, double* %4
%31 = load double, double* %4
%32 = fadd double -1.000000e+00, %31
%33 = load double, double* %4
%34 = load double, double* %4
%35 = fmul double %33, %34
%36 = fdiv double %35, 3.000000e+00
%37 = fsub double %32, %36
%38 = load double, double* %4
%39 = fmul double 0x3FC38E38E38E38E4, %38
%40 = load double, double* %4
%41 = fmul double %39, %40
%42 = load double, double* %4
%43 = call double @llvm.fmuladd.f64(double %41, double %42, double %37)
store double %43, double* %7
br label %47
44: ; preds = %22
%45 = load double, double* %3
%46 = call double @log(double %45)
store double %46, double* %7
br label %47
47: ; preds = %44, %25
%48 = load double, double* %3
%49 = fcmp ogt double %48, 3.000000e+00
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = load double, double* %7
%52 = load double, double* %7
%53 = call double @log(double %52)
%54 = fsub double %51, %53
store double %54, double* %7
br label %55
55: ; preds = %50, %47
store i32 0, i32* %9
br label %56
56: ; preds = %96, %55
%57 = load i32, i32* %9
%58 = icmp slt i32 %57, 20
br i1 %58, label %59, label %99
59: ; preds = %56
%60 = load double, double* %7
%61 = call double @gp_exp(double %60)
store double %61, double* %5
%62 = load double, double* %7
%63 = load double, double* %5
%64 = load double, double* %3
%65 = fneg double %64
%66 = call double @llvm.fmuladd.f64(double %62, double %63, double %65)
store double %66, double* %6
%67 = load double, double* %6
%68 = load double, double* %5
%69 = load double, double* %7
%70 = fadd double %69, 1.000000e+00
%71 = load double, double* %7
%72 = fadd double %71, 2.000000e+00
%73 = fmul double 5.000000e-01, %72
%74 = load double, double* %6
%75 = fmul double %73, %74
%76 = load double, double* %7
%77 = fadd double %76, 1.000000e+00
%78 = fdiv double %75, %77
%79 = fneg double %78
%80 = call double @llvm.fmuladd.f64(double %68, double %70, double %79)
%81 = fdiv double %67, %80
store double %81, double* %6
%82 = load double, double* %7
%83 = load double, double* %6
%84 = fsub double %82, %83
store double %84, double* %7
%85 = load double, double* %6
%86 = call double @llvm.fabs.f64(double %85)
%87 = load double, double* %8
%88 = load double, double* %7
%89 = call double @llvm.fabs.f64(double %88)
%90 = fadd double 1.000000e+00, %89
%91 = fmul double %87, %90
%92 = fcmp olt double %86, %91
br i1 %92, label %93, label %95
93: ; preds = %59
%94 = load double, double* %7
store double %94, double* %2
br label %100
95: ; preds = %59
br label %96
96: ; preds = %95
%97 = load i32, i32* %9
%98 = add nsw i32 %97, 1
store i32 %98, i32* %9
br label %56
99: ; preds = %56
store double -1.000000e+00, double* %2
br label %100
100: ; preds = %99, %93, %20, %14
%101 = load double, double* %2
ret double %101
}

LLVM IR (-O2):
define double @lambertw(double %0) {
%2 = fcmp olt double %0, 0xBFD78B56362CEF38
br i1 %2, label %51, label %3
3: ; preds = %1
%4 = tail call double @llvm.fabs.f64(double %0)
%5 = fcmp ugt double %4, 1.000000e-08
br i1 %5, label %6, label %51
6: ; preds = %3
%7 = fcmp olt double %0, 1.000000e+00
br i1 %7, label %8, label %19
8: ; preds = %6
%9 = tail call double @llvm.fmuladd.f64(double %0, double 0x4005BF0A8B145769, double 1.000000e+00)
%10 = fmul double %9, 2.000000e+00
%11 = tail call double @sqrt(double %10)
%12 = fadd double %11, -1.000000e+00
%13 = fmul double %11, %11
%14 = fdiv double %13, 3.000000e+00
%15 = fsub double %12, %14
%16 = fmul double %11, 0x3FC38E38E38E38E4
%17 = fmul double %11, %16
%18 = tail call double @llvm.fmuladd.f64(double %17, double %11, double %15)
br label %21
19: ; preds = %6
%20 = tail call double @log(double %0)
br label %21
21: ; preds = %19, %8
%22 = phi double [ %18, %8 ], [ %20, %19 ]
%23 = fcmp ogt double %0, 3.000000e+00
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = tail call double @log(double %22)
%26 = fsub double %22, %25
br label %27
27: ; preds = %24, %21
%28 = phi double [ %26, %24 ], [ %22, %21 ]
%29 = fneg double %0
br label %33
30: ; preds = %33
%31 = add nuw nsw i32 %34, 1
%32 = icmp eq i32 %31, 20
br i1 %32, label %51, label %33
33: ; preds = %27, %30
%34 = phi i32 [ 0, %27 ], [ %31, %30 ]
%35 = phi double [ %28, %27 ], [ %45, %30 ]
%36 = tail call double @gp_exp(double %35)
%37 = tail call double @llvm.fmuladd.f64(double %35, double %36, double %29)
%38 = fadd double %35, 1.000000e+00
%39 = fadd double %35, 2.000000e+00
%40 = fmul double %39, -5.000000e-01
%41 = fmul double %40, %37
%42 = fdiv double %41, %38
%43 = tail call double @llvm.fmuladd.f64(double %36, double %38, double %42)
%44 = fdiv double %37, %43
%45 = fsub double %35, %44
%46 = tail call double @llvm.fabs.f64(double %44)
%47 = tail call double @llvm.fabs.f64(double %45)
%48 = fadd double %47, 1.000000e+00
%49 = fmul double %48, 1.000000e-08
%50 = fcmp olt double %46, %49
br i1 %50, label %51, label %30
51: ; preds = %30, %33, %3, %1
%52 = phi double [ -1.000000e+00, %1 ], [ %0, %3 ], [ -1.000000e+00, %30 ], [ %45, %33 ]
ret double %52
}