#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 *);
int m_LU(double *, int, int /*<<< orphan*/ *, int *);
double *m_dup(double *, int, int);
double m_prod(double *, int);
double m_det(double *A, int nrow) {
  int per, s;
  double *B, a;
  B = m_dup(A, nrow, nrow);
  s = m_LU(B, nrow, NULL, &per);
  if (s) {
    a = 0;
  } else {
    a = m_prod(B, nrow);
    a = (per == 1) ? a : -a;
  }
  free(B);
  return a;
}


x86 assembly (clang, -O0):
<m_det>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <m_dup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x10(%rbp),%rcx
call   1040 <m_LU@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1190 <m_det+0x50>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11e5 <m_det+0xa5>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <m_prod@plt>
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    11ba <m_det+0x7a>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11db <m_det+0x9b>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_det>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebp
mov    %esi,%edx
call   1060 <m_dup@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rcx
mov    %rax,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   1040 <m_LU@plt>
xorps  %xmm0,%xmm0
test   %eax,%eax
jne    1182 <m_det+0x42>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <m_prod@plt>
cmpl   $0x1,0xc(%rsp)
je     1182 <m_det+0x42>
xorps  0xe7e(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
movaps 0x10(%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @m_det(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%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 = load i32, i32* %4
%12 = call double* @m_dup(double* %9, i32 %10, i32 %11)
store double* %12, double** %7
%13 = load double*, double** %7
%14 = load i32, i32* %4
%15 = call i32 @m_LU(double* %13, i32 %14, i32* null, i32* %5)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %2
store double 0.000000e+00, double* %8
br label %32
19: ; preds = %2
%20 = load double*, double** %7
%21 = load i32, i32* %4
%22 = call double @m_prod(double* %20, i32 %21)
store double %22, double* %8
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load double, double* %8
br label %30
27: ; preds = %19
%28 = load double, double* %8
%29 = fneg double %28
br label %30
30: ; preds = %27, %25
%31 = phi double [ %26, %25 ], [ %29, %27 ]
store double %31, double* %8
br label %32
32: ; preds = %30, %18
%33 = load double*, double** %7
%34 = call i32 @free(double* %33)
%35 = load double, double* %8
ret double %35
}

LLVM IR (-O2):
define double @m_det(double* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call double* @m_dup(double* %0, i32 %1, i32 %1)
%6 = call i32 @m_LU(double* %5, i32 %1, i32* null, i32* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = call double @m_prod(double* %5, i32 %1)
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 1
%12 = fneg double %9
%13 = select i1 %11, double %9, double %12
br label %14
14: ; preds = %2, %8
%15 = phi double [ %13, %8 ], [ 0.000000e+00, %2 ]
%16 = call i32 @free(double* %5)
ret double %15
}