#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 exp(scalar_t__);
scalar_t__ lchoose(int, int);
void hypergeometric_downsample_fsp(double *d_fsp, double *fsp, int n, int N,
                                   int include_invariant) {
  int m, k;
  if (include_invariant) {
    for (m = 0; m <= N; m++) {
      for (k = 0; k <= m && k <= n; k++)
        d_fsp[k] +=
            exp(lchoose(m, k) + lchoose(N - m, n - k) - lchoose(N, n)) * fsp[m];
    }
  } else {
    for (m = 1; m <= N; m++) {
      for (k = 1; k <= m && k < n; k++)
        d_fsp[k] +=
            exp(lchoose(m, k) + lchoose(N - m, n - k) - lchoose(N, n)) * fsp[m];
    }
  }
}


x86 assembly (clang, -O0):
<hypergeometric_downsample_fsp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     121d <hypergeometric_downsample_fsp+0xfd>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     1218 <hypergeometric_downsample_fsp+0xf8>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0x20(%rbp),%ecx
mov    %al,-0x25(%rbp)
jg     117b <hypergeometric_downsample_fsp+0x5b>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
setle  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    118b <hypergeometric_downsample_fsp+0x6b>
jmp    1205 <hypergeometric_downsample_fsp+0xe5>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1030 <lchoose@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%edi
sub    -0x20(%rbp),%edi
mov    -0x14(%rbp),%esi
sub    -0x24(%rbp),%esi
call   1030 <lchoose@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <lchoose@plt>
mov    -0x30(%rbp),%rdi
sub    %rax,%rdi
call   1040 <exp@plt>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115e <hypergeometric_downsample_fsp+0x3e>
jmp    120a <hypergeometric_downsample_fsp+0xea>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114b <hypergeometric_downsample_fsp+0x2b>
jmp    12f6 <hypergeometric_downsample_fsp+0x1d6>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     12f1 <hypergeometric_downsample_fsp+0x1d1>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0x20(%rbp),%ecx
mov    %al,-0x39(%rbp)
jg     1254 <hypergeometric_downsample_fsp+0x134>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1264 <hypergeometric_downsample_fsp+0x144>
jmp    12de <hypergeometric_downsample_fsp+0x1be>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1030 <lchoose@plt>
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%edi
sub    -0x20(%rbp),%edi
mov    -0x14(%rbp),%esi
sub    -0x24(%rbp),%esi
call   1030 <lchoose@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <lchoose@plt>
mov    -0x48(%rbp),%rdi
sub    %rax,%rdi
call   1040 <exp@plt>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1237 <hypergeometric_downsample_fsp+0x117>
jmp    12e3 <hypergeometric_downsample_fsp+0x1c3>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1224 <hypergeometric_downsample_fsp+0x104>
jmp    12f6 <hypergeometric_downsample_fsp+0x1d6>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hypergeometric_downsample_fsp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,0x30(%rsp)
mov    %rdi,%r14
test   %r8d,%r8d
mov    %rcx,0x8(%rsp)
je     121e <hypergeometric_downsample_fsp+0xfe>
test   %ecx,%ecx
js     1308 <hypergeometric_downsample_fsp+0x1e8>
mov    0x8(%rsp),%rax
add    $0x1,%eax
mov    %rax,0x20(%rsp)
xor    %r15d,%r15d
mov    %rdx,0x10(%rsp)
jmp    1184 <hypergeometric_downsample_fsp+0x64>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r15
cmp    0x20(%rsp),%r15
mov    0x10(%rsp),%rdx
je     1308 <hypergeometric_downsample_fsp+0x1e8>
cmp    %r15d,%edx
mov    %r15d,%eax
cmovb  %edx,%eax
mov    %rax,0x18(%rsp)
test   %edx,%edx
js     1170 <hypergeometric_downsample_fsp+0x50>
mov    0x18(%rsp),%rax
add    $0x1,%eax
mov    %rax,0x18(%rsp)
mov    0x8(%rsp),%rax
mov    %eax,%r13d
sub    %r15d,%r13d
mov    0x10(%rsp),%rax
mov    %eax,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %ebx,%esi
call   1030 <lchoose@plt>
mov    %rax,%r12
mov    %r13d,%edi
mov    %ebp,%esi
call   1030 <lchoose@plt>
add    %rax,%r12
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1030 <lchoose@plt>
sub    %rax,%r12
mov    %r12,%rdi
call   1040 <exp@plt>
mov    0x30(%rsp),%rax
mulsd  (%rax,%r15,8),%xmm0
addsd  (%r14,%rbx,8),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    %rbx,0x18(%rsp)
jne    11c0 <hypergeometric_downsample_fsp+0xa0>
jmp    1170 <hypergeometric_downsample_fsp+0x50>
test   %ecx,%ecx
jle    1308 <hypergeometric_downsample_fsp+0x1e8>
lea    -0x2(%rdx),%eax
mov    %eax,0x2c(%rsp)
lea    -0x1(%rdx),%eax
mov    %eax,0x28(%rsp)
xor    %ecx,%ecx
mov    $0x1,%r13d
mov    %rdx,0x10(%rsp)
jmp    126a <hypergeometric_downsample_fsp+0x14a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r13
mov    0x20(%rsp),%ecx
add    $0x1,%ecx
cmp    0x8(%rsp),%ecx
mov    0x10(%rsp),%rdx
je     1308 <hypergeometric_downsample_fsp+0x1e8>
mov    0x2c(%rsp),%eax
cmp    %eax,%ecx
mov    %eax,%r12d
mov    %ecx,0x20(%rsp)
cmovb  %ecx,%r12d
cmp    $0x2,%edx
jl     1250 <hypergeometric_downsample_fsp+0x130>
neg    %r12
mov    0x8(%rsp),%rax
sub    %r13d,%eax
mov    %eax,0x18(%rsp)
mov    $0x1,%ebx
mov    0x28(%rsp),%r15d
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %ebx,%esi
call   1030 <lchoose@plt>
mov    %rax,%rbp
mov    0x18(%rsp),%edi
mov    %r15d,%esi
call   1030 <lchoose@plt>
add    %rax,%rbp
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1030 <lchoose@plt>
sub    %rax,%rbp
mov    %rbp,%rdi
call   1040 <exp@plt>
mov    0x30(%rsp),%rax
mulsd  (%rax,%r13,8),%xmm0
addsd  (%r14,%rbx,8),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0xffffffff,%r15d
lea    (%r12,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x2,%rax
jne    12a0 <hypergeometric_downsample_fsp+0x180>
jmp    1250 <hypergeometric_downsample_fsp+0x130>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @hypergeometric_downsample_fsp(double* %0, double* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store double* %0, double** %6
store double* %1, double** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = load i32, i32* %10
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %67
15: ; preds = %5
store i32 0, i32* %11
br label %16
16: ; preds = %63, %15
%17 = load i32, i32* %11
%18 = load i32, i32* %9
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %66
20: ; preds = %16
store i32 0, i32* %12
br label %21
21: ; preds = %59, %20
%22 = load i32, i32* %12
%23 = load i32, i32* %11
%24 = icmp sle i32 %22, %23
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32, i32* %12
%27 = load i32, i32* %8
%28 = icmp sle i32 %26, %27
br label %29
29: ; preds = %25, %21
%30 = phi i1 [ false, %21 ], [ %28, %25 ]
br i1 %30, label %31, label %62
31: ; preds = %29
%32 = load i32, i32* %11
%33 = load i32, i32* %12
%34 = call i64 @lchoose(i32 %32, i32 %33)
%35 = load i32, i32* %9
%36 = load i32, i32* %11
%37 = sub nsw i32 %35, %36
%38 = load i32, i32* %8
%39 = load i32, i32* %12
%40 = sub nsw i32 %38, %39
%41 = call i64 @lchoose(i32 %37, i32 %40)
%42 = add nsw i64 %34, %41
%43 = load i32, i32* %9
%44 = load i32, i32* %8
%45 = call i64 @lchoose(i32 %43, i32 %44)
%46 = sub nsw i64 %42, %45
%47 = call double @exp(i64 %46)
%48 = load double*, double** %7
%49 = load i32, i32* %11
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
%52 = load double, double* %51
%53 = load double*, double** %6
%54 = load i32, i32* %12
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = load double, double* %56
%58 = call double @llvm.fmuladd.f64(double %47, double %52, double %57)
store double %58, double* %56
br label %59
59: ; preds = %31
%60 = load i32, i32* %12
%61 = add nsw i32 %60, 1
store i32 %61, i32* %12
br label %21
62: ; preds = %29
br label %63
63: ; preds = %62
%64 = load i32, i32* %11
%65 = add nsw i32 %64, 1
store i32 %65, i32* %11
br label %16
66: ; preds = %16
br label %119
67: ; preds = %5
store i32 1, i32* %11
br label %68
68: ; preds = %115, %67
%69 = load i32, i32* %11
%70 = load i32, i32* %9
%71 = icmp sle i32 %69, %70
br i1 %71, label %72, label %118
72: ; preds = %68
store i32 1, i32* %12
br label %73
73: ; preds = %111, %72
%74 = load i32, i32* %12
%75 = load i32, i32* %11
%76 = icmp sle i32 %74, %75
br i1 %76, label %77, label %81
77: ; preds = %73
%78 = load i32, i32* %12
%79 = load i32, i32* %8
%80 = icmp slt i32 %78, %79
br label %81
81: ; preds = %77, %73
%82 = phi i1 [ false, %73 ], [ %80, %77 ]
br i1 %82, label %83, label %114
83: ; preds = %81
%84 = load i32, i32* %11
%85 = load i32, i32* %12
%86 = call i64 @lchoose(i32 %84, i32 %85)
%87 = load i32, i32* %9
%88 = load i32, i32* %11
%89 = sub nsw i32 %87, %88
%90 = load i32, i32* %8
%91 = load i32, i32* %12
%92 = sub nsw i32 %90, %91
%93 = call i64 @lchoose(i32 %89, i32 %92)
%94 = add nsw i64 %86, %93
%95 = load i32, i32* %9
%96 = load i32, i32* %8
%97 = call i64 @lchoose(i32 %95, i32 %96)
%98 = sub nsw i64 %94, %97
%99 = call double @exp(i64 %98)
%100 = load double*, double** %7
%101 = load i32, i32* %11
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds double, double* %100, i64 %102
%104 = load double, double* %103
%105 = load double*, double** %6
%106 = load i32, i32* %12
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds double, double* %105, i64 %107
%109 = load double, double* %108
%110 = call double @llvm.fmuladd.f64(double %99, double %104, double %109)
store double %110, double* %108
br label %111
111: ; preds = %83
%112 = load i32, i32* %12
%113 = add nsw i32 %112, 1
store i32 %113, i32* %12
br label %73
114: ; preds = %81
br label %115
115: ; preds = %114
%116 = load i32, i32* %11
%117 = add nsw i32 %116, 1
store i32 %117, i32* %11
br label %68
118: ; preds = %68
br label %119
119: ; preds = %118, %66
ret void
}

LLVM IR (-O2):
define void @hypergeometric_downsample_fsp(double* nocapture %0, double* nocapture %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp eq i32 %4, 0
br i1 %6, label %13, label %7
7: ; preds = %5
%8 = icmp slt i32 %3, 0
br i1 %8, label %76, label %9
9: ; preds = %7
%10 = icmp sgt i32 %2, -1
%11 = add nuw i32 %3, 1
%12 = zext i32 %11 to i64
br label %18
13: ; preds = %5
%14 = icmp slt i32 %3, 1
br i1 %14, label %76, label %15
15: ; preds = %13
%16 = icmp sgt i32 %2, 1
%17 = add i32 %2, -2
br label %46
18: ; preds = %9, %43
%19 = phi i64 [ 0, %9 ], [ %44, %43 ]
%20 = trunc i64 %19 to i32
br i1 %10, label %21, label %43
21: ; preds = %18
%22 = call i32 @llvm.umin.i32(i32 %2, i32 %20)
%23 = add nuw i32 %22, 1
%24 = sub nsw i32 %3, %20
%25 = getelementptr inbounds double, double* %1, i64 %19
%26 = zext i32 %23 to i64
br label %27
27: ; preds = %21, %27
%28 = phi i64 [ 0, %21 ], [ %41, %27 ]
%29 = trunc i64 %28 to i32
%30 = tail call i64 @lchoose(i32 %20, i32 %29)
%31 = sub nsw i32 %2, %29
%32 = tail call i64 @lchoose(i32 %24, i32 %31)
%33 = add nsw i64 %32, %30
%34 = tail call i64 @lchoose(i32 %3, i32 %2)
%35 = sub i64 %33, %34
%36 = tail call double @exp(i64 %35)
%37 = load double, double* %25
%38 = getelementptr inbounds double, double* %0, i64 %28
%39 = load double, double* %38
%40 = tail call double @llvm.fmuladd.f64(double %36, double %37, double %39)
store double %40, double* %38
%41 = add nuw nsw i64 %28, 1
%42 = icmp eq i64 %41, %26
br i1 %42, label %43, label %27
43: ; preds = %27, %18
%44 = add nuw nsw i64 %19, 1
%45 = icmp eq i64 %44, %12
br i1 %45, label %76, label %18
46: ; preds = %15, %72
%47 = phi i64 [ 1, %15 ], [ %73, %72 ]
%48 = phi i32 [ 0, %15 ], [ %74, %72 ]
br i1 %16, label %49, label %72
49: ; preds = %46
%50 = call i32 @llvm.umin.i32(i32 %48, i32 %17)
%51 = add nuw nsw i32 %50, 2
%52 = trunc i64 %47 to i32
%53 = sub nsw i32 %3, %52
%54 = getelementptr inbounds double, double* %1, i64 %47
%55 = zext i32 %51 to i64
br label %56
56: ; preds = %49, %56
%57 = phi i64 [ 1, %49 ], [ %70, %56 ]
%58 = trunc i64 %57 to i32
%59 = tail call i64 @lchoose(i32 %52, i32 %58)
%60 = sub nsw i32 %2, %58
%61 = tail call i64 @lchoose(i32 %53, i32 %60)
%62 = add nsw i64 %61, %59
%63 = tail call i64 @lchoose(i32 %3, i32 %2)
%64 = sub i64 %62, %63
%65 = tail call double @exp(i64 %64)
%66 = load double, double* %54
%67 = getelementptr inbounds double, double* %0, i64 %57
%68 = load double, double* %67
%69 = tail call double @llvm.fmuladd.f64(double %65, double %66, double %68)
store double %69, double* %67
%70 = add nuw nsw i64 %57, 1
%71 = icmp eq i64 %70, %55
br i1 %71, label %72, label %56
72: ; preds = %56, %46
%73 = add nuw nsw i64 %47, 1
%74 = add nuw nsw i32 %48, 1
%75 = icmp eq i32 %74, %3
br i1 %75, label %76, label %46
76: ; preds = %43, %72, %7, %13
ret void
}