#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*/ d_zeros(double **, int, int);
int /*<<< orphan*/ dgemm_nn_3l(int, int, int, double *, int, double *, int,
                               double *, int);
int /*<<< orphan*/ dmcopy(int, int, double *, int, double *, int);
int /*<<< orphan*/ dscal_3l(int, double, double *);
int /*<<< orphan*/ free(double *);
double frexp(double, int *);
double onenorm(int, int, double *);
int /*<<< orphan*/ padeapprox(int, int, double *);
double pow(int, int);
void expm(int row, double *A) {
  int i;
  int m_vals[] = {3, 5, 7, 9, 13};
  double theta[] = {0.01495585217958292, 0.2539398330063230, 0.9504178996162932,
                    2.097847961257068, 5.371920351148152};
  int lentheta = 5;
  double normA = onenorm(row, row, A);
  if (normA <= theta[4]) {
    for (i = 0; i < lentheta; i++) {
      if (normA <= theta[i]) {
        padeapprox(m_vals[i], row, A);
        break;
      }
    }
  } else {
    int s;
    double t = frexp(normA / (theta[4]), &s);
    s = s - (t == 0.5);
    t = pow(2, -s);
    int row2 = row * row;
    dscal_3l(row2, t, A);
    padeapprox(m_vals[4], row, A);
    double *temp;
    d_zeros(&temp, row, row);
    for (i = 0; i < s; i++) {
      dgemm_nn_3l(row, row, row, A, row, A, row, temp, row);
      dmcopy(row, row, temp, row, A, row);
    }
    free(temp);
  }
}


