#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*/ DiscreteGammaMean(double *, double, double, int);
int /*<<< orphan*/ DiscreteGammaMedian(double *, double, double, int);
void DiscreteGamma(double *f, double *r, double alpha, double beta, int ncat,
                   int useMean) {
  const double freq = 1.0 / ((double)ncat);
  int i;
  for (i = 0; i < ncat; ++i)
    f[i] = freq;
  if (useMean)
    DiscreteGammaMean(r, alpha, beta, ncat);
  else
    DiscreteGammaMedian(r, alpha, beta, ncat);
}


x86 assembly (clang, -O0):
<DiscreteGamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
mov    %ecx,-0x28(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm1
movsd  0xeb3(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1189 <DiscreteGamma+0x69>
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    115d <DiscreteGamma+0x3d>
cmpl   $0x0,-0x28(%rbp)
je     11ae <DiscreteGamma+0x8e>
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    -0x24(%rbp),%esi
call   1030 <DiscreteGammaMean@plt>
jmp    11c4 <DiscreteGamma+0xa4>
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    -0x24(%rbp),%esi
call   1040 <DiscreteGammaMedian@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DiscreteGamma>:
mov    %rsi,%r8
test   %edx,%edx
jle    125e <DiscreteGamma+0x13e>
cvtsi2sd %edx,%xmm3
movsd  0xec9(%rip),%xmm2
divsd  %xmm3,%xmm2
mov    %edx,%r10d
cmp    $0x4,%edx
jae    114a <DiscreteGamma+0x2a>
xor    %eax,%eax
jmp    1250 <DiscreteGamma+0x130>
mov    %r10d,%eax
and    $0xfffffffc,%eax
movapd %xmm2,%xmm3
unpcklpd %xmm2,%xmm3
lea    -0x4(%rax),%rsi
mov    %rsi,%r11
shr    $0x2,%r11
add    $0x1,%r11
mov    %r11d,%r9d
and    $0x7,%r9d
cmp    $0x1c,%rsi
jae    117b <DiscreteGamma+0x5b>
xor    %esi,%esi
jmp    1215 <DiscreteGamma+0xf5>
and    $0xfffffffffffffff8,%r11
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movupd %xmm3,(%rdi,%rsi,8)
movupd %xmm3,0x10(%rdi,%rsi,8)
movupd %xmm3,0x20(%rdi,%rsi,8)
movupd %xmm3,0x30(%rdi,%rsi,8)
movupd %xmm3,0x40(%rdi,%rsi,8)
movupd %xmm3,0x50(%rdi,%rsi,8)
movupd %xmm3,0x60(%rdi,%rsi,8)
movupd %xmm3,0x70(%rdi,%rsi,8)
movupd %xmm3,0x80(%rdi,%rsi,8)
movupd %xmm3,0x90(%rdi,%rsi,8)
movupd %xmm3,0xa0(%rdi,%rsi,8)
movupd %xmm3,0xb0(%rdi,%rsi,8)
movupd %xmm3,0xc0(%rdi,%rsi,8)
movupd %xmm3,0xd0(%rdi,%rsi,8)
movupd %xmm3,0xe0(%rdi,%rsi,8)
movupd %xmm3,0xf0(%rdi,%rsi,8)
add    $0x20,%rsi
add    $0xfffffffffffffff8,%r11
jne    1190 <DiscreteGamma+0x70>
test   %r9,%r9
je     1246 <DiscreteGamma+0x126>
lea    (%rdi,%rsi,8),%r11
add    $0x10,%r11
shl    $0x5,%r9
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
movupd %xmm3,-0x10(%r11,%rsi,1)
movupd %xmm3,(%r11,%rsi,1)
add    $0x20,%rsi
cmp    %rsi,%r9
jne    1230 <DiscreteGamma+0x110>
cmp    %r10,%rax
je     125e <DiscreteGamma+0x13e>
nopl   0x0(%rax,%rax,1)
movsd  %xmm2,(%rdi,%rax,8)
add    $0x1,%rax
cmp    %rax,%r10
jne    1250 <DiscreteGamma+0x130>
mov    %r8,%rdi
mov    %edx,%esi
test   %ecx,%ecx
je     126c <DiscreteGamma+0x14c>
jmp    1030 <DiscreteGammaMean@plt>
jmp    1040 <DiscreteGammaMedian@plt>

LLVM IR (-O0):
define void @DiscreteGamma(double* %0, double* %1, double %2, double %3, i32 %4, i32 %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca i32
store double* %0, double** %7
store double* %1, double** %8
store double %2, double* %9
store double %3, double* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%15 = load i32, i32* %11
%16 = sitofp i32 %15 to double
%17 = fdiv double 1.000000e+00, %16
store double %17, double* %13
store i32 0, i32* %14
br label %18
18: ; preds = %28, %6
%19 = load i32, i32* %14
%20 = load i32, i32* %11
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %31
22: ; preds = %18
%23 = load double, double* %13
%24 = load double*, double** %7
%25 = load i32, i32* %14
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
store double %23, double* %27
br label %28
28: ; preds = %22
%29 = load i32, i32* %14
%30 = add nsw i32 %29, 1
store i32 %30, i32* %14
br label %18
31: ; preds = %18
%32 = load i32, i32* %12
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load double*, double** %8
%36 = load double, double* %9
%37 = load double, double* %10
%38 = load i32, i32* %11
%39 = call i32 @DiscreteGammaMean(double* %35, double %36, double %37, i32 %38)
br label %46
40: ; preds = %31
%41 = load double*, double** %8
%42 = load double, double* %9
%43 = load double, double* %10
%44 = load i32, i32* %11
%45 = call i32 @DiscreteGammaMedian(double* %41, double %42, double %43, i32 %44)
br label %46
46: ; preds = %40, %34
ret void
}

LLVM IR (-O2):
define void @DiscreteGamma(double* nocapture writeonly %0, double* %1, double %2, double %3, i32 %4, i32 %5) {
%7 = sitofp i32 %4 to double
%8 = fdiv double 1.000000e+00, %7
%9 = icmp sgt i32 %4, 0
br i1 %9, label %10, label %93
10: ; preds = %6
%11 = zext i32 %4 to i64
%12 = icmp ult i32 %4, 4
br i1 %12, label %86, label %13
13: ; preds = %10
%14 = and i64 %11, 4294967292
%15 = insertelement <2 x double> poison, double %8, i64 0
%16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
%17 = insertelement <2 x double> poison, double %8, i64 0
%18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
%19 = add nsw i64 %14, -4
%20 = lshr exact i64 %19, 2
%21 = add nuw nsw i64 %20, 1
%22 = and i64 %21, 7
%23 = icmp ult i64 %19, 28
br i1 %23, label %71, label %24
24: ; preds = %13
%25 = and i64 %21, 9223372036854775800
br label %26
26: ; preds = %26, %24
%27 = phi i64 [ 0, %24 ], [ %68, %26 ]
%28 = phi i64 [ 0, %24 ], [ %69, %26 ]
%29 = getelementptr inbounds double, double* %0, i64 %27
%30 = bitcast double* %29 to <2 x double>*
store <2 x double> %16, <2 x double>* %30
%31 = getelementptr inbounds double, double* %29, i64 2
%32 = bitcast double* %31 to <2 x double>*
store <2 x double> %18, <2 x double>* %32
%33 = or i64 %27, 4
%34 = getelementptr inbounds double, double* %0, i64 %33
%35 = bitcast double* %34 to <2 x double>*
store <2 x double> %16, <2 x double>* %35
%36 = getelementptr inbounds double, double* %34, i64 2
%37 = bitcast double* %36 to <2 x double>*
store <2 x double> %18, <2 x double>* %37
%38 = or i64 %27, 8
%39 = getelementptr inbounds double, double* %0, i64 %38
%40 = bitcast double* %39 to <2 x double>*
store <2 x double> %16, <2 x double>* %40
%41 = getelementptr inbounds double, double* %39, i64 2
%42 = bitcast double* %41 to <2 x double>*
store <2 x double> %18, <2 x double>* %42
%43 = or i64 %27, 12
%44 = getelementptr inbounds double, double* %0, i64 %43
%45 = bitcast double* %44 to <2 x double>*
store <2 x double> %16, <2 x double>* %45
%46 = getelementptr inbounds double, double* %44, i64 2
%47 = bitcast double* %46 to <2 x double>*
store <2 x double> %18, <2 x double>* %47
%48 = or i64 %27, 16
%49 = getelementptr inbounds double, double* %0, i64 %48
%50 = bitcast double* %49 to <2 x double>*
store <2 x double> %16, <2 x double>* %50
%51 = getelementptr inbounds double, double* %49, i64 2
%52 = bitcast double* %51 to <2 x double>*
store <2 x double> %18, <2 x double>* %52
%53 = or i64 %27, 20
%54 = getelementptr inbounds double, double* %0, i64 %53
%55 = bitcast double* %54 to <2 x double>*
store <2 x double> %16, <2 x double>* %55
%56 = getelementptr inbounds double, double* %54, i64 2
%57 = bitcast double* %56 to <2 x double>*
store <2 x double> %18, <2 x double>* %57
%58 = or i64 %27, 24
%59 = getelementptr inbounds double, double* %0, i64 %58
%60 = bitcast double* %59 to <2 x double>*
store <2 x double> %16, <2 x double>* %60
%61 = getelementptr inbounds double, double* %59, i64 2
%62 = bitcast double* %61 to <2 x double>*
store <2 x double> %18, <2 x double>* %62
%63 = or i64 %27, 28
%64 = getelementptr inbounds double, double* %0, i64 %63
%65 = bitcast double* %64 to <2 x double>*
store <2 x double> %16, <2 x double>* %65
%66 = getelementptr inbounds double, double* %64, i64 2
%67 = bitcast double* %66 to <2 x double>*
store <2 x double> %18, <2 x double>* %67
%68 = add nuw i64 %27, 32
%69 = add i64 %28, 8
%70 = icmp eq i64 %69, %25
br i1 %70, label %71, label %26
71: ; preds = %26, %13
%72 = phi i64 [ 0, %13 ], [ %68, %26 ]
%73 = icmp eq i64 %22, 0
br i1 %73, label %84, label %74
74: ; preds = %71, %74
%75 = phi i64 [ %81, %74 ], [ %72, %71 ]
%76 = phi i64 [ %82, %74 ], [ 0, %71 ]
%77 = getelementptr inbounds double, double* %0, i64 %75
%78 = bitcast double* %77 to <2 x double>*
store <2 x double> %16, <2 x double>* %78
%79 = getelementptr inbounds double, double* %77, i64 2
%80 = bitcast double* %79 to <2 x double>*
store <2 x double> %18, <2 x double>* %80
%81 = add nuw i64 %75, 4
%82 = add i64 %76, 1
%83 = icmp eq i64 %82, %22
br i1 %83, label %84, label %74
84: ; preds = %74, %71
%85 = icmp eq i64 %14, %11
br i1 %85, label %93, label %86
86: ; preds = %10, %84
%87 = phi i64 [ 0, %10 ], [ %14, %84 ]
br label %88
88: ; preds = %86, %88
%89 = phi i64 [ %91, %88 ], [ %87, %86 ]
%90 = getelementptr inbounds double, double* %0, i64 %89
store double %8, double* %90
%91 = add nuw nsw i64 %89, 1
%92 = icmp eq i64 %91, %11
br i1 %92, label %93, label %88
93: ; preds = %88, %84, %6
%94 = icmp eq i32 %5, 0
br i1 %94, label %97, label %95
95: ; preds = %93
%96 = tail call i32 @DiscreteGammaMean(double* %1, double %2, double %3, i32 %4)
br label %99
97: ; preds = %93
%98 = tail call i32 @DiscreteGammaMedian(double* %1, double %2, double %3, i32 %4)
br label %99
99: ; preds = %97, %95
ret void
}