#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 exp(double);
int /*<<< orphan*/ rax_free(double *);
scalar_t__ rax_malloc(int);
void coreGTRCAT_BINARY(int upper, int numberOfCategories, double *sum,
                       volatile double *d1, volatile double *d2, double *rptr,
                       double *EIGN, int *cptr, double lz, int *wgt) {
  int i;
  double *d, *d_start, tmp_0, inv_Li, dlnLidlz, d2lnLidlz2, dlnLdlz = 0.0,
                                                            d2lnLdlz2 = 0.0;
  double e[2];
  double dd1;
  e[0] = EIGN[0];
  e[1] = EIGN[0] * EIGN[0];
  d = d_start = (double *)rax_malloc(numberOfCategories * sizeof(double));
  dd1 = e[0] * lz;
  for (i = 0; i < numberOfCategories; i++)
    d[i] = exp(dd1 * rptr[i]);
  for (i = 0; i < upper; i++) {
    double r = rptr[cptr[i]], wr1 = r * wgt[i], wr2 = r * r * wgt[i];
    d = &d_start[cptr[i]];
    inv_Li = sum[2 * i];
    inv_Li += (tmp_0 = d[0] * sum[2 * i + 1]);
    inv_Li = 1.0 / FABS(inv_Li);
    dlnLidlz = tmp_0 * e[0];
    d2lnLidlz2 = tmp_0 * e[1];
    dlnLidlz *= inv_Li;
    d2lnLidlz2 *= inv_Li;
    dlnLdlz += wr1 * dlnLidlz;
    d2lnLdlz2 += wr2 * (d2lnLidlz2 - dlnLidlz * dlnLidlz);
  }
  *d1 = dlnLdlz;
  *d2 = d2lnLdlz2;
  rax_free(d_start);
}


