#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 pnorm(double);
double sqrt(double);
int bpest(int n, double ps, double g, double *xl, double *xu) {
  double w;
  if (n < 1 || ps <= 0.0 || ps >= 1.0 || g <= 0.0 || g >= 1.0)
    return 999;
  w = pnorm((1.0 + g) * 0.5) * sqrt(ps * (1.0 - ps) / (double)n);
  *xl = ps - w;
  *xu = ps + w;
  return 0;
}


x86 assembly (clang, -O0):
<bpest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     1191 <bpest+0x71>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jae    1191 <bpest+0x71>
movsd  -0x10(%rbp),%xmm0
movsd  0xe9e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1191 <bpest+0x71>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jae    1191 <bpest+0x71>
movsd  -0x18(%rbp),%xmm0
movsd  0xe79(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     119d <bpest+0x7d>
movl   $0x3e7,-0x4(%rbp)
jmp    1220 <bpest+0x100>
movsd  0xe5b(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xe56(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <pnorm@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe33(%rip),%xmm1
subsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x10(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpest>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
ucomisd 0xed0(%rip),%xmm1
mov    $0x3e7,%eax
jae    1200 <bpest+0xe0>
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    1200 <bpest+0xe0>
ucomisd 0xeab(%rip),%xmm2
jae    1200 <bpest+0xe0>
mov    %edi,%ebp
test   %edi,%edi
jle    1200 <bpest+0xe0>
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jae    1200 <bpest+0xe0>
mov    %rdx,%r14
mov    %rsi,%rbx
addsd  0xe7f(%rip),%xmm1
mulsd  0xe7f(%rip),%xmm1
movapd %xmm1,%xmm0
movsd  %xmm2,(%rsp)
call   1030 <pnorm@plt>
movsd  (%rsp),%xmm1
movapd %xmm0,%xmm2
movsd  0xe58(%rip),%xmm3
subsd  %xmm1,%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  %xmm1,%xmm3
divsd  %xmm0,%xmm3
movapd %xmm3,%xmm0
ucomisd 0xe49(%rip),%xmm3
jb     11cf <bpest+0xaf>
sqrtsd %xmm0,%xmm0
jmp    11e5 <bpest+0xc5>
movsd  %xmm2,0x8(%rsp)
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm2
movapd %xmm1,%xmm0
subsd  %xmm2,%xmm0
movsd  %xmm0,(%rbx)
addsd  %xmm1,%xmm2
movsd  %xmm2,(%r14)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bpest(i32 %0, double %1, double %2, double* %3, double* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double*
%11 = alloca double*
%12 = alloca double
store i32 %0, i32* %7
store double %1, double* %8
store double %2, double* %9
store double* %3, double** %10
store double* %4, double** %11
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 1
br i1 %14, label %27, label %15
15: ; preds = %5
%16 = load double, double* %8
%17 = fcmp ole double %16, 0.000000e+00
br i1 %17, label %27, label %18
18: ; preds = %15
%19 = load double, double* %8
%20 = fcmp oge double %19, 1.000000e+00
br i1 %20, label %27, label %21
21: ; preds = %18
%22 = load double, double* %9
%23 = fcmp ole double %22, 0.000000e+00
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load double, double* %9
%26 = fcmp oge double %25, 1.000000e+00
br i1 %26, label %27, label %28
27: ; preds = %24, %21, %18, %15, %5
store i32 999, i32* %6
br label %50
28: ; preds = %24
%29 = load double, double* %9
%30 = fadd double 1.000000e+00, %29
%31 = fmul double %30, 5.000000e-01
%32 = call double @pnorm(double %31)
%33 = load double, double* %8
%34 = load double, double* %8
%35 = fsub double 1.000000e+00, %34
%36 = fmul double %33, %35
%37 = load i32, i32* %7
%38 = sitofp i32 %37 to double
%39 = fdiv double %36, %38
%40 = call double @sqrt(double %39)
%41 = fmul double %32, %40
store double %41, double* %12
%42 = load double, double* %8
%43 = load double, double* %12
%44 = fsub double %42, %43
%45 = load double*, double** %10
store double %44, double* %45
%46 = load double, double* %8
%47 = load double, double* %12
%48 = fadd double %46, %47
%49 = load double*, double** %11
store double %48, double* %49
store i32 0, i32* %6
br label %50
50: ; preds = %28, %27
%51 = load i32, i32* %6
ret i32 %51
}

LLVM IR (-O2):
define i32 @bpest(i32 %0, double %1, double %2, double* nocapture writeonly %3, double* nocapture writeonly %4) {
%6 = icmp slt i32 %0, 1
%7 = fcmp ole double %1, 0.000000e+00
%8 = or i1 %6, %7
%9 = fcmp oge double %1, 1.000000e+00
%10 = or i1 %9, %8
%11 = fcmp ole double %2, 0.000000e+00
%12 = or i1 %11, %10
%13 = fcmp oge double %2, 1.000000e+00
%14 = or i1 %13, %12
br i1 %14, label %27, label %15
15: ; preds = %5
%16 = fadd double %2, 1.000000e+00
%17 = fmul double %16, 5.000000e-01
%18 = tail call double @pnorm(double %17)
%19 = fsub double 1.000000e+00, %1
%20 = fmul double %19, %1
%21 = sitofp i32 %0 to double
%22 = fdiv double %20, %21
%23 = tail call double @sqrt(double %22)
%24 = fmul double %18, %23
%25 = fsub double %1, %24
store double %25, double* %3
%26 = fadd double %24, %1
store double %26, double* %4
br label %27
27: ; preds = %5, %15
%28 = phi i32 [ 0, %15 ], [ 999, %5 ]
ret i32 %28
}