#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 asum2(double *, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fatalx(char *, int);
int /*<<< orphan*/ free(double *);
double twnorm(double, double, double);
double twtail(double);
int /*<<< orphan*/ vst(double *, double *, double, int);
double dotwcalc(double *lambda, int m, double *ptw, double *pzn, double *pzvar,
                int minm) {
  double nv, mv, tzn, tm;
  double *evals;
  double y, top, bot, zn, tw, ystat;
  double tail, lsum;
  if (m < minm) {
    *pzn = *pzvar = *ptw = -1;
    return -1.0;
  }
  lsum = asum(lambda, m);
  if (lsum <= 0.0) {
    *pzn = *pzvar = *ptw = -1;
    return -1.0;
  }
  tzn = *pzn;
  tm = (double)m;
  y = (double)m / lsum;
  ystat = lambda[0] * y * tzn;
  if (tzn > 0.0) {
    tw = twnorm(ystat, tm, tzn);
    *pzn = tzn;
    *ptw = tw;
    tail = twtail(tw);
    return tail;
  }
  if ((evals = (double *)calloc((m), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", m);
  vst(evals, lambda, y, m);
  top = (double)(m * (m + 2));
  bot = asum2(evals, m) - (double)m;
  zn = top / bot;
  y = evals[0] * zn;
  tw = twnorm(y, tm, zn);
  *pzn = zn;
  *ptw = tw;
  tail = twtail(tw);
  free(evals);
  return tail;
}


x86 assembly (clang, -O0):
<dotwcalc>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11f0 <dotwcalc+0x70>
mov    -0x20(%rbp),%rax
movsd  0xe46(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
movsd  0xe36(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  0xe26(%rip),%xmm0
movsd  %xmm0,(%rax)
movsd  0xe1a(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1402 <dotwcalc+0x282>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <asum@plt>
movsd  %xmm0,-0xa0(%rbp)
ff
xorps  %xmm0,%xmm0
ucomisd -0xa0(%rbp),%xmm0
ff
jb     1257 <dotwcalc+0xd7>
mov    -0x20(%rbp),%rax
movsd  0xddf(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
movsd  0xdcf(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
movsd  0xdbf(%rip),%xmm0
movsd  %xmm0,(%rax)
movsd  0xdb3(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1402 <dotwcalc+0x282>
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
divsd  -0xa0(%rbp),%xmm0
ff
movsd  %xmm0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mulsd  -0x68(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    130f <dotwcalc+0x18f>
movsd  -0x90(%rbp),%xmm0
ff
movsd  -0x58(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
call   1080 <twnorm@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x88(%rbp),%xmm0
ff
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x88(%rbp),%xmm0
ff
call   10a0 <twtail@plt>
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x98(%rbp),%xmm0
ff
movsd  %xmm0,-0x8(%rbp)
jmp    1402 <dotwcalc+0x282>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x60(%rbp)
cmp    $0x0,%rax
jne    1339 <dotwcalc+0x1b9>
mov    -0x14(%rbp),%esi
lea    0xcd4(%rip),%rdi
call   1050 <fatalx@plt>
mov    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsd  -0x68(%rbp),%xmm0
mov    -0x14(%rbp),%edx
call   1040 <vst@plt>
mov    -0x14(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1090 <asum2@plt>
cvtsi2sdl -0x14(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x70(%rbp),%xmm0
divsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x60(%rbp),%rax
movsd  (%rax),%xmm0
mulsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
movsd  -0x80(%rbp),%xmm2
call   1080 <twnorm@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x80(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x88(%rbp),%xmm0
ff
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x88(%rbp),%xmm0
ff
call   10a0 <twtail@plt>
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x98(%rbp),%xmm0
ff
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dotwcalc>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r12
mov    %rcx,%r15
mov    %rdx,%r14
cmp    %r9d,%esi
jl     11ff <dotwcalc+0x7f>
mov    %esi,%ebx
mov    %rdi,%r13
call   1070 <asum@plt>
xorpd  %xmm4,%xmm4
ucomisd %xmm0,%xmm4
jae    11ff <dotwcalc+0x7f>
cvtsi2sd %ebx,%xmm1
movsd  (%r15),%xmm2
movapd %xmm1,%xmm3
divsd  %xmm0,%xmm3
ucomisd %xmm4,%xmm2
jbe    1229 <dotwcalc+0xa9>
mulsd  0x0(%r13),%xmm3
mulsd  %xmm2,%xmm3
movapd %xmm3,%xmm0
movsd  %xmm2,(%rsp)
call   1080 <twnorm@plt>
movsd  (%rsp),%xmm1
movsd  %xmm1,(%r15)
movsd  %xmm0,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    10a0 <twtail@plt>
movabs $0xbff0000000000000,%rax
mov    %rax,(%r14)
mov    %rax,(%r12)
mov    %rax,(%r15)
movsd  0xde5(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
movsd  %xmm3,(%rsp)
movsd  %xmm1,0x8(%rsp)
mov    %ebx,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1256 <dotwcalc+0xd6>
lea    0xdb9(%rip),%rdi
mov    %ebx,%esi
call   1050 <fatalx@plt>
mov    %r12,%rdi
mov    %r13,%rsi
movsd  (%rsp),%xmm0
mov    %ebx,%edx
call   1040 <vst@plt>
lea    0x2(%rbx),%eax
imul   %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
mov    %r12,%rdi
mov    %ebx,%esi
call   1090 <asum2@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm1,%xmm0
movsd  (%rsp),%xmm2
divsd  %xmm0,%xmm2
movsd  %xmm2,(%rsp)
movsd  (%r12),%xmm0
mulsd  %xmm2,%xmm0
call   1080 <twnorm@plt>
movsd  (%rsp),%xmm1
movsd  %xmm1,(%r15)
movsd  %xmm0,(%r14)
call   10a0 <twtail@plt>
movsd  %xmm0,(%rsp)
mov    %r12,%rdi
call   1030 <free@plt>
movsd  (%rsp),%xmm0
jmp    121b <dotwcalc+0x9b>

LLVM IR (-O0):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define double @dotwcalc(double* %0, i32 %1, double* %2, double* %3, double* %4, i32 %5) {
%7 = alloca double
%8 = alloca double*
%9 = alloca i32
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double*
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca double
store double* %0, double** %8
store i32 %1, i32* %9
store double* %2, double** %10
store double* %3, double** %11
store double* %4, double** %12
store i32 %5, i32* %13
%27 = load i32, i32* %9
%28 = load i32, i32* %13
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %6
%31 = load double*, double** %10
store double -1.000000e+00, double* %31
%32 = load double*, double** %12
store double -1.000000e+00, double* %32
%33 = load double*, double** %11
store double -1.000000e+00, double* %33
store double -1.000000e+00, double* %7
br label %120
34: ; preds = %6
%35 = load double*, double** %8
%36 = load i32, i32* %9
%37 = call double @asum(double* %35, i32 %36)
store double %37, double* %26
%38 = load double, double* %26
%39 = fcmp ole double %38, 0.000000e+00
br i1 %39, label %40, label %44
40: ; preds = %34
%41 = load double*, double** %10
store double -1.000000e+00, double* %41
%42 = load double*, double** %12
store double -1.000000e+00, double* %42
%43 = load double*, double** %11
store double -1.000000e+00, double* %43
store double -1.000000e+00, double* %7
br label %120
44: ; preds = %34
%45 = load double*, double** %11
%46 = load double, double* %45
store double %46, double* %16
%47 = load i32, i32* %9
%48 = sitofp i32 %47 to double
store double %48, double* %17
%49 = load i32, i32* %9
%50 = sitofp i32 %49 to double
%51 = load double, double* %26
%52 = fdiv double %50, %51
store double %52, double* %19
%53 = load double*, double** %8
%54 = getelementptr inbounds double, double* %53, i64 0
%55 = load double, double* %54
%56 = load double, double* %19
%57 = fmul double %55, %56
%58 = load double, double* %16
%59 = fmul double %57, %58
store double %59, double* %24
%60 = load double, double* %16
%61 = fcmp ogt double %60, 0.000000e+00
br i1 %61, label %62, label %74
62: ; preds = %44
%63 = load double, double* %24
%64 = load double, double* %17
%65 = load double, double* %16
%66 = call double @twnorm(double %63, double %64, double %65)
store double %66, double* %23
%67 = load double, double* %16
%68 = load double*, double** %11
store double %67, double* %68
%69 = load double, double* %23
%70 = load double*, double** %10
store double %69, double* %70
%71 = load double, double* %23
%72 = call double @twtail(double %71)
store double %72, double* %25
%73 = load double, double* %25
store double %73, double* %7
br label %120
74: ; preds = %44
%75 = load i32, i32* %9
%76 = call i64 @calloc(i32 %75, i32 8)
%77 = inttoptr i64 %76 to double*
store double* %77, double** %18
%78 = icmp eq double* %77, null
br i1 %78, label %79, label %82
79: ; preds = %74
%80 = load i32, i32* %9
%81 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %80)
br label %82
82: ; preds = %79, %74
%83 = load double*, double** %18
%84 = load double*, double** %8
%85 = load double, double* %19
%86 = load i32, i32* %9
%87 = call i32 @vst(double* %83, double* %84, double %85, i32 %86)
%88 = load i32, i32* %9
%89 = load i32, i32* %9
%90 = add nsw i32 %89, 2
%91 = mul nsw i32 %88, %90
%92 = sitofp i32 %91 to double
store double %92, double* %20
%93 = load double*, double** %18
%94 = load i32, i32* %9
%95 = call double @asum2(double* %93, i32 %94)
%96 = load i32, i32* %9
%97 = sitofp i32 %96 to double
%98 = fsub double %95, %97
store double %98, double* %21
%99 = load double, double* %20
%100 = load double, double* %21
%101 = fdiv double %99, %100
store double %101, double* %22
%102 = load double*, double** %18
%103 = getelementptr inbounds double, double* %102, i64 0
%104 = load double, double* %103
%105 = load double, double* %22
%106 = fmul double %104, %105
store double %106, double* %19
%107 = load double, double* %19
%108 = load double, double* %17
%109 = load double, double* %22
%110 = call double @twnorm(double %107, double %108, double %109)
store double %110, double* %23
%111 = load double, double* %22
%112 = load double*, double** %11
store double %111, double* %112
%113 = load double, double* %23
%114 = load double*, double** %10
store double %113, double* %114
%115 = load double, double* %23
%116 = call double @twtail(double %115)
store double %116, double* %25
%117 = load double*, double** %18
%118 = call i32 @free(double* %117)
%119 = load double, double* %25
store double %119, double* %7
br label %120
120: ; preds = %82, %62, %40, %30
%121 = load double, double* %7
ret double %121
}

LLVM IR (-O2):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define double @dotwcalc(double* %0, i32 %1, double* nocapture writeonly %2, double* nocapture %3, double* nocapture writeonly %4, i32 %5) {
%7 = icmp slt i32 %1, %5
br i1 %7, label %8, label %9
8: ; preds = %6
store double -1.000000e+00, double* %2
store double -1.000000e+00, double* %4
store double -1.000000e+00, double* %3
br label %43
9: ; preds = %6
%10 = tail call double @asum(double* %0, i32 %1)
%11 = fcmp ugt double %10, 0.000000e+00
br i1 %11, label %13, label %12
12: ; preds = %9
store double -1.000000e+00, double* %2
store double -1.000000e+00, double* %4
store double -1.000000e+00, double* %3
br label %43
13: ; preds = %9
%14 = load double, double* %3
%15 = sitofp i32 %1 to double
%16 = fdiv double %15, %10
%17 = fcmp ogt double %14, 0.000000e+00
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load double, double* %0
%20 = fmul double %16, %19
%21 = fmul double %14, %20
%22 = tail call double @twnorm(double %21, double %15, double %14)
store double %14, double* %3
store double %22, double* %2
%23 = tail call double @twtail(double %22)
br label %43
24: ; preds = %13
%25 = tail call i64 @calloc(i32 %1, i32 8)
%26 = inttoptr i64 %25 to double*
%27 = icmp eq i64 %25, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %30
30: ; preds = %28, %24
%31 = tail call i32 @vst(double* %26, double* %0, double %16, i32 %1)
%32 = add nsw i32 %1, 2
%33 = mul nsw i32 %32, %1
%34 = sitofp i32 %33 to double
%35 = tail call double @asum2(double* %26, i32 %1)
%36 = fsub double %35, %15
%37 = fdiv double %34, %36
%38 = load double, double* %26
%39 = fmul double %38, %37
%40 = tail call double @twnorm(double %39, double %15, double %37)
store double %37, double* %3
store double %40, double* %2
%41 = tail call double @twtail(double %40)
%42 = tail call i32 @free(double* %26)
br label %43
43: ; preds = %30, %18, %12, %8
%44 = phi double [ -1.000000e+00, %8 ], [ -1.000000e+00, %12 ], [ %23, %18 ], [ %41, %30 ]
ret double %44
}