#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 asum(double *, int);
double sqrt(double);
double vldot(double *, double *, int);
int /*<<< orphan*/ vsp(double *, double *, double, int);
int /*<<< orphan*/ vst(double *, double *, double, int);
double hwstat(double *x) {
  double p, q, ysum, s1, y1, y2, ychi, sig;
  double a1[3], a2[3];
  ysum = asum(x, 3);
  if (ysum < 0.001)
    return 0.0;
  s1 = 2 * x[2] + x[1];
  p = 0.5 * s1 / ysum;
  q = 1.0 - p;
  a1[0] = q * q;
  a1[1] = 2 * p * q;
  a1[2] = p * p;
  vsp(a1, a1, 1.0e-8, 3);
  vst(a2, x, 1.0 / ysum, 3);
  vsp(a2, a2, 1.0e-8, 3);
  y2 = vldot(x, a2, 3);
  y1 = vldot(x, a1, 3);
  ychi = 2.0 * (y2 - y1);
  sig = sqrt(ychi + 1.0e-8);
  if (a2[1] < a1[1])
    sig = -sig;
  return sig;
}


x86 assembly (clang, -O0):
<hwstat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3,%esi
call   1060 <asum@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  0xe86(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1192 <hwstat+0x42>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1310 <hwstat+0x1c0>
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe67(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe48(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xe1f(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
lea    -0x70(%rbp),%rdi
lea    -0x70(%rbp),%rsi
movsd  0xde9(%rip),%xmm0
mov    $0x3,%edx
call   1040 <vsp@plt>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsd  0xddc(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
mov    $0x3,%edx
call   1030 <vst@plt>
lea    -0x90(%rbp),%rdi
lea    -0x90(%rbp),%rsi
movsd  0xda7(%rip),%xmm0
mov    $0x3,%edx
call   1040 <vsp@plt>
mov    -0x10(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x3,%edx
call   1050 <vldot@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x3,%edx
call   1050 <vldot@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x40(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
movsd  0xd62(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xd49(%rip),%xmm0
addsd  -0x48(%rbp),%xmm0
call   1070 <sqrt@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x88(%rbp),%xmm1
ff
movsd  -0x68(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1306 <hwstat+0x1b6>
movsd  -0x50(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hwstat>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%rbx
mov    $0x3,%esi
call   1060 <asum@plt>
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
movsd  0xe8a(%rip),%xmm1
ucomisd %xmm2,%xmm1
ja     12ad <hwstat+0x15d>
movsd  0x10(%rbx),%xmm0
addsd  %xmm0,%xmm0
addsd  0x8(%rbx),%xmm0
mulsd  0xe72(%rip),%xmm0
divsd  %xmm2,%xmm0
movsd  0xe6e(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm2,0x8(%rsp)
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%rsp)
movapd %xmm0,%xmm2
addsd  %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
unpcklpd %xmm0,%xmm1
mulpd  %xmm2,%xmm1
movupd %xmm1,0x18(%rsp)
lea    0x10(%rsp),%r14
movsd  0xe37(%rip),%xmm0
mov    %r14,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1040 <vsp@plt>
movsd  0xe17(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
lea    0x30(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1030 <vst@plt>
mov    %r15,%rdi
mov    %r15,%rsi
movsd  0xdf6(%rip),%xmm0
mov    $0x3,%edx
call   1040 <vsp@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1050 <vldot@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1050 <vldot@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
addsd  %xmm1,%xmm1
addsd  0xdb0(%rip),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
movapd %xmm1,%xmm0
jb     127f <hwstat+0x12f>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    1288 <hwstat+0x138>
call   1070 <sqrt@plt>
movapd %xmm0,%xmm1
movsd  0x38(%rsp),%xmm0
movapd 0xd8a(%rip),%xmm2
cmpltsd 0x18(%rsp),%xmm0
xorpd  %xmm1,%xmm2
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @hwstat(double* %0) {
%2 = alloca double
%3 = alloca double*
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca [3 x double]
%13 = alloca [3 x double]
store double* %0, double** %3
%14 = load double*, double** %3
%15 = call double @asum(double* %14, i32 3)
store double %15, double* %6
%16 = load double, double* %6
%17 = fcmp olt double %16, 1.000000e-03
br i1 %17, label %18, label %19
18: ; preds = %1
store double 0.000000e+00, double* %2
br label %80
19: ; preds = %1
%20 = load double*, double** %3
%21 = getelementptr inbounds double, double* %20, i64 2
%22 = load double, double* %21
%23 = load double*, double** %3
%24 = getelementptr inbounds double, double* %23, i64 1
%25 = load double, double* %24
%26 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %22, double %25)
store double %26, double* %7
%27 = load double, double* %7
%28 = fmul double 5.000000e-01, %27
%29 = load double, double* %6
%30 = fdiv double %28, %29
store double %30, double* %4
%31 = load double, double* %4
%32 = fsub double 1.000000e+00, %31
store double %32, double* %5
%33 = load double, double* %5
%34 = load double, double* %5
%35 = fmul double %33, %34
%36 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
store double %35, double* %36
%37 = load double, double* %4
%38 = fmul double 2.000000e+00, %37
%39 = load double, double* %5
%40 = fmul double %38, %39
%41 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 1
store double %40, double* %41
%42 = load double, double* %4
%43 = load double, double* %4
%44 = fmul double %42, %43
%45 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 2
store double %44, double* %45
%46 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%47 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%48 = call i32 @vsp(double* %46, double* %47, double 1.000000e-08, i32 3)
%49 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%50 = load double*, double** %3
%51 = load double, double* %6
%52 = fdiv double 1.000000e+00, %51
%53 = call i32 @vst(double* %49, double* %50, double %52, i32 3)
%54 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%55 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%56 = call i32 @vsp(double* %54, double* %55, double 1.000000e-08, i32 3)
%57 = load double*, double** %3
%58 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%59 = call double @vldot(double* %57, double* %58, i32 3)
store double %59, double* %9
%60 = load double*, double** %3
%61 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%62 = call double @vldot(double* %60, double* %61, i32 3)
store double %62, double* %8
%63 = load double, double* %9
%64 = load double, double* %8
%65 = fsub double %63, %64
%66 = fmul double 2.000000e+00, %65
store double %66, double* %10
%67 = load double, double* %10
%68 = fadd double %67, 1.000000e-08
%69 = call double @sqrt(double %68)
store double %69, double* %11
%70 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 1
%71 = load double, double* %70
%72 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 1
%73 = load double, double* %72
%74 = fcmp olt double %71, %73
br i1 %74, label %75, label %78
75: ; preds = %19
%76 = load double, double* %11
%77 = fneg double %76
store double %77, double* %11
br label %78
78: ; preds = %75, %19
%79 = load double, double* %11
store double %79, double* %2
br label %80
80: ; preds = %78, %18
%81 = load double, double* %2
ret double %81
}

LLVM IR (-O2):
define double @hwstat(double* %0) {
%2 = alloca [3 x double]
%3 = alloca [3 x double]
%4 = bitcast [3 x double]* %2 to i8*
%5 = bitcast [3 x double]* %3 to i8*
%6 = tail call double @asum(double* %0, i32 3)
%7 = fcmp olt double %6, 1.000000e-03
br i1 %7, label %44, label %8
8: ; preds = %1
%9 = getelementptr inbounds double, double* %0, i64 2
%10 = load double, double* %9
%11 = getelementptr inbounds double, double* %0, i64 1
%12 = load double, double* %11
%13 = tail call double @llvm.fmuladd.f64(double %10, double 2.000000e+00, double %12)
%14 = fmul double %13, 5.000000e-01
%15 = fdiv double %14, %6
%16 = fsub double 1.000000e+00, %15
%17 = fmul double %16, %16
%18 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 0
store double %17, double* %18
%19 = fmul double %15, 2.000000e+00
%20 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 0, i64 1
%21 = insertelement <2 x double> poison, double %19, i64 0
%22 = insertelement <2 x double> %21, double %15, i64 1
%23 = insertelement <2 x double> poison, double %16, i64 0
%24 = insertelement <2 x double> %23, double %15, i64 1
%25 = fmul <2 x double> %22, %24
%26 = bitcast double* %20 to <2 x double>*
store <2 x double> %25, <2 x double>* %26
%27 = call i32 @vsp(double* %18, double* %18, double 1.000000e-08, i32 3)
%28 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 0
%29 = fdiv double 1.000000e+00, %6
%30 = call i32 @vst(double* %28, double* %0, double %29, i32 3)
%31 = call i32 @vsp(double* %28, double* %28, double 1.000000e-08, i32 3)
%32 = call double @vldot(double* %0, double* %28, i32 3)
%33 = call double @vldot(double* %0, double* %18, i32 3)
%34 = fsub double %32, %33
%35 = fmul double %34, 2.000000e+00
%36 = fadd double %35, 1.000000e-08
%37 = call double @sqrt(double %36)
%38 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 1
%39 = load double, double* %38
%40 = load double, double* %20
%41 = fcmp olt double %39, %40
%42 = fneg double %37
%43 = select i1 %41, double %42, double %37
br label %44
44: ; preds = %1, %8
%45 = phi double [ %43, %8 ], [ 0.000000e+00, %1 ]
ret double %45
}