#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 IncompleteGamma(double, double, double);
double LnGamma(double);
double PointChi2(int, double);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
void makeGammaCats(int model, double *alphas, double *gammaRates) {
  int i, K = 4;
  double factor, lnga1, alfa, beta;
  double *gammaProbs = (double *)malloc(K * sizeof(double));
  alfa = beta = alphas[model];
  assert(alfa >= 0.02);
  factor = alfa / beta * K;
  lnga1 = LnGamma(alfa + 1);
  for (i = 0; i < K - 1; i++)
    gammaProbs[i] = PointChi2((i + 1.0) / K, 2.0 * (alfa)) / (2.0 * (beta));
  for (i = 0; i < K - 1; i++)
    gammaProbs[i] = IncompleteGamma(gammaProbs[i] * beta, alfa + 1, lnga1);
  gammaRates[model * K] = gammaProbs[0] * factor;
  gammaRates[model * K + (K - 1)] = (1 - gammaProbs[K - 2]) * factor;
  for (i = 1; i < K - 1; i++)
    gammaRates[model * K + i] = (gammaProbs[i] - gammaProbs[i - 1]) * factor;
  free(gammaProbs);
  return;
}


x86 assembly (clang, -O0):
<makeGammaCats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x4,-0x20(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe57(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movsd  -0x38(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe1e(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
call   1080 <LnGamma@plt>
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1265 <makeGammaCats+0x105>
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xdea(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
movsd  0xde1(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
call   1060 <PointChi2@plt>
movsd  0xdcf(%rip),%xmm1
mulsd  -0x40(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x48(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f8 <makeGammaCats+0x98>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12c1 <makeGammaCats+0x161>
mov    -0x48(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  0xd69(%rip),%xmm1
addsd  -0x38(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
call   1040 <IncompleteGamma@plt>
mov    -0x48(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    126c <makeGammaCats+0x10c>
mov    -0x48(%rbp),%rax
movsd  (%rax),%xmm0
mulsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
imul   -0x20(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsd  0xd0a(%rip),%xmm0
subsd  (%rax,%rcx,8),%xmm0
mulsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
imul   -0x20(%rbp),%ecx
mov    -0x20(%rbp),%edx
sub    $0x1,%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    137b <makeGammaCats+0x21b>
mov    -0x48(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x48(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
mulsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
imul   -0x20(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1322 <makeGammaCats+0x1c2>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeGammaCats>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
movslq %ebp,%rbp
movsd  (%r15,%rbp,8),%xmm0
movsd  %xmm0,(%rsp)
xor    %edi,%edi
ucomisd 0xe69(%rip),%xmm0
setae  %dil
call   1050 <assert@plt>
movsd  (%rsp),%xmm0
movapd %xmm0,%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
addsd  0xe4d(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
call   1080 <LnGamma@plt>
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
addsd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
call   1060 <PointChi2@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx)
xor    %edi,%edi
movapd %xmm1,%xmm0
call   1060 <PointChi2@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rbx)
xor    %edi,%edi
movapd %xmm1,%xmm0
call   1060 <PointChi2@plt>
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rbx)
movsd  (%rbx),%xmm0
mulsd  (%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
call   1040 <IncompleteGamma@plt>
movsd  %xmm0,(%rbx)
movsd  0x8(%rbx),%xmm0
mulsd  (%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
call   1040 <IncompleteGamma@plt>
movsd  %xmm0,0x8(%rbx)
movsd  (%rsp),%xmm0
mulsd  0x10(%rbx),%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
call   1040 <IncompleteGamma@plt>
movsd  0x20(%rsp),%xmm1
mulsd  0xd89(%rip),%xmm1
movsd  %xmm0,0x10(%rbx)
movsd  (%rbx),%xmm0
mulsd  %xmm1,%xmm0
lea    0x0(,%rbp,4),%eax
cltq
movsd  %xmm0,(%r14,%rax,8)
movsd  0xd5d(%rip),%xmm0
subsd  0x10(%rbx),%xmm0
mulsd  %xmm1,%xmm0
lea    0x3(,%rbp,4),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%r14,%rcx,8)
movsd  0x8(%rbx),%xmm0
subsd  (%rbx),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%r14,%rax,8)
movsd  0x10(%rbx),%xmm0
subsd  0x8(%rbx),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%r14,%rax,8)
mov    %rbx,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @makeGammaCats(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double*
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
store i32 4, i32* %8
%14 = load i32, i32* %8
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 8
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to double*
store double* %19, double** %13
%20 = load double*, double** %5
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
store double %24, double* %12
store double %24, double* %11
%25 = load double, double* %11
%26 = fcmp oge double %25, 2.000000e-02
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load double, double* %11
%30 = load double, double* %12
%31 = fdiv double %29, %30
%32 = load i32, i32* %8
%33 = sitofp i32 %32 to double
%34 = fmul double %31, %33
store double %34, double* %9
%35 = load double, double* %11
%36 = fadd double %35, 1.000000e+00
%37 = call double @LnGamma(double %36)
store double %37, double* %10
store i32 0, i32* %7
br label %38
38: ; preds = %61, %3
%39 = load i32, i32* %7
%40 = load i32, i32* %8
%41 = sub nsw i32 %40, 1
%42 = icmp slt i32 %39, %41
br i1 %42, label %43, label %64
43: ; preds = %38
%44 = load i32, i32* %7
%45 = sitofp i32 %44 to double
%46 = fadd double %45, 1.000000e+00
%47 = load i32, i32* %8
%48 = sitofp i32 %47 to double
%49 = fdiv double %46, %48
%50 = fptosi double %49 to i32
%51 = load double, double* %11
%52 = fmul double 2.000000e+00, %51
%53 = call double @PointChi2(i32 %50, double %52)
%54 = load double, double* %12
%55 = fmul double 2.000000e+00, %54
%56 = fdiv double %53, %55
%57 = load double*, double** %13
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %57, i64 %59
store double %56, double* %60
br label %61
61: ; preds = %43
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
br label %38
64: ; preds = %38
store i32 0, i32* %7
br label %65
65: ; preds = %86, %64
%66 = load i32, i32* %7
%67 = load i32, i32* %8
%68 = sub nsw i32 %67, 1
%69 = icmp slt i32 %66, %68
br i1 %69, label %70, label %89
70: ; preds = %65
%71 = load double*, double** %13
%72 = load i32, i32* %7
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %71, i64 %73
%75 = load double, double* %74
%76 = load double, double* %12
%77 = fmul double %75, %76
%78 = load double, double* %11
%79 = fadd double %78, 1.000000e+00
%80 = load double, double* %10
%81 = call double @IncompleteGamma(double %77, double %79, double %80)
%82 = load double*, double** %13
%83 = load i32, i32* %7
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %82, i64 %84
store double %81, double* %85
br label %86
86: ; preds = %70
%87 = load i32, i32* %7
%88 = add nsw i32 %87, 1
store i32 %88, i32* %7
br label %65
89: ; preds = %65
%90 = load double*, double** %13
%91 = getelementptr inbounds double, double* %90, i64 0
%92 = load double, double* %91
%93 = load double, double* %9
%94 = fmul double %92, %93
%95 = load double*, double** %6
%96 = load i32, i32* %4
%97 = load i32, i32* %8
%98 = mul nsw i32 %96, %97
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds double, double* %95, i64 %99
store double %94, double* %100
%101 = load double*, double** %13
%102 = load i32, i32* %8
%103 = sub nsw i32 %102, 2
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds double, double* %101, i64 %104
%106 = load double, double* %105
%107 = fsub double 1.000000e+00, %106
%108 = load double, double* %9
%109 = fmul double %107, %108
%110 = load double*, double** %6
%111 = load i32, i32* %4
%112 = load i32, i32* %8
%113 = mul nsw i32 %111, %112
%114 = load i32, i32* %8
%115 = sub nsw i32 %114, 1
%116 = add nsw i32 %113, %115
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds double, double* %110, i64 %117
store double %109, double* %118
store i32 1, i32* %7
br label %119
119: ; preds = %147, %89
%120 = load i32, i32* %7
%121 = load i32, i32* %8
%122 = sub nsw i32 %121, 1
%123 = icmp slt i32 %120, %122
br i1 %123, label %124, label %150
124: ; preds = %119
%125 = load double*, double** %13
%126 = load i32, i32* %7
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds double, double* %125, i64 %127
%129 = load double, double* %128
%130 = load double*, double** %13
%131 = load i32, i32* %7
%132 = sub nsw i32 %131, 1
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds double, double* %130, i64 %133
%135 = load double, double* %134
%136 = fsub double %129, %135
%137 = load double, double* %9
%138 = fmul double %136, %137
%139 = load double*, double** %6
%140 = load i32, i32* %4
%141 = load i32, i32* %8
%142 = mul nsw i32 %140, %141
%143 = load i32, i32* %7
%144 = add nsw i32 %142, %143
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds double, double* %139, i64 %145
store double %138, double* %146
br label %147
147: ; preds = %124
%148 = load i32, i32* %7
%149 = add nsw i32 %148, 1
store i32 %149, i32* %7
br label %119
150: ; preds = %119
%151 = load double*, double** %13
%152 = call i32 @free(double* %151)
ret void
}

LLVM IR (-O2):
define void @makeGammaCats(i32 %0, double* nocapture %1, double* nocapture writeonly %2) {
%4 = tail call i64 @malloc(i32 32)
%5 = inttoptr i64 %4 to double*
%6 = sext i32 %0 to i64
%7 = getelementptr inbounds double, double* %1, i64 %6
%8 = load double, double* %7
%9 = fcmp oge double %8, 2.000000e-02
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = fdiv double %8, %8
%13 = fadd double %8, 1.000000e+00
%14 = tail call double @LnGamma(double %13)
%15 = fmul double %8, 2.000000e+00
%16 = tail call double @PointChi2(i32 0, double %15)
%17 = fdiv double %16, %15
store double %17, double* %5
%18 = tail call double @PointChi2(i32 0, double %15)
%19 = fdiv double %18, %15
%20 = getelementptr inbounds double, double* %5, i64 1
store double %19, double* %20
%21 = tail call double @PointChi2(i32 0, double %15)
%22 = fdiv double %21, %15
%23 = getelementptr inbounds double, double* %5, i64 2
store double %22, double* %23
%24 = load double, double* %5
%25 = fmul double %8, %24
%26 = tail call double @IncompleteGamma(double %25, double %13, double %14)
store double %26, double* %5
%27 = load double, double* %20
%28 = fmul double %8, %27
%29 = tail call double @IncompleteGamma(double %28, double %13, double %14)
store double %29, double* %20
%30 = load double, double* %23
%31 = fmul double %8, %30
%32 = tail call double @IncompleteGamma(double %31, double %13, double %14)
store double %32, double* %23
%33 = fmul double %12, 4.000000e+00
%34 = load double, double* %5
%35 = fmul double %33, %34
%36 = shl nsw i32 %0, 2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %2, i64 %37
store double %35, double* %38
%39 = load double, double* %23
%40 = fsub double 1.000000e+00, %39
%41 = fmul double %33, %40
%42 = or i32 %36, 3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %2, i64 %43
store double %41, double* %44
%45 = load double, double* %20
%46 = load double, double* %5
%47 = fsub double %45, %46
%48 = fmul double %33, %47
%49 = or i64 %37, 1
%50 = getelementptr inbounds double, double* %2, i64 %49
store double %48, double* %50
%51 = load double, double* %23
%52 = load double, double* %20
%53 = fsub double %51, %52
%54 = fmul double %33, %53
%55 = or i64 %37, 2
%56 = getelementptr inbounds double, double* %2, i64 %55
store double %54, double* %56
%57 = tail call i32 @free(double* %5)
ret void
}