#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 vtst(int sw1, int n, double s, double v, double al, int *sw2, double *x20,
         double *x21, double *x22) {
  double qc1;
  if (n < 2 || al <= 0.0 || al >= 1.0)
    return 999;
  if (sw1 < 0)
    n--;
  *x20 = s / v;
  if (*sw2 < 0)
    qc1 = al;
  else
    qc1 = 0.5 * al;
  *x21 = pchi(qc1, n);
  *x22 = pchi(1.0 - qc1, n);
  if (*x20<*x21 && * x20> * x22)
    *sw2 = 0;
  else
    *sw2 = 1;
  return 0;
}


x86 assembly (clang, -O0):
<vtst>:
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)
mov    %r8,-0x40(%rbp)
mov    %r9,-0x48(%rbp)
cmpl   $0x2,-0xc(%rbp)
jl     116c <vtst+0x5c>
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jae    116c <vtst+0x5c>
movsd  -0x28(%rbp),%xmm0
movsd  0xe9e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1178 <vtst+0x68>
movl   $0x3e7,-0x4(%rbp)
jmp    124d <vtst+0x13d>
cmpl   $0x0,-0x8(%rbp)
jge    118b <vtst+0x7b>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
cmpl   $0x0,(%rax)
jge    11b9 <vtst+0xa9>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    11cb <vtst+0xbb>
movsd  0xe47(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
mov    -0xc(%rbp),%edi
call   1030 <pchi@plt>
mov    -0x40(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  0xe18(%rip),%xmm0
subsd  -0x50(%rbp),%xmm0
mov    -0xc(%rbp),%edi
call   1030 <pchi@plt>
mov    -0x48(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    123c <vtst+0x12c>
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x48(%rbp),%rax
ucomisd (%rax),%xmm0
jbe    123c <vtst+0x12c>
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
jmp    1246 <vtst+0x136>
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vtst>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
ucomisd 0xedc(%rip),%xmm2
mov    $0x3e7,%eax
jae    11bd <vtst+0xad>
cmp    $0x2,%esi
jl     11bd <vtst+0xad>
xorpd  %xmm3,%xmm3
ucomisd %xmm2,%xmm3
jae    11bd <vtst+0xad>
mov    %r9,%r15
mov    %r8,%r12
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %edi,%ebp
sar    $0x1f,%ebp
add    %esi,%ebp
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rcx)
cmpl   $0x0,(%rdx)
js     116a <vtst+0x5a>
mulsd  0xe9e(%rip),%xmm2
movsd  %xmm2,0x8(%rsp)
movapd %xmm2,%xmm0
mov    %ebp,%edi
call   1030 <pchi@plt>
movsd  %xmm0,(%r12)
movsd  0xe77(%rip),%xmm0
subsd  0x8(%rsp),%xmm0
mov    %ebp,%edi
call   1030 <pchi@plt>
movsd  %xmm0,(%r15)
movsd  (%rbx),%xmm1
movsd  (%r12),%xmm2
ucomisd %xmm1,%xmm2
setbe  %al
ucomisd %xmm0,%xmm1
setbe  %cl
or     %al,%cl
movzbl %cl,%eax
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @vtst(i32 %0, i32 %1, double %2, double %3, double %4, i32* nocapture %5, double* nocapture %6, double* nocapture %7, double* nocapture writeonly %8) {
%10 = icmp slt i32 %1, 2
%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
br i1 %14, label %32, label %15
15: ; preds = %9
%16 = ashr i32 %0, 31
%17 = add nsw i32 %16, %1
%18 = fdiv double %2, %3
store double %18, double* %6
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 0
%21 = fmul double %4, 5.000000e-01
%22 = select i1 %20, double %4, double %21
%23 = tail call double @pchi(double %22, i32 %17)
store double %23, double* %7
%24 = fsub double 1.000000e+00, %22
%25 = tail call double @pchi(double %24, i32 %17)
store double %25, double* %8
%26 = load double, double* %6
%27 = load double, double* %7
%28 = fcmp uge double %26, %27
%29 = fcmp ule double %26, %25
%30 = select i1 %28, i1 true, i1 %29
%31 = zext i1 %30 to i32
store i32 %31, i32* %5
br label %32
32: ; preds = %9, %15
%33 = phi i32 [ 0, %15 ], [ 999, %9 ]
ret i32 %33
}