#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 **cofactorMatrix(double **, int);
double matrixDeterminant(double **, int);
int /*<<< orphan*/ resetMartixDoubleZero(double **, int, int);
double **scalarMultiplyMatrix(double **, double, int, int);
double **trasposeMatrix(double **, int, int);
double **matrixInverse(double **A, int n) {
  double **B, **C;
  double invDet, det;
  det = matrixDeterminant(A, n);
  if (det != 0) {
    invDet = 1.0 / det;
    B = cofactorMatrix(A, n);
    C = trasposeMatrix(B, n, n);
    B = scalarMultiplyMatrix(C, invDet, n, n);
  } else {
    B = allocateDoubleMatrix(n, n);
    resetMartixDoubleZero(B, n, n);
  }
  return B;
}


x86 assembly (clang, -O0):
<matrixInverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <matrixDeterminant@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    119d <matrixInverse+0x3d>
jp     119d <matrixInverse+0x3d>
jmp    11ef <matrixInverse+0x8f>
movsd  0xe5b(%rip),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <cofactorMatrix@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1080 <trasposeMatrix@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movsd  -0x28(%rbp),%xmm0
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1070 <scalarMultiplyMatrix@plt>
mov    %rax,-0x18(%rbp)
jmp    120d <matrixInverse+0xad>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <allocateDoubleMatrix@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <resetMartixDoubleZero@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrixInverse>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
call   1050 <matrixDeterminant@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    117a <matrixInverse+0x1a>
jnp    11b9 <matrixInverse+0x59>
movsd  0xe7e(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <cofactorMatrix@plt>
mov    %rax,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
call   1080 <trasposeMatrix@plt>
mov    %rax,%rdi
movsd  (%rsp),%xmm0
mov    %ebx,%esi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <scalarMultiplyMatrix@plt>
mov    %ebx,%edi
mov    %ebx,%esi
call   1030 <allocateDoubleMatrix@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
call   1040 <resetMartixDoubleZero@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double** @matrixInverse(double** %0, i32 %1) {
%3 = alloca double**
%4 = alloca i32
%5 = alloca double**
%6 = alloca double**
%7 = alloca double
%8 = alloca double
store double** %0, double*** %3
store i32 %1, i32* %4
%9 = load double**, double*** %3
%10 = load i32, i32* %4
%11 = call double @matrixDeterminant(double** %9, i32 %10)
store double %11, double* %8
%12 = load double, double* %8
%13 = fcmp une double %12, 0.000000e+00
br i1 %13, label %14, label %29
14: ; preds = %2
%15 = load double, double* %8
%16 = fdiv double 1.000000e+00, %15
store double %16, double* %7
%17 = load double**, double*** %3
%18 = load i32, i32* %4
%19 = call double** @cofactorMatrix(double** %17, i32 %18)
store double** %19, double*** %5
%20 = load double**, double*** %5
%21 = load i32, i32* %4
%22 = load i32, i32* %4
%23 = call double** @trasposeMatrix(double** %20, i32 %21, i32 %22)
store double** %23, double*** %6
%24 = load double**, double*** %6
%25 = load double, double* %7
%26 = load i32, i32* %4
%27 = load i32, i32* %4
%28 = call double** @scalarMultiplyMatrix(double** %24, double %25, i32 %26, i32 %27)
store double** %28, double*** %5
br label %37
29: ; preds = %2
%30 = load i32, i32* %4
%31 = load i32, i32* %4
%32 = call double** @allocateDoubleMatrix(i32 %30, i32 %31)
store double** %32, double*** %5
%33 = load double**, double*** %5
%34 = load i32, i32* %4
%35 = load i32, i32* %4
%36 = call i32 @resetMartixDoubleZero(double** %33, i32 %34, i32 %35)
br label %37
37: ; preds = %29, %14
%38 = load double**, double*** %5
ret double** %38
}

LLVM IR (-O2):
define double** @matrixInverse(double** %0, i32 %1) {
%3 = tail call double @matrixDeterminant(double** %0, i32 %1)
%4 = fcmp une double %3, 0.000000e+00
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = fdiv double 1.000000e+00, %3
%7 = tail call double** @cofactorMatrix(double** %0, i32 %1)
%8 = tail call double** @trasposeMatrix(double** %7, i32 %1, i32 %1)
%9 = tail call double** @scalarMultiplyMatrix(double** %8, double %6, i32 %1, i32 %1)
br label %13
10: ; preds = %2
%11 = tail call double** @allocateDoubleMatrix(i32 %1, i32 %1)
%12 = tail call i32 @resetMartixDoubleZero(double** %11, i32 %1, i32 %1)
br label %13
13: ; preds = %10, %5
%14 = phi double** [ %9, %5 ], [ %11, %10 ]
ret double** %14
}