#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 /*<<< orphan*/);
double *calloc(int, int);
int /*<<< orphan*/ free(double *);
double *malloc(int);
int /*<<< orphan*/ matexp_pade_fillmats(int, int, int, double *, double *,
                                        double *, double *);
int /*<<< orphan*/ memcpy(double *, double *, int);
int /*<<< orphan*/ p_matcopy(double *, int *, double *, int *);
int /*<<< orphan*/ p_mateye(double *, int *);
int /*<<< orphan*/ p_matprod(double *, int *, double *, int *, double *, int *);
int /*<<< orphan*/ pdims_(int *, int *, int *);
void p_matexp_pade(double *A, int *desca, int p, double *N, double *D) {
  int m, n;
  int i;
  int ldm[2], blacs[5];
  double *B, *C;
  pdims_(desca, ldm, blacs);
  m = ldm[0];
  n = ldm[1];
  m = m ? m : 1;
  n = n ? n : 1;
  B = calloc(m * n, sizeof(double));
  C = malloc(m * n * sizeof(double));
  assert(B != NULL);
  assert(C != NULL);
  p_matcopy(A, desca, C, desca);
  p_mateye(D, desca);
  memcpy(N, D, m * n * sizeof(double));
  for (i = 1; i <= p; i++) {
    if (i > 1)
      p_matprod(A, desca, B, desca, C, desca);
    matexp_pade_fillmats(m, n, i, N, D, B, C);
  }
  free(B);
  free(C);
}


