#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 DiscreteGamma(double *rK, double alfa, double beta, int K, int median) {
  int i;
  double gap05, t, factor, lnga1;
  factor = alfa / beta * K;
  gap05 = 1.0 / (2.0 * K);
  if (median) {
    for (i = 0; i < K; i++)
      rK[i] = PointChi2((i * 2.0 + 1.0) * gap05, 2.0 * (alfa)) / (2.0 * (beta));
    for (i = 0, t = 0; i < K; i++)
      t += rK[i];
    for (i = 0; i < K; i++)
      rK[i] *= factor / t;
  } else {
    lnga1 = LnGamma(alfa + 1);
    for (i = 0; i < K - 1; i++)
      rK[i] = PointChi2((i + 1.0) / K, 2.0 * (alfa)) / (2.0 * (beta));
    for (i = 0; i < K - 1; i++)
      rK[i] = IncompleteGamma(rK[i] * beta, alfa + 1.0, lnga1);
    rK[K - 1] = 1.0;
    for (i = K - 1; i > 0; i--) {
      rK[i] -= rK[i - 1];
      rK[i] *= factor;
    }
    rK[0] *= factor;
  }
  return (0);
}


x86 assembly (clang, -O0):
<DiscreteGamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %edx,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xe97(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xe83(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1281 <DiscreteGamma+0x151>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ff <DiscreteGamma+0xcf>
cvtsi2sdl -0x24(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe4c(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%edi
movsd  0xe3f(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1040 <PointChi2@plt>
movsd  0xe2d(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1197 <DiscreteGamma+0x67>
movl   $0x0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    123f <DiscreteGamma+0x10f>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    120e <DiscreteGamma+0xde>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    127c <DiscreteGamma+0x14c>
movsd  -0x40(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1246 <DiscreteGamma+0x116>
jmp    13f3 <DiscreteGamma+0x2c3>
movsd  0xd77(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1050 <LnGamma@plt>
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    130c <DiscreteGamma+0x1dc>
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  0xd43(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
movsd  0xd32(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1040 <PointChi2@plt>
movsd  0xd20(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    129f <DiscreteGamma+0x16f>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1368 <DiscreteGamma+0x238>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  0xcc2(%rip),%xmm1
addsd  -0x10(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
call   1030 <IncompleteGamma@plt>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1313 <DiscreteGamma+0x1e3>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  0xc83(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    13e2 <DiscreteGamma+0x2b2>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    138b <DiscreteGamma+0x25b>
movsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DiscreteGamma>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %esi,%r14d
movapd %xmm0,%xmm2
mov    %rdi,%rbx
cvtsi2sd %esi,%xmm4
divsd  %xmm1,%xmm0
mulsd  %xmm4,%xmm0
movsd  0xea6(%rip),%xmm3
test   %edx,%edx
je     1216 <DiscreteGamma+0xe6>
test   %r14d,%r14d
jle    14d7 <DiscreteGamma+0x3a7>
movapd %xmm0,0x20(%rsp)
addsd  %xmm4,%xmm4
movapd %xmm3,%xmm0
divsd  %xmm4,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    %r14d,%r15d
addsd  %xmm2,%xmm2
addsd  %xmm1,%xmm1
xor    %ebp,%ebp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
addsd  %xmm0,%xmm0
addsd  %xmm3,%xmm0
mulsd  0x18(%rsp),%xmm0
cvttsd2si %xmm0,%edi
movapd %xmm2,%xmm0
call   1040 <PointChi2@plt>
movsd  0xe36(%rip),%xmm3
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    11a0 <DiscreteGamma+0x70>
test   %r14d,%r14d
movapd 0x20(%rsp),%xmm5
jle    14d7 <DiscreteGamma+0x3a7>
lea    -0x1(%r15),%rcx
mov    %r15d,%eax
and    $0x7,%eax
cmp    $0x7,%rcx
jae    1388 <DiscreteGamma+0x258>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
jmp    13d8 <DiscreteGamma+0x2a8>
movsd  %xmm4,0x18(%rsp)
movsd  %xmm1,0x10(%rsp)
movapd %xmm0,0x20(%rsp)
movsd  0xdd0(%rip),%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,0x40(%rsp)
movsd  %xmm2,0x8(%rsp)
call   1050 <LnGamma@plt>
lea    -0x1(%r14),%r12d
cmp    $0x2,%r14d
jl     1364 <DiscreteGamma+0x234>
movsd  %xmm0,0x38(%rsp)
movsd  0x8(%rsp),%xmm1
addsd  %xmm1,%xmm1
movsd  0x10(%rsp),%xmm0
addsd  %xmm0,%xmm0
movsd  %xmm0,0x48(%rsp)
mov    %r12d,%r15d
xor    %ebp,%ebp
movsd  %xmm1,0x8(%rsp)
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
addsd  0xd71(%rip),%xmm0
divsd  0x18(%rsp),%xmm0
cvttsd2si %xmm0,%edi
movapd %xmm1,%xmm0
call   1040 <PointChi2@plt>
movsd  0x8(%rsp),%xmm1
divsd  0x48(%rsp),%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1280 <DiscreteGamma+0x150>
cmp    $0x2,%r14d
jl     1364 <DiscreteGamma+0x234>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsd  (%rbx,%rbp,8),%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  0x40(%rsp),%xmm1
movsd  0x38(%rsp),%xmm2
call   1030 <IncompleteGamma@plt>
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    12d0 <DiscreteGamma+0x1a0>
movslq %r12d,%rax
movabs $0x3ff0000000000000,%rcx
mov    %rcx,(%rbx,%rax,8)
cmp    $0x2,%r14d
movapd 0x20(%rsp),%xmm4
jl     137b <DiscreteGamma+0x24b>
cmp    $0x1,%r12d
mov    %r15,%r9
adc    $0xffffffffffffffff,%r9
add    $0x1,%r9
cmp    $0x4,%r9
jae    14ef <DiscreteGamma+0x3bf>
mov    %r15,%rax
add    $0x1,%rax
nopw   0x0(%rax,%rax,1)
lea    -0x2(%rax),%ecx
movsd  -0x8(%rbx,%rax,8),%xmm0
subsd  (%rbx,%rcx,8),%xmm0
mulsd  %xmm4,%xmm0
movsd  %xmm0,-0x8(%rbx,%rax,8)
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
ja     1340 <DiscreteGamma+0x210>
jmp    137b <DiscreteGamma+0x24b>
movslq %r12d,%rax
movabs $0x3ff0000000000000,%rcx
mov    %rcx,(%rbx,%rax,8)
movapd 0x20(%rsp),%xmm4
mulsd  (%rbx),%xmm4
movsd  %xmm4,(%rbx)
jmp    14d7 <DiscreteGamma+0x3a7>
mov    %r15d,%edx
and    $0xfffffff8,%edx
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
addsd  (%rbx,%rcx,8),%xmm0
addsd  0x8(%rbx,%rcx,8),%xmm0
addsd  0x10(%rbx,%rcx,8),%xmm0
addsd  0x18(%rbx,%rcx,8),%xmm0
addsd  0x20(%rbx,%rcx,8),%xmm0
addsd  0x28(%rbx,%rcx,8),%xmm0
addsd  0x30(%rbx,%rcx,8),%xmm0
addsd  0x38(%rbx,%rcx,8),%xmm0
add    $0x8,%rcx
cmp    %rcx,%rdx
jne    13a0 <DiscreteGamma+0x270>
test   %rax,%rax
je     13fe <DiscreteGamma+0x2ce>
lea    (%rbx,%rcx,8),%rcx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addsd  (%rcx,%rdx,8),%xmm0
add    $0x1,%rdx
cmp    %rdx,%rax
jne    13f0 <DiscreteGamma+0x2c0>
test   %r14d,%r14d
jle    14d7 <DiscreteGamma+0x3a7>
divsd  %xmm0,%xmm5
cmp    $0x4,%r15d
jae    1418 <DiscreteGamma+0x2e8>
xor    %eax,%eax
jmp    14c0 <DiscreteGamma+0x390>
mov    %r15d,%eax
and    $0xfffffffc,%eax
movapd %xmm5,%xmm0
unpcklpd %xmm5,%xmm0
lea    -0x4(%rax),%rcx
mov    %rcx,%rdx
shr    $0x2,%rdx
add    $0x1,%rdx
test   %rcx,%rcx
je     14e6 <DiscreteGamma+0x3b6>
mov    %rdx,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movupd (%rbx,%rcx,8),%xmm1
movupd 0x10(%rbx,%rcx,8),%xmm2
movupd 0x20(%rbx,%rcx,8),%xmm3
movupd 0x30(%rbx,%rcx,8),%xmm4
mulpd  %xmm0,%xmm1
mulpd  %xmm0,%xmm2
movupd %xmm1,(%rbx,%rcx,8)
movupd %xmm2,0x10(%rbx,%rcx,8)
mulpd  %xmm0,%xmm3
mulpd  %xmm0,%xmm4
movupd %xmm3,0x20(%rbx,%rcx,8)
movupd %xmm4,0x30(%rbx,%rcx,8)
add    $0x8,%rcx
add    $0xfffffffffffffffe,%rsi
jne    1450 <DiscreteGamma+0x320>
test   $0x1,%dl
je     14bb <DiscreteGamma+0x38b>
movupd (%rbx,%rcx,8),%xmm1
movupd 0x10(%rbx,%rcx,8),%xmm2
mulpd  %xmm0,%xmm1
mulpd  %xmm0,%xmm2
movupd %xmm1,(%rbx,%rcx,8)
movupd %xmm2,0x10(%rbx,%rcx,8)
cmp    %r15,%rax
je     14d7 <DiscreteGamma+0x3a7>
movsd  (%rbx,%rax,8),%xmm0
mulsd  %xmm5,%xmm0
movsd  %xmm0,(%rbx,%rax,8)
add    $0x1,%rax
cmp    %rax,%r15
jne    14c0 <DiscreteGamma+0x390>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ecx,%ecx
test   $0x1,%dl
jne    149d <DiscreteGamma+0x36d>
jmp    14bb <DiscreteGamma+0x38b>
cmp    $0x1,%r12d
mov    %r15,%rcx
adc    $0xffffffffffffffff,%rcx
add    $0xfffffffe,%r14d
mov    $0x8,%edx
mov    %rcx,%rax
mul    %rdx
seto   %dl
cmp    %ecx,%r14d
jb     1330 <DiscreteGamma+0x200>
shr    $0x20,%rcx
jne    1330 <DiscreteGamma+0x200>
lea    (%rbx,%r15,8),%rcx
mov    %rcx,%rdi
sub    %rax,%rdi
cmp    %rcx,%rdi
ja     1330 <DiscreteGamma+0x200>
test   %dl,%dl
jne    1330 <DiscreteGamma+0x200>
lea    (%rbx,%r14,8),%rcx
mov    %rcx,%rdi
sub    %rax,%rdi
cmp    %rcx,%rdi
ja     1330 <DiscreteGamma+0x200>
test   %dl,%dl
jne    1330 <DiscreteGamma+0x200>
xor    %eax,%eax
test   %r12d,%r12d
setne  %al
lea    (%rbx,%rax,8),%rcx
lea    (%rbx,%r14,8),%rdx
add    $0x8,%rdx
cmp    %rdx,%rcx
jae    1589 <DiscreteGamma+0x459>
lea    (%rbx,%r15,8),%rcx
add    $0x8,%rcx
add    %r14,%rax
sub    %r15,%rax
lea    (%rbx,%rax,8),%rax
cmp    %rcx,%rax
jb     1330 <DiscreteGamma+0x200>
mov    %r9,%r8
and    $0xfffffffffffffffc,%r8
mov    %r15,%rax
sub    %r8,%rax
movapd %xmm4,%xmm0
unpcklpd %xmm4,%xmm0
mov    %r8,%rdx
neg    %rdx
mov    $0xffffffff,%edi
add    %r15,%rdi
lea    (%rbx,%r15,8),%rbp
add    $0xfffffffffffffff8,%rbp
xor    %ecx,%ecx
shufpd $0x1,%xmm0,%xmm0
lea    (%rdi,%rcx,1),%esi
movupd -0x18(%rbx,%rsi,8),%xmm1
movupd -0x8(%rbx,%rsi,8),%xmm2
movupd -0x10(%rbp,%rcx,8),%xmm3
subpd  %xmm1,%xmm3
movupd 0x0(%rbp,%rcx,8),%xmm1
subpd  %xmm2,%xmm1
mulpd  %xmm0,%xmm1
movupd %xmm1,0x0(%rbp,%rcx,8)
mulpd  %xmm0,%xmm3
movupd %xmm3,-0x10(%rbp,%rcx,8)
add    $0xfffffffffffffffc,%rcx
cmp    %rcx,%rdx
jne    15bb <DiscreteGamma+0x48b>
cmp    %r8,%r9
je     137b <DiscreteGamma+0x24b>
jmp    1333 <DiscreteGamma+0x203>

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

LLVM IR (-O2):
define i32 @DiscreteGamma(double* nocapture %0, double %1, double %2, i32 %3, i32 %4) {
%6 = fdiv double %1, %2
%7 = sitofp i32 %3 to double
%8 = fmul double %6, %7
%9 = fmul double %7, 2.000000e+00
%10 = fdiv double 1.000000e+00, %9
%11 = icmp eq i32 %4, 0
br i1 %11, label %161, label %12
12: ; preds = %5
%13 = icmp sgt i32 %3, 0
br i1 %13, label %14, label %310
14: ; preds = %12
%15 = fmul double %1, 2.000000e+00
%16 = fmul double %2, 2.000000e+00
%17 = zext i32 %3 to i64
br label %25
18: ; preds = %25
br i1 %13, label %19, label %310
19: ; preds = %18
%20 = add nsw i64 %17, -1
%21 = and i64 %17, 7
%22 = icmp ult i64 %20, 7
br i1 %22, label %37, label %23
23: ; preds = %19
%24 = and i64 %17, 4294967288
br label %116
25: ; preds = %14, %25
%26 = phi i64 [ 0, %14 ], [ %35, %25 ]
%27 = trunc i64 %26 to i32
%28 = sitofp i32 %27 to double
%29 = tail call double @llvm.fmuladd.f64(double %28, double 2.000000e+00, double 1.000000e+00)
%30 = fmul double %10, %29
%31 = fptosi double %30 to i32
%32 = tail call double @PointChi2(i32 %31, double %15)
%33 = fdiv double %32, %16
%34 = getelementptr inbounds double, double* %0, i64 %26
store double %33, double* %34
%35 = add nuw nsw i64 %26, 1
%36 = icmp eq i64 %35, %17
br i1 %36, label %18, label %25
37: ; preds = %116, %19
%38 = phi double [ undef, %19 ], [ %150, %116 ]
%39 = phi i64 [ 0, %19 ], [ %151, %116 ]
%40 = phi double [ 0.000000e+00, %19 ], [ %150, %116 ]
%41 = icmp eq i64 %21, 0
br i1 %41, label %52, label %42
42: ; preds = %37, %42
%43 = phi i64 [ %49, %42 ], [ %39, %37 ]
%44 = phi double [ %48, %42 ], [ %40, %37 ]
%45 = phi i64 [ %50, %42 ], [ 0, %37 ]
%46 = getelementptr inbounds double, double* %0, i64 %43
%47 = load double, double* %46
%48 = fadd double %44, %47
%49 = add nuw nsw i64 %43, 1
%50 = add i64 %45, 1
%51 = icmp eq i64 %50, %21
br i1 %51, label %52, label %42
52: ; preds = %42, %37
%53 = phi double [ %38, %37 ], [ %48, %42 ]
br i1 %13, label %54, label %310
54: ; preds = %52
%55 = fdiv double %8, %53
%56 = zext i32 %3 to i64
%57 = icmp ult i32 %3, 4
br i1 %57, label %114, label %58
58: ; preds = %54
%59 = and i64 %17, 4294967292
%60 = insertelement <2 x double> poison, double %55, i64 0
%61 = shufflevector <2 x double> %60, <2 x double> poison, <2 x i32> zeroinitializer
%62 = insertelement <2 x double> poison, double %55, i64 0
%63 = shufflevector <2 x double> %62, <2 x double> poison, <2 x i32> zeroinitializer
%64 = add nsw i64 %59, -4
%65 = lshr exact i64 %64, 2
%66 = add nuw nsw i64 %65, 1
%67 = and i64 %66, 1
%68 = icmp eq i64 %64, 0
br i1 %68, label %98, label %69
69: ; preds = %58
%70 = and i64 %66, 9223372036854775806
br label %71
71: ; preds = %71, %69
%72 = phi i64 [ 0, %69 ], [ %95, %71 ]
%73 = phi i64 [ 0, %69 ], [ %96, %71 ]
%74 = getelementptr inbounds double, double* %0, i64 %72
%75 = bitcast double* %74 to <2 x double>*
%76 = load <2 x double>, <2 x double>* %75
%77 = getelementptr inbounds double, double* %74, i64 2
%78 = bitcast double* %77 to <2 x double>*
%79 = load <2 x double>, <2 x double>* %78
%80 = fmul <2 x double> %61, %76
%81 = fmul <2 x double> %63, %79
%82 = bitcast double* %74 to <2 x double>*
store <2 x double> %80, <2 x double>* %82
%83 = bitcast double* %77 to <2 x double>*
store <2 x double> %81, <2 x double>* %83
%84 = or i64 %72, 4
%85 = getelementptr inbounds double, double* %0, i64 %84
%86 = bitcast double* %85 to <2 x double>*
%87 = load <2 x double>, <2 x double>* %86
%88 = getelementptr inbounds double, double* %85, i64 2
%89 = bitcast double* %88 to <2 x double>*
%90 = load <2 x double>, <2 x double>* %89
%91 = fmul <2 x double> %61, %87
%92 = fmul <2 x double> %63, %90
%93 = bitcast double* %85 to <2 x double>*
store <2 x double> %91, <2 x double>* %93
%94 = bitcast double* %88 to <2 x double>*
store <2 x double> %92, <2 x double>* %94
%95 = add nuw i64 %72, 8
%96 = add i64 %73, 2
%97 = icmp eq i64 %96, %70
br i1 %97, label %98, label %71
98: ; preds = %71, %58
%99 = phi i64 [ 0, %58 ], [ %95, %71 ]
%100 = icmp eq i64 %67, 0
br i1 %100, label %112, label %101
101: ; preds = %98
%102 = getelementptr inbounds double, double* %0, i64 %99
%103 = bitcast double* %102 to <2 x double>*
%104 = load <2 x double>, <2 x double>* %103
%105 = getelementptr inbounds double, double* %102, i64 2
%106 = bitcast double* %105 to <2 x double>*
%107 = load <2 x double>, <2 x double>* %106
%108 = fmul <2 x double> %61, %104
%109 = fmul <2 x double> %63, %107
%110 = bitcast double* %102 to <2 x double>*
store <2 x double> %108, <2 x double>* %110
%111 = bitcast double* %105 to <2 x double>*
store <2 x double> %109, <2 x double>* %111
br label %112
112: ; preds = %98, %101
%113 = icmp eq i64 %59, %17
br i1 %113, label %310, label %114
114: ; preds = %54, %112
%115 = phi i64 [ 0, %54 ], [ %59, %112 ]
br label %154
116: ; preds = %116, %23
%117 = phi i64 [ 0, %23 ], [ %151, %116 ]
%118 = phi double [ 0.000000e+00, %23 ], [ %150, %116 ]
%119 = phi i64 [ 0, %23 ], [ %152, %116 ]
%120 = getelementptr inbounds double, double* %0, i64 %117
%121 = load double, double* %120
%122 = fadd double %118, %121
%123 = or i64 %117, 1
%124 = getelementptr inbounds double, double* %0, i64 %123
%125 = load double, double* %124
%126 = fadd double %122, %125
%127 = or i64 %117, 2
%128 = getelementptr inbounds double, double* %0, i64 %127
%129 = load double, double* %128
%130 = fadd double %126, %129
%131 = or i64 %117, 3
%132 = getelementptr inbounds double, double* %0, i64 %131
%133 = load double, double* %132
%134 = fadd double %130, %133
%135 = or i64 %117, 4
%136 = getelementptr inbounds double, double* %0, i64 %135
%137 = load double, double* %136
%138 = fadd double %134, %137
%139 = or i64 %117, 5
%140 = getelementptr inbounds double, double* %0, i64 %139
%141 = load double, double* %140
%142 = fadd double %138, %141
%143 = or i64 %117, 6
%144 = getelementptr inbounds double, double* %0, i64 %143
%145 = load double, double* %144
%146 = fadd double %142, %145
%147 = or i64 %117, 7
%148 = getelementptr inbounds double, double* %0, i64 %147
%149 = load double, double* %148
%150 = fadd double %146, %149
%151 = add nuw nsw i64 %117, 8
%152 = add i64 %119, 8
%153 = icmp eq i64 %152, %24
br i1 %153, label %37, label %116
154: ; preds = %114, %154
%155 = phi i64 [ %159, %154 ], [ %115, %114 ]
%156 = getelementptr inbounds double, double* %0, i64 %155
%157 = load double, double* %156
%158 = fmul double %55, %157
store double %158, double* %156
%159 = add nuw nsw i64 %155, 1
%160 = icmp eq i64 %159, %56
br i1 %160, label %310, label %154
161: ; preds = %5
%162 = fadd double %1, 1.000000e+00
%163 = tail call double @LnGamma(double %162)
%164 = add i32 %3, -1
%165 = icmp sgt i32 %3, 1
br i1 %165, label %166, label %193
166: ; preds = %161
%167 = fmul double %1, 2.000000e+00
%168 = fmul double %2, 2.000000e+00
%169 = zext i32 %164 to i64
br label %173
170: ; preds = %173
br i1 %165, label %171, label %193
171: ; preds = %170
%172 = zext i32 %164 to i64
br label %185
173: ; preds = %166, %173
%174 = phi i64 [ 0, %166 ], [ %183, %173 ]
%175 = trunc i64 %174 to i32
%176 = sitofp i32 %175 to double
%177 = fadd double %176, 1.000000e+00
%178 = fdiv double %177, %7
%179 = fptosi double %178 to i32
%180 = tail call double @PointChi2(i32 %179, double %167)
%181 = fdiv double %180, %168
%182 = getelementptr inbounds double, double* %0, i64 %174
store double %181, double* %182
%183 = add nuw nsw i64 %174, 1
%184 = icmp eq i64 %183, %169
br i1 %184, label %170, label %173
185: ; preds = %171, %185
%186 = phi i64 [ 0, %171 ], [ %191, %185 ]
%187 = getelementptr inbounds double, double* %0, i64 %186
%188 = load double, double* %187
%189 = fmul double %188, %2
%190 = tail call double @IncompleteGamma(double %189, double %162, double %163)
store double %190, double* %187
%191 = add nuw nsw i64 %186, 1
%192 = icmp eq i64 %191, %172
br i1 %192, label %196, label %185
193: ; preds = %170, %161
%194 = sext i32 %164 to i64
%195 = getelementptr inbounds double, double* %0, i64 %194
store double 1.000000e+00, double* %195
br label %307
196: ; preds = %185
%197 = sext i32 %164 to i64
%198 = getelementptr inbounds double, double* %0, i64 %197
store double 1.000000e+00, double* %198
br i1 %165, label %199, label %307
199: ; preds = %196
%200 = zext i32 %164 to i64
%201 = add nuw nsw i64 %169, 1
%202 = icmp ne i32 %164, 0
%203 = sext i1 %202 to i64
%204 = add nsw i64 %201, %203
%205 = icmp ult i64 %204, 4
br i1 %205, label %294, label %206
206: ; preds = %199
%207 = icmp ne i32 %164, 0
%208 = sext i1 %207 to i64
%209 = add nsw i64 %208, %169
%210 = add i32 %3, -2
%211 = trunc i64 %209 to i32
%212 = icmp ult i32 %210, %211
%213 = icmp ugt i64 %209, 4294967295
%214 = or i1 %212, %213
%215 = getelementptr double, double* %0, i64 %169
%216 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %209, i64 8)
%217 = extractvalue { i64, i1 } %216, 0
%218 = extractvalue { i64, i1 } %216, 1
%219 = bitcast double* %215 to i8*
%220 = sub i64 0, %217
%221 = getelementptr i8, i8* %219, i64 %220
%222 = icmp ugt i8* %221, %219
%223 = or i1 %222, %218
%224 = zext i32 %210 to i64
%225 = getelementptr double, double* %0, i64 %224
%226 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %209, i64 8)
%227 = extractvalue { i64, i1 } %226, 0
%228 = extractvalue { i64, i1 } %226, 1
%229 = bitcast double* %225 to i8*
%230 = sub i64 0, %227
%231 = getelementptr i8, i8* %229, i64 %230
%232 = icmp ugt i8* %231, %229
%233 = or i1 %232, %228
%234 = or i1 %214, %223
%235 = or i1 %234, %233
br i1 %235, label %294, label %236
236: ; preds = %206
%237 = icmp ne i32 %164, 0
%238 = zext i1 %237 to i64
%239 = getelementptr double, double* %0, i64 %238
%240 = add nuw nsw i64 %169, 1
%241 = getelementptr double, double* %0, i64 %240
%242 = add i32 %3, -2
%243 = zext i32 %242 to i64
%244 = add nuw nsw i64 %238, %243
%245 = sub nsw i64 %244, %169
%246 = getelementptr double, double* %0, i64 %245
%247 = add nuw nsw i64 %243, 1
%248 = getelementptr double, double* %0, i64 %247
%249 = icmp ult double* %239, %248
%250 = icmp ult double* %246, %241
%251 = and i1 %249, %250
br i1 %251, label %294, label %252
252: ; preds = %236
%253 = and i64 %204, -4
%254 = sub nsw i64 %200, %253
%255 = insertelement <2 x double> poison, double %8, i64 0
%256 = shufflevector <2 x double> %255, <2 x double> poison, <2 x i32> zeroinitializer
%257 = insertelement <2 x double> poison, double %8, i64 0
%258 = shufflevector <2 x double> %257, <2 x double> poison, <2 x i32> zeroinitializer
br label %259
259: ; preds = %259, %252
%260 = phi i64 [ 0, %252 ], [ %290, %259 ]
%261 = sub i64 %200, %260
%262 = add i64 %261, 4294967295
%263 = and i64 %262, 4294967295
%264 = getelementptr inbounds double, double* %0, i64 %263
%265 = getelementptr inbounds double, double* %264, i64 -1
%266 = bitcast double* %265 to <2 x double>*
%267 = load <2 x double>, <2 x double>* %266
%268 = getelementptr inbounds double, double* %264, i64 -2
%269 = getelementptr inbounds double, double* %268, i64 -1
%270 = bitcast double* %269 to <2 x double>*
%271 = load <2 x double>, <2 x double>* %270
%272 = getelementptr inbounds double, double* %0, i64 %261
%273 = getelementptr inbounds double, double* %272, i64 -1
%274 = bitcast double* %273 to <2 x double>*
%275 = load <2 x double>, <2 x double>* %274
%276 = getelementptr inbounds double, double* %272, i64 -2
%277 = getelementptr inbounds double, double* %276, i64 -1
%278 = bitcast double* %277 to <2 x double>*
%279 = load <2 x double>, <2 x double>* %278
%280 = fsub <2 x double> %275, %267
%281 = shufflevector <2 x double> %280, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%282 = fsub <2 x double> %279, %271
%283 = shufflevector <2 x double> %282, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%284 = fmul <2 x double> %256, %281
%285 = fmul <2 x double> %258, %283
%286 = shufflevector <2 x double> %284, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%287 = bitcast double* %273 to <2 x double>*
store <2 x double> %286, <2 x double>* %287
%288 = shufflevector <2 x double> %285, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%289 = bitcast double* %277 to <2 x double>*
store <2 x double> %288, <2 x double>* %289
%290 = add nuw i64 %260, 4
%291 = icmp eq i64 %290, %253
br i1 %291, label %292, label %259
292: ; preds = %259
%293 = icmp eq i64 %204, %253
br i1 %293, label %307, label %294
294: ; preds = %236, %206, %199, %292
%295 = phi i64 [ %200, %236 ], [ %200, %206 ], [ %200, %199 ], [ %254, %292 ]
br label %296
296: ; preds = %294, %296
%297 = phi i64 [ %298, %296 ], [ %295, %294 ]
%298 = add nsw i64 %297, -1
%299 = and i64 %298, 4294967295
%300 = getelementptr inbounds double, double* %0, i64 %299
%301 = load double, double* %300
%302 = getelementptr inbounds double, double* %0, i64 %297
%303 = load double, double* %302
%304 = fsub double %303, %301
%305 = fmul double %8, %304
store double %305, double* %302
%306 = icmp ugt i64 %297, 1
br i1 %306, label %296, label %307
307: ; preds = %296, %292, %193, %196
%308 = load double, double* %0
%309 = fmul double %8, %308
store double %309, double* %0
br label %310
310: ; preds = %154, %112, %12, %18, %52, %307
ret i32 0
}