#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*/ lm_check_inverse(double *const, double *const, int const,
                                    int, int *const);
int /*<<< orphan*/ lm_decompose_LUP(double *const, int const, int, int *const,
                                    int *const);
int /*<<< orphan*/ lm_invert_LUP(double *const, int const, int *const,
                                 double *const);
int /*<<< orphan*/ memcpy(double *const, double *const, int const);
void lm_invert(double *const A, const int n, int *const P, double *const ws,
               double *const IA, int *const failure) {
  memcpy(ws, A, n * n * sizeof(double));
  lm_decompose_LUP(ws, n, 1e-12, P, failure);
  if (*failure)
    return;
  lm_invert_LUP(ws, n, P, IA);
  lm_check_inverse(IA, A, n, 1e-6, failure);
  lm_check_inverse(A, IA, n, 1e-6, failure);
  if (*failure)
    return;
}


x86 assembly (clang, -O0):
<lm_invert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    -0x30(%rbp),%r8
xor    %edx,%edx
call   1030 <lm_decompose_LUP@plt>
mov    -0x30(%rbp),%rax
cmpl   $0x0,(%rax)
je     11a3 <lm_invert+0x63>
jmp    11f5 <lm_invert+0xb5>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1060 <lm_invert_LUP@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x30(%rbp),%r8
xor    %ecx,%ecx
call   1040 <lm_check_inverse@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x30(%rbp),%r8
xor    %ecx,%ecx
call   1040 <lm_check_inverse@plt>
mov    -0x30(%rbp),%rax
cmpl   $0x0,(%rax)
je     11f5 <lm_invert+0xb5>
jmp    11f5 <lm_invert+0xb5>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lm_invert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r13
mov    %r8,%r14
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %esi,%ebp
mov    %rdi,%r15
mov    %esi,%edx
imul   %esi,%edx
shl    $0x3,%edx
mov    %rcx,%rdi
mov    %r15,%rsi
call   1050 <memcpy@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %edx,%edx
mov    %r12,%rcx
mov    %r13,%r8
call   1030 <lm_decompose_LUP@plt>
cmpl   $0x0,0x0(%r13)
je     1197 <lm_invert+0x57>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %r14,%rcx
call   1060 <lm_invert_LUP@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    %r13,%r8
call   1040 <lm_check_inverse@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    %r13,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <lm_check_inverse@plt>

LLVM IR (-O0):
define void @lm_invert(double* %0, i32 %1, i32* %2, double* %3, double* %4, i32* %5) {
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca double*
%11 = alloca double*
%12 = alloca i32*
store double* %0, double** %7
store i32 %1, i32* %8
store i32* %2, i32** %9
store double* %3, double** %10
store double* %4, double** %11
store i32* %5, i32** %12
%13 = load double*, double** %10
%14 = load double*, double** %7
%15 = load i32, i32* %8
%16 = load i32, i32* %8
%17 = mul nsw i32 %15, %16
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 8
%20 = trunc i64 %19 to i32
%21 = call i32 @memcpy(double* %13, double* %14, i32 %20)
%22 = load double*, double** %10
%23 = load i32, i32* %8
%24 = load i32*, i32** %9
%25 = load i32*, i32** %12
%26 = call i32 @lm_decompose_LUP(double* %22, i32 %23, i32 0, i32* %24, i32* %25)
%27 = load i32*, i32** %12
%28 = load i32, i32* %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %6
br label %51
31: ; preds = %6
%32 = load double*, double** %10
%33 = load i32, i32* %8
%34 = load i32*, i32** %9
%35 = load double*, double** %11
%36 = call i32 @lm_invert_LUP(double* %32, i32 %33, i32* %34, double* %35)
%37 = load double*, double** %11
%38 = load double*, double** %7
%39 = load i32, i32* %8
%40 = load i32*, i32** %12
%41 = call i32 @lm_check_inverse(double* %37, double* %38, i32 %39, i32 0, i32* %40)
%42 = load double*, double** %7
%43 = load double*, double** %11
%44 = load i32, i32* %8
%45 = load i32*, i32** %12
%46 = call i32 @lm_check_inverse(double* %42, double* %43, i32 %44, i32 0, i32* %45)
%47 = load i32*, i32** %12
%48 = load i32, i32* %47
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %31
br label %51
51: ; preds = %30, %50, %31
ret void
}

LLVM IR (-O2):
define void @lm_invert(double* %0, i32 %1, i32* %2, double* %3, double* %4, i32* %5) {
%7 = shl i32 %1, 3
%8 = mul i32 %7, %1
%9 = tail call i32 @memcpy(double* %3, double* %0, i32 %8)
%10 = tail call i32 @lm_decompose_LUP(double* %3, i32 %1, i32 0, i32* %2, i32* %5)
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %6
%14 = tail call i32 @lm_invert_LUP(double* %3, i32 %1, i32* %2, double* %4)
%15 = tail call i32 @lm_check_inverse(double* %4, double* %0, i32 %1, i32 0, i32* %5)
%16 = tail call i32 @lm_check_inverse(double* %0, double* %4, i32 %1, i32 0, i32* %5)
br label %17
17: ; preds = %13, %6
ret void
}