#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 pt(double, int);
double sqrt(double);
int thomp(int n, double xk, double xbar, double v, double al, int *sw,
          double *t0, double *t) {
  double w;
  if (n < 3 || al <= 0.0 || al >= 1.0)
    return 999;
  w = (xk - xbar) / sqrt(v);
  n -= 2;
  *t0 = sqrt((double)n) * w / sqrt((double)n + 1.0 - w * w);
  *t = pt(al, n);
  if (fabs(*t0) >= *t)
    *sw = 1;
  else
    *sw = 0;
  return 0;
}


x86 assembly (clang, -O0):
<thomp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
mov    %rdx,-0x38(%rbp)
mov    %rcx,-0x40(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     117a <thomp+0x5a>
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jae    117a <thomp+0x5a>
movsd  -0x28(%rbp),%xmm0
movsd  0xe90(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1186 <thomp+0x66>
movl   $0x3e7,-0x4(%rbp)
jmp    1276 <thomp+0x156>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x8(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
call   1040 <sqrt@plt>
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xe26(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%edi
call   1030 <pt@plt>
mov    -0x40(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm0
movaps 0xdcc(%rip),%xmm1
pand   %xmm1,%xmm0
mov    -0x40(%rbp),%rax
ucomisd (%rax),%xmm0
jb     1265 <thomp+0x145>
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
jmp    126f <thomp+0x14f>
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thomp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
ucomisd 0xece(%rip),%xmm3
mov    $0x3e7,%eax
jae    1245 <thomp+0x125>
mov    %edi,%ebp
cmp    $0x3,%edi
jl     1245 <thomp+0x125>
movapd %xmm0,%xmm4
xorpd  %xmm0,%xmm0
ucomisd %xmm3,%xmm0
jae    1245 <thomp+0x125>
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r14
subsd  %xmm1,%xmm4
ucomisd %xmm0,%xmm2
movsd  %xmm3,0x8(%rsp)
jb     117c <thomp+0x5c>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
jmp    118f <thomp+0x6f>
movapd %xmm2,%xmm0
movsd  %xmm4,(%rsp)
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm4
add    $0xfffffffe,%ebp
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
divsd  %xmm0,%xmm4
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     11b0 <thomp+0x90>
xorps  %xmm2,%xmm2
sqrtsd %xmm1,%xmm2
jmp    11d7 <thomp+0xb7>
movapd %xmm1,%xmm0
movsd  %xmm4,(%rsp)
movsd  %xmm1,0x10(%rsp)
call   1040 <sqrt@plt>
movsd  0x10(%rsp),%xmm1
movsd  (%rsp),%xmm4
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
mulsd  %xmm4,%xmm2
addsd  0xe1d(%rip),%xmm1
mulsd  %xmm4,%xmm4
subsd  %xmm4,%xmm1
ucomisd %xmm0,%xmm1
jb     11fa <thomp+0xda>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    120d <thomp+0xed>
movapd %xmm1,%xmm0
movsd  %xmm2,(%rsp)
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm2
movsd  %xmm2,(%rbx)
movapd %xmm1,%xmm0
mov    %ebp,%edi
call   1030 <pt@plt>
movsd  %xmm0,(%r15)
movsd  (%rbx),%xmm1
andpd  0xdd9(%rip),%xmm1
xor    %eax,%eax
ucomisd %xmm0,%xmm1
setae  %al
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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