#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 log(double);
double rand1();
double sqrt(double);
double gdev(const int ia) {
  int j;
  double am, e, s, v1, v2, x, y;
  if (ia < 1) {
  };
  if (ia < 6) {
    x = 1.0;
    for (j = 1; j <= ia; j++)
      x *= rand1();
    x = -log(x);
  } else {
    do {
      do {
        do {
          v1 = rand1();
          v2 = 2.0 * rand1() - 1.0;
        } while (v1 * v1 + v2 * v2 > 1.0);
        y = v2 / v1;
        am = ia - 1;
        s = sqrt(2.0 * am + 1.0);
        x = s * y + am;
      } while (x <= 0.0);
      e = (1.0 + y * y) * exp(am * log(x / am) - s * y);
    } while (rand1() > e);
  }
  return x;
}


x86 assembly (clang, -O0):
<gdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jge    115a <gdev+0x1a>
jmp    115a <gdev+0x1a>
cmpl   $0x6,-0x4(%rbp)
jge    11ce <gdev+0x8e>
movsd  0xe9c(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11a3 <gdev+0x63>
mov    $0x0,%al
call   1030 <rand1@plt>
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1178 <gdev+0x38>
movsd  -0x38(%rbp),%xmm0
call   1050 <log@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1330 <gdev+0x1f0>
jmp    11d3 <gdev+0x93>
jmp    11d8 <gdev+0x98>
jmp    11dd <gdev+0x9d>
mov    $0x0,%al
call   1030 <rand1@plt>
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <rand1@plt>
addsd  %xmm0,%xmm0
movsd  0xe04(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xddf(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     11dd <gdev+0x9d>
movsd  -0x30(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xda6(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jae    11d8 <gdev+0x98>
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd58(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <rand1@plt>
ucomisd -0x18(%rbp),%xmm0
ja     11d3 <gdev+0x93>
jmp    1330 <gdev+0x1f0>
movsd  -0x38(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdev>:
push   %rbx
sub    $0x40,%rsp
mov    %edi,%ebx
cmp    $0x6,%edi
jge    119e <gdev+0x5e>
movsd  0xeac(%rip),%xmm0
test   %ebx,%ebx
jle    1188 <gdev+0x48>
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1030 <rand1@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x10(%rsp),%xmm0
add    $0xffffffff,%ebx
jne    1160 <gdev+0x20>
call   1050 <log@plt>
movapd %xmm0,%xmm1
xorpd  0xe77(%rip),%xmm1
jmp    12e2 <gdev+0x1a2>
add    $0xffffffff,%ebx
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x20(%rsp)
addsd  %xmm0,%xmm0
addsd  0xe49(%rip),%xmm0
movsd  %xmm0,0x28(%rsp)
sqrtsd %xmm0,%xmm0
movsd  %xmm0,0x38(%rsp)
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rand1@plt>
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1030 <rand1@plt>
movsd  0x10(%rsp),%xmm4
movapd %xmm0,%xmm3
addsd  %xmm0,%xmm3
addsd  0xe0e(%rip),%xmm3
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
movapd %xmm4,%xmm1
mulsd  %xmm4,%xmm1
addsd  %xmm0,%xmm1
ucomisd 0xdea(%rip),%xmm1
movsd  0xde2(%rip),%xmm1
ja     11d0 <gdev+0x90>
movsd  0x28(%rsp),%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
xorpd  %xmm0,%xmm0
movsd  0x38(%rsp),%xmm5
jae    1267 <gdev+0x127>
movsd  0x28(%rsp),%xmm0
movsd  %xmm3,0x8(%rsp)
call   1060 <sqrt@plt>
movsd  0x10(%rsp),%xmm4
movsd  0x8(%rsp),%xmm3
movsd  0xda1(%rip),%xmm1
movapd %xmm0,%xmm5
xorpd  %xmm0,%xmm0
divsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm5
movapd %xmm5,%xmm2
addsd  0x20(%rsp),%xmm2
ucomisd %xmm2,%xmm0
jae    11d0 <gdev+0x90>
mulsd  %xmm3,%xmm3
addsd  %xmm1,%xmm3
movsd  %xmm3,0x8(%rsp)
movapd %xmm2,%xmm0
divsd  0x20(%rsp),%xmm0
movapd %xmm2,0x10(%rsp)
movsd  %xmm5,0x30(%rsp)
call   1050 <log@plt>
mulsd  0x20(%rsp),%xmm0
subsd  0x30(%rsp),%xmm0
call   1040 <exp@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <rand1@plt>
movapd 0x10(%rsp),%xmm1
ucomisd 0x8(%rsp),%xmm0
ja     11d0 <gdev+0x90>
movapd %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define double @gdev(i32 %0) {
%2 = icmp slt i32 %0, 6
br i1 %2, label %7, label %3
3: ; preds = %1
%4 = add nsw i32 %0, -1
%5 = sitofp i32 %4 to double
%6 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double 1.000000e+00)
br label %20
7: ; preds = %1
%8 = icmp slt i32 %0, 1
br i1 %8, label %16, label %9
9: ; preds = %7, %9
%10 = phi i32 [ %14, %9 ], [ 1, %7 ]
%11 = phi double [ %13, %9 ], [ 1.000000e+00, %7 ]
%12 = tail call double (...) @rand1()
%13 = fmul double %11, %12
%14 = add nuw i32 %10, 1
%15 = icmp eq i32 %10, %0
br i1 %15, label %16, label %9
16: ; preds = %9, %7
%17 = phi double [ 1.000000e+00, %7 ], [ %13, %9 ]
%18 = tail call double @log(double %17)
%19 = fneg double %18
br label %44
20: ; preds = %27, %3
%21 = tail call double (...) @rand1()
%22 = tail call double (...) @rand1()
%23 = tail call double @llvm.fmuladd.f64(double %22, double 2.000000e+00, double -1.000000e+00)
%24 = fmul double %23, %23
%25 = tail call double @llvm.fmuladd.f64(double %21, double %21, double %24)
%26 = fcmp ogt double %25, 1.000000e+00
br i1 %26, label %27, label %28
27: ; preds = %20, %33, %28
br label %20
28: ; preds = %20
%29 = fdiv double %23, %21
%30 = tail call double @sqrt(double %6)
%31 = tail call double @llvm.fmuladd.f64(double %30, double %29, double %5)
%32 = fcmp ugt double %31, 0.000000e+00
br i1 %32, label %33, label %27
33: ; preds = %28
%34 = tail call double @llvm.fmuladd.f64(double %29, double %29, double 1.000000e+00)
%35 = fdiv double %31, %5
%36 = tail call double @log(double %35)
%37 = fneg double %30
%38 = fmul double %29, %37
%39 = tail call double @llvm.fmuladd.f64(double %5, double %36, double %38)
%40 = tail call double @exp(double %39)
%41 = fmul double %34, %40
%42 = tail call double (...) @rand1()
%43 = fcmp ogt double %42, %41
br i1 %43, label %27, label %44
44: ; preds = %33, %16
%45 = phi double [ %19, %16 ], [ %31, %33 ]
ret double %45
}