#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*/ assert(int);
double exp(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ free(double *);
double log(double);
double log1p(double);
double log_sum(double, double);
double *malloc(int);
double pow(double, double);
int /*<<< orphan*/ stderr;
double *pruned_calc_prob_dist(const int *quals, int N, int K) {
  double *probvec = NULL;
  double *probvec_prev = NULL;
  double *probvec_swp = NULL;
  int n;
  if (NULL == (probvec = malloc((K + 1) * sizeof(double)))) {
    fprintf(stderr, "FATAL: couldn't allocate memory at %d\n", 192);
    return NULL;
  }
  if (NULL == (probvec_prev = malloc((K + 1) * sizeof(double)))) {
    fprintf(stderr, "FATAL: couldn't allocate memory at %d\n", 197);
    return NULL;
  }
  probvec_prev[0] = 0.0;
  for (n = 1; n <= N; n++) {
    int k;
    double pvalue;
    double pn = (pow(10.0, -1.0 * (quals[n - 1]) / 10.0));
    double log_pn = log(pn);
    double log_1_pn = log1p(-pn);
    assert(((quals[n - 1]) > 1 && (quals[n - 1]) < 100));
    if (n < K) {
      probvec_prev[n] = -1e100;
    }
    for (k = ((n) < (K - 1) ? (n) : (K - 1)); k >= 1; k--) {
      assert(probvec_prev[k] <= 0.0 && probvec_prev[k - 1] <= 0.0);
      probvec[k] =
          log_sum(probvec_prev[k] + log_1_pn, probvec_prev[k - 1] + log_pn);
    }
    k = 0;
    assert(probvec_prev[k] <= 0.0);
    probvec[k] = probvec_prev[k] + log_1_pn;
    if (n == K) {
      probvec[K] = probvec_prev[K - 1] + log_pn;
    } else if (n > K) {
      assert(probvec_prev[K] <= 0.0 && probvec_prev[K - 1] <= 0.0);
      probvec[K] = log_sum(probvec_prev[K], probvec_prev[K - 1] + log_pn);
      pvalue = exp(probvec[K]);
    }
    if (n < N) {
      probvec_swp = probvec;
      probvec = probvec_prev;
      probvec_prev = probvec_swp;
    }
  }
free_and_exit:
  free(probvec_prev);
  return probvec;
}


x86 assembly (clang, -O0):
<pruned_calc_prob_dist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1206 <pruned_calc_prob_dist+0x76>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    $0xc0,%edx
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1569 <pruned_calc_prob_dist+0x3d9>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1252 <pruned_calc_prob_dist+0xc2>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
mov    $0xc5,%edx
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1569 <pruned_calc_prob_dist+0x3d9>
mov    -0x28(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1553 <pruned_calc_prob_dist+0x3c3>
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm0
movsd  0xd7e(%rip),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xd6a(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd5e(%rip),%xmm0
call   10a0 <pow@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1090 <log@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   10b0 <log1p@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rdx
xor    %eax,%eax
cmpl   $0x1,(%rcx,%rdx,4)
mov    %al,-0x59(%rbp)
jle    1314 <pruned_calc_prob_dist+0x184>
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmpl   $0x64,(%rax,%rcx,4)
setl   %al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x34(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1342 <pruned_calc_prob_dist+0x1b2>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  0xcd3(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    135e <pruned_calc_prob_dist+0x1ce>
mov    -0x34(%rbp),%eax
mov    %eax,-0x60(%rbp)
jmp    1367 <pruned_calc_prob_dist+0x1d7>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x38(%rbp)
jl     1403 <pruned_calc_prob_dist+0x273>
mov    -0x28(%rbp),%rcx
movslq -0x38(%rbp),%rdx
xor    %eax,%eax
xorps  %xmm0,%xmm0
ucomisd (%rcx,%rdx,8),%xmm0
mov    %al,-0x61(%rbp)
jb     13ad <pruned_calc_prob_dist+0x21d>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
setae  %al
mov    %al,-0x61(%rbp)
mov    -0x61(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x58(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
addsd  -0x50(%rbp),%xmm1
call   1060 <log_sum@plt>
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    136d <pruned_calc_prob_dist+0x1dd>
movl   $0x0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x58(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    147b <pruned_calc_prob_dist+0x2eb>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x50(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    151c <pruned_calc_prob_dist+0x38c>
mov    -0x34(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1517 <pruned_calc_prob_dist+0x387>
mov    -0x28(%rbp),%rcx
movslq -0x18(%rbp),%rdx
xor    %eax,%eax
xorps  %xmm0,%xmm0
ucomisd (%rcx,%rdx,8),%xmm0
mov    %al,-0x62(%rbp)
jb     14bd <pruned_calc_prob_dist+0x32d>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
setae  %al
mov    %al,-0x62(%rbp)
mov    -0x62(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
addsd  -0x50(%rbp),%xmm1
call   1060 <log_sum@plt>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1080 <exp@plt>
movsd  %xmm0,-0x40(%rbp)
jmp    151c <pruned_calc_prob_dist+0x38c>
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1540 <pruned_calc_prob_dist+0x3b0>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1545 <pruned_calc_prob_dist+0x3b5>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1264 <pruned_calc_prob_dist+0xd4>
jmp    1558 <pruned_calc_prob_dist+0x3c8>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pruned_calc_prob_dist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %esi,%r12d
mov    %rdi,0x60(%rsp)
mov    %rdx,0x28(%rsp)
lea    0x8(,%rdx,8),%r14d
mov    %r14d,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     142f <pruned_calc_prob_dist+0x29f>
mov    %rax,%rbp
mov    %r14d,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1446 <pruned_calc_prob_dist+0x2b6>
mov    %rax,%r15
movq   $0x0,(%rax)
test   %r12d,%r12d
jle    1464 <pruned_calc_prob_dist+0x2d4>
mov    0x28(%rsp),%rax
lea    -0x1(%rax),%ecx
movslq %eax,%r13
mov    %ecx,0xc(%rsp)
movslq %ecx,%rcx
mov    %rcx,0x10(%rsp)
mov    %eax,%eax
mov    %rax,0x58(%rsp)
mov    %r12d,%eax
mov    %rax,0x50(%rsp)
add    $0x1,%r12d
mov    $0x1,%r14d
mov    %r12,0x20(%rsp)
mov    %r13,0x18(%rsp)
jmp    1270 <pruned_calc_prob_dist+0xe0>
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
movsd  (%rsp),%xmm0
addsd  (%rbx,%rax,8),%xmm0
mov    0x18(%rsp),%r13
movsd  %xmm0,0x0(%rbp,%r13,8)
mov    0x20(%rsp),%r12
cmp    0x50(%rsp),%r14
mov    %rbx,%rdi
cmovb  %rbp,%rdi
cmovb  %rbx,%rbp
add    $0x1,%r14
mov    %rdi,%r15
cmp    %r12,%r14
je     1467 <pruned_calc_prob_dist+0x2d7>
mov    %rbp,0x38(%rsp)
mov    0xc(%rsp),%eax
cmp    %eax,%r14d
mov    %eax,%ebx
cmovl  %r14d,%ebx
mov    0x60(%rsp),%rbp
xorps  %xmm1,%xmm1
cvtsi2sdl -0x4(%rbp,%r14,4),%xmm1
divsd  0xd67(%rip),%xmm1
movsd  0xd67(%rip),%xmm0
call   10a0 <pow@plt>
movaps %xmm0,0x40(%rsp)
call   1090 <log@plt>
movsd  %xmm0,(%rsp)
movapd 0x40(%rsp),%xmm0
xorpd  0xd5d(%rip),%xmm0
call   10b0 <log1p@plt>
movsd  %xmm0,0x40(%rsp)
mov    -0x4(%rbp,%r14,4),%eax
add    $0xfffffffe,%eax
xor    %edi,%edi
cmp    $0x62,%eax
setb   %dil
call   1040 <assert@plt>
cmp    %r13,%r14
jge    12f7 <pruned_calc_prob_dist+0x167>
movabs $0xd4b249ad2594c37d,%rax
49 b2 d4
mov    %rax,(%r15,%r14,8)
mov    %r15,0x30(%rsp)
cmpl   $0x2,0x28(%rsp)
xorpd  %xmm0,%xmm0
jl     1380 <pruned_calc_prob_dist+0x1f0>
lea    -0x1(%rbx),%eax
lea    0x1(%rbx),%r12d
mov    0x30(%rsp),%rcx
lea    (%rcx,%rax,8),%r15
mov    0x38(%rsp),%rax
lea    (%rax,%rbx,8),%r13
lea    (%rcx,%rbx,8),%rbx
xor    %ebp,%ebp
jmp    1374 <pruned_calc_prob_dist+0x1e4>
nopl   0x0(%rax,%rax,1)
ucomisd (%r15,%rbp,8),%xmm0
setae  %al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  (%rbx,%rbp,8),%xmm0
addsd  0x40(%rsp),%xmm0
movsd  (%r15,%rbp,8),%xmm1
addsd  (%rsp),%xmm1
call   1060 <log_sum@plt>
movsd  %xmm0,0x0(%r13,%rbp,8)
add    $0xffffffffffffffff,%rbp
lea    (%r12,%rbp,1),%eax
cmp    $0x1,%eax
xorpd  %xmm0,%xmm0
jle    1380 <pruned_calc_prob_dist+0x1f0>
ucomisd (%rbx,%rbp,8),%xmm0
jae    1330 <pruned_calc_prob_dist+0x1a0>
xor    %eax,%eax
jmp    1339 <pruned_calc_prob_dist+0x1a9>
nop
xor    %edi,%edi
mov    0x30(%rsp),%rbx
ucomisd (%rbx),%xmm0
setae  %dil
call   1040 <assert@plt>
movsd  0x40(%rsp),%xmm0
addsd  (%rbx),%xmm0
mov    0x38(%rsp),%rbp
movsd  %xmm0,0x0(%rbp)
cmp    0x58(%rsp),%r14
je     1230 <pruned_calc_prob_dist+0xa0>
mov    0x18(%rsp),%r13
cmp    %r13,%r14
mov    0x20(%rsp),%r12
jle    1250 <pruned_calc_prob_dist+0xc0>
xorpd  %xmm0,%xmm0
ucomisd (%rbx,%r13,8),%xmm0
mov    0x10(%rsp),%r15
jae    13db <pruned_calc_prob_dist+0x24b>
xor    %eax,%eax
jmp    13e4 <pruned_calc_prob_dist+0x254>
ucomisd (%rbx,%r15,8),%xmm0
setae  %al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  (%rbx,%r13,8),%xmm0
movsd  (%rsp),%xmm1
addsd  (%rbx,%r15,8),%xmm1
call   1060 <log_sum@plt>
movsd  %xmm0,0x0(%rbp,%r13,8)
ucomisd 0xbff(%rip),%xmm0
ja     1425 <pruned_calc_prob_dist+0x295>
movsd  0xbfd(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1250 <pruned_calc_prob_dist+0xc0>
call   1080 <exp@plt>
jmp    1250 <pruned_calc_prob_dist+0xc0>
mov    0x2baa(%rip),%rax
mov    (%rax),%edi
lea    0xbf1(%rip),%rsi
mov    $0xc0,%edx
jmp    145b <pruned_calc_prob_dist+0x2cb>
mov    0x2b93(%rip),%rax
mov    (%rax),%edi
lea    0xbda(%rip),%rsi
mov    $0xc5,%edx
call   1050 <fprintf@plt>
xor    %ebp,%ebp
jmp    146c <pruned_calc_prob_dist+0x2dc>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"FATAL: couldn't allocate memory at %d\0A\00"
define double* @pruned_calc_prob_dist(i32* %0, i32 %1, i32 %2) {
%4 = alloca double*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store double* null, double** %8
store double* null, double** %9
store double* null, double** %10
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = trunc i64 %20 to i32
%22 = call double* @malloc(i32 %21)
store double* %22, double** %8
%23 = icmp eq double* null, %22
br i1 %23, label %24, label %27
24: ; preds = %3
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 192)
store double* null, double** %4
br label %246
27: ; preds = %3
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = mul i64 %30, 8
%32 = trunc i64 %31 to i32
%33 = call double* @malloc(i32 %32)
store double* %33, double** %9
%34 = icmp eq double* null, %33
br i1 %34, label %35, label %38
35: ; preds = %27
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 197)
store double* null, double** %4
br label %246
38: ; preds = %27
%39 = load double*, double** %9
%40 = getelementptr inbounds double, double* %39, i64 0
store double 0.000000e+00, double* %40
store i32 1, i32* %11
br label %41
41: ; preds = %238, %38
%42 = load i32, i32* %11
%43 = load i32, i32* %6
%44 = icmp sle i32 %42, %43
br i1 %44, label %45, label %241
45: ; preds = %41
%46 = load i32*, i32** %5
%47 = load i32, i32* %11
%48 = sub nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %46, i64 %49
%51 = load i32, i32* %50
%52 = sitofp i32 %51 to double
%53 = fmul double -1.000000e+00, %52
%54 = fdiv double %53, 1.000000e+01
%55 = call double @pow(double 1.000000e+01, double %54)
store double %55, double* %14
%56 = load double, double* %14
%57 = call double @log(double %56)
store double %57, double* %15
%58 = load double, double* %14
%59 = fneg double %58
%60 = call double @log1p(double %59)
store double %60, double* %16
%61 = load i32*, i32** %5
%62 = load i32, i32* %11
%63 = sub nsw i32 %62, 1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %61, i64 %64
%66 = load i32, i32* %65
%67 = icmp sgt i32 %66, 1
br i1 %67, label %68, label %76
68: ; preds = %45
%69 = load i32*, i32** %5
%70 = load i32, i32* %11
%71 = sub nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %69, i64 %72
%74 = load i32, i32* %73
%75 = icmp slt i32 %74, 100
br label %76
76: ; preds = %68, %45
%77 = phi i1 [ false, %45 ], [ %75, %68 ]
%78 = zext i1 %77 to i32
%79 = call i32 @assert(i32 %78)
%80 = load i32, i32* %11
%81 = load i32, i32* %7
%82 = icmp slt i32 %80, %81
br i1 %82, label %83, label %88
83: ; preds = %76
%84 = load double*, double** %9
%85 = load i32, i32* %11
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %84, i64 %86
store double -1.000000e+100, double* %87
br label %88
88: ; preds = %83, %76
%89 = load i32, i32* %11
%90 = load i32, i32* %7
%91 = sub nsw i32 %90, 1
%92 = icmp slt i32 %89, %91
br i1 %92, label %93, label %95
93: ; preds = %88
%94 = load i32, i32* %11
br label %98
95: ; preds = %88
%96 = load i32, i32* %7
%97 = sub nsw i32 %96, 1
br label %98
98: ; preds = %95, %93
%99 = phi i32 [ %94, %93 ], [ %97, %95 ]
store i32 %99, i32* %12
br label %100
100: ; preds = %142, %98
%101 = load i32, i32* %12
%102 = icmp sge i32 %101, 1
br i1 %102, label %103, label %145
103: ; preds = %100
%104 = load double*, double** %9
%105 = load i32, i32* %12
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds double, double* %104, i64 %106
%108 = load double, double* %107
%109 = fcmp ole double %108, 0.000000e+00
br i1 %109, label %110, label %118
110: ; preds = %103
%111 = load double*, double** %9
%112 = load i32, i32* %12
%113 = sub nsw i32 %112, 1
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds double, double* %111, i64 %114
%116 = load double, double* %115
%117 = fcmp ole double %116, 0.000000e+00
br label %118
118: ; preds = %110, %103
%119 = phi i1 [ false, %103 ], [ %117, %110 ]
%120 = zext i1 %119 to i32
%121 = call i32 @assert(i32 %120)
%122 = load double*, double** %9
%123 = load i32, i32* %12
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds double, double* %122, i64 %124
%126 = load double, double* %125
%127 = load double, double* %16
%128 = fadd double %126, %127
%129 = load double*, double** %9
%130 = load i32, i32* %12
%131 = sub nsw i32 %130, 1
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds double, double* %129, i64 %132
%134 = load double, double* %133
%135 = load double, double* %15
%136 = fadd double %134, %135
%137 = call double @log_sum(double %128, double %136)
%138 = load double*, double** %8
%139 = load i32, i32* %12
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds double, double* %138, i64 %140
store double %137, double* %141
br label %142
142: ; preds = %118
%143 = load i32, i32* %12
%144 = add nsw i32 %143, -1
store i32 %144, i32* %12
br label %100
145: ; preds = %100
store i32 0, i32* %12
%146 = load double*, double** %9
%147 = load i32, i32* %12
%148 = sext i32 %147 to i64
%149 = getelementptr inbounds double, double* %146, i64 %148
%150 = load double, double* %149
%151 = fcmp ole double %150, 0.000000e+00
%152 = zext i1 %151 to i32
%153 = call i32 @assert(i32 %152)
%154 = load double*, double** %9
%155 = load i32, i32* %12
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds double, double* %154, i64 %156
%158 = load double, double* %157
%159 = load double, double* %16
%160 = fadd double %158, %159
%161 = load double*, double** %8
%162 = load i32, i32* %12
%163 = sext i32 %162 to i64
%164 = getelementptr inbounds double, double* %161, i64 %163
store double %160, double* %164
%165 = load i32, i32* %11
%166 = load i32, i32* %7
%167 = icmp eq i32 %165, %166
br i1 %167, label %168, label %181
168: ; preds = %145
%169 = load double*, double** %9
%170 = load i32, i32* %7
%171 = sub nsw i32 %170, 1
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds double, double* %169, i64 %172
%174 = load double, double* %173
%175 = load double, double* %15
%176 = fadd double %174, %175
%177 = load double*, double** %8
%178 = load i32, i32* %7
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds double, double* %177, i64 %179
store double %176, double* %180
br label %229
181: ; preds = %145
%182 = load i32, i32* %11
%183 = load i32, i32* %7
%184 = icmp sgt i32 %182, %183
br i1 %184, label %185, label %228
185: ; preds = %181
%186 = load double*, double** %9
%187 = load i32, i32* %7
%188 = sext i32 %187 to i64
%189 = getelementptr inbounds double, double* %186, i64 %188
%190 = load double, double* %189
%191 = fcmp ole double %190, 0.000000e+00
br i1 %191, label %192, label %200
192: ; preds = %185
%193 = load double*, double** %9
%194 = load i32, i32* %7
%195 = sub nsw i32 %194, 1
%196 = sext i32 %195 to i64
%197 = getelementptr inbounds double, double* %193, i64 %196
%198 = load double, double* %197
%199 = fcmp ole double %198, 0.000000e+00
br label %200
200: ; preds = %192, %185
%201 = phi i1 [ false, %185 ], [ %199, %192 ]
%202 = zext i1 %201 to i32
%203 = call i32 @assert(i32 %202)
%204 = load double*, double** %9
%205 = load i32, i32* %7
%206 = sext i32 %205 to i64
%207 = getelementptr inbounds double, double* %204, i64 %206
%208 = load double, double* %207
%209 = load double*, double** %9
%210 = load i32, i32* %7
%211 = sub nsw i32 %210, 1
%212 = sext i32 %211 to i64
%213 = getelementptr inbounds double, double* %209, i64 %212
%214 = load double, double* %213
%215 = load double, double* %15
%216 = fadd double %214, %215
%217 = call double @log_sum(double %208, double %216)
%218 = load double*, double** %8
%219 = load i32, i32* %7
%220 = sext i32 %219 to i64
%221 = getelementptr inbounds double, double* %218, i64 %220
store double %217, double* %221
%222 = load double*, double** %8
%223 = load i32, i32* %7
%224 = sext i32 %223 to i64
%225 = getelementptr inbounds double, double* %222, i64 %224
%226 = load double, double* %225
%227 = call double @exp(double %226)
store double %227, double* %13
br label %228
228: ; preds = %200, %181
br label %229
229: ; preds = %228, %168
%230 = load i32, i32* %11
%231 = load i32, i32* %6
%232 = icmp slt i32 %230, %231
br i1 %232, label %233, label %237
233: ; preds = %229
%234 = load double*, double** %8
store double* %234, double** %10
%235 = load double*, double** %9
store double* %235, double** %8
%236 = load double*, double** %10
store double* %236, double** %9
br label %237
237: ; preds = %233, %229
br label %238
238: ; preds = %237
%239 = load i32, i32* %11
%240 = add nsw i32 %239, 1
store i32 %240, i32* %11
br label %41
241: ; preds = %41
br label %242
242: ; preds = %241
%243 = load double*, double** %9
%244 = call i32 @free(double* %243)
%245 = load double*, double** %8
store double* %245, double** %4
br label %246
246: ; preds = %242, %35, %24
%247 = load double*, double** %4
ret double* %247
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"FATAL: couldn't allocate memory at %d\0A\00"
define noalias double* @pruned_calc_prob_dist(i32* nocapture %0, i32 %1, i32 %2) {
%4 = shl i32 %2, 3
%5 = add i32 %4, 8
%6 = tail call double* @malloc(i32 %5)
%7 = icmp eq double* %6, null
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 192)
br label %127
11: ; preds = %3
%12 = tail call double* @malloc(i32 %5)
%13 = icmp eq double* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 197)
br label %127
17: ; preds = %11
store double 0.000000e+00, double* %12
%18 = icmp slt i32 %1, 1
br i1 %18, label %123, label %19
19: ; preds = %17
%20 = add i32 %2, -1
%21 = sext i32 %2 to i64
%22 = sext i32 %20 to i64
%23 = zext i32 %2 to i64
%24 = zext i32 %1 to i64
%25 = add nuw i32 %1, 1
%26 = zext i32 %25 to i64
%27 = icmp sgt i32 %2, 1
br label %28
28: ; preds = %19, %117
%29 = phi i64 [ 1, %19 ], [ %121, %117 ]
%30 = phi double* [ %6, %19 ], [ %120, %117 ]
%31 = phi double* [ %12, %19 ], [ %119, %117 ]
%32 = trunc i64 %29 to i32
%33 = call i32 @llvm.smin.i32(i32 %32, i32 %20)
%34 = zext i32 %33 to i64
%35 = add nsw i64 %29, -1
%36 = getelementptr inbounds i32, i32* %0, i64 %35
%37 = load i32, i32* %36
%38 = sitofp i32 %37 to double
%39 = fdiv double %38, -1.000000e+01
%40 = tail call double @pow(double 1.000000e+01, double %39)
%41 = tail call double @log(double %40)
%42 = fneg double %40
%43 = tail call double @log1p(double %42)
%44 = load i32, i32* %36
%45 = add i32 %44, -2
%46 = icmp ult i32 %45, 98
%47 = zext i1 %46 to i32
%48 = tail call i32 @assert(i32 %47)
%49 = icmp slt i64 %29, %21
br i1 %49, label %50, label %52
50: ; preds = %28
%51 = getelementptr inbounds double, double* %31, i64 %29
store double -1.000000e+100, double* %51
br label %52
52: ; preds = %50, %28
br i1 %27, label %53, label %79
53: ; preds = %52, %65
%54 = phi i64 [ %71, %65 ], [ %34, %52 ]
%55 = trunc i64 %54 to i32
%56 = getelementptr inbounds double, double* %31, i64 %54
%57 = load double, double* %56
%58 = fcmp ugt double %57, 0.000000e+00
br i1 %58, label %65, label %59
59: ; preds = %53
%60 = add i64 %54, 4294967295
%61 = and i64 %60, 4294967295
%62 = getelementptr inbounds double, double* %31, i64 %61
%63 = load double, double* %62
%64 = fcmp ole double %63, 0.000000e+00
br label %65
65: ; preds = %59, %53
%66 = phi i1 [ false, %53 ], [ %64, %59 ]
%67 = zext i1 %66 to i32
%68 = tail call i32 @assert(i32 %67)
%69 = load double, double* %56
%70 = fadd double %43, %69
%71 = add nsw i64 %54, -1
%72 = and i64 %71, 4294967295
%73 = getelementptr inbounds double, double* %31, i64 %72
%74 = load double, double* %73
%75 = fadd double %41, %74
%76 = tail call double @log_sum(double %70, double %75)
%77 = getelementptr inbounds double, double* %30, i64 %54
store double %76, double* %77
%78 = icmp sgt i32 %55, 1
br i1 %78, label %53, label %79
79: ; preds = %65, %52
%80 = load double, double* %31
%81 = fcmp ole double %80, 0.000000e+00
%82 = zext i1 %81 to i32
%83 = tail call i32 @assert(i32 %82)
%84 = load double, double* %31
%85 = fadd double %43, %84
store double %85, double* %30
%86 = icmp eq i64 %29, %23
br i1 %86, label %87, label %92
87: ; preds = %79
%88 = getelementptr inbounds double, double* %31, i64 %22
%89 = load double, double* %88
%90 = fadd double %41, %89
%91 = getelementptr inbounds double, double* %30, i64 %21
store double %90, double* %91
br label %117
92: ; preds = %79
%93 = icmp sgt i64 %29, %21
br i1 %93, label %94, label %117
94: ; preds = %92
%95 = getelementptr inbounds double, double* %31, i64 %21
%96 = load double, double* %95
%97 = fcmp ugt double %96, 0.000000e+00
br i1 %97, label %102, label %98
98: ; preds = %94
%99 = getelementptr inbounds double, double* %31, i64 %22
%100 = load double, double* %99
%101 = fcmp ole double %100, 0.000000e+00
br label %102
102: ; preds = %98, %94
%103 = phi i1 [ false, %94 ], [ %101, %98 ]
%104 = zext i1 %103 to i32
%105 = tail call i32 @assert(i32 %104)
%106 = load double, double* %95
%107 = getelementptr inbounds double, double* %31, i64 %22
%108 = load double, double* %107
%109 = fadd double %41, %108
%110 = tail call double @log_sum(double %106, double %109)
%111 = getelementptr inbounds double, double* %30, i64 %21
store double %110, double* %111
%112 = fcmp olt double %110, -7.450000e+02
%113 = fcmp ogt double %110, 7.090000e+02
%114 = or i1 %113, %112
br i1 %114, label %115, label %117
115: ; preds = %102
%116 = tail call double @exp(double %110)
br label %117
117: ; preds = %115, %102, %92, %87
%118 = icmp ult i64 %29, %24
%119 = select i1 %118, double* %30, double* %31
%120 = select i1 %118, double* %31, double* %30
%121 = add nuw nsw i64 %29, 1
%122 = icmp eq i64 %121, %26
br i1 %122, label %123, label %28
123: ; preds = %117, %17
%124 = phi double* [ %12, %17 ], [ %119, %117 ]
%125 = phi double* [ %6, %17 ], [ %120, %117 ]
%126 = tail call i32 @free(double* %124)
br label %127
127: ; preds = %123, %14, %8
%128 = phi double* [ null, %8 ], [ null, %14 ], [ %125, %123 ]
ret double* %128
}