#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 addlog(double, double);
double drand2();
double exp(double);
int /*<<< orphan*/ fatalx(char *);
double log(double);
double samppow(double e, double a, double b) {
  double ztot, rhs, zlog, ee, x;
  double y1, y2, u;
  ee = e + 1.0;
  if (ee < 0.0)
    fatalx("e must be > -1 \n");
  if (b < a)
    return samppow(e, b, a);
  if (a == b)
    return a;
  u = (drand2());
  if (u == 0.0)
    u = 0.5;
  y1 = ee * log(b) + log(u);
  if (a == 0.0)
    zlog = y1;
  else {
    y2 = ee * log(a) + log(1.0 - u);
    zlog = addlog(y1, y2);
  }
  x = exp(zlog / ee);
  return x;
}


x86 assembly (clang, -O0):
<samppow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  0xe7e(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    11a6 <samppow+0x46>
lea    0xe6f(%rip),%rdi
call   1030 <fatalx@plt>
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d8 <samppow+0x78>
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
call   1040 <samppow@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1309 <samppow+0x1a9>
movsd  -0x18(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    11fd <samppow+0x9d>
jp     11fd <samppow+0x9d>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1309 <samppow+0x1a9>
mov    $0x0,%al
call   1050 <drand2@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    122e <samppow+0xce>
jp     122e <samppow+0xce>
movsd  0xddf(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1080 <log@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x60(%rbp),%xmm0
call   1080 <log@plt>
movsd  -0x70(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1292 <samppow+0x132>
jp     1292 <samppow+0x132>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    12eb <samppow+0x18b>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1080 <log@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  0xd4d(%rip),%xmm0
subsd  -0x60(%rbp),%xmm0
call   1080 <log@plt>
movsd  -0x80(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
call   1070 <addlog@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
call   1060 <exp@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<samppow>:
push   %rbx
sub    $0x30,%rsp
addsd  0xea3(%rip),%xmm0
xorpd  %xmm4,%xmm4
lea    0xeb0(%rip),%rbx
movsd  %xmm0,0x18(%rsp)
jmp    117a <samppow+0x2a>
ucomisd %xmm3,%xmm2
movapd %xmm3,%xmm1
jbe    11b4 <samppow+0x64>
movapd %xmm2,%xmm3
movapd %xmm1,%xmm2
ucomisd %xmm0,%xmm4
jbe    1170 <samppow+0x20>
mov    %rbx,%rdi
movsd  %xmm2,0x10(%rsp)
movsd  %xmm3,0x8(%rsp)
call   1030 <fatalx@plt>
xorpd  %xmm4,%xmm4
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
movsd  0x18(%rsp),%xmm0
jmp    1170 <samppow+0x20>
jne    11c2 <samppow+0x72>
jp     11c2 <samppow+0x72>
movapd %xmm2,%xmm0
add    $0x30,%rsp
pop    %rbx
ret
xor    %eax,%eax
movsd  %xmm2,0x10(%rsp)
movsd  %xmm3,0x8(%rsp)
call   1040 <drand2@plt>
xorpd  %xmm1,%xmm1
movapd %xmm0,%xmm2
cmpeqsd %xmm1,%xmm2
movsd  0xe1e(%rip),%xmm1
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movapd %xmm2,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
call   1070 <log@plt>
movsd  %xmm0,0x8(%rsp)
movapd 0x20(%rsp),%xmm0
call   1070 <log@plt>
movsd  0x10(%rsp),%xmm2
movsd  0x18(%rsp),%xmm1
movsd  0x8(%rsp),%xmm3
mulsd  %xmm1,%xmm3
addsd  %xmm0,%xmm3
movapd %xmm3,%xmm0
ucomisd 0xdd2(%rip),%xmm2
jne    1242 <samppow+0xf2>
jnp    128b <samppow+0x13b>
movsd  %xmm0,0x8(%rsp)
movapd %xmm2,%xmm0
call   1070 <log@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0xda1(%rip),%xmm0
subsd  0x20(%rsp),%xmm0
call   1070 <log@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
call   1060 <addlog@plt>
movsd  0x18(%rsp),%xmm1
divsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
jmp    1050 <exp@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"e must be > -1 \0A\00"
define double @samppow(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%16 = load double, double* %5
%17 = fadd double %16, 1.000000e+00
store double %17, double* %11
%18 = load double, double* %11
%19 = fcmp olt double %18, 0.000000e+00
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 @fatalx(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %3
%23 = load double, double* %7
%24 = load double, double* %6
%25 = fcmp olt double %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load double, double* %5
%28 = load double, double* %7
%29 = load double, double* %6
%30 = call double @samppow(double %27, double %28, double %29)
store double %30, double* %4
br label %70
31: ; preds = %22
%32 = load double, double* %6
%33 = load double, double* %7
%34 = fcmp oeq double %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = load double, double* %6
store double %36, double* %4
br label %70
37: ; preds = %31
%38 = call double (...) @drand2()
store double %38, double* %15
%39 = load double, double* %15
%40 = fcmp oeq double %39, 0.000000e+00
br i1 %40, label %41, label %42
41: ; preds = %37
store double 5.000000e-01, double* %15
br label %42
42: ; preds = %41, %37
%43 = load double, double* %11
%44 = load double, double* %7
%45 = call double @log(double %44)
%46 = load double, double* %15
%47 = call double @log(double %46)
%48 = call double @llvm.fmuladd.f64(double %43, double %45, double %47)
store double %48, double* %13
%49 = load double, double* %6
%50 = fcmp oeq double %49, 0.000000e+00
br i1 %50, label %51, label %53
51: ; preds = %42
%52 = load double, double* %13
store double %52, double* %10
br label %64
53: ; preds = %42
%54 = load double, double* %11
%55 = load double, double* %6
%56 = call double @log(double %55)
%57 = load double, double* %15
%58 = fsub double 1.000000e+00, %57
%59 = call double @log(double %58)
%60 = call double @llvm.fmuladd.f64(double %54, double %56, double %59)
store double %60, double* %14
%61 = load double, double* %13
%62 = load double, double* %14
%63 = call double @addlog(double %61, double %62)
store double %63, double* %10
br label %64
64: ; preds = %53, %51
%65 = load double, double* %10
%66 = load double, double* %11
%67 = fdiv double %65, %66
%68 = call double @exp(double %67)
store double %68, double* %12
%69 = load double, double* %12
store double %69, double* %4
br label %70
70: ; preds = %64, %35, %26
%71 = load double, double* %4
ret double %71
}

LLVM IR (-O2):
@.str = [17 x i8] c"e must be > -1 \0A\00"
define double @samppow(double %0, double %1, double %2) {
%4 = fadd double %0, 1.000000e+00
%5 = fcmp olt double %4, 0.000000e+00
br label %6
6: ; preds = %11, %3
%7 = phi double [ %1, %3 ], [ %8, %11 ]
%8 = phi double [ %2, %3 ], [ %7, %11 ]
br i1 %5, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @fatalx(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = fcmp olt double %8, %7
br i1 %12, label %6, label %13
13: ; preds = %11
%14 = fcmp oeq double %7, %8
br i1 %14, label %33, label %15
15: ; preds = %13
%16 = tail call double (...) @drand2()
%17 = fcmp oeq double %16, 0.000000e+00
%18 = select i1 %17, double 5.000000e-01, double %16
%19 = tail call double @log(double %8)
%20 = tail call double @log(double %18)
%21 = tail call double @llvm.fmuladd.f64(double %4, double %19, double %20)
%22 = fcmp oeq double %7, 0.000000e+00
br i1 %22, label %29, label %23
23: ; preds = %15
%24 = tail call double @log(double %7)
%25 = fsub double 1.000000e+00, %18
%26 = tail call double @log(double %25)
%27 = tail call double @llvm.fmuladd.f64(double %4, double %24, double %26)
%28 = tail call double @addlog(double %21, double %27)
br label %29
29: ; preds = %15, %23
%30 = phi double [ %28, %23 ], [ %21, %15 ]
%31 = fdiv double %30, %4
%32 = tail call double @exp(double %31)
br label %33
33: ; preds = %13, %29
%34 = phi double [ %32, %29 ], [ %7, %13 ]
ret double %34
}