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


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

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

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

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