#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*/ gfks_matrix_element_minor(float *, float *, int, int);
void gfks_matrix_determinant(float *result, float m[], int matrix_size) {
  if (matrix_size == 1) {
    *result = m[0];
    return;
  }
  float final_result = 0.0f;
  short int alt = 0;
  int i;
  for (i = 0; i < matrix_size; i++) {
    float result2;
    gfks_matrix_element_minor(&result2, m, matrix_size, i * matrix_size);
    if (alt == 0) {
      final_result += m[i * matrix_size] * result2;
      alt = 1;
    } else {
      final_result -= m[i * matrix_size] * result2;
      alt = 0;
    }
  }
  *result = final_result;
}


x86 assembly (clang, -O0):
<gfks_matrix_determinant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1142 <gfks_matrix_determinant+0x32>
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
jmp    1219 <gfks_matrix_determinant+0x109>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movw   $0x0,-0x1a(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    120c <gfks_matrix_determinant+0xfc>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
imul   -0x14(%rbp),%ecx
lea    -0x24(%rbp),%rdi
call   1030 <gfks_matrix_element_minor@plt>
movswl -0x1a(%rbp),%eax
cmp    $0x0,%eax
jne    11bc <gfks_matrix_determinant+0xac>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x14(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
movss  -0x24(%rbp),%xmm2
movss  -0x18(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movw   $0x1,-0x1a(%rbp)
jmp    11f9 <gfks_matrix_determinant+0xe9>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x14(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
movss  -0x24(%rbp),%xmm2
movss  -0x18(%rbp),%xmm1
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movw   $0x0,-0x1a(%rbp)
jmp    11fe <gfks_matrix_determinant+0xee>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1157 <gfks_matrix_determinant+0x47>
movss  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gfks_matrix_determinant>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %rdi,0x8(%rsp)
cmp    $0x1,%edx
jne    1133 <gfks_matrix_determinant+0x23>
movss  (%r12),%xmm0
jmp    11b1 <gfks_matrix_determinant+0xa1>
jl     11ae <gfks_matrix_determinant+0x9e>
mov    %edx,%r13d
mov    %edx,%ebp
lea    0x0(,%rbp,4),%rax
mov    %rax,0x10(%rsp)
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
mov    %r12,%r15
xor    %r14d,%r14d
jmp    1184 <gfks_matrix_determinant+0x74>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    $0x1,%r14d
mulss  0x4(%rsp),%xmm0
movss  (%rsp),%xmm1
addss  %xmm0,%xmm1
movaps %xmm1,%xmm0
add    0x10(%rsp),%r15
add    %r13d,%ebx
add    $0xffffffffffffffff,%rbp
je     11b1 <gfks_matrix_determinant+0xa1>
movss  %xmm0,(%rsp)
lea    0x4(%rsp),%rdi
mov    %r12,%rsi
mov    %r13d,%edx
mov    %ebx,%ecx
call   1030 <gfks_matrix_element_minor@plt>
movss  (%r15),%xmm0
test   %r14d,%r14d
je     1160 <gfks_matrix_determinant+0x50>
xorps  0xe54(%rip),%xmm0
jmp    1160 <gfks_matrix_determinant+0x50>
xorps  %xmm0,%xmm0
mov    0x8(%rsp),%rax
movss  %xmm0,(%rax)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @gfks_matrix_determinant(float* nocapture writeonly %0, float* %1, i32 %2) {
%4 = alloca float
%5 = icmp eq i32 %2, 1
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %31
8: ; preds = %6
%9 = bitcast float* %4 to i8*
%10 = zext i32 %2 to i64
%11 = zext i32 %2 to i64
br label %14
12: ; preds = %3
%13 = load float, float* %1
br label %31
14: ; preds = %8, %14
%15 = phi i64 [ 0, %8 ], [ %29, %14 ]
%16 = phi i32 [ 0, %8 ], [ %27, %14 ]
%17 = phi float [ 0.000000e+00, %8 ], [ %28, %14 ]
%18 = mul nsw i64 %15, %10
%19 = trunc i64 %18 to i32
%20 = call i32 @gfks_matrix_element_minor(float* %4, float* %1, i32 %2, i32 %19)
%21 = icmp eq i32 %16, 0
%22 = getelementptr inbounds float, float* %1, i64 %18
%23 = load float, float* %22
%24 = load float, float* %4
%25 = fneg float %23
%26 = select i1 %21, float %23, float %25
%27 = xor i32 %16, 1
%28 = call float @llvm.fmuladd.f32(float %26, float %24, float %17)
%29 = add nuw nsw i64 %15, 1
%30 = icmp eq i64 %29, %11
br i1 %30, label %31, label %14
31: ; preds = %14, %6, %12
%32 = phi float [ %13, %12 ], [ 0.000000e+00, %6 ], [ %28, %14 ]
store float %32, float* %0
ret void
}