#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 **allocateDoubleMatrix(int, int);
double matrixDeterminant(int /*<<< orphan*/, int);
int /*<<< orphan*/ minorMatrix(double **, int, int, int);
double pow(int, int);
double **cofactorMatrix(double **A, int n) {
  double **B;
  int i, j;
  B = allocateDoubleMatrix(n, n);
  for (j = 0; j < n; j++) {
    for (i = 0; i < n; i++) {
      B[j][i] =
          pow(-1, i + j) * matrixDeterminant(minorMatrix(A, n, i, j), n - 1);
    }
  }
  return B;
}


x86 assembly (clang, -O0):
<cofactorMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <allocateDoubleMatrix@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fa <cofactorMatrix+0xba>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e7 <cofactorMatrix+0xa7>
mov    -0x1c(%rbp),%esi
add    -0x20(%rbp),%esi
mov    $0xffffffff,%edi
call   1060 <pow@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1040 <minorMatrix@plt>
mov    %eax,%edi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
call   1050 <matrixDeterminant@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1178 <cofactorMatrix+0x38>
jmp    11ec <cofactorMatrix+0xac>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1165 <cofactorMatrix+0x25>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cofactorMatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
mov    %esi,%edi
call   1030 <allocateDoubleMatrix@plt>
mov    %rax,%r12
test   %r14d,%r14d
jle    11cb <cofactorMatrix+0x8b>
mov    %r14d,%r13d
add    $0xffffffff,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%rbx,%rbp,1),%esi
mov    $0xffffffff,%edi
call   1060 <pow@plt>
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
mov    %r13d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1040 <minorMatrix@plt>
mov    %eax,%edi
mov    %r14d,%esi
call   1050 <matrixDeterminant@plt>
mulsd  (%rsp),%xmm0
mov    (%r12,%rbp,8),%rax
movsd  %xmm0,(%rax,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1180 <cofactorMatrix+0x40>
add    $0x1,%rbp
cmp    %r13,%rbp
jne    1170 <cofactorMatrix+0x30>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double** @cofactorMatrix(double** %0, i32 %1) {
%3 = alloca double**
%4 = alloca i32
%5 = alloca double**
%6 = alloca i32
%7 = alloca i32
store double** %0, double*** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = load i32, i32* %4
%10 = call double** @allocateDoubleMatrix(i32 %8, i32 %9)
store double** %10, double*** %5
store i32 0, i32* %7
br label %11
11: ; preds = %46, %2
%12 = load i32, i32* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %49
15: ; preds = %11
store i32 0, i32* %6
br label %16
16: ; preds = %42, %15
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %45
20: ; preds = %16
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = add nsw i32 %21, %22
%24 = call double @pow(i32 -1, i32 %23)
%25 = load double**, double*** %3
%26 = load i32, i32* %4
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = call i32 @minorMatrix(double** %25, i32 %26, i32 %27, i32 %28)
%30 = load i32, i32* %4
%31 = sub nsw i32 %30, 1
%32 = call double @matrixDeterminant(i32 %29, i32 %31)
%33 = fmul double %24, %32
%34 = load double**, double*** %5
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double*, double** %34, i64 %36
%38 = load double*, double** %37
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
store double %33, double* %41
br label %42
42: ; preds = %20
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %16
45: ; preds = %16
br label %46
46: ; preds = %45
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %11
49: ; preds = %11
%50 = load double**, double*** %5
ret double** %50
}

LLVM IR (-O2):
define double** @cofactorMatrix(double** %0, i32 %1) {
%3 = tail call double** @allocateDoubleMatrix(i32 %1, i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %28
5: ; preds = %2
%6 = add nsw i32 %1, -1
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %25, %5
%9 = phi i64 [ 0, %5 ], [ %26, %25 ]
%10 = getelementptr inbounds double*, double** %3, i64 %9
%11 = trunc i64 %9 to i32
br label %12
12: ; preds = %8, %12
%13 = phi i64 [ 0, %8 ], [ %23, %12 ]
%14 = add nuw nsw i64 %13, %9
%15 = trunc i64 %14 to i32
%16 = tail call double @pow(i32 -1, i32 %15)
%17 = trunc i64 %13 to i32
%18 = tail call i32 @minorMatrix(double** %0, i32 %1, i32 %17, i32 %11)
%19 = tail call double @matrixDeterminant(i32 %18, i32 %6)
%20 = fmul double %16, %19
%21 = load double*, double** %10
%22 = getelementptr inbounds double, double* %21, i64 %13
store double %20, double* %22
%23 = add nuw nsw i64 %13, 1
%24 = icmp eq i64 %23, %7
br i1 %24, label %25, label %12
25: ; preds = %12
%26 = add nuw nsw i64 %9, 1
%27 = icmp eq i64 %26, %7
br i1 %27, label %28, label %8
28: ; preds = %25, %2
ret double** %3
}