#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 exp(double const);
int /*<<< orphan*/ free(double *);
double log(double const);
scalar_t__ malloc(int);
void calcDiagptable(const double z, const int states,
                    const int numberOfCategories, const double *rptr,
                    const double *EIGN, double *diagptable) {
  int i, l;
  double lz, *lza = (double *)malloc(sizeof(double) * states);
  if (z < 1.0E-15)
    lz = log(1.0E-15);
  else
    lz = log(z);
  for (i = 0; i < states; i++)
    lza[i] = EIGN[i] * lz;
  for (i = 0; i < numberOfCategories; i++) {
    diagptable[i * states] = 1.0;
    for (l = 1; l < states; l++)
      diagptable[i * states + l] = exp(rptr[i] * lza[l]);
  }
  free(lza);
}


x86 assembly (clang, -O0):
<calcDiagptable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x40(%rbp)
movsd  0xe86(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    119c <calcDiagptable+0x5c>
movsd  0xe73(%rip),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x38(%rbp)
jmp    11ab <calcDiagptable+0x6b>
movsd  -0x8(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11eb <calcDiagptable+0xab>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x38(%rbp),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b2 <calcDiagptable+0x72>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1282 <calcDiagptable+0x142>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
movsd  0xdf4(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    126f <calcDiagptable+0x12f>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x30(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
call   1050 <exp@plt>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x30(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1220 <calcDiagptable+0xe0>
jmp    1274 <calcDiagptable+0x134>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11f2 <calcDiagptable+0xb2>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcDiagptable>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,%rbp
mov    %rdx,%r12
mov    %esi,%r14d
movsd  %xmm0,0x8(%rsp)
mov    %rdi,(%rsp)
lea    0x0(,%rdi,8),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movsd  0xe8b(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm0
jbe    1193 <calcDiagptable+0x53>
movsd  0xe6f(%rip),%xmm0
jmp    119c <calcDiagptable+0x5c>
movapd %xmm1,%xmm0
call   1060 <log@plt>
mov    (%rsp),%rax
mov    %eax,%r13d
test   %eax,%eax
jle    1316 <calcDiagptable+0x1d6>
cmpl   $0x4,(%rsp)
jb     11d2 <calcDiagptable+0x92>
lea    0x0(,%r13,8),%rax
add    %rbp,%rax
cmp    %rax,%rbx
jae    126d <calcDiagptable+0x12d>
lea    (%rbx,%r13,8),%rax
cmp    %rbp,%rax
jbe    126d <calcDiagptable+0x12d>
xor    %eax,%eax
mov    %rax,%rcx
not    %rcx
add    %r13,%rcx
mov    %r13,%rdx
and    $0x3,%rdx
je     1209 <calcDiagptable+0xc9>
cs nopw 0x0(%rax,%rax,1)
movsd  0x0(%rbp,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rax,8)
add    $0x1,%rax
add    $0xffffffffffffffff,%rdx
jne    11f0 <calcDiagptable+0xb0>
cmp    $0x3,%rcx
jb     1316 <calcDiagptable+0x1d6>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  0x0(%rbp,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rax,8)
movsd  0x8(%rbp,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rbx,%rax,8)
movsd  0x10(%rbp,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rbx,%rax,8)
movsd  0x18(%rbp,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rbx,%rax,8)
add    $0x4,%rax
cmp    %rax,%r13
jne    1220 <calcDiagptable+0xe0>
jmp    1316 <calcDiagptable+0x1d6>
mov    %r13d,%eax
and    $0xfffffffc,%eax
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x4(%rax),%rcx
mov    %rcx,%rdx
shr    $0x2,%rdx
add    $0x1,%rdx
test   %rcx,%rcx
je     13c9 <calcDiagptable+0x289>
mov    %rdx,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %ecx,%ecx
nopl   0x0(%rax)
movupd 0x0(%rbp,%rcx,8),%xmm2
movupd 0x10(%rbp,%rcx,8),%xmm3
mulpd  %xmm1,%xmm2
mulpd  %xmm1,%xmm3
movupd %xmm2,(%rbx,%rcx,8)
movupd %xmm3,0x10(%rbx,%rcx,8)
movupd 0x20(%rbp,%rcx,8),%xmm2
movupd 0x30(%rbp,%rcx,8),%xmm3
mulpd  %xmm1,%xmm2
mulpd  %xmm1,%xmm3
movupd %xmm2,0x20(%rbx,%rcx,8)
movupd %xmm3,0x30(%rbx,%rcx,8)
add    $0x8,%rcx
add    $0xfffffffffffffffe,%rsi
jne    12a0 <calcDiagptable+0x160>
test   $0x1,%dl
je     130d <calcDiagptable+0x1cd>
movupd 0x0(%rbp,%rcx,8),%xmm2
movupd 0x10(%rbp,%rcx,8),%xmm3
mulpd  %xmm1,%xmm2
mulpd  %xmm1,%xmm3
movupd %xmm2,(%rbx,%rcx,8)
movupd %xmm3,0x10(%rbx,%rcx,8)
cmp    %r13,%rax
jne    11d4 <calcDiagptable+0x94>
test   %r14d,%r14d
jle    13b3 <calcDiagptable+0x273>
movslq (%rsp),%rax
mov    %r14d,%ecx
mov    %rcx,0x20(%rsp)
mov    %rax,0x8(%rsp)
lea    0x0(,%rax,8),%rax
mov    %rax,0x18(%rsp)
xor    %r14d,%r14d
mov    0x10(%rsp),%rbp
jmp    1360 <calcDiagptable+0x220>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
add    0x18(%rsp),%rbp
cmp    0x20(%rsp),%r14
je     13b3 <calcDiagptable+0x273>
mov    %r14,%rax
imul   0x8(%rsp),%rax
mov    0x10(%rsp),%rcx
movabs $0x3ff0000000000000,%rdx
mov    %rdx,(%rcx,%rax,8)
cmpl   $0x2,(%rsp)
jl     1350 <calcDiagptable+0x210>
mov    $0x1,%r15d
nopl   0x0(%rax,%rax,1)
movsd  (%r12,%r14,8),%xmm0
mulsd  (%rbx,%r15,8),%xmm0
call   1050 <exp@plt>
movsd  %xmm0,0x0(%rbp,%r15,8)
add    $0x1,%r15
cmp    %r15,%r13
jne    1390 <calcDiagptable+0x250>
jmp    1350 <calcDiagptable+0x210>
mov    %rbx,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
xor    %ecx,%ecx
test   $0x1,%dl
jne    12ee <calcDiagptable+0x1ae>
jmp    130d <calcDiagptable+0x1cd>

LLVM IR (-O0):
define void @calcDiagptable(double %0, i32 %1, i32 %2, double* %3, double* %4, double* %5) {
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double*
store double %0, double* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store double* %3, double** %10
store double* %4, double** %11
store double* %5, double** %12
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = mul i64 8, %18
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to double*
store double* %22, double** %16
%23 = load double, double* %7
%24 = fcmp olt double %23, 1.000000e-15
br i1 %24, label %25, label %27
25: ; preds = %6
%26 = call double @log(double 1.000000e-15)
store double %26, double* %15
br label %30
27: ; preds = %6
%28 = load double, double* %7
%29 = call double @log(double %28)
store double %29, double* %15
br label %30
30: ; preds = %27, %25
store i32 0, i32* %13
br label %31
31: ; preds = %47, %30
%32 = load i32, i32* %13
%33 = load i32, i32* %8
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = load double*, double** %11
%37 = load i32, i32* %13
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
%40 = load double, double* %39
%41 = load double, double* %15
%42 = fmul double %40, %41
%43 = load double*, double** %16
%44 = load i32, i32* %13
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
store double %42, double* %46
br label %47
47: ; preds = %35
%48 = load i32, i32* %13
%49 = add nsw i32 %48, 1
store i32 %49, i32* %13
br label %31
50: ; preds = %31
store i32 0, i32* %13
br label %51
51: ; preds = %91, %50
%52 = load i32, i32* %13
%53 = load i32, i32* %9
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %94
55: ; preds = %51
%56 = load double*, double** %12
%57 = load i32, i32* %13
%58 = load i32, i32* %8
%59 = mul nsw i32 %57, %58
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %56, i64 %60
store double 1.000000e+00, double* %61
store i32 1, i32* %14
br label %62
62: ; preds = %87, %55
%63 = load i32, i32* %14
%64 = load i32, i32* %8
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %90
66: ; preds = %62
%67 = load double*, double** %10
%68 = load i32, i32* %13
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds double, double* %67, i64 %69
%71 = load double, double* %70
%72 = load double*, double** %16
%73 = load i32, i32* %14
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds double, double* %72, i64 %74
%76 = load double, double* %75
%77 = fmul double %71, %76
%78 = call double @exp(double %77)
%79 = load double*, double** %12
%80 = load i32, i32* %13
%81 = load i32, i32* %8
%82 = mul nsw i32 %80, %81
%83 = load i32, i32* %14
%84 = add nsw i32 %82, %83
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds double, double* %79, i64 %85
store double %78, double* %86
br label %87
87: ; preds = %66
%88 = load i32, i32* %14
%89 = add nsw i32 %88, 1
store i32 %89, i32* %14
br label %62
90: ; preds = %62
br label %91
91: ; preds = %90
%92 = load i32, i32* %13
%93 = add nsw i32 %92, 1
store i32 %93, i32* %13
br label %51
94: ; preds = %51
%95 = load double*, double** %16
%96 = call i32 @free(double* %95)
ret void
}

LLVM IR (-O2):
define void @calcDiagptable(double %0, i32 %1, i32 %2, double* nocapture %3, double* nocapture %4, double* nocapture writeonly %5) {
%7 = shl i32 %1, 3
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double*
%10 = inttoptr i64 %8 to i8*
%11 = fcmp olt double %0, 1.000000e-15
br i1 %11, label %14, label %12
12: ; preds = %6
%13 = tail call double @log(double %0)
br label %14
14: ; preds = %6, %12
%15 = phi double [ %13, %12 ], [ 0xC04144F69FF9FFC4, %6 ]
%16 = icmp sgt i32 %1, 0
br i1 %16, label %17, label %108
17: ; preds = %14
%18 = zext i32 %1 to i64
%19 = icmp ult i32 %1, 4
br i1 %19, label %89, label %20
20: ; preds = %17
%21 = getelementptr double, double* %9, i64 %18
%22 = getelementptr double, double* %4, i64 %18
%23 = bitcast double* %22 to i8*
%24 = icmp ult i8* %10, %23
%25 = icmp ugt double* %21, %4
%26 = and i1 %24, %25
br i1 %26, label %89, label %27
27: ; preds = %20
%28 = and i64 %18, 4294967292
%29 = insertelement <2 x double> poison, double %15, i64 0
%30 = shufflevector <2 x double> %29, <2 x double> poison, <2 x i32> zeroinitializer
%31 = insertelement <2 x double> poison, double %15, i64 0
%32 = shufflevector <2 x double> %31, <2 x double> poison, <2 x i32> zeroinitializer
%33 = add nsw i64 %28, -4
%34 = lshr exact i64 %33, 2
%35 = add nuw nsw i64 %34, 1
%36 = and i64 %35, 1
%37 = icmp eq i64 %33, 0
br i1 %37, label %71, label %38
38: ; preds = %27
%39 = and i64 %35, 9223372036854775806
br label %40
40: ; preds = %40, %38
%41 = phi i64 [ 0, %38 ], [ %68, %40 ]
%42 = phi i64 [ 0, %38 ], [ %69, %40 ]
%43 = getelementptr inbounds double, double* %4, i64 %41
%44 = bitcast double* %43 to <2 x double>*
%45 = load <2 x double>, <2 x double>* %44
%46 = getelementptr inbounds double, double* %43, i64 2
%47 = bitcast double* %46 to <2 x double>*
%48 = load <2 x double>, <2 x double>* %47
%49 = fmul <2 x double> %30, %45
%50 = fmul <2 x double> %32, %48
%51 = getelementptr inbounds double, double* %9, i64 %41
%52 = bitcast double* %51 to <2 x double>*
store <2 x double> %49, <2 x double>* %52
%53 = getelementptr inbounds double, double* %51, i64 2
%54 = bitcast double* %53 to <2 x double>*
store <2 x double> %50, <2 x double>* %54
%55 = or i64 %41, 4
%56 = getelementptr inbounds double, double* %4, i64 %55
%57 = bitcast double* %56 to <2 x double>*
%58 = load <2 x double>, <2 x double>* %57
%59 = getelementptr inbounds double, double* %56, i64 2
%60 = bitcast double* %59 to <2 x double>*
%61 = load <2 x double>, <2 x double>* %60
%62 = fmul <2 x double> %30, %58
%63 = fmul <2 x double> %32, %61
%64 = getelementptr inbounds double, double* %9, i64 %55
%65 = bitcast double* %64 to <2 x double>*
store <2 x double> %62, <2 x double>* %65
%66 = getelementptr inbounds double, double* %64, i64 2
%67 = bitcast double* %66 to <2 x double>*
store <2 x double> %63, <2 x double>* %67
%68 = add nuw i64 %41, 8
%69 = add i64 %42, 2
%70 = icmp eq i64 %69, %39
br i1 %70, label %71, label %40
71: ; preds = %40, %27
%72 = phi i64 [ 0, %27 ], [ %68, %40 ]
%73 = icmp eq i64 %36, 0
br i1 %73, label %87, label %74
74: ; preds = %71
%75 = getelementptr inbounds double, double* %4, i64 %72
%76 = bitcast double* %75 to <2 x double>*
%77 = load <2 x double>, <2 x double>* %76
%78 = getelementptr inbounds double, double* %75, i64 2
%79 = bitcast double* %78 to <2 x double>*
%80 = load <2 x double>, <2 x double>* %79
%81 = fmul <2 x double> %30, %77
%82 = fmul <2 x double> %32, %80
%83 = getelementptr inbounds double, double* %9, i64 %72
%84 = bitcast double* %83 to <2 x double>*
store <2 x double> %81, <2 x double>* %84
%85 = getelementptr inbounds double, double* %83, i64 2
%86 = bitcast double* %85 to <2 x double>*
store <2 x double> %82, <2 x double>* %86
br label %87
87: ; preds = %71, %74
%88 = icmp eq i64 %28, %18
br i1 %88, label %108, label %89
89: ; preds = %20, %17, %87
%90 = phi i64 [ 0, %20 ], [ 0, %17 ], [ %28, %87 ]
%91 = xor i64 %90, -1
%92 = add nsw i64 %91, %18
%93 = and i64 %18, 3
%94 = icmp eq i64 %93, 0
br i1 %94, label %105, label %95
95: ; preds = %89, %95
%96 = phi i64 [ %102, %95 ], [ %90, %89 ]
%97 = phi i64 [ %103, %95 ], [ 0, %89 ]
%98 = getelementptr inbounds double, double* %4, i64 %96
%99 = load double, double* %98
%100 = fmul double %15, %99
%101 = getelementptr inbounds double, double* %9, i64 %96
store double %100, double* %101
%102 = add nuw nsw i64 %96, 1
%103 = add i64 %97, 1
%104 = icmp eq i64 %103, %93
br i1 %104, label %105, label %95
105: ; preds = %95, %89
%106 = phi i64 [ %90, %89 ], [ %102, %95 ]
%107 = icmp ult i64 %92, 3
br i1 %107, label %108, label %115
108: ; preds = %105, %115, %87, %14
%109 = icmp sgt i32 %2, 0
br i1 %109, label %110, label %158
110: ; preds = %108
%111 = icmp sgt i32 %1, 1
%112 = sext i32 %1 to i64
%113 = zext i32 %2 to i64
%114 = zext i32 %1 to i64
br label %138
115: ; preds = %105, %115
%116 = phi i64 [ %136, %115 ], [ %106, %105 ]
%117 = getelementptr inbounds double, double* %4, i64 %116
%118 = load double, double* %117
%119 = fmul double %15, %118
%120 = getelementptr inbounds double, double* %9, i64 %116
store double %119, double* %120
%121 = add nuw nsw i64 %116, 1
%122 = getelementptr inbounds double, double* %4, i64 %121
%123 = load double, double* %122
%124 = fmul double %15, %123
%125 = getelementptr inbounds double, double* %9, i64 %121
store double %124, double* %125
%126 = add nuw nsw i64 %116, 2
%127 = getelementptr inbounds double, double* %4, i64 %126
%128 = load double, double* %127
%129 = fmul double %15, %128
%130 = getelementptr inbounds double, double* %9, i64 %126
store double %129, double* %130
%131 = add nuw nsw i64 %116, 3
%132 = getelementptr inbounds double, double* %4, i64 %131
%133 = load double, double* %132
%134 = fmul double %15, %133
%135 = getelementptr inbounds double, double* %9, i64 %131
store double %134, double* %135
%136 = add nuw nsw i64 %116, 4
%137 = icmp eq i64 %136, %18
br i1 %137, label %108, label %115
138: ; preds = %110, %155
%139 = phi i64 [ 0, %110 ], [ %156, %155 ]
%140 = mul nsw i64 %139, %112
%141 = getelementptr inbounds double, double* %5, i64 %140
store double 1.000000e+00, double* %141
br i1 %111, label %142, label %155
142: ; preds = %138
%143 = getelementptr inbounds double, double* %3, i64 %139
br label %144
144: ; preds = %142, %144
%145 = phi i64 [ 1, %142 ], [ %153, %144 ]
%146 = load double, double* %143
%147 = getelementptr inbounds double, double* %9, i64 %145
%148 = load double, double* %147
%149 = fmul double %146, %148
%150 = tail call double @exp(double %149)
%151 = add nsw i64 %145, %140
%152 = getelementptr inbounds double, double* %5, i64 %151
store double %150, double* %152
%153 = add nuw nsw i64 %145, 1
%154 = icmp eq i64 %153, %114
br i1 %154, label %155, label %144
155: ; preds = %144, %138
%156 = add nuw nsw i64 %139, 1
%157 = icmp eq i64 %156, %113
br i1 %157, label %158, label %138
158: ; preds = %155, %108
%159 = tail call i32 @free(double* %9)
ret void
}