#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 */
int /*<<< orphan*/ drand();
scalar_t__ log(int /*<<< orphan*/);
double rand_gamma(int alpha, double beta) {
  int i = 0;
  double y = 0;
  for (i = 0; i < alpha; i++) {
    y += log(drand());
  }
  y *= -(1.0 / beta);
  return y;
}


x86 assembly (clang, -O0):
<rand_gamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    117d <rand_gamma+0x5d>
mov    $0x0,%al
call   1030 <drand@plt>
mov    %eax,%edi
call   1040 <log@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1146 <rand_gamma+0x26>
movsd  0xe7b(%rip),%xmm0
divsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_gamma>:
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,(%rsp)
test   %edi,%edi
jle    116d <rand_gamma+0x4d>
mov    %edi,%ebx
xorpd  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1030 <drand@plt>
mov    %eax,%edi
call   1040 <log@plt>
movsd  0x8(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm1
add    $0xffffffff,%ebx
jne    1140 <rand_gamma+0x20>
jmp    1171 <rand_gamma+0x51>
xorpd  %xmm1,%xmm1
movsd  0xe87(%rip),%xmm0
divsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @rand_gamma(i32 %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca i32
%6 = alloca double
store i32 %0, i32* %3
store double %1, double* %4
store i32 0, i32* %5
store double 0.000000e+00, double* %6
store i32 0, i32* %5
br label %7
7: ; preds = %17, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %3
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = call i32 (...) @drand()
%13 = call i64 @log(i32 %12)
%14 = sitofp i64 %13 to double
%15 = load double, double* %6
%16 = fadd double %15, %14
store double %16, double* %6
br label %17
17: ; preds = %11
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %7
20: ; preds = %7
%21 = load double, double* %4
%22 = fdiv double 1.000000e+00, %21
%23 = fneg double %22
%24 = load double, double* %6
%25 = fmul double %24, %23
store double %25, double* %6
%26 = load double, double* %6
ret double %26
}

LLVM IR (-O2):
define double @rand_gamma(i32 %0, double %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %13
4: ; preds = %2, %4
%5 = phi double [ %10, %4 ], [ 0.000000e+00, %2 ]
%6 = phi i32 [ %11, %4 ], [ 0, %2 ]
%7 = tail call i32 (...) @drand()
%8 = tail call i64 @log(i32 %7)
%9 = sitofp i64 %8 to double
%10 = fadd double %5, %9
%11 = add nuw nsw i32 %6, 1
%12 = icmp eq i32 %11, %0
br i1 %12, label %13, label %4
13: ; preds = %4, %2
%14 = phi double [ 0.000000e+00, %2 ], [ %10, %4 ]
%15 = fdiv double -1.000000e+00, %1
%16 = fmul double %15, %14
ret double %16
}