#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 binomial(unsigned int, unsigned int);
double pow(int, unsigned int);
double bernstein(unsigned int n, unsigned int v, double x) {
  assert(v <= n);
  return binomial(n, v) * pow(x, v) * pow(1. - x, n - v);
}


x86 assembly (clang, -O0):
<bernstein>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <binomial@plt>
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe74(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%edi
mov    -0x4(%rbp),%esi
sub    -0x8(%rbp),%esi
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bernstein>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %esi,%ebx
mov    %edi,%ebp
xor    %edi,%edi
mov    %ebp,%r14d
sub    %esi,%r14d
setae  %dil
call   1040 <assert@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <binomial@plt>
movsd  %xmm0,(%rsp)
cvttsd2si 0x8(%rsp),%edi
mov    %ebx,%esi
call   1050 <pow@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0xe80(%rip),%xmm0
subsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
mov    %r14d,%esi
call   1050 <pow@plt>
mulsd  (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @bernstein(i32 %0, i32 %1, double %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
store i32 %0, i32* %4
store i32 %1, i32* %5
store double %2, double* %6
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp ule i32 %7, %8
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i32, i32* %4
%13 = load i32, i32* %5
%14 = call double @binomial(i32 %12, i32 %13)
%15 = load double, double* %6
%16 = fptosi double %15 to i32
%17 = load i32, i32* %5
%18 = call double @pow(i32 %16, i32 %17)
%19 = fmul double %14, %18
%20 = load double, double* %6
%21 = fsub double 1.000000e+00, %20
%22 = fptosi double %21 to i32
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = sub i32 %23, %24
%26 = call double @pow(i32 %22, i32 %25)
%27 = fmul double %19, %26
ret double %27
}

LLVM IR (-O2):
define double @bernstein(i32 %0, i32 %1, double %2) {
%4 = icmp uge i32 %0, %1
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call double @binomial(i32 %0, i32 %1)
%8 = fptosi double %2 to i32
%9 = tail call double @pow(i32 %8, i32 %1)
%10 = fmul double %7, %9
%11 = fsub double 1.000000e+00, %2
%12 = fptosi double %11 to i32
%13 = sub i32 %0, %1
%14 = tail call double @pow(i32 %12, i32 %13)
%15 = fmul double %10, %14
ret double %15
}