#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*/ free(double **);
double **matrix_minor(double **, unsigned int, unsigned int, unsigned int);
double pow(int, unsigned int);
double do_determinant(double **m, unsigned int n, unsigned int row) {
  if (n == 1)
    return **m;
  if (n == 2)
    return m[0][0] * m[1][1] - m[1][0] * m[0][1];
  double det = 0;
  for (unsigned int col = 0; col < n; col++) {
    double **minor = matrix_minor(m, n, row, col);
    det += pow(-1, row + col) * m[row][col] * do_determinant(minor, n - 1, row);
    free(minor);
  }
  return det;
}


x86 assembly (clang, -O0):
<do_determinant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1171 <do_determinant+0x31>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127a <do_determinant+0x13a>
cmpl   $0x2,-0x14(%rbp)
jne    11d4 <do_determinant+0x94>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsd  0x8(%rax),%xmm2
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mulsd  0x8(%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127a <do_determinant+0x13a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1270 <do_determinant+0x130>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x24(%rbp),%ecx
call   1040 <matrix_minor@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%esi
add    -0x24(%rbp),%esi
mov    $0xffffffff,%edi
call   1050 <pow@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    -0x24(%rbp),%ecx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    -0x18(%rbp),%edx
call   1060 <do_determinant@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e3 <do_determinant+0xa3>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_determinant>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %esi,%esi
je     1187 <do_determinant+0x47>
mov    %esi,%r15d
mov    %rdi,%r12
cmp    $0x1,%esi
je     118d <do_determinant+0x4d>
cmp    $0x2,%r15d
jne    119f <do_determinant+0x5f>
mov    (%r12),%rax
mov    0x8(%r12),%rcx
movsd  0x8(%rax),%xmm1
mulsd  (%rcx),%xmm1
movsd  (%rax),%xmm0
mulsd  0x8(%rcx),%xmm0
subsd  %xmm1,%xmm0
jmp    1227 <do_determinant+0xe7>
xorpd  %xmm0,%xmm0
jmp    1195 <do_determinant+0x55>
mov    (%r12),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,(%rsp)
jmp    1222 <do_determinant+0xe2>
mov    %r15d,%r13d
mov    %edx,%ebx
add    $0xffffffff,%r15d
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xor    %ebp,%ebp
mov    %edx,0xc(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1040 <matrix_minor@plt>
mov    %rax,%r14
lea    (%rbx,%rbp,1),%esi
mov    $0xffffffff,%edi
call   1050 <pow@plt>
mov    (%r12,%rbx,8),%rax
mulsd  (%rax,%rbp,8),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %r14,%rdi
mov    %r15d,%esi
mov    0xc(%rsp),%edx
call   1060 <do_determinant@plt>
mulsd  0x10(%rsp),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    11c0 <do_determinant+0x80>
movsd  (%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @do_determinant(double** %0, i32 %1, i32 %2) {
%4 = alloca double
%5 = alloca double**
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
%10 = alloca double**
store double** %0, double*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load double**, double*** %5
%15 = load double*, double** %14
%16 = load double, double* %15
store double %16, double* %4
br label %83
17: ; preds = %3
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %44
20: ; preds = %17
%21 = load double**, double*** %5
%22 = getelementptr inbounds double*, double** %21, i64 0
%23 = load double*, double** %22
%24 = getelementptr inbounds double, double* %23, i64 0
%25 = load double, double* %24
%26 = load double**, double*** %5
%27 = getelementptr inbounds double*, double** %26, i64 1
%28 = load double*, double** %27
%29 = getelementptr inbounds double, double* %28, i64 1
%30 = load double, double* %29
%31 = load double**, double*** %5
%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 = load double**, double*** %5
%37 = getelementptr inbounds double*, double** %36, i64 0
%38 = load double*, double** %37
%39 = getelementptr inbounds double, double* %38, i64 1
%40 = load double, double* %39
%41 = fmul double %35, %40
%42 = fneg double %41
%43 = call double @llvm.fmuladd.f64(double %25, double %30, double %42)
store double %43, double* %4
br label %83
44: ; preds = %17
store double 0.000000e+00, double* %8
store i32 0, i32* %9
br label %45
45: ; preds = %78, %44
%46 = load i32, i32* %9
%47 = load i32, i32* %6
%48 = icmp ult i32 %46, %47
br i1 %48, label %49, label %81
49: ; preds = %45
%50 = load double**, double*** %5
%51 = load i32, i32* %6
%52 = load i32, i32* %7
%53 = load i32, i32* %9
%54 = call double** @matrix_minor(double** %50, i32 %51, i32 %52, i32 %53)
store double** %54, double*** %10
%55 = load i32, i32* %7
%56 = load i32, i32* %9
%57 = add i32 %55, %56
%58 = call double @pow(i32 -1, i32 %57)
%59 = load double**, double*** %5
%60 = load i32, i32* %7
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds double*, double** %59, i64 %61
%63 = load double*, double** %62
%64 = load i32, i32* %9
%65 = zext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
%67 = load double, double* %66
%68 = fmul double %58, %67
%69 = load double**, double*** %10
%70 = load i32, i32* %6
%71 = sub i32 %70, 1
%72 = load i32, i32* %7
%73 = call double @do_determinant(double** %69, i32 %71, i32 %72)
%74 = load double, double* %8
%75 = call double @llvm.fmuladd.f64(double %68, double %73, double %74)
store double %75, double* %8
%76 = load double**, double*** %10
%77 = call i32 @free(double** %76)
br label %78
78: ; preds = %49
%79 = load i32, i32* %9
%80 = add i32 %79, 1
store i32 %80, i32* %9
br label %45
81: ; preds = %45
%82 = load double, double* %8
store double %82, double* %4
br label %83
83: ; preds = %81, %20, %13
%84 = load double, double* %4
ret double %84
}

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