#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 asum(double *, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fatalx(char *, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ genlogbin(double *, int, double);
int /*<<< orphan*/ vexp(double *, double *, int);
double binomtail(int n, int t, double p, char c) {
  double *bindis;
  double val;
  if ((bindis = (double *)calloc((n + 1), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n + 1);
  genlogbin(bindis, n, p);
  vexp(bindis, bindis, n + 1);
  if (c == '+')
    val = asum(bindis + t, n - t + 1);
  else
    val = asum(bindis, t);
  free(bindis);
  return val;
}


x86 assembly (clang, -O0):
<binomtail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a8 <binomtail+0x48>
mov    -0x4(%rbp),%esi
add    $0x1,%esi
lea    0xe5d(%rip),%rdi
call   1050 <fatalx@plt>
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%esi
movsd  -0x10(%rbp),%xmm0
call   1080 <genlogbin@plt>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x4(%rbp),%edx
add    $0x1,%edx
call   1030 <vexp@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x2b,%eax
jne    1200 <binomtail+0xa0>
mov    -0x20(%rbp),%rdi
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x4(%rbp),%esi
sub    -0x8(%rbp),%esi
add    $0x1,%esi
call   1070 <asum@plt>
movsd  %xmm0,-0x28(%rbp)
jmp    1211 <binomtail+0xb1>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <asum@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binomtail>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r15d
movsd  %xmm0,0x8(%rsp)
mov    %esi,%r14d
mov    %edi,%r12d
lea    0x1(%r12),%ebp
mov    %ebp,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a2 <binomtail+0x42>
lea    0xe65(%rip),%rdi
mov    %ebp,%esi
call   1050 <fatalx@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
movsd  0x8(%rsp),%xmm0
call   1080 <genlogbin@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <vexp@plt>
cmp    $0x2b,%r15b
jne    11d4 <binomtail+0x74>
movslq %r14d,%rax
lea    (%rbx,%rax,8),%rdi
sub    %r14d,%ebp
mov    %ebp,%esi
jmp    11da <binomtail+0x7a>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1070 <asum@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1040 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define double @binomtail(i32 %0, i32 %1, double %2, i8 signext %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i8
%9 = alloca double*
%10 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store double %2, double* %7
store i8 %3, i8* %8
%11 = load i32, i32* %5
%12 = add nsw i32 %11, 1
%13 = call i64 @calloc(i32 %12, i32 8)
%14 = inttoptr i64 %13 to double*
store double* %14, double** %9
%15 = icmp eq double* %14, null
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
%19 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %4
%21 = load double*, double** %9
%22 = load i32, i32* %5
%23 = load double, double* %7
%24 = call i32 @genlogbin(double* %21, i32 %22, double %23)
%25 = load double*, double** %9
%26 = load double*, double** %9
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
%29 = call i32 @vexp(double* %25, double* %26, i32 %28)
%30 = load i8, i8* %8
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 43
br i1 %32, label %33, label %43
33: ; preds = %20
%34 = load double*, double** %9
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = sub nsw i32 %38, %39
%41 = add nsw i32 %40, 1
%42 = call double @asum(double* %37, i32 %41)
store double %42, double* %10
br label %47
43: ; preds = %20
%44 = load double*, double** %9
%45 = load i32, i32* %6
%46 = call double @asum(double* %44, i32 %45)
store double %46, double* %10
br label %47
47: ; preds = %43, %33
%48 = load double*, double** %9
%49 = call i32 @free(double* %48)
%50 = load double, double* %10
ret double %50
}

LLVM IR (-O2):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define double @binomtail(i32 %0, i32 %1, double %2, i8 signext %3) {
%5 = add i32 %0, 1
%6 = tail call i64 @calloc(i32 %5, i32 8)
%7 = inttoptr i64 %6 to double*
%8 = icmp eq i64 %6, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %11
11: ; preds = %9, %4
%12 = tail call i32 @genlogbin(double* %7, i32 %0, double %2)
%13 = tail call i32 @vexp(double* %7, double* %7, i32 %5)
%14 = icmp eq i8 %3, 43
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = sext i32 %1 to i64
%17 = getelementptr inbounds double, double* %7, i64 %16
%18 = sub i32 %5, %1
%19 = tail call double @asum(double* %17, i32 %18)
br label %22
20: ; preds = %11
%21 = tail call double @asum(double* %7, i32 %1)
br label %22
22: ; preds = %20, %15
%23 = phi double [ %19, %15 ], [ %21, %20 ]
%24 = tail call i32 @free(double* %7)
ret double %23
}