#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 pchi(double, int);
int vest(int sw, int n, double s, double g, double *xl, double *xu) {
  double q1;
  if (n < 2 || g <= 0.0 || g >= 1.0)
    return 999;
  if (sw < 0)
    n--;
  q1 = (1.0 + g) * 0.5;
  *xl = s / pchi(1.0 - q1, n);
  *xu = s / pchi(q1, n);
  return 0;
}


x86 assembly (clang, -O0):
<vest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
cmpl   $0x2,-0xc(%rbp)
jl     115f <vest+0x4f>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jae    115f <vest+0x4f>
movsd  -0x20(%rbp),%xmm0
movsd  0xeab(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     116b <vest+0x5b>
movl   $0x3e7,-0x4(%rbp)
jmp    1201 <vest+0xf1>
cmpl   $0x0,-0x8(%rbp)
jge    117e <vest+0x6e>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
movsd  0xe7a(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xe75(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xe52(%rip),%xmm0
subsd  -0x38(%rbp),%xmm0
mov    -0xc(%rbp),%edi
call   1030 <pchi@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0xc(%rbp),%edi
call   1030 <pchi@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vest>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
ucomisd 0xee0(%rip),%xmm1
mov    $0x3e7,%eax
jae    119b <vest+0x8b>
cmp    $0x2,%esi
jl     119b <vest+0x8b>
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    119b <vest+0x8b>
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %edi,%ebp
sar    $0x1f,%ebp
add    %esi,%ebp
movsd  0xeb1(%rip),%xmm0
addsd  %xmm0,%xmm1
mulsd  0xead(%rip),%xmm1
movsd  %xmm1,0x8(%rsp)
subsd  %xmm1,%xmm0
mov    %ebp,%edi
movsd  %xmm2,(%rsp)
call   1030 <pchi@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx)
movsd  0x8(%rsp),%xmm0
mov    %ebp,%edi
call   1030 <pchi@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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