#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 fabs(double);
double pnorm(double);
double sqrt(double);
int bpdest(int n1, int n2, double ps1, double ps2, double g, double *xl,
           double *xu) {
  double p, w;
  if (n1 < 1 || n2 < 1 || g <= 0.0 || g >= 1.0 || ps1 <= 0.0 || ps1 >= 1.0 ||
      ps2 <= 0.0 || ps2 >= 1.0)
    return 999;
  p = fabs(ps1 - ps2);
  w = pnorm((1.0 + g) * 0.5) *
      sqrt(ps1 * (1.0 - ps1) / (double)n1 + ps2 * (1.0 - ps2) / (double)n2);
  *xl = p - w;
  *xu = p + w;
  return 0;
}


x86 assembly (clang, -O0):
<bpdest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     11c8 <bpdest+0xa8>
cmpl   $0x1,-0xc(%rbp)
jl     11c8 <bpdest+0xa8>
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jae    11c8 <bpdest+0xa8>
movsd  -0x28(%rbp),%xmm0
movsd  0xe8c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    11c8 <bpdest+0xa8>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jae    11c8 <bpdest+0xa8>
movsd  -0x18(%rbp),%xmm0
movsd  0xe67(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    11c8 <bpdest+0xa8>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jae    11c8 <bpdest+0xa8>
movsd  -0x20(%rbp),%xmm0
movsd  0xe42(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11d4 <bpdest+0xb4>
movl   $0x3e7,-0x4(%rbp)
jmp    1294 <bpdest+0x174>
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movaps 0xe2b(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe0a(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  0xe05(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <pnorm@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xde2(%rip),%xmm1
subsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xdc3(%rip),%xmm2
subsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm1
cvtsi2sdl -0xc(%rbp),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpdest>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
ucomisd 0xece(%rip),%xmm1
mov    $0x3e7,%eax
jae    1265 <bpdest+0x145>
movapd %xmm0,%xmm3
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    1265 <bpdest+0x145>
ucomisd 0xea9(%rip),%xmm3
jae    1265 <bpdest+0x145>
xorpd  %xmm0,%xmm0
ucomisd %xmm3,%xmm0
jae    1265 <bpdest+0x145>
ucomisd 0xe8d(%rip),%xmm2
jae    1265 <bpdest+0x145>
mov    %edi,%ebx
test   %edi,%edi
jle    1265 <bpdest+0x145>
mov    %esi,%ebp
test   %esi,%esi
jle    1265 <bpdest+0x145>
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jae    1265 <bpdest+0x145>
mov    %rcx,%r14
mov    %rdx,%r15
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
andpd  0xe6f(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
addsd  0xe41(%rip),%xmm2
mulsd  0xe41(%rip),%xmm2
movapd %xmm2,%xmm0
movsd  %xmm1,(%rsp)
movsd  %xmm3,0x8(%rsp)
call   1030 <pnorm@plt>
movapd %xmm0,%xmm2
movsd  0xe19(%rip),%xmm3
movapd %xmm3,%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
divsd  %xmm1,%xmm0
movsd  (%rsp),%xmm1
subsd  %xmm1,%xmm3
mulsd  %xmm1,%xmm3
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
divsd  %xmm1,%xmm3
addsd  %xmm0,%xmm3
movapd %xmm3,%xmm0
ucomisd 0xde4(%rip),%xmm3
jb     1234 <bpdest+0x114>
sqrtsd %xmm0,%xmm0
jmp    1243 <bpdest+0x123>
movsd  %xmm2,(%rsp)
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm2
mulsd  %xmm0,%xmm2
movapd 0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
subsd  %xmm2,%xmm0
movsd  %xmm0,(%r15)
addsd  %xmm1,%xmm2
movsd  %xmm2,(%r14)
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bpdest(i32 %0, i32 %1, double %2, double %3, double %4, double* %5, double* %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double*
%15 = alloca double*
%16 = alloca double
%17 = alloca double
store i32 %0, i32* %9
store i32 %1, i32* %10
store double %2, double* %11
store double %3, double* %12
store double %4, double* %13
store double* %5, double** %14
store double* %6, double** %15
%18 = load i32, i32* %9
%19 = icmp slt i32 %18, 1
br i1 %19, label %41, label %20
20: ; preds = %7
%21 = load i32, i32* %10
%22 = icmp slt i32 %21, 1
br i1 %22, label %41, label %23
23: ; preds = %20
%24 = load double, double* %13
%25 = fcmp ole double %24, 0.000000e+00
br i1 %25, label %41, label %26
26: ; preds = %23
%27 = load double, double* %13
%28 = fcmp oge double %27, 1.000000e+00
br i1 %28, label %41, label %29
29: ; preds = %26
%30 = load double, double* %11
%31 = fcmp ole double %30, 0.000000e+00
br i1 %31, label %41, label %32
32: ; preds = %29
%33 = load double, double* %11
%34 = fcmp oge double %33, 1.000000e+00
br i1 %34, label %41, label %35
35: ; preds = %32
%36 = load double, double* %12
%37 = fcmp ole double %36, 0.000000e+00
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = load double, double* %12
%40 = fcmp oge double %39, 1.000000e+00
br i1 %40, label %41, label %42
41: ; preds = %38, %35, %32, %29, %26, %23, %20, %7
store i32 999, i32* %8
br label %76
42: ; preds = %38
%43 = load double, double* %11
%44 = load double, double* %12
%45 = fsub double %43, %44
%46 = call double @llvm.fabs.f64(double %45)
store double %46, double* %16
%47 = load double, double* %13
%48 = fadd double 1.000000e+00, %47
%49 = fmul double %48, 5.000000e-01
%50 = call double @pnorm(double %49)
%51 = load double, double* %11
%52 = load double, double* %11
%53 = fsub double 1.000000e+00, %52
%54 = fmul double %51, %53
%55 = load i32, i32* %9
%56 = sitofp i32 %55 to double
%57 = fdiv double %54, %56
%58 = load double, double* %12
%59 = load double, double* %12
%60 = fsub double 1.000000e+00, %59
%61 = fmul double %58, %60
%62 = load i32, i32* %10
%63 = sitofp i32 %62 to double
%64 = fdiv double %61, %63
%65 = fadd double %57, %64
%66 = call double @sqrt(double %65)
%67 = fmul double %50, %66
store double %67, double* %17
%68 = load double, double* %16
%69 = load double, double* %17
%70 = fsub double %68, %69
%71 = load double*, double** %14
store double %70, double* %71
%72 = load double, double* %16
%73 = load double, double* %17
%74 = fadd double %72, %73
%75 = load double*, double** %15
store double %74, double* %75
store i32 0, i32* %8
br label %76
76: ; preds = %42, %41
%77 = load i32, i32* %8
ret i32 %77
}

LLVM IR (-O2):
define i32 @bpdest(i32 %0, i32 %1, double %2, double %3, double %4, double* nocapture writeonly %5, double* nocapture writeonly %6) {
%8 = icmp slt i32 %0, 1
%9 = icmp slt i32 %1, 1
%10 = or i1 %8, %9
%11 = fcmp ole double %4, 0.000000e+00
%12 = or i1 %10, %11
%13 = fcmp oge double %4, 1.000000e+00
%14 = or i1 %13, %12
%15 = fcmp ole double %2, 0.000000e+00
%16 = or i1 %15, %14
%17 = fcmp oge double %2, 1.000000e+00
%18 = or i1 %17, %16
%19 = fcmp ole double %3, 0.000000e+00
%20 = or i1 %19, %18
%21 = fcmp oge double %3, 1.000000e+00
%22 = or i1 %21, %20
br i1 %22, label %42, label %23
23: ; preds = %7
%24 = fsub double %2, %3
%25 = tail call double @llvm.fabs.f64(double %24)
%26 = fadd double %4, 1.000000e+00
%27 = fmul double %26, 5.000000e-01
%28 = tail call double @pnorm(double %27)
%29 = fsub double 1.000000e+00, %2
%30 = fmul double %29, %2
%31 = sitofp i32 %0 to double
%32 = fdiv double %30, %31
%33 = fsub double 1.000000e+00, %3
%34 = fmul double %33, %3
%35 = sitofp i32 %1 to double
%36 = fdiv double %34, %35
%37 = fadd double %32, %36
%38 = tail call double @sqrt(double %37)
%39 = fmul double %28, %38
%40 = fsub double %25, %39
store double %40, double* %5
%41 = fadd double %25, %39
store double %41, double* %6
br label %42
42: ; preds = %7, %23
%43 = phi i32 [ 0, %23 ], [ 999, %7 ]
ret i32 %43
}