x86 assembly (clang, -O0):
<coreGTRCAT_BINARY>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    0x10(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <rax_malloc@plt>
mov    %rax,-0x48(%rbp)
mov    %rax,-0x40(%rbp)
movsd  -0x90(%rbp),%xmm0
ff
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121e <coreGTRCAT_BINARY+0xde>
movsd  -0x98(%rbp),%xmm0
ff
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
call   1060 <exp@plt>
mov    -0x40(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11dd <coreGTRCAT_BINARY+0x9d>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    13cb <coreGTRCAT_BINARY+0x28b>
mov    -0x28(%rbp),%rax
mov    0x18(%rbp),%rcx
movslq -0x34(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0xa0(%rbp),%xmm0
ff
mov    0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0xa0(%rbp),%xmm0
ff
mulsd  -0xa0(%rbp),%xmm0
ff
mov    0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
mov    -0x48(%rbp),%rax
mov    0x18(%rbp),%rcx
movslq -0x34(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
call   1030 <FABS@plt>
movaps %xmm0,%xmm1
movsd  0xcf5(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
mulsd  -0x90(%rbp),%xmm0
ff
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm0
mulsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x68(%rbp)
movsd  -0x58(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x58(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0xa8(%rbp),%xmm0
ff
movsd  -0x60(%rbp),%xmm2
movsd  -0x70(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0xb0(%rbp),%xmm0
ff
movsd  -0x68(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm3
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  -0x78(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1225 <coreGTRCAT_BINARY+0xe5>
movsd  -0x70(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x78(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x48(%rbp),%rdi
call   1050 <rax_free@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<coreGTRCAT_BINARY>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
movsd  %xmm0,0x10(%rsp)
mov    %r9,%r12
mov    %r8,%r15
mov    %rcx,0x48(%rsp)
mov    %rdx,%r13
mov    %esi,%ebp
mov    %edi,0x20(%rsp)
mov    0xc0(%rsp),%rax
mov    %rax,0x40(%rsp)
mov    0xb8(%rsp),%rax
mov    %rax,0x38(%rsp)
mov    0xb0(%rsp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x0(,%rbp,8),%edi
call   1040 <rax_malloc@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    11e0 <coreGTRCAT_BINARY+0xa0>
movsd  0x10(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %ebp,%ebp
xor    %ebx,%ebx
nopl   (%rax)
movsd  (%r12,%rbx,8),%xmm0
mulsd  0x10(%rsp),%xmm0
call   1060 <exp@plt>
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11c0 <coreGTRCAT_BINARY+0x80>
mov    0x20(%rsp),%eax
test   %eax,%eax
jle    12df <coreGTRCAT_BINARY+0x19f>
mov    %r15,0x30(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,0x58(%rsp)
mov    %eax,%eax
shl    $0x2,%rax
mov    %rax,0x50(%rsp)
xorpd  %xmm0,%xmm0
xor    %r15d,%r15d
mov    0x40(%rsp),%rbx
mov    0x38(%rsp),%rbp
nopl   (%rax)
movapd %xmm0,0x10(%rsp)
movslq 0x0(%rbp,%r15,1),%rax
movsd  (%r12,%rax,8),%xmm0
xorps  %xmm2,%xmm2
cvtsi2sdl (%rbx,%r15,1),%xmm2
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
unpcklpd %xmm2,%xmm2
mulpd  %xmm1,%xmm2
movapd %xmm2,0x20(%rsp)
movsd  (%r14,%rax,8),%xmm1
mulsd  0x8(%r13,%r15,4),%xmm1
movapd %xmm1,0x60(%rsp)
movsd  0x0(%r13,%r15,4),%xmm0
addsd  %xmm1,%xmm0
call   1030 <FABS@plt>
movapd 0x60(%rsp),%xmm2
movsd  0xd7b(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  %xmm2,%xmm0
mulsd  0x58(%rsp),%xmm2
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm2
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
subsd  %xmm1,%xmm2
movapd 0x10(%rsp),%xmm1
unpcklpd %xmm0,%xmm2
mulpd  0x20(%rsp),%xmm2
movapd %xmm2,%xmm0
addpd  %xmm1,%xmm0
add    $0x4,%r15
cmp    %r15,0x50(%rsp)
jne    1220 <coreGTRCAT_BINARY+0xe0>
addpd  %xmm1,%xmm2
mov    0x30(%rsp),%r15
jmp    12e3 <coreGTRCAT_BINARY+0x1a3>
xorpd  %xmm2,%xmm2
mov    0x48(%rsp),%rax
movhpd %xmm2,(%rax)
movlpd %xmm2,(%r15)
mov    %r14,%rdi
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <rax_free@plt>

LLVM IR (-O0):
define void @coreGTRCAT_BINARY(i32 %0, i32 %1, double* %2, double* %3, double* %4, double* %5, double* %6, i32* %7, double %8, i32* %9) {
%11 = alloca i32
%12 = alloca i32
%13 = alloca double*
%14 = alloca double*
%15 = alloca double*
%16 = alloca double*
%17 = alloca double*
%18 = alloca i32*
%19 = alloca double
%20 = alloca i32*
%21 = alloca i32
%22 = alloca double*
%23 = alloca double*
%24 = alloca double
%25 = alloca double
%26 = alloca double
%27 = alloca double
%28 = alloca double
%29 = alloca double
%30 = alloca [2 x double]
%31 = alloca double
%32 = alloca double
%33 = alloca double
%34 = 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 double* %5, double** %16
store double* %6, double** %17
store i32* %7, i32** %18
store double %8, double* %19
store i32* %9, i32** %20
store double 0.000000e+00, double* %28
store double 0.000000e+00, double* %29
%35 = load double*, double** %17
%36 = getelementptr inbounds double, double* %35, i64 0
%37 = load double, double* %36
%38 = getelementptr inbounds [2 x double], [2 x double]* %30, i64 0, i64 0
store double %37, double* %38
%39 = load double*, double** %17
%40 = getelementptr inbounds double, double* %39, i64 0
%41 = load double, double* %40
%42 = load double*, double** %17
%43 = getelementptr inbounds double, double* %42, i64 0
%44 = load double, double* %43
%45 = fmul double %41, %44
%46 = getelementptr inbounds [2 x double], [2 x double]* %30, i64 0, i64 1
store double %45, double* %46
%47 = load i32, i32* %12
%48 = sext i32 %47 to i64
%49 = mul i64 %48, 8
%50 = trunc i64 %49 to i32
%51 = call i64 @rax_malloc(i32 %50)
%52 = inttoptr i64 %51 to double*
store double* %52, double** %23
store double* %52, double** %22
%53 = getelementptr inbounds [2 x double], [2 x double]* %30, i64 0, i64 0
%54 = load double, double* %53
%55 = load double, double* %19
%56 = fmul double %54, %55
store double %56, double* %31
store i32 0, i32* %21
br label %57
57: ; preds = %74, %10
%58 = load i32, i32* %21
%59 = load i32, i32* %12
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %77
61: ; preds = %57
%62 = load double, double* %31
%63 = load double*, double** %16
%64 = load i32, i32* %21
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
%67 = load double, double* %66
%68 = fmul double %62, %67
%69 = call double @exp(double %68)
%70 = load double*, double** %22
%71 = load i32, i32* %21
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
store double %69, double* %73
br label %74
74: ; preds = %61
%75 = load i32, i32* %21
%76 = add nsw i32 %75, 1
store i32 %76, i32* %21
br label %57
77: ; preds = %57
store i32 0, i32* %21
br label %78
78: ; preds = %166, %77
%79 = load i32, i32* %21
%80 = load i32, i32* %11
%81 = icmp slt i32 %79, %80
br i1 %81, label %82, label %169
82: ; preds = %78
%83 = load double*, double** %16
%84 = load i32*, i32** %18
%85 = load i32, i32* %21
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i32, i32* %84, i64 %86
%88 = load i32, i32* %87
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds double, double* %83, i64 %89
%91 = load double, double* %90
store double %91, double* %32
%92 = load double, double* %32
%93 = load i32*, i32** %20
%94 = load i32, i32* %21
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i32, i32* %93, i64 %95
%97 = load i32, i32* %96
%98 = sitofp i32 %97 to double
%99 = fmul double %92, %98
store double %99, double* %33
%100 = load double, double* %32
%101 = load double, double* %32
%102 = fmul double %100, %101
%103 = load i32*, i32** %20
%104 = load i32, i32* %21
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i32, i32* %103, i64 %105
%107 = load i32, i32* %106
%108 = sitofp i32 %107 to double
%109 = fmul double %102, %108
store double %109, double* %34
%110 = load double*, double** %23
%111 = load i32*, i32** %18
%112 = load i32, i32* %21
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds i32, i32* %111, i64 %113
%115 = load i32, i32* %114
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds double, double* %110, i64 %116
store double* %117, double** %22
%118 = load double*, double** %13
%119 = load i32, i32* %21
%120 = mul nsw i32 2, %119
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds double, double* %118, i64 %121
%123 = load double, double* %122
store double %123, double* %25
%124 = load double*, double** %22
%125 = getelementptr inbounds double, double* %124, i64 0
%126 = load double, double* %125
%127 = load double*, double** %13
%128 = load i32, i32* %21
%129 = mul nsw i32 2, %128
%130 = add nsw i32 %129, 1
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds double, double* %127, i64 %131
%133 = load double, double* %132
%134 = fmul double %126, %133
store double %134, double* %24
%135 = load double, double* %25
%136 = fadd double %135, %134
store double %136, double* %25
%137 = load double, double* %25
%138 = call double @FABS(double %137)
%139 = fdiv double 1.000000e+00, %138
store double %139, double* %25
%140 = load double, double* %24
%141 = getelementptr inbounds [2 x double], [2 x double]* %30, i64 0, i64 0
%142 = load double, double* %141
%143 = fmul double %140, %142
store double %143, double* %26
%144 = load double, double* %24
%145 = getelementptr inbounds [2 x double], [2 x double]* %30, i64 0, i64 1
%146 = load double, double* %145
%147 = fmul double %144, %146
store double %147, double* %27
%148 = load double, double* %25
%149 = load double, double* %26
%150 = fmul double %149, %148
store double %150, double* %26
%151 = load double, double* %25
%152 = load double, double* %27
%153 = fmul double %152, %151
store double %153, double* %27
%154 = load double, double* %33
%155 = load double, double* %26
%156 = load double, double* %28
%157 = call double @llvm.fmuladd.f64(double %154, double %155, double %156)
store double %157, double* %28
%158 = load double, double* %34
%159 = load double, double* %27
%160 = load double, double* %26
%161 = load double, double* %26
%162 = fneg double %160
%163 = call double @llvm.fmuladd.f64(double %162, double %161, double %159)
%164 = load double, double* %29
%165 = call double @llvm.fmuladd.f64(double %158, double %163, double %164)
store double %165, double* %29
br label %166
166: ; preds = %82
%167 = load i32, i32* %21
%168 = add nsw i32 %167, 1
store i32 %168, i32* %21
br label %78
169: ; preds = %78
%170 = load double, double* %28
%171 = load double*, double** %14
store volatile double %170, double* %171
%172 = load double, double* %29
%173 = load double*, double** %15
store volatile double %172, double* %173
%174 = load double*, double** %23
%175 = call i32 @rax_free(double* %174)
ret void
}

LLVM IR (-O2):
define void @coreGTRCAT_BINARY(i32 %0, i32 %1, double* nocapture %2, double* %3, double* %4, double* nocapture %5, double* nocapture %6, i32* nocapture %7, double %8, i32* nocapture %9) {
%11 = load double, double* %6
%12 = fmul double %11, %11
%13 = shl i32 %1, 3
%14 = tail call i64 @rax_malloc(i32 %13)
%15 = inttoptr i64 %14 to double*
%16 = fmul double %11, %8
%17 = icmp sgt i32 %1, 0
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = zext i32 %1 to i64
br label %24
20: ; preds = %24, %10
%21 = icmp sgt i32 %0, 0
br i1 %21, label %22, label %75
22: ; preds = %20
%23 = zext i32 %0 to i64
br label %33
24: ; preds = %18, %24
%25 = phi i64 [ 0, %18 ], [ %31, %24 ]
%26 = getelementptr inbounds double, double* %5, i64 %25
%27 = load double, double* %26
%28 = fmul double %16, %27
%29 = tail call double @exp(double %28)
%30 = getelementptr inbounds double, double* %15, i64 %25
store double %29, double* %30
%31 = add nuw nsw i64 %25, 1
%32 = icmp eq i64 %31, %19
br i1 %32, label %20, label %24
33: ; preds = %22, %33
%34 = phi i64 [ 0, %22 ], [ %71, %33 ]
%35 = phi <2 x double> [ zeroinitializer, %22 ], [ %70, %33 ]
%36 = getelementptr inbounds i32, i32* %7, i64 %34
%37 = load i32, i32* %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %5, i64 %38
%40 = load double, double* %39
%41 = getelementptr inbounds i32, i32* %9, i64 %34
%42 = load i32, i32* %41
%43 = sitofp i32 %42 to double
%44 = fmul double %40, %40
%45 = insertelement <2 x double> poison, double %44, i64 0
%46 = insertelement <2 x double> %45, double %40, i64 1
%47 = insertelement <2 x double> poison, double %43, i64 0
%48 = shufflevector <2 x double> %47, <2 x double> poison, <2 x i32> zeroinitializer
%49 = fmul <2 x double> %46, %48
%50 = getelementptr inbounds double, double* %15, i64 %38
%51 = shl nuw nsw i64 %34, 1
%52 = getelementptr inbounds double, double* %2, i64 %51
%53 = load double, double* %52
%54 = load double, double* %50
%55 = or i64 %51, 1
%56 = getelementptr inbounds double, double* %2, i64 %55
%57 = load double, double* %56
%58 = fmul double %54, %57
%59 = fadd double %53, %58
%60 = tail call double @FABS(double %59)
%61 = fdiv double 1.000000e+00, %60
%62 = fmul double %11, %58
%63 = fmul double %12, %58
%64 = fmul double %62, %61
%65 = fmul double %63, %61
%66 = fneg double %64
%67 = tail call double @llvm.fmuladd.f64(double %66, double %64, double %65)
%68 = insertelement <2 x double> poison, double %67, i64 0
%69 = insertelement <2 x double> %68, double %64, i64 1
%70 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %49, <2 x double> %69, <2 x double> %35)
%71 = add nuw nsw i64 %34, 1
%72 = icmp eq i64 %71, %23
br i1 %72, label %73, label %33
73: ; preds = %33
%74 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %49, <2 x double> %69, <2 x double> %35)
br label %75
75: ; preds = %73, %20
%76 = phi <2 x double> [ zeroinitializer, %20 ], [ %74, %73 ]
%77 = extractelement <2 x double> %76, i64 1
store volatile double %77, double* %3
%78 = extractelement <2 x double> %76, i64 0
store volatile double %78, double* %4
%79 = tail call i32 @rax_free(double* %15)
ret void
}