#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 */
struct matrix4 {
  int dummy;
};

/* Variables and functions */
float get_3x3_determinant(float *);
int /*<<< orphan*/ get_3x3_submatrix(float *, struct matrix4 const *,
                                     int /*<<< orphan*/, int);
float matrix4_determinant(const struct matrix4 *m) {
  const float *mf = (const float *)m;
  float det, result = 0.0f, i = 1.0f;
  float m3x3[9];
  int n;
  for (n = 0; n < 4; n++, i = -i) {
    get_3x3_submatrix(m3x3, m, 0, n);
    det = get_3x3_determinant(m3x3);
    result += mf[n] * det * i;
  }
  return result;
}


x86 assembly (clang, -O0):
<matrix4_determinant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xebc(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x4,-0x44(%rbp)
jge    11c8 <matrix4_determinant+0xa8>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x44(%rbp),%ecx
xor    %edx,%edx
call   1030 <get_3x3_submatrix@plt>
lea    -0x40(%rbp),%rdi
call   1040 <get_3x3_determinant@plt>
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm2
movss  -0x18(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
movss  -0x1c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    1150 <matrix4_determinant+0x30>
movss  -0x18(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix4_determinant>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <get_3x3_submatrix@plt>
mov    %r14,%rdi
call   1040 <get_3x3_determinant@plt>
mulss  (%rbx),%xmm0
xorps  %xmm1,%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,0xc(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    $0x1,%ecx
call   1030 <get_3x3_submatrix@plt>
mov    %r14,%rdi
call   1040 <get_3x3_determinant@plt>
mulss  0x4(%rbx),%xmm0
movss  0xc(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,0xc(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    $0x2,%ecx
call   1030 <get_3x3_submatrix@plt>
mov    %r14,%rdi
call   1040 <get_3x3_determinant@plt>
mulss  0x8(%rbx),%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    $0x3,%ecx
call   1030 <get_3x3_submatrix@plt>
mov    %r14,%rdi
call   1040 <get_3x3_determinant@plt>
mulss  0xc(%rbx),%xmm0
movss  0xc(%rsp),%xmm1
subss  %xmm0,%xmm1
movaps %xmm1,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.matrix4 = type { i32 }
define float @matrix4_determinant(%struct.matrix4* %0) {
%2 = alloca %struct.matrix4*
%3 = alloca float*
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca [9 x float]
%8 = alloca i32
store %struct.matrix4* %0, %struct.matrix4** %2
%9 = load %struct.matrix4*, %struct.matrix4** %2
%10 = bitcast %struct.matrix4* %9 to float*
store float* %10, float** %3
store float 0.000000e+00, float* %5
store float 1.000000e+00, float* %6
store i32 0, i32* %8
br label %11
11: ; preds = %31, %1
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %36
14: ; preds = %11
%15 = getelementptr inbounds [9 x float], [9 x float]* %7, i64 0, i64 0
%16 = load %struct.matrix4*, %struct.matrix4** %2
%17 = load i32, i32* %8
%18 = call i32 @get_3x3_submatrix(float* %15, %struct.matrix4* %16, i32 0, i32 %17)
%19 = getelementptr inbounds [9 x float], [9 x float]* %7, i64 0, i64 0
%20 = call float @get_3x3_determinant(float* %19)
store float %20, float* %4
%21 = load float*, float** %3
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds float, float* %21, i64 %23
%25 = load float, float* %24
%26 = load float, float* %4
%27 = fmul float %25, %26
%28 = load float, float* %6
%29 = load float, float* %5
%30 = call float @llvm.fmuladd.f32(float %27, float %28, float %29)
store float %30, float* %5
br label %31
31: ; preds = %14
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
%34 = load float, float* %6
%35 = fneg float %34
store float %35, float* %6
br label %11
36: ; preds = %11
%37 = load float, float* %5
ret float %37
}

LLVM IR (-O2):
%struct.matrix4 = type { i32 }
define float @matrix4_determinant(%struct.matrix4* %0) {
%2 = alloca [9 x float]
%3 = bitcast [9 x float]* %2 to i8*
%4 = getelementptr inbounds [9 x float], [9 x float]* %2, i64 0, i64 0
%5 = call i32 @get_3x3_submatrix(float* %4, %struct.matrix4* %0, i32 0, i32 0)
%6 = call float @get_3x3_determinant(float* %4)
%7 = bitcast %struct.matrix4* %0 to float*
%8 = load float, float* %7
%9 = fmul float %6, %8
%10 = fadd float %9, 0.000000e+00
%11 = call i32 @get_3x3_submatrix(float* %4, %struct.matrix4* %0, i32 0, i32 1)
%12 = call float @get_3x3_determinant(float* %4)
%13 = getelementptr inbounds %struct.matrix4, %struct.matrix4* %0, i64 1
%14 = bitcast %struct.matrix4* %13 to float*
%15 = load float, float* %14
%16 = fmul float %12, %15
%17 = call float @llvm.fmuladd.f32(float %16, float -1.000000e+00, float %10)
%18 = call i32 @get_3x3_submatrix(float* %4, %struct.matrix4* %0, i32 0, i32 2)
%19 = call float @get_3x3_determinant(float* %4)
%20 = getelementptr inbounds %struct.matrix4, %struct.matrix4* %0, i64 2
%21 = bitcast %struct.matrix4* %20 to float*
%22 = load float, float* %21
%23 = fmul float %19, %22
%24 = fadd float %23, %17
%25 = call i32 @get_3x3_submatrix(float* %4, %struct.matrix4* %0, i32 0, i32 3)
%26 = call float @get_3x3_determinant(float* %4)
%27 = getelementptr inbounds %struct.matrix4, %struct.matrix4* %0, i64 3
%28 = bitcast %struct.matrix4* %27 to float*
%29 = load float, float* %28
%30 = fmul float %26, %29
%31 = call float @llvm.fmuladd.f32(float %30, float -1.000000e+00, float %24)
ret float %31
}