#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*/ EXIT_FAILURE;
double dbinom_raw(double, unsigned int, double, int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
double floor(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
double mydbinom(double x, unsigned int n, double p, int l) {
  if (p < 0 || p > 1) {
    fprintf(stderr, "p not in [0, 1]");
    exit(EXIT_FAILURE);
  }
  double X = floor(x + 0.5);
  return dbinom_raw(X, n, p, 1 - p, l);
}


x86 assembly (clang, -O0):
<mydbinom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
ja     117d <mydbinom+0x3d>
movsd  -0x18(%rbp),%xmm0
movsd  0xe8d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11a0 <mydbinom+0x60>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movsd  0xe60(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
call   1060 <floor@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0xc(%rbp),%edi
movsd  -0x18(%rbp),%xmm1
movsd  0xe34(%rip),%xmm2
subsd  -0x18(%rbp),%xmm2
cvttsd2si %xmm2,%esi
mov    -0x1c(%rbp),%edx
call   1030 <dbinom_raw@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mydbinom>:
push   %rbp
push   %rbx
push   %rax
xorpd  %xmm2,%xmm2
ucomisd %xmm1,%xmm2
ja     1191 <mydbinom+0x51>
ucomisd 0xeab(%rip),%xmm1
ja     1191 <mydbinom+0x51>
mov    %esi,%ebx
mov    %edi,%ebp
addsd  0xea5(%rip),%xmm0
movsd  %xmm1,(%rsp)
call   1060 <floor@plt>
movsd  0xe8b(%rip),%xmm2
movsd  (%rsp),%xmm1
subsd  %xmm1,%xmm2
cvttsd2si %xmm2,%esi
mov    %ebp,%edi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <dbinom_raw@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"p not in [0, 1]\00"
@EXIT_FAILURE = global i32 0
define double @mydbinom(double %0, i32 %1, double %2, i32 %3) {
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca double
store double %0, double* %5
store i32 %1, i32* %6
store double %2, double* %7
store i32 %3, i32* %8
%10 = load double, double* %7
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %15, label %12
12: ; preds = %4
%13 = load double, double* %7
%14 = fcmp ogt double %13, 1.000000e+00
br i1 %14, label %15, label %20
15: ; preds = %12, %4
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %12
%21 = load double, double* %5
%22 = fadd double %21, 5.000000e-01
%23 = call double @llvm.floor.f64(double %22)
store double %23, double* %9
%24 = load double, double* %9
%25 = load i32, i32* %6
%26 = load double, double* %7
%27 = load double, double* %7
%28 = fsub double 1.000000e+00, %27
%29 = fptosi double %28 to i32
%30 = load i32, i32* %8
%31 = call double @dbinom_raw(double %24, i32 %25, double %26, i32 %29, i32 %30)
ret double %31
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"p not in [0, 1]\00"
@EXIT_FAILURE = global i32 0
define double @mydbinom(double %0, i32 %1, double %2, i32 %3) {
%5 = fcmp olt double %2, 0.000000e+00
%6 = fcmp ogt double %2, 1.000000e+00
%7 = or i1 %5, %6
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %4
%14 = fadd double %0, 5.000000e-01
%15 = tail call double @llvm.floor.f64(double %14)
%16 = fsub double 1.000000e+00, %2
%17 = fptosi double %16 to i32
%18 = tail call double @dbinom_raw(double %15, i32 %1, double %2, i32 %17, i32 %3)
ret double %18
}