#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 */
int /*<<< orphan*/ assert(int);
double exp(double);
double log(double);
void calcDiagptableFlex_LG4(double z, int numberOfCategories, double *rptr,
                            double *EIGN[4], double *diagptable,
                            const int numStates) {
  int i, l;
  double lz;
  assert(numStates <= 64);
  if (z < 1.0E-15)
    lz = log(1.0E-15);
  else
    lz = log(z);
  for (i = 0; i < numberOfCategories; i++) {
    diagptable[i * numStates] = 1.0;
    for (l = 1; l < numStates; l++)
      diagptable[i * numStates + l] = exp(rptr[i] * EIGN[i][l - 1] * lz);
  }
}


x86 assembly (clang, -O0):
<calcDiagptableFlex_LG4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
cmpl   $0x40,-0x2c(%rbp)
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movsd  0xe97(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    118b <calcDiagptableFlex_LG4+0x5b>
movsd  0xe84(%rip),%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x40(%rbp)
jmp    119a <calcDiagptableFlex_LG4+0x6a>
movsd  -0x8(%rbp),%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1243 <calcDiagptableFlex_LG4+0x113>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%ecx
imul   -0x2c(%rbp),%ecx
movslq %ecx,%rcx
movsd  0xe45(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1230 <calcDiagptableFlex_LG4+0x100>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm0
mulsd  -0x40(%rbp),%xmm0
call   1040 <exp@plt>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%ecx
imul   -0x2c(%rbp),%ecx
add    -0x34(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11cf <calcDiagptableFlex_LG4+0x9f>
jmp    1235 <calcDiagptableFlex_LG4+0x105>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11a1 <calcDiagptableFlex_LG4+0x71>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcDiagptableFlex_LG4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,0x18(%rsp)
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r12d
movsd  %xmm0,0x10(%rsp)
xor    %edi,%edi
mov    %r8d,0xc(%rsp)
cmp    $0x41,%r8d
setl   %dil
call   1030 <assert@plt>
movsd  0xe9a(%rip),%xmm0
movsd  0x10(%rsp),%xmm1
ucomisd %xmm1,%xmm0
jbe    118c <calcDiagptableFlex_LG4+0x5c>
movsd  0xe7e(%rip),%xmm1
test   %r12d,%r12d
jg     11a2 <calcDiagptableFlex_LG4+0x72>
jmp    1251 <calcDiagptableFlex_LG4+0x121>
movapd %xmm1,%xmm0
call   1050 <log@plt>
movapd %xmm0,%xmm1
test   %r12d,%r12d
jle    1251 <calcDiagptableFlex_LG4+0x121>
mov    0xc(%rsp),%eax
movslq %eax,%rcx
mov    %r12d,%edx
mov    %rdx,0x28(%rsp)
mov    %eax,%r14d
mov    0x18(%rsp),%rax
lea    0x8(%rax),%r15
mov    %rcx,0x30(%rsp)
lea    0x0(,%rcx,8),%rax
mov    %rax,0x20(%rsp)
add    $0xffffffffffffffff,%r14
xor    %r13d,%r13d
movsd  %xmm1,0x10(%rsp)
jmp    11f0 <calcDiagptableFlex_LG4+0xc0>
xchg   %ax,%ax
add    $0x1,%r13
add    0x20(%rsp),%r15
cmp    0x28(%rsp),%r13
je     1251 <calcDiagptableFlex_LG4+0x121>
mov    %r13,%rax
imul   0x30(%rsp),%rax
mov    0x18(%rsp),%rcx
movabs $0x3ff0000000000000,%rdx
mov    %rdx,(%rcx,%rax,8)
cmpl   $0x2,0xc(%rsp)
jl     11e0 <calcDiagptableFlex_LG4+0xb0>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
movsd  0x0(%rbp,%r13,8),%xmm0
mov    (%rbx,%r13,8),%rax
mulsd  (%rax,%r12,8),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <exp@plt>
movsd  0x10(%rsp),%xmm1
movsd  %xmm0,(%r15,%r12,8)
add    $0x1,%r12
cmp    %r12,%r14
jne    1220 <calcDiagptableFlex_LG4+0xf0>
jmp    11e0 <calcDiagptableFlex_LG4+0xb0>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @calcDiagptableFlex_LG4(double %0, i32 %1, double* nocapture %2, double** nocapture %3, double* nocapture writeonly %4, i32 %5) {
%7 = icmp slt i32 %5, 65
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = fcmp olt double %0, 1.000000e-15
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = tail call double @log(double %0)
br label %13
13: ; preds = %6, %11
%14 = phi double [ %12, %11 ], [ 0xC04144F69FF9FFC4, %6 ]
%15 = icmp sgt i32 %1, 0
br i1 %15, label %16, label %45
16: ; preds = %13
%17 = icmp sgt i32 %5, 1
%18 = sext i32 %5 to i64
%19 = zext i32 %1 to i64
%20 = zext i32 %5 to i64
br label %21
21: ; preds = %16, %42
%22 = phi i64 [ 0, %16 ], [ %43, %42 ]
%23 = mul nsw i64 %22, %18
%24 = getelementptr inbounds double, double* %4, i64 %23
store double 1.000000e+00, double* %24
br i1 %17, label %25, label %42
25: ; preds = %21
%26 = getelementptr inbounds double, double* %2, i64 %22
%27 = getelementptr inbounds double*, double** %3, i64 %22
br label %28
28: ; preds = %25, %28
%29 = phi i64 [ 1, %25 ], [ %40, %28 ]
%30 = load double, double* %26
%31 = load double*, double** %27
%32 = add nsw i64 %29, -1
%33 = getelementptr inbounds double, double* %31, i64 %32
%34 = load double, double* %33
%35 = fmul double %30, %34
%36 = fmul double %14, %35
%37 = tail call double @exp(double %36)
%38 = add nsw i64 %29, %23
%39 = getelementptr inbounds double, double* %4, i64 %38
store double %37, double* %39
%40 = add nuw nsw i64 %29, 1
%41 = icmp eq i64 %40, %20
br i1 %41, label %42, label %28
42: ; preds = %28, %21
%43 = add nuw nsw i64 %22, 1
%44 = icmp eq i64 %43, %19
br i1 %44, label %45, label %21
45: ; preds = %42, %13
ret void
}