#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 drand2();
double exp(double);
double log(double);
double pow(double, double);
double randev0(double a) {
  double r1, r2, x, w;
  double t = 1.0 - a;
  double p = t / (t + a * exp(-t));
  double s = 1.0 / a;
  for (;;) {
    r1 = (drand2());
    if (r1 <= p) {
      x = t * pow(r1 / p, s);
      w = x;
    } else {
      x = t + log((1.0 - p) / (1.0 - r1));
      w = t * log(x / t);
    }
    r2 = (drand2());
    if ((1.0 - r2) <= w) {
      if ((1.0 / r2 - 1.0) <= w)
        continue;
      if (-log(r2) <= w)
        continue;
    }
    if (x == 0.0)
      x = 1.0e-20;
    return x;
  }
}


x86 assembly (clang, -O0):
<randev0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xeab(%rip),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1040 <exp@plt>
movsd  -0x58(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe37(%rip),%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1030 <drand2@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1231 <randev0+0xf1>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
call   1060 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1299 <randev0+0x159>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xdbd(%rip),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  0xdb0(%rip),%xmm1
subsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <drand2@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xd53(%rip),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1328 <randev0+0x1e8>
movsd  0xd37(%rip),%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xd2a(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     12ee <randev0+0x1ae>
jmp    11d3 <randev0+0x93>
movsd  -0x18(%rbp),%xmm0
call   1050 <log@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1323 <randev0+0x1e3>
jmp    11d3 <randev0+0x93>
jmp    1328 <randev0+0x1e8>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    134d <randev0+0x20d>
jp     134d <randev0+0x20d>
movsd  0xcc0(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randev0>:
sub    $0x58,%rsp
movsd  %xmm0,0x8(%rsp)
movsd  0xeae(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
movapd 0xebc(%rip),%xmm0
xorpd  %xmm1,%xmm0
call   1040 <exp@plt>
movsd  0xe8b(%rip),%xmm1
movsd  0x8(%rsp),%xmm3
mulsd  %xmm3,%xmm0
movapd 0x10(%rsp),%xmm2
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm2
movapd %xmm1,%xmm0
divsd  %xmm3,%xmm0
movsd  %xmm0,0x28(%rsp)
movapd %xmm2,0x40(%rsp)
subsd  %xmm2,%xmm1
movsd  %xmm1,0x20(%rsp)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <drand2@plt>
movapd 0x40(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jae    1210 <randev0+0xd0>
movsd  0xe35(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  0x20(%rsp),%xmm0
divsd  %xmm1,%xmm0
call   1050 <log@plt>
movapd 0x10(%rsp),%xmm1
addsd  %xmm1,%xmm0
movapd %xmm0,0x30(%rsp)
divsd  %xmm1,%xmm0
call   1050 <log@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    1231 <randev0+0xf1>
cs nopw 0x0(%rax,%rax,1)
nop
divsd  %xmm1,%xmm0
movsd  0x28(%rsp),%xmm1
call   1060 <pow@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd %xmm0,0x30(%rsp)
xor    %eax,%eax
call   1030 <drand2@plt>
movsd  0xdc0(%rip),%xmm3
movapd %xmm3,%xmm1
subsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm2
ucomisd %xmm1,%xmm2
jb     1291 <randev0+0x151>
movapd %xmm3,%xmm1
divsd  %xmm0,%xmm1
addsd  0xda4(%rip),%xmm1
ucomisd %xmm1,%xmm2
jae    11b0 <randev0+0x70>
movsd  %xmm2,0x8(%rsp)
call   1050 <log@plt>
xorpd  0xd9f(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jae    11b0 <randev0+0x70>
xorpd  %xmm0,%xmm0
movapd 0x30(%rsp),%xmm2
cmpeqsd %xmm2,%xmm0
movsd  0xd68(%rip),%xmm1
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
add    $0x58,%rsp
ret

LLVM IR (-O0):
define double @randev0(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 double
store double %0, double* %2
%10 = load double, double* %2
%11 = fsub double 1.000000e+00, %10
store double %11, double* %7
%12 = load double, double* %7
%13 = load double, double* %7
%14 = load double, double* %2
%15 = load double, double* %7
%16 = fneg double %15
%17 = call double @exp(double %16)
%18 = call double @llvm.fmuladd.f64(double %14, double %17, double %13)
%19 = fdiv double %12, %18
store double %19, double* %8
%20 = load double, double* %2
%21 = fdiv double 1.000000e+00, %20
store double %21, double* %9
br label %22
22: ; preds = %70, %63, %1
%23 = call double (...) @drand2()
store double %23, double* %3
%24 = load double, double* %3
%25 = load double, double* %8
%26 = fcmp ole double %24, %25
br i1 %26, label %27, label %36
27: ; preds = %22
%28 = load double, double* %7
%29 = load double, double* %3
%30 = load double, double* %8
%31 = fdiv double %29, %30
%32 = load double, double* %9
%33 = call double @pow(double %31, double %32)
%34 = fmul double %28, %33
store double %34, double* %5
%35 = load double, double* %5
store double %35, double* %6
br label %51
36: ; preds = %22
%37 = load double, double* %7
%38 = load double, double* %8
%39 = fsub double 1.000000e+00, %38
%40 = load double, double* %3
%41 = fsub double 1.000000e+00, %40
%42 = fdiv double %39, %41
%43 = call double @log(double %42)
%44 = fadd double %37, %43
store double %44, double* %5
%45 = load double, double* %7
%46 = load double, double* %5
%47 = load double, double* %7
%48 = fdiv double %46, %47
%49 = call double @log(double %48)
%50 = fmul double %45, %49
store double %50, double* %6
br label %51
51: ; preds = %36, %27
%52 = call double (...) @drand2()
store double %52, double* %4
%53 = load double, double* %4
%54 = fsub double 1.000000e+00, %53
%55 = load double, double* %6
%56 = fcmp ole double %54, %55
br i1 %56, label %57, label %72
57: ; preds = %51
%58 = load double, double* %4
%59 = fdiv double 1.000000e+00, %58
%60 = fsub double %59, 1.000000e+00
%61 = load double, double* %6
%62 = fcmp ole double %60, %61
br i1 %62, label %63, label %64
63: ; preds = %57
br label %22
64: ; preds = %57
%65 = load double, double* %4
%66 = call double @log(double %65)
%67 = fneg double %66
%68 = load double, double* %6
%69 = fcmp ole double %67, %68
br i1 %69, label %70, label %71
70: ; preds = %64
br label %22
71: ; preds = %64
br label %72
72: ; preds = %71, %51
%73 = load double, double* %5
%74 = fcmp oeq double %73, 0.000000e+00
br i1 %74, label %75, label %76
75: ; preds = %72
store double 0x3BC79CA10C924223, double* %5
br label %76
76: ; preds = %75, %72
%77 = load double, double* %5
ret double %77
}

LLVM IR (-O2):
define double @randev0(double %0) {
%2 = fsub double 1.000000e+00, %0
%3 = fneg double %2
%4 = tail call double @exp(double %3)
%5 = tail call double @llvm.fmuladd.f64(double %0, double %4, double %2)
%6 = fdiv double %2, %5
%7 = fdiv double 1.000000e+00, %0
%8 = fsub double 1.000000e+00, %6
br label %9
9: ; preds = %34, %1
%10 = tail call double (...) @drand2()
%11 = fcmp ugt double %10, %6
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = fdiv double %10, %6
%14 = tail call double @pow(double %13, double %7)
%15 = fmul double %2, %14
br label %24
16: ; preds = %9
%17 = fsub double 1.000000e+00, %10
%18 = fdiv double %8, %17
%19 = tail call double @log(double %18)
%20 = fadd double %2, %19
%21 = fdiv double %20, %2
%22 = tail call double @log(double %21)
%23 = fmul double %2, %22
br label %24
24: ; preds = %16, %12
%25 = phi double [ %15, %12 ], [ %23, %16 ]
%26 = phi double [ %15, %12 ], [ %20, %16 ]
%27 = tail call double (...) @drand2()
%28 = fsub double 1.000000e+00, %27
%29 = fcmp ugt double %28, %25
br i1 %29, label %39, label %30
30: ; preds = %24
%31 = fdiv double 1.000000e+00, %27
%32 = fadd double %31, -1.000000e+00
%33 = fcmp ugt double %32, %25
br i1 %33, label %35, label %34
34: ; preds = %30, %35
br label %9
35: ; preds = %30
%36 = tail call double @log(double %27)
%37 = fneg double %36
%38 = fcmp ult double %25, %37
br i1 %38, label %39, label %34
39: ; preds = %35, %24
%40 = fcmp oeq double %26, 0.000000e+00
%41 = select i1 %40, double 0x3BC79CA10C924223, double %26
ret double %41
}