x86 assembly (clang, -O0):
<expm>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe74(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe72(%rip),%eax
mov    %eax,-0x20(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1080 <memset@plt>
movsd  0xe37(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xe22(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xe0d(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xdf8(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xde3(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x5,-0x64(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1070 <onenorm@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     12ae <expm+0x10e>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    12a9 <expm+0x109>
movsd  -0x70(%rbp),%xmm1
movslq -0x14(%rbp),%rax
movsd  -0x60(%rbp,%rax,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1296 <expm+0xf6>
movslq -0x14(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1060 <padeapprox@plt>
jmp    12a9 <expm+0x109>
jmp    129b <expm+0xfb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1258 <expm+0xb8>
jmp    13c2 <expm+0x222>
movsd  -0x70(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
lea    -0x74(%rbp),%rdi
call   1090 <frexp@plt>
movsd  %xmm0,-0x80(%rbp)
mov    -0x74(%rbp),%eax
movsd  -0x80(%rbp),%xmm0
movsd  0xd52(%rip),%xmm1
ucomisd %xmm1,%xmm0
sete   %cl
setnp  %dl
and    %dl,%cl
and    $0x1,%cl
movzbl %cl,%ecx
sub    %ecx,%eax
mov    %eax,-0x74(%rbp)
xor    %esi,%esi
sub    -0x74(%rbp),%esi
mov    $0x2,%edi
call   10b0 <pow@plt>
movsd  %xmm0,-0x80(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x4(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%edi
movsd  -0x80(%rbp),%xmm0
mov    -0x10(%rbp),%rsi
call   10c0 <dscal_3l@plt>
mov    -0x20(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1060 <padeapprox@plt>
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    -0x90(%rbp),%rdi
call   1030 <d_zeros@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x74(%rbp),%eax
jge    13b6 <expm+0x216>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    -0x4(%rbp),%r8d
mov    -0x10(%rbp),%r9
mov    -0x4(%rbp),%r11d
mov    -0x90(%rbp),%r10
mov    -0x4(%rbp),%eax
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   10a0 <dgemm_nn_3l@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x90(%rbp),%rdx
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%r8
mov    -0x4(%rbp),%r9d
call   1050 <dmcopy@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    134a <expm+0x1aa>
mov    -0x90(%rbp),%rdi
call   1040 <free@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expm>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    %edi,%esi
mov    %r14,%rdx
call   1070 <onenorm@plt>
movsd  0xe50(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    1270 <expm+0xe0>
divsd  0xe3e(%rip),%xmm0
lea    0xc(%rsp),%rdi
call   1080 <frexp@plt>
cmpeqsd 0xe53(%rip),%xmm0
movq   %xmm0,%r15
add    0xc(%rsp),%r15d
mov    %r15d,%esi
neg    %esi
mov    $0x2,%edi
call   10a0 <pow@plt>
mov    %ebx,%edi
imul   %ebx,%edi
mov    %r14,%rsi
call   10b0 <dscal_3l@plt>
mov    $0xd,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1060 <padeapprox@plt>
mov    %rsp,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
call   1030 <d_zeros@plt>
test   %r15d,%r15d
jle    125d <expm+0xcd>
nopl   0x0(%rax,%rax,1)
sub    $0x8,%rsp
mov    %ebx,%edi
mov    %ebx,%esi
mov    %ebx,%edx
mov    %r14,%rcx
mov    %ebx,%r8d
mov    %r14,%r9
push   %rbx
push   0x10(%rsp)
push   %rbx
call   1090 <dgemm_nn_3l@plt>
add    $0x20,%rsp
mov    (%rsp),%rdx
mov    %ebx,%edi
mov    %ebx,%esi
mov    %ebx,%ecx
mov    %r14,%r8
mov    %ebx,%r9d
call   1050 <dmcopy@plt>
add    $0xffffffff,%r15d
jne    1220 <expm+0x90>
mov    (%rsp),%rdi
call   1040 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
movsd  0xd90(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    12be <expm+0x12e>
mov    $0x1,%eax
movsd  0xd85(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    12c0 <expm+0x130>
mov    $0x2,%eax
movsd  0xd7a(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    12c0 <expm+0x130>
mov    $0x3,%eax
movsd  0xd6f(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    12c0 <expm+0x130>
mov    $0x4,%eax
jmp    12c0 <expm+0x130>
xor    %eax,%eax
lea    0xd69(%rip),%rcx
mov    (%rcx,%rax,4),%edi
mov    %ebx,%esi
mov    %r14,%rdx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <padeapprox@plt>

LLVM IR (-O0):
@__const.expm.m_vals = [5 x i32] [i32 3, i32 5, i32 7, i32 9, i32 13]
define void @expm(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca i32
%6 = alloca [5 x i32]
%7 = alloca [5 x double]
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
%11 = alloca double
%12 = alloca i32
%13 = alloca double*
store i32 %0, i32* %3
store double* %1, double** %4
%14 = bitcast [5 x i32]* %6 to i8*
%15 = bitcast [5 x double]* %7 to i8*
%16 = bitcast i8* %15 to [5 x double]*
%17 = getelementptr inbounds [5 x double], [5 x double]* %16, i32 0, i32 0
store double 0x3F8EA12C7FF600EE, double* %17
%18 = getelementptr inbounds [5 x double], [5 x double]* %16, i32 0, i32 1
store double 0x3FD0408CDB7A7CA9, double* %18
%19 = getelementptr inbounds [5 x double], [5 x double]* %16, i32 0, i32 2
store double 0x3FEE69D2CC8C51D7, double* %19
%20 = getelementptr inbounds [5 x double], [5 x double]* %16, i32 0, i32 3
store double 0x4000C864830CA293, double* %20
%21 = getelementptr inbounds [5 x double], [5 x double]* %16, i32 0, i32 4
store double 0x40157CD8B04397B4, double* %21
store i32 5, i32* %8
%22 = load i32, i32* %3
%23 = load i32, i32* %3
%24 = load double*, double** %4
%25 = call double @onenorm(i32 %22, i32 %23, double* %24)
store double %25, double* %9
%26 = load double, double* %9
%27 = getelementptr inbounds [5 x double], [5 x double]* %7, i64 0, i64 4
%28 = load double, double* %27
%29 = fcmp ole double %26, %28
br i1 %29, label %30, label %55
30: ; preds = %2
store i32 0, i32* %5
br label %31
31: ; preds = %51, %30
%32 = load i32, i32* %5
%33 = load i32, i32* %8
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %54
35: ; preds = %31
%36 = load double, double* %9
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [5 x double], [5 x double]* %7, i64 0, i64 %38
%40 = load double, double* %39
%41 = fcmp ole double %36, %40
br i1 %41, label %42, label %50
42: ; preds = %35
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = load i32, i32* %3
%48 = load double*, double** %4
%49 = call i32 @padeapprox(i32 %46, i32 %47, double* %48)
br label %54
50: ; preds = %35
br label %51
51: ; preds = %50
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
br label %31
54: ; preds = %42, %31
br label %112
55: ; preds = %2
%56 = load double, double* %9
%57 = getelementptr inbounds [5 x double], [5 x double]* %7, i64 0, i64 4
%58 = load double, double* %57
%59 = fdiv double %56, %58
%60 = call double @frexp(double %59, i32* %10)
store double %60, double* %11
%61 = load i32, i32* %10
%62 = load double, double* %11
%63 = fcmp oeq double %62, 5.000000e-01
%64 = zext i1 %63 to i32
%65 = sub nsw i32 %61, %64
store i32 %65, i32* %10
%66 = load i32, i32* %10
%67 = sub nsw i32 0, %66
%68 = call double @pow(i32 2, i32 %67)
store double %68, double* %11
%69 = load i32, i32* %3
%70 = load i32, i32* %3
%71 = mul nsw i32 %69, %70
store i32 %71, i32* %12
%72 = load i32, i32* %12
%73 = load double, double* %11
%74 = load double*, double** %4
%75 = call i32 @dscal_3l(i32 %72, double %73, double* %74)
%76 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 4
%77 = load i32, i32* %76
%78 = load i32, i32* %3
%79 = load double*, double** %4
%80 = call i32 @padeapprox(i32 %77, i32 %78, double* %79)
%81 = load i32, i32* %3
%82 = load i32, i32* %3
%83 = call i32 @d_zeros(double** %13, i32 %81, i32 %82)
store i32 0, i32* %5
br label %84
84: ; preds = %106, %55
%85 = load i32, i32* %5
%86 = load i32, i32* %10
%87 = icmp slt i32 %85, %86
br i1 %87, label %88, label %109
88: ; preds = %84
%89 = load i32, i32* %3
%90 = load i32, i32* %3
%91 = load i32, i32* %3
%92 = load double*, double** %4
%93 = load i32, i32* %3
%94 = load double*, double** %4
%95 = load i32, i32* %3
%96 = load double*, double** %13
%97 = load i32, i32* %3
%98 = call i32 @dgemm_nn_3l(i32 %89, i32 %90, i32 %91, double* %92, i32 %93, double* %94, i32 %95, double* %96, i32 %97)
%99 = load i32, i32* %3
%100 = load i32, i32* %3
%101 = load double*, double** %13
%102 = load i32, i32* %3
%103 = load double*, double** %4
%104 = load i32, i32* %3
%105 = call i32 @dmcopy(i32 %99, i32 %100, double* %101, i32 %102, double* %103, i32 %104)
br label %106
106: ; preds = %88
%107 = load i32, i32* %5
%108 = add nsw i32 %107, 1
store i32 %108, i32* %5
br label %84
109: ; preds = %84
%110 = load double*, double** %13
%111 = call i32 @free(double* %110)
br label %112
112: ; preds = %109, %54
ret void
}

LLVM IR (-O2):
@__const.expm.m_vals = [5 x i32] [i32 3, i32 5, i32 7, i32 9, i32 13]
define void @expm(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = tail call double @onenorm(i32 %0, i32 %0, double* %1)
%6 = fcmp ugt double %5, 0x40157CD8B04397B4
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = fcmp ugt double %5, 0x3F8EA12C7FF600EE
br i1 %8, label %14, label %9
9: ; preds = %20, %18, %16, %14, %7
%10 = phi i64 [ 0, %7 ], [ 1, %14 ], [ 2, %16 ], [ 3, %18 ], [ 4, %20 ]
%11 = getelementptr inbounds [5 x i32], [5 x i32]* @__const.expm.m_vals, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = tail call i32 @padeapprox(i32 %12, i32 %0, double* %1)
br label %48
14: ; preds = %7
%15 = fcmp ugt double %5, 0x3FD0408CDB7A7CA9
br i1 %15, label %16, label %9
16: ; preds = %14
%17 = fcmp ugt double %5, 0x3FEE69D2CC8C51D7
br i1 %17, label %18, label %9
18: ; preds = %16
%19 = fcmp ugt double %5, 0x4000C864830CA293
br i1 %19, label %20, label %9
20: ; preds = %18
br label %9
21: ; preds = %2
%22 = bitcast i32* %3 to i8*
%23 = fdiv double %5, 0x40157CD8B04397B4
%24 = call double @frexp(double %23, i32* %3)
%25 = load i32, i32* %3
%26 = fcmp oeq double %24, 5.000000e-01
%27 = sext i1 %26 to i32
%28 = add i32 %25, %27
%29 = sub nsw i32 0, %28
%30 = tail call double @pow(i32 2, i32 %29)
%31 = mul nsw i32 %0, %0
%32 = tail call i32 @dscal_3l(i32 %31, double %30, double* %1)
%33 = tail call i32 @padeapprox(i32 13, i32 %0, double* %1)
%34 = bitcast double** %4 to i8*
%35 = call i32 @d_zeros(double** %4, i32 %0, i32 %0)
%36 = icmp sgt i32 %28, 0
br i1 %36, label %37, label %45
37: ; preds = %21, %37
%38 = phi i32 [ %43, %37 ], [ 0, %21 ]
%39 = load double*, double** %4
%40 = call i32 @dgemm_nn_3l(i32 %0, i32 %0, i32 %0, double* %1, i32 %0, double* %1, i32 %0, double* %39, i32 %0)
%41 = load double*, double** %4
%42 = call i32 @dmcopy(i32 %0, i32 %0, double* %41, i32 %0, double* %1, i32 %0)
%43 = add nuw nsw i32 %38, 1
%44 = icmp eq i32 %43, %28
br i1 %44, label %45, label %37
45: ; preds = %37, %21
%46 = load double*, double** %4
%47 = call i32 @free(double* %46)
br label %48
48: ; preds = %9, %45
ret void
}