#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 betafraction(double, double, double);
double exp(double);
double gamma(double);
double log(double);
int /*<<< orphan*/ printf(char *);
double beta(double a, double b, double x) {
  double y;
  if (a <= 0.0) {
    printf("parameter a<=0!");
    return -1.0;
  }
  if (b <= 0.0) {
    printf("parameter b<=0!");
    return -1.0;
  }
  if ((x < 0.0 || x > 1.0)) {
    y = 0.0;
  } else {
    y = exp(a * log(x) + b * log(1.0 - x));
    y *= gamma(a + b) / (gamma(a) * gamma(b));
  }
  if (x < (a + 1.0) / (a + b + 2.0)) {
    y *= betafraction(a, b, x) / a;
  } else {
    y *= -betafraction(b, a, 1.0 - x) / b;
    y += 1.0;
  }
  return y;
}


x86 assembly (clang, -O0):
<beta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1193 <beta+0x43>
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
movsd  0xe87(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1356 <beta+0x206>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     11bf <beta+0x6f>
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
movsd  0xe5b(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1356 <beta+0x206>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
ja     11e4 <beta+0x94>
movsd  -0x20(%rbp),%xmm0
movsd  0xe26(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11f1 <beta+0xa1>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    129a <beta+0x14a>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xde4(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
call   1060 <log@plt>
movsd  -0x50(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <exp@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
call   1030 <gamma@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <gamma@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <gamma@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  0xd59(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
addsd  -0x18(%rbp),%xmm2
movsd  0xd4a(%rip),%xmm3
addsd  %xmm3,%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    12f8 <beta+0x1a8>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1070 <betafraction@plt>
divsd  -0x10(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    134c <beta+0x1fc>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xcf6(%rip),%xmm2
subsd  -0x20(%rbp),%xmm2
call   1070 <betafraction@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xcbe(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<beta>:
sub    $0x38,%rsp
movapd %xmm0,%xmm3
xorpd  %xmm0,%xmm0
ucomisd %xmm3,%xmm0
jae    124f <beta+0xff>
ucomisd %xmm1,%xmm0
jae    1258 <beta+0x108>
movapd %xmm2,%xmm4
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
movsd  %xmm1,0x10(%rsp)
movsd  %xmm3,0x8(%rsp)
ja     1271 <beta+0x121>
ucomisd 0xe72(%rip),%xmm4
ja     1271 <beta+0x121>
movapd %xmm4,%xmm0
movsd  %xmm4,0x18(%rsp)
call   1060 <log@plt>
movsd  %xmm0,(%rsp)
movsd  0xe50(%rip),%xmm0
subsd  0x18(%rsp),%xmm0
call   1060 <log@plt>
mulsd  0x10(%rsp),%xmm0
movsd  (%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
addsd  %xmm1,%xmm0
call   1050 <exp@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
call   1030 <gamma@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <gamma@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
call   1030 <gamma@plt>
movsd  0x28(%rsp),%xmm2
movsd  0x18(%rsp),%xmm4
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm1
mulsd  0x20(%rsp),%xmm0
movsd  (%rsp),%xmm5
divsd  %xmm0,%xmm5
mulsd  0x30(%rsp),%xmm5
movsd  %xmm5,(%rsp)
jmp    1282 <beta+0x132>
lea    0xdc2(%rip),%rdi
jmp    125f <beta+0x10f>
lea    0xdc9(%rip),%rdi
call   1040 <printf@plt>
movsd  0xd94(%rip),%xmm0
add    $0x38,%rsp
ret
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
movapd %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  0xd7e(%rip),%xmm0
addsd  0xd7e(%rip),%xmm2
addsd  %xmm3,%xmm0
divsd  %xmm2,%xmm0
ucomisd %xmm4,%xmm0
jbe    12c5 <beta+0x175>
movapd %xmm3,%xmm0
movapd %xmm4,%xmm2
call   1070 <betafraction@plt>
divsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x38,%rsp
ret
movsd  0xd3b(%rip),%xmm2
subsd  %xmm4,%xmm2
movapd %xmm1,%xmm0
movapd %xmm3,%xmm1
call   1070 <betafraction@plt>
divsd  0x10(%rsp),%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xd13(%rip),%xmm0
subsd  %xmm1,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"parameter a<=0!\00"
@.str.1 = [16 x i8] c"parameter b<=0!\00"
define double @beta(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%9 = load double, double* %5
%10 = fcmp ole double %9, 0.000000e+00
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store double -1.000000e+00, double* %4
br label %82
13: ; preds = %3
%14 = load double, double* %6
%15 = fcmp ole double %14, 0.000000e+00
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store double -1.000000e+00, double* %4
br label %82
18: ; preds = %13
%19 = load double, double* %7
%20 = fcmp olt double %19, 0.000000e+00
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load double, double* %7
%23 = fcmp ogt double %22, 1.000000e+00
br i1 %23, label %24, label %25
24: ; preds = %21, %18
store double 0.000000e+00, double* %8
br label %48
25: ; preds = %21
%26 = load double, double* %5
%27 = load double, double* %7
%28 = call double @log(double %27)
%29 = load double, double* %6
%30 = load double, double* %7
%31 = fsub double 1.000000e+00, %30
%32 = call double @log(double %31)
%33 = fmul double %29, %32
%34 = call double @llvm.fmuladd.f64(double %26, double %28, double %33)
%35 = call double @exp(double %34)
store double %35, double* %8
%36 = load double, double* %5
%37 = load double, double* %6
%38 = fadd double %36, %37
%39 = call double @gamma(double %38)
%40 = load double, double* %5
%41 = call double @gamma(double %40)
%42 = load double, double* %6
%43 = call double @gamma(double %42)
%44 = fmul double %41, %43
%45 = fdiv double %39, %44
%46 = load double, double* %8
%47 = fmul double %46, %45
store double %47, double* %8
br label %48
48: ; preds = %25, %24
%49 = load double, double* %7
%50 = load double, double* %5
%51 = fadd double %50, 1.000000e+00
%52 = load double, double* %5
%53 = load double, double* %6
%54 = fadd double %52, %53
%55 = fadd double %54, 2.000000e+00
%56 = fdiv double %51, %55
%57 = fcmp olt double %49, %56
br i1 %57, label %58, label %67
58: ; preds = %48
%59 = load double, double* %5
%60 = load double, double* %6
%61 = load double, double* %7
%62 = call double @betafraction(double %59, double %60, double %61)
%63 = load double, double* %5
%64 = fdiv double %62, %63
%65 = load double, double* %8
%66 = fmul double %65, %64
store double %66, double* %8
br label %80
67: ; preds = %48
%68 = load double, double* %6
%69 = load double, double* %5
%70 = load double, double* %7
%71 = fsub double 1.000000e+00, %70
%72 = call double @betafraction(double %68, double %69, double %71)
%73 = fneg double %72
%74 = load double, double* %6
%75 = fdiv double %73, %74
%76 = load double, double* %8
%77 = fmul double %76, %75
store double %77, double* %8
%78 = load double, double* %8
%79 = fadd double %78, 1.000000e+00
store double %79, double* %8
br label %80
80: ; preds = %67, %58
%81 = load double, double* %8
store double %81, double* %4
br label %82
82: ; preds = %80, %16, %11
%83 = load double, double* %4
ret double %83
}

LLVM IR (-O2):
@.str = [16 x i8] c"parameter a<=0!\00"
@.str.1 = [16 x i8] c"parameter b<=0!\00"
define double @beta(double %0, double %1, double %2) {
%4 = fcmp ugt double %0, 0.000000e+00
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %49
7: ; preds = %3
%8 = fcmp ugt double %1, 0.000000e+00
br i1 %8, label %11, label %9
9: ; preds = %7
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %49
11: ; preds = %7
%12 = fcmp olt double %2, 0.000000e+00
%13 = fcmp ogt double %2, 1.000000e+00
%14 = or i1 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = fadd double %0, %1
br label %31
17: ; preds = %11
%18 = tail call double @log(double %2)
%19 = fsub double 1.000000e+00, %2
%20 = tail call double @log(double %19)
%21 = fmul double %20, %1
%22 = tail call double @llvm.fmuladd.f64(double %0, double %18, double %21)
%23 = tail call double @exp(double %22)
%24 = fadd double %0, %1
%25 = tail call double @gamma(double %24)
%26 = tail call double @gamma(double %0)
%27 = tail call double @gamma(double %1)
%28 = fmul double %26, %27
%29 = fdiv double %25, %28
%30 = fmul double %23, %29
br label %31
31: ; preds = %15, %17
%32 = phi double [ %16, %15 ], [ %24, %17 ]
%33 = phi double [ 0.000000e+00, %15 ], [ %30, %17 ]
%34 = fadd double %0, 1.000000e+00
%35 = fadd double %32, 2.000000e+00
%36 = fdiv double %34, %35
%37 = fcmp ogt double %36, %2
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = tail call double @betafraction(double %0, double %1, double %2)
%40 = fdiv double %39, %0
%41 = fmul double %33, %40
br label %49
42: ; preds = %31
%43 = fsub double 1.000000e+00, %2
%44 = tail call double @betafraction(double %1, double %0, double %43)
%45 = fneg double %44
%46 = fdiv double %45, %1
%47 = fmul double %33, %46
%48 = fadd double %47, 1.000000e+00
br label %49
49: ; preds = %38, %42, %9, %5
%50 = phi double [ -1.000000e+00, %5 ], [ -1.000000e+00, %9 ], [ %41, %38 ], [ %48, %42 ]
ret double %50
}