#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_upsample(double *fsp, double weight, int N, int k, int n) {
  int m;
  if (weight == 0.)
    return;
  m = k;
  while (N - m >= n - k) {
    fsp[m] +=
        exp(lchoose(m, k) + lchoose(N - m, n - k) - lchoose(N, n)) * weight;
    m++;
  }
}


x86 assembly (clang, -O0):
<hypergeometric_upsample>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1157 <hypergeometric_upsample+0x37>
jp     1157 <hypergeometric_upsample+0x37>
jmp    11e3 <hypergeometric_upsample+0xc3>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    -0x18(%rbp),%ecx
cmp    %ecx,%eax
jl     11e3 <hypergeometric_upsample+0xc3>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <lchoose@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
sub    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
sub    -0x18(%rbp),%esi
call   1030 <lchoose@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <lchoose@plt>
mov    -0x28(%rbp),%rdi
sub    %rax,%rdi
call   1040 <exp@plt>
movsd  -0x10(%rbp),%xmm2
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115d <hypergeometric_upsample+0x3d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hypergeometric_upsample>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0xc(%rsp)
mov    %esi,0x8(%rsp)
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    114a <hypergeometric_upsample+0x2a>
jnp    11d7 <hypergeometric_upsample+0xb7>
mov    0x8(%rsp),%eax
cmp    0xc(%rsp),%eax
jl     11d7 <hypergeometric_upsample+0xb7>
mov    %edx,%r12d
mov    0xc(%rsp),%eax
sub    %edx,%eax
movslq %edx,%rcx
movslq 0x8(%rsp),%rbp
movslq %eax,%r13
lea    (%rdi,%rcx,8),%r14
sub    %rcx,%rbp
xor    %r15d,%r15d
movsd  %xmm1,0x10(%rsp)
nopl   0x0(%rax)
lea    (%r12,%r15,1),%edi
mov    %r12d,%esi
call   1030 <lchoose@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %r13d,%esi
call   1030 <lchoose@plt>
add    %rax,%rbx
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
call   1030 <lchoose@plt>
sub    %rax,%rbx
mov    %rbx,%rdi
call   1040 <exp@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm0
addsd  (%r14,%r15,8),%xmm0
movsd  %xmm0,(%r14,%r15,8)
add    $0x1,%r15
add    $0xffffffffffffffff,%rbp
cmp    %r13,%rbp
jge    1180 <hypergeometric_upsample+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @hypergeometric_upsample(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
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
%12 = load double, double* %7
%13 = fcmp oeq double %12, 0.000000e+00
br i1 %13, label %14, label %15
14: ; preds = %5
br label %51
15: ; preds = %5
%16 = load i32, i32* %9
store i32 %16, i32* %11
br label %17
17: ; preds = %25, %15
%18 = load i32, i32* %8
%19 = load i32, i32* %11
%20 = sub nsw i32 %18, %19
%21 = load i32, i32* %10
%22 = load i32, i32* %9
%23 = sub nsw i32 %21, %22
%24 = icmp sge i32 %20, %23
br i1 %24, label %25, label %51
25: ; preds = %17
%26 = load i32, i32* %11
%27 = load i32, i32* %9
%28 = call i64 @lchoose(i32 %26, i32 %27)
%29 = load i32, i32* %8
%30 = load i32, i32* %11
%31 = sub nsw i32 %29, %30
%32 = load i32, i32* %10
%33 = load i32, i32* %9
%34 = sub nsw i32 %32, %33
%35 = call i64 @lchoose(i32 %31, i32 %34)
%36 = add nsw i64 %28, %35
%37 = load i32, i32* %8
%38 = load i32, i32* %10
%39 = call i64 @lchoose(i32 %37, i32 %38)
%40 = sub nsw i64 %36, %39
%41 = call double @exp(i64 %40)
%42 = load double, double* %7
%43 = load double*, double** %6
%44 = load i32, i32* %11
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
%47 = load double, double* %46
%48 = call double @llvm.fmuladd.f64(double %41, double %42, double %47)
store double %48, double* %46
%49 = load i32, i32* %11
%50 = add nsw i32 %49, 1
store i32 %50, i32* %11
br label %17
51: ; preds = %14, %17
ret void
}

LLVM IR (-O2):
define void @hypergeometric_upsample(double* nocapture %0, double %1, i32 %2, i32 %3, i32 %4) {
%6 = fcmp oeq double %1, 0.000000e+00
br i1 %6, label %32, label %7
7: ; preds = %5
%8 = sub nsw i32 %4, %3
%9 = icmp slt i32 %2, %4
br i1 %9, label %32, label %10
10: ; preds = %7
%11 = sub nsw i32 %2, %3
%12 = sext i32 %3 to i64
%13 = sext i32 %2 to i64
%14 = sext i32 %8 to i64
br label %15
15: ; preds = %10, %15
%16 = phi i64 [ %12, %10 ], [ %28, %15 ]
%17 = phi i32 [ %11, %10 ], [ %31, %15 ]
%18 = trunc i64 %16 to i32
%19 = tail call i64 @lchoose(i32 %18, i32 %3)
%20 = tail call i64 @lchoose(i32 %17, i32 %8)
%21 = add nsw i64 %20, %19
%22 = tail call i64 @lchoose(i32 %2, i32 %4)
%23 = sub i64 %21, %22
%24 = tail call double @exp(i64 %23)
%25 = getelementptr inbounds double, double* %0, i64 %16
%26 = load double, double* %25
%27 = tail call double @llvm.fmuladd.f64(double %24, double %1, double %26)
store double %27, double* %25
%28 = add i64 %16, 1
%29 = sub nsw i64 %13, %28
%30 = icmp slt i64 %29, %14
%31 = trunc i64 %29 to i32
br i1 %30, label %32, label %15
32: ; preds = %15, %7, %5
ret void
}