x86 assembly (clang, -O0):
<p_matexp_pade>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1040 <pdims_@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11ed <p_matexp_pade+0x4d>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x64(%rbp)
jmp    11fa <p_matexp_pade+0x5a>
mov    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11fa <p_matexp_pade+0x5a>
mov    -0x64(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1215 <p_matexp_pade+0x75>
mov    -0x30(%rbp),%eax
mov    %eax,-0x68(%rbp)
jmp    1222 <p_matexp_pade+0x82>
mov    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1222 <p_matexp_pade+0x82>
mov    -0x68(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
imul   -0x30(%rbp),%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x2c(%rbp),%eax
imul   -0x30(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x58(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
cmpq   $0x0,-0x60(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    -0x10(%rbp),%rcx
call   10c0 <p_matcopy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <p_mateye@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%eax
imul   -0x30(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edx
call   1090 <memcpy@plt>
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1321 <p_matexp_pade+0x181>
cmpl   $0x1,-0x34(%rbp)
jle    12f1 <p_matexp_pade+0x151>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x60(%rbp),%r8
mov    -0x10(%rbp),%r9
call   1050 <p_matprod@plt>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x58(%rbp),%r9
mov    -0x60(%rbp),%rax
mov    %rax,(%rsp)
call   1060 <matexp_pade_fillmats@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12be <p_matexp_pade+0x11e>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p_matexp_pade>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r8,0x28(%rsp)
mov    %rcx,0x18(%rsp)
mov    %rdx,0x30(%rsp)
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0x20(%rsp),%rsi
lea    0x40(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <pdims_@plt>
mov    0x20(%rsp),%ecx
mov    0x24(%rsp),%r13d
test   %ecx,%ecx
mov    $0x1,%eax
cmove  %eax,%ecx
test   %r13d,%r13d
cmove  %eax,%r13d
mov    %r13d,0x10(%rsp)
mov    %ecx,0x14(%rsp)
imul   %ecx,%r13d
mov    %r13d,%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %rax,%r14
shl    $0x3,%r13d
mov    %r13d,%edi
call   10b0 <malloc@plt>
mov    %rax,%r15
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1080 <assert@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1080 <assert@plt>
mov    %r12,0x38(%rsp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
call   10c0 <p_matcopy@plt>
mov    0x28(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <p_mateye@plt>
mov    0x18(%rsp),%rdi
mov    %rbp,%r12
mov    %rbp,%rsi
mov    %r13d,%edx
call   1090 <memcpy@plt>
mov    0x30(%rsp),%rax
test   %eax,%eax
jle    12f8 <p_matexp_pade+0x158>
mov    %rax,%r13
mov    %r15,(%rsp)
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
mov    $0x1,%edx
mov    0x18(%rsp),%rcx
mov    %r12,%r8
mov    %r14,%r9
call   1060 <matexp_pade_fillmats@plt>
cmp    $0x1,%r13d
je     12f8 <p_matexp_pade+0x158>
neg    %r13d
mov    $0x2,%ebp
nopl   0x0(%rax,%rax,1)
mov    0x38(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %r15,%r8
mov    %rbx,%r9
call   1050 <p_matprod@plt>
mov    %r15,(%rsp)
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
mov    %ebp,%edx
mov    0x18(%rsp),%rcx
mov    %r12,%r8
mov    %r14,%r9
call   1060 <matexp_pade_fillmats@plt>
lea    0x1(%r13,%rbp,1),%eax
mov    %ebp,%ecx
add    $0x1,%ecx
mov    %ecx,%ebp
cmp    $0x1,%eax
jne    12b0 <p_matexp_pade+0x110>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @p_matexp_pade(double* %0, i32* %1, i32 %2, double* %3, double* %4) {
%6 = alloca double*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [2 x i32]
%15 = alloca [5 x i32]
%16 = alloca double*
%17 = alloca double*
store double* %0, double** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store double* %3, double** %9
store double* %4, double** %10
%18 = load i32*, i32** %7
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 0
%20 = getelementptr inbounds [5 x i32], [5 x i32]* %15, i64 0, i64 0
%21 = call i32 @pdims_(i32* %18, i32* %19, i32* %20)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 0
%23 = load i32, i32* %22
store i32 %23, i32* %11
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 1
%25 = load i32, i32* %24
store i32 %25, i32* %12
%26 = load i32, i32* %11
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %5
%29 = load i32, i32* %11
br label %31
30: ; preds = %5
br label %31
31: ; preds = %30, %28
%32 = phi i32 [ %29, %28 ], [ 1, %30 ]
store i32 %32, i32* %11
%33 = load i32, i32* %12
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = load i32, i32* %12
br label %38
37: ; preds = %31
br label %38
38: ; preds = %37, %35
%39 = phi i32 [ %36, %35 ], [ 1, %37 ]
store i32 %39, i32* %12
%40 = load i32, i32* %11
%41 = load i32, i32* %12
%42 = mul nsw i32 %40, %41
%43 = call double* @calloc(i32 %42, i32 8)
store double* %43, double** %16
%44 = load i32, i32* %11
%45 = load i32, i32* %12
%46 = mul nsw i32 %44, %45
%47 = sext i32 %46 to i64
%48 = mul i64 %47, 8
%49 = trunc i64 %48 to i32
%50 = call double* @malloc(i32 %49)
store double* %50, double** %17
%51 = load double*, double** %16
%52 = icmp ne double* %51, null
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
%55 = load double*, double** %17
%56 = icmp ne double* %55, null
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
%59 = load double*, double** %6
%60 = load i32*, i32** %7
%61 = load double*, double** %17
%62 = load i32*, i32** %7
%63 = call i32 @p_matcopy(double* %59, i32* %60, double* %61, i32* %62)
%64 = load double*, double** %10
%65 = load i32*, i32** %7
%66 = call i32 @p_mateye(double* %64, i32* %65)
%67 = load double*, double** %9
%68 = load double*, double** %10
%69 = load i32, i32* %11
%70 = load i32, i32* %12
%71 = mul nsw i32 %69, %70
%72 = sext i32 %71 to i64
%73 = mul i64 %72, 8
%74 = trunc i64 %73 to i32
%75 = call i32 @memcpy(double* %67, double* %68, i32 %74)
store i32 1, i32* %13
br label %76
76: ; preds = %100, %38
%77 = load i32, i32* %13
%78 = load i32, i32* %8
%79 = icmp sle i32 %77, %78
br i1 %79, label %80, label %103
80: ; preds = %76
%81 = load i32, i32* %13
%82 = icmp sgt i32 %81, 1
br i1 %82, label %83, label %91
83: ; preds = %80
%84 = load double*, double** %6
%85 = load i32*, i32** %7
%86 = load double*, double** %16
%87 = load i32*, i32** %7
%88 = load double*, double** %17
%89 = load i32*, i32** %7
%90 = call i32 @p_matprod(double* %84, i32* %85, double* %86, i32* %87, double* %88, i32* %89)
br label %91
91: ; preds = %83, %80
%92 = load i32, i32* %11
%93 = load i32, i32* %12
%94 = load i32, i32* %13
%95 = load double*, double** %9
%96 = load double*, double** %10
%97 = load double*, double** %16
%98 = load double*, double** %17
%99 = call i32 @matexp_pade_fillmats(i32 %92, i32 %93, i32 %94, double* %95, double* %96, double* %97, double* %98)
br label %100
100: ; preds = %91
%101 = load i32, i32* %13
%102 = add nsw i32 %101, 1
store i32 %102, i32* %13
br label %76
103: ; preds = %76
%104 = load double*, double** %16
%105 = call i32 @free(double* %104)
%106 = load double*, double** %17
%107 = call i32 @free(double* %106)
ret void
}

LLVM IR (-O2):
define void @p_matexp_pade(double* %0, i32* %1, i32 %2, double* %3, double* %4) {
%6 = alloca [2 x i32]
%7 = alloca [5 x i32]
%8 = bitcast [2 x i32]* %6 to i8*
%9 = bitcast [5 x i32]* %7 to i8*
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%11 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 0
%12 = call i32 @pdims_(i32* %1, i32* %10, i32* %11)
%13 = load i32, i32* %10
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%15 = load i32, i32* %14
%16 = icmp eq i32 %13, 0
%17 = select i1 %16, i32 1, i32 %13
%18 = icmp eq i32 %15, 0
%19 = select i1 %18, i32 1, i32 %15
%20 = mul nsw i32 %19, %17
%21 = call double* @calloc(i32 %20, i32 8)
%22 = shl i32 %20, 3
%23 = call double* @malloc(i32 %22)
%24 = icmp ne double* %21, null
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = icmp ne double* %23, null
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = call i32 @p_matcopy(double* %0, i32* %1, double* %23, i32* %1)
%31 = call i32 @p_mateye(double* %4, i32* %1)
%32 = call i32 @memcpy(double* %3, double* %4, i32 %22)
%33 = icmp slt i32 %2, 1
br i1 %33, label %43, label %34
34: ; preds = %5
%35 = call i32 @matexp_pade_fillmats(i32 %17, i32 %19, i32 1, double* %3, double* %4, double* %21, double* %23)
%36 = icmp eq i32 %2, 1
br i1 %36, label %43, label %37
37: ; preds = %34, %37
%38 = phi i32 [ %41, %37 ], [ 2, %34 ]
%39 = call i32 @p_matprod(double* %0, i32* %1, double* %21, i32* %1, double* %23, i32* %1)
%40 = call i32 @matexp_pade_fillmats(i32 %17, i32 %19, i32 %38, double* %3, double* %4, double* %21, double* %23)
%41 = add nuw i32 %38, 1
%42 = icmp eq i32 %38, %2
br i1 %42, label %43, label %37
43: ; preds = %37, %34, %5
%44 = call i32 @free(double* %21)
%45 = call i32 @free(double* %23)
ret void
}