#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*/ isnan(double);
double log(int);
double log_combination_k_r(unsigned int, double);
double dnbinom(unsigned int x, double size, double p) {
  double c, p0, p1, val;
  c = log_combination_k_r(x, size);
  assert(!isnan(c));
  p0 = log(p) * x;
  p1 = log(1 - p) * size;
  val = c + p0 + p1;
  assert(!isnan(val));
  return exp(val);
}


x86 assembly (clang, -O0):
<dnbinom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    -0x4(%rbp),%edi
movsd  -0x10(%rbp),%xmm0
call   1050 <log_combination_k_r@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <isnan@plt>
test   %eax,%eax
sete   %al
movzbl %al,%edi
call   1030 <assert@plt>
cvttsd2si -0x18(%rbp),%edi
call   1070 <log@plt>
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe4f(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <log@plt>
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1060 <isnan@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movsd  -0x38(%rbp),%xmm0
call   1040 <exp@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dnbinom>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x18(%rsp)
mov    %edi,%ebx
call   1050 <log_combination_k_r@plt>
movsd  %xmm0,0x10(%rsp)
call   1060 <isnan@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <assert@plt>
cvttsd2si (%rsp),%edi
call   1070 <log@plt>
mov    %ebx,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe5b(%rip),%xmm0
subsd  (%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <log@plt>
mulsd  0x18(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  0x10(%rsp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
call   1060 <isnan@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <assert@plt>
movsd  (%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
jmp    1040 <exp@plt>

LLVM IR (-O0):
define double @dnbinom(i32 %0, double %1, double %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store i32 %0, i32* %4
store double %1, double* %5
store double %2, double* %6
%11 = load i32, i32* %4
%12 = load double, double* %5
%13 = call double @log_combination_k_r(i32 %11, double %12)
store double %13, double* %7
%14 = load double, double* %7
%15 = call i32 @isnan(double %14)
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load double, double* %6
%21 = fptosi double %20 to i32
%22 = call double @log(i32 %21)
%23 = load i32, i32* %4
%24 = uitofp i32 %23 to double
%25 = fmul double %22, %24
store double %25, double* %8
%26 = load double, double* %6
%27 = fsub double 1.000000e+00, %26
%28 = fptosi double %27 to i32
%29 = call double @log(i32 %28)
%30 = load double, double* %5
%31 = fmul double %29, %30
store double %31, double* %9
%32 = load double, double* %7
%33 = load double, double* %8
%34 = fadd double %32, %33
%35 = load double, double* %9
%36 = fadd double %34, %35
store double %36, double* %10
%37 = load double, double* %10
%38 = call i32 @isnan(double %37)
%39 = icmp ne i32 %38, 0
%40 = xor i1 %39, true
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = load double, double* %10
%44 = call double @exp(double %43)
ret double %44
}

LLVM IR (-O2):
define double @dnbinom(i32 %0, double %1, double %2) {
%4 = tail call double @log_combination_k_r(i32 %0, double %1)
%5 = tail call i32 @isnan(double %4)
%6 = icmp eq i32 %5, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = fptosi double %2 to i32
%10 = tail call double @log(i32 %9)
%11 = uitofp i32 %0 to double
%12 = fmul double %10, %11
%13 = fsub double 1.000000e+00, %2
%14 = fptosi double %13 to i32
%15 = tail call double @log(i32 %14)
%16 = fmul double %15, %1
%17 = fadd double %4, %12
%18 = fadd double %17, %16
%19 = tail call i32 @isnan(double %18)
%20 = icmp eq i32 %19, 0
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = tail call double @exp(double %18)
ret double %23
}