#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*/ LUBackSubstitution(int, double **, int *, double *);
long LUDecompose(int, double **, double *, int *);
int InvertMatrix(int dim, double **a, double *d_work, int *i_work,
                 double **aInv) {
  unsigned i, j;
  if (LUDecompose(dim, a, d_work, i_work) == 0L)
    return 0;
  for (j = 0; j < dim; j++) {
    for (i = 0; i < dim; i++)
      d_work[i] = 0.0;
    d_work[j] = 1.0;
    LUBackSubstitution(dim, a, i_work, d_work);
    for (i = 0; i < dim; i++)
      aInv[i][j] = d_work[i];
  }
  return 1;
}


x86 assembly (clang, -O0):
<InvertMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <LUDecompose@plt>
cmp    $0x0,%rax
jne    1165 <InvertMatrix+0x45>
movl   $0x0,-0x4(%rbp)
jmp    122a <InvertMatrix+0x10a>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    1223 <InvertMatrix+0x103>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    11a8 <InvertMatrix+0x88>
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117f <InvertMatrix+0x5f>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
movsd  0xe49(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1040 <LUBackSubstitution@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    1210 <InvertMatrix+0xf0>
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    -0x30(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d7 <InvertMatrix+0xb7>
jmp    1215 <InvertMatrix+0xf5>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    116c <InvertMatrix+0x4c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<InvertMatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r15
mov    %rdx,%rbx
mov    %edi,%ebp
mov    %rsi,0x18(%rsp)
mov    %rcx,0x20(%rsp)
call   1030 <LUDecompose@plt>
test   %rax,%rax
je     127c <InvertMatrix+0x14c>
mov    $0x1,%eax
test   %ebp,%ebp
je     1285 <InvertMatrix+0x155>
mov    %ebp,0x4(%rsp)
mov    %ebp,%r13d
lea    0x0(,%r13,8),%rax
mov    %rax,0x10(%rsp)
lea    -0x1(%r13),%rax
mov    %rax,0x8(%rsp)
mov    %r13d,%r14d
and    $0x3,%r14d
mov    %r13d,%r12d
and    $0xfffffffc,%r12d
xor    %ebp,%ebp
jmp    11ad <InvertMatrix+0x7d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %r13,%rbp
je     1280 <InvertMatrix+0x150>
mov    %rbx,%rdi
xor    %esi,%esi
mov    0x10(%rsp),%rdx
call   1040 <memset@plt>
movabs $0x3ff0000000000000,%rax
mov    %rax,(%rbx,%rbp,8)
mov    0x4(%rsp),%edi
mov    0x18(%rsp),%rsi
mov    0x20(%rsp),%rdx
mov    %rbx,%rcx
call   1050 <LUBackSubstitution@plt>
cmpq   $0x3,0x8(%rsp)
jae    11f0 <InvertMatrix+0xc0>
xor    %eax,%eax
jmp    1247 <InvertMatrix+0x117>
nopl   0x0(%rax)
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  (%rbx,%rax,8),%xmm0
mov    (%r15,%rax,8),%rcx
movsd  %xmm0,(%rcx,%rbp,8)
movsd  0x8(%rbx,%rax,8),%xmm0
mov    0x8(%r15,%rax,8),%rcx
movsd  %xmm0,(%rcx,%rbp,8)
movsd  0x10(%rbx,%rax,8),%xmm0
mov    0x10(%r15,%rax,8),%rcx
movsd  %xmm0,(%rcx,%rbp,8)
movsd  0x18(%rbx,%rax,8),%xmm0
mov    0x18(%r15,%rax,8),%rcx
movsd  %xmm0,(%rcx,%rbp,8)
add    $0x4,%rax
cmp    %rax,%r12
jne    1200 <InvertMatrix+0xd0>
test   %r14,%r14
je     11a0 <InvertMatrix+0x70>
lea    (%r15,%rax,8),%rcx
lea    (%rbx,%rax,8),%rax
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
movsd  (%rax,%rdx,8),%xmm0
mov    (%rcx,%rdx,8),%rsi
movsd  %xmm0,(%rsi,%rbp,8)
add    $0x1,%rdx
cmp    %rdx,%r14
jne    1260 <InvertMatrix+0x130>
jmp    11a0 <InvertMatrix+0x70>
xor    %eax,%eax
jmp    1285 <InvertMatrix+0x155>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @InvertMatrix(i32 %0, double** %1, double* %2, i32* %3, double** %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca double**
%9 = alloca double*
%10 = alloca i32*
%11 = alloca double**
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %7
store double** %1, double*** %8
store double* %2, double** %9
store i32* %3, i32** %10
store double** %4, double*** %11
%14 = load i32, i32* %7
%15 = load double**, double*** %8
%16 = load double*, double** %9
%17 = load i32*, i32** %10
%18 = call i64 @LUDecompose(i32 %14, double** %15, double* %16, i32* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %5
store i32 0, i32* %6
br label %75
21: ; preds = %5
store i32 0, i32* %13
br label %22
22: ; preds = %71, %21
%23 = load i32, i32* %13
%24 = load i32, i32* %7
%25 = icmp ult i32 %23, %24
br i1 %25, label %26, label %74
26: ; preds = %22
store i32 0, i32* %12
br label %27
27: ; preds = %36, %26
%28 = load i32, i32* %12
%29 = load i32, i32* %7
%30 = icmp ult i32 %28, %29
br i1 %30, label %31, label %39
31: ; preds = %27
%32 = load double*, double** %9
%33 = load i32, i32* %12
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
store double 0.000000e+00, double* %35
br label %36
36: ; preds = %31
%37 = load i32, i32* %12
%38 = add i32 %37, 1
store i32 %38, i32* %12
br label %27
39: ; preds = %27
%40 = load double*, double** %9
%41 = load i32, i32* %13
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
store double 1.000000e+00, double* %43
%44 = load i32, i32* %7
%45 = load double**, double*** %8
%46 = load i32*, i32** %10
%47 = load double*, double** %9
%48 = call i32 @LUBackSubstitution(i32 %44, double** %45, i32* %46, double* %47)
store i32 0, i32* %12
br label %49
49: ; preds = %67, %39
%50 = load i32, i32* %12
%51 = load i32, i32* %7
%52 = icmp ult i32 %50, %51
br i1 %52, label %53, label %70
53: ; preds = %49
%54 = load double*, double** %9
%55 = load i32, i32* %12
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds double, double* %54, i64 %56
%58 = load double, double* %57
%59 = load double**, double*** %11
%60 = load i32, i32* %12
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds double*, double** %59, i64 %61
%63 = load double*, double** %62
%64 = load i32, i32* %13
%65 = zext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
store double %58, double* %66
br label %67
67: ; preds = %53
%68 = load i32, i32* %12
%69 = add i32 %68, 1
store i32 %69, i32* %12
br label %49
70: ; preds = %49
br label %71
71: ; preds = %70
%72 = load i32, i32* %13
%73 = add i32 %72, 1
store i32 %73, i32* %13
br label %22
74: ; preds = %22
store i32 1, i32* %6
br label %75
75: ; preds = %74, %20
%76 = load i32, i32* %6
ret i32 %76
}

LLVM IR (-O2):
define i32 @InvertMatrix(i32 %0, double** %1, double* %2, i32* %3, double** nocapture %4) {
%6 = bitcast double* %2 to i8*
%7 = tail call i64 @LUDecompose(i32 %0, double** %1, double* %2, i32* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %68, label %9
9: ; preds = %5
%10 = icmp eq i32 %0, 0
br i1 %10, label %68, label %11
11: ; preds = %9
%12 = zext i32 %0 to i64
%13 = shl nuw nsw i64 %12, 3
%14 = add nsw i64 %12, -1
%15 = and i64 %12, 3
%16 = icmp ult i64 %14, 3
%17 = and i64 %12, 4294967292
%18 = icmp eq i64 %15, 0
br label %19
19: ; preds = %11, %65
%20 = phi i64 [ 0, %11 ], [ %66, %65 ]
%21 = getelementptr inbounds double, double* %2, i64 %20
store double 1.000000e+00, double* %21
%22 = tail call i32 @LUBackSubstitution(i32 %0, double** %1, i32* %3, double* %2)
br i1 %16, label %52, label %23
23: ; preds = %19, %23
%24 = phi i64 [ %49, %23 ], [ 0, %19 ]
%25 = phi i64 [ %50, %23 ], [ 0, %19 ]
%26 = getelementptr inbounds double, double* %2, i64 %24
%27 = load double, double* %26
%28 = getelementptr inbounds double*, double** %4, i64 %24
%29 = load double*, double** %28
%30 = getelementptr inbounds double, double* %29, i64 %20
store double %27, double* %30
%31 = or i64 %24, 1
%32 = getelementptr inbounds double, double* %2, i64 %31
%33 = load double, double* %32
%34 = getelementptr inbounds double*, double** %4, i64 %31
%35 = load double*, double** %34
%36 = getelementptr inbounds double, double* %35, i64 %20
store double %33, double* %36
%37 = or i64 %24, 2
%38 = getelementptr inbounds double, double* %2, i64 %37
%39 = load double, double* %38
%40 = getelementptr inbounds double*, double** %4, i64 %37
%41 = load double*, double** %40
%42 = getelementptr inbounds double, double* %41, i64 %20
store double %39, double* %42
%43 = or i64 %24, 3
%44 = getelementptr inbounds double, double* %2, i64 %43
%45 = load double, double* %44
%46 = getelementptr inbounds double*, double** %4, i64 %43
%47 = load double*, double** %46
%48 = getelementptr inbounds double, double* %47, i64 %20
store double %45, double* %48
%49 = add nuw nsw i64 %24, 4
%50 = add i64 %25, 4
%51 = icmp eq i64 %50, %17
br i1 %51, label %52, label %23
52: ; preds = %23, %19
%53 = phi i64 [ 0, %19 ], [ %49, %23 ]
br i1 %18, label %65, label %54
54: ; preds = %52, %54
%55 = phi i64 [ %62, %54 ], [ %53, %52 ]
%56 = phi i64 [ %63, %54 ], [ 0, %52 ]
%57 = getelementptr inbounds double, double* %2, i64 %55
%58 = load double, double* %57
%59 = getelementptr inbounds double*, double** %4, i64 %55
%60 = load double*, double** %59
%61 = getelementptr inbounds double, double* %60, i64 %20
store double %58, double* %61
%62 = add nuw nsw i64 %55, 1
%63 = add i64 %56, 1
%64 = icmp eq i64 %63, %15
br i1 %64, label %65, label %54
65: ; preds = %54, %52
%66 = add nuw nsw i64 %20, 1
%67 = icmp eq i64 %66, %12
br i1 %67, label %68, label %19
68: ; preds = %65, %9, %5
%69 = phi i32 [ 0, %5 ], [ 1, %9 ], [ 1, %65 ]
ret i32 %69
}