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


x86 assembly (clang, -O0):
<matrixDeterminant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
call   1030 <allocateDoubleMatrix@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0xc(%rbp)
jne    11cf <matrixDeterminant+0x8f>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
movsd  0x8(%rax),%xmm2
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsd  0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mulsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1255 <matrixDeterminant+0x115>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1250 <matrixDeterminant+0x110>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
xor    %ecx,%ecx
call   1040 <minorMatrix@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%esi
mov    $0xffffffff,%edi
call   1060 <pow@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x10(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
call   1050 <matrixDeterminant@plt>
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11d6 <matrixDeterminant+0x96>
jmp    1255 <matrixDeterminant+0x115>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrixDeterminant>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r15
lea    -0x1(%rbx),%r14d
mov    %r14d,%edi
mov    %r14d,%esi
call   1030 <allocateDoubleMatrix@plt>
cmp    $0x2,%ebx
jne    1187 <matrixDeterminant+0x47>
mov    (%r15),%rax
mov    0x8(%r15),%rcx
movsd  (%rcx),%xmm1
mulsd  0x8(%rax),%xmm1
movsd  (%rax),%xmm0
mulsd  0x8(%rcx),%xmm0
subsd  %xmm1,%xmm0
jmp    1204 <matrixDeterminant+0xc4>
test   %ebx,%ebx
jle    1200 <matrixDeterminant+0xc0>
mov    %ebx,%r12d
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1040 <minorMatrix@plt>
mov    %rax,%rbp
mov    $0xffffffff,%edi
mov    %ebx,%esi
call   1060 <pow@plt>
mov    (%r15),%rax
mulsd  (%rax,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbp,%rdi
mov    %r14d,%esi
call   1050 <matrixDeterminant@plt>
mulsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11a0 <matrixDeterminant+0x60>
jmp    1204 <matrixDeterminant+0xc4>
xorpd  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @matrixDeterminant(double** %0, i32 %1) {
%3 = alloca double**
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca double**
store double** %0, double*** %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %6
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 1
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
%12 = call double** @allocateDoubleMatrix(i32 %9, i32 %11)
store double** %12, double*** %7
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %39
15: ; preds = %2
%16 = load double**, double*** %3
%17 = getelementptr inbounds double*, double** %16, i64 0
%18 = load double*, double** %17
%19 = getelementptr inbounds double, double* %18, i64 0
%20 = load double, double* %19
%21 = load double**, double*** %3
%22 = getelementptr inbounds double*, double** %21, i64 1
%23 = load double*, double** %22
%24 = getelementptr inbounds double, double* %23, i64 1
%25 = load double, double* %24
%26 = load double**, double*** %3
%27 = getelementptr inbounds double*, double** %26, i64 0
%28 = load double*, double** %27
%29 = getelementptr inbounds double, double* %28, i64 1
%30 = load double, double* %29
%31 = load double**, double*** %3
%32 = getelementptr inbounds double*, double** %31, i64 1
%33 = load double*, double** %32
%34 = getelementptr inbounds double, double* %33, i64 0
%35 = load double, double* %34
%36 = fmul double %30, %35
%37 = fneg double %36
%38 = call double @llvm.fmuladd.f64(double %20, double %25, double %37)
store double %38, double* %6
br label %69
39: ; preds = %2
store i32 0, i32* %5
br label %40
40: ; preds = %65, %39
%41 = load i32, i32* %5
%42 = load i32, i32* %4
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %68
44: ; preds = %40
%45 = load double**, double*** %3
%46 = load i32, i32* %4
%47 = load i32, i32* %5
%48 = call double** @minorMatrix(double** %45, i32 %46, i32 %47, i32 0)
store double** %48, double*** %7
%49 = load i32, i32* %5
%50 = call double @pow(i32 -1, i32 %49)
%51 = load double**, double*** %3
%52 = getelementptr inbounds double*, double** %51, i64 0
%53 = load double*, double** %52
%54 = load i32, i32* %5
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = load double, double* %56
%58 = fmul double %50, %57
%59 = load double**, double*** %7
%60 = load i32, i32* %4
%61 = sub nsw i32 %60, 1
%62 = call double @matrixDeterminant(double** %59, i32 %61)
%63 = load double, double* %6
%64 = call double @llvm.fmuladd.f64(double %58, double %62, double %63)
store double %64, double* %6
br label %65
65: ; preds = %44
%66 = load i32, i32* %5
%67 = add nsw i32 %66, 1
store i32 %67, i32* %5
br label %40
68: ; preds = %40
br label %69
69: ; preds = %68, %15
%70 = load double, double* %6
ret double %70
}

LLVM IR (-O2):
define double @matrixDeterminant(double** %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = tail call double** @allocateDoubleMatrix(i32 %3, i32 %3)
%5 = icmp eq i32 %1, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %37
8: ; preds = %6
%9 = zext i32 %1 to i64
br label %23
10: ; preds = %2
%11 = load double*, double** %0
%12 = load double, double* %11
%13 = getelementptr inbounds double*, double** %0, i64 1
%14 = load double*, double** %13
%15 = getelementptr inbounds double, double* %14, i64 1
%16 = load double, double* %15
%17 = getelementptr inbounds double, double* %11, i64 1
%18 = load double, double* %17
%19 = load double, double* %14
%20 = fneg double %18
%21 = fmul double %19, %20
%22 = tail call double @llvm.fmuladd.f64(double %12, double %16, double %21)
br label %37
23: ; preds = %8, %23
%24 = phi i64 [ 0, %8 ], [ %35, %23 ]
%25 = phi double [ 0.000000e+00, %8 ], [ %34, %23 ]
%26 = trunc i64 %24 to i32
%27 = tail call double** @minorMatrix(double** %0, i32 %1, i32 %26, i32 0)
%28 = tail call double @pow(i32 -1, i32 %26)
%29 = load double*, double** %0
%30 = getelementptr inbounds double, double* %29, i64 %24
%31 = load double, double* %30
%32 = fmul double %28, %31
%33 = tail call double @matrixDeterminant(double** %27, i32 %3)
%34 = tail call double @llvm.fmuladd.f64(double %32, double %33, double %25)
%35 = add nuw nsw i64 %24, 1
%36 = icmp eq i64 %35, %9
br i1 %36, label %37, label %23
37: ; preds = %23, %6, %10
%38 = phi double [ %22, %10 ], [ 0.000000e+00, %6 ], [ %34, %23 ]
ret double %38
}