#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 */
double **dmatrix(int /*<<< orphan*/, int, int /*<<< orphan*/, int);
int /*<<< orphan*/ free_dmatrix(double **, int /*<<< orphan*/, int,
                                int /*<<< orphan*/, int);
int lu_invert(double **, int);
int matrix_mult(double **, int, int, double **, int, int, double **, int, int);
int /*<<< orphan*/ matrix_trans(double **, double **, int, int);
int lu_psinvert(double **out, double **in, int m, int n) {
  int rv = 0;
  double **tr;
  double **sq;
  tr = dmatrix(0, n - 1, 0, m - 1);
  matrix_trans(tr, in, m, n);
  if (m > n) {
    sq = dmatrix(0, n - 1, 0, n - 1);
    if ((rv = matrix_mult(sq, n, n, tr, n, m, in, m, n)) == 0) {
      if ((rv = lu_invert(sq, n)) == 0) {
        rv = matrix_mult(out, n, m, sq, n, n, tr, n, m);
      }
    }
    free_dmatrix(sq, 0, n - 1, 0, n - 1);
  } else {
    sq = dmatrix(0, m - 1, 0, m - 1);
    if ((rv = matrix_mult(sq, m, m, in, m, n, tr, n, m)) == 0) {
      if ((rv = lu_invert(sq, m)) == 0) {
        rv = matrix_mult(out, n, m, tr, n, m, sq, m, m);
      }
    }
    free_dmatrix(sq, 0, m - 1, 0, m - 1);
  }
  free_dmatrix(tr, 0, n - 1, 0, m - 1);
  return rv;
}


x86 assembly (clang, -O0):
<lu_psinvert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
sub    $0x1,%esi
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
xor    %edx,%edx
mov    %edx,%edi
call   1050 <dmatrix@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <matrix_trans@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1270 <lu_psinvert+0x120>
mov    -0x18(%rbp),%esi
sub    $0x1,%esi
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
xor    %edx,%edx
mov    %edx,%edi
call   1050 <dmatrix@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%r8d
mov    -0x14(%rbp),%r9d
mov    -0x10(%rbp),%r11
mov    -0x14(%rbp),%r10d
mov    -0x18(%rbp),%eax
mov    %r11,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1060 <matrix_mult@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    1250 <lu_psinvert+0x100>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <lu_invert@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    124b <lu_psinvert+0xfb>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%r8d
mov    -0x18(%rbp),%r9d
mov    -0x28(%rbp),%r11
mov    -0x18(%rbp),%r10d
mov    -0x14(%rbp),%eax
mov    %r11,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1060 <matrix_mult@plt>
mov    %eax,-0x1c(%rbp)
jmp    1250 <lu_psinvert+0x100>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
mov    -0x18(%rbp),%r8d
sub    $0x1,%r8d
xor    %ecx,%ecx
mov    %ecx,%esi
call   1070 <free_dmatrix@plt>
jmp    1336 <lu_psinvert+0x1e6>
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
xor    %edx,%edx
mov    %edx,%edi
call   1050 <dmatrix@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    -0x18(%rbp),%r9d
mov    -0x28(%rbp),%r11
mov    -0x18(%rbp),%r10d
mov    -0x14(%rbp),%eax
mov    %r11,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1060 <matrix_mult@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    131b <lu_psinvert+0x1cb>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <lu_invert@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    1316 <lu_psinvert+0x1c6>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%r8d
mov    -0x14(%rbp),%r9d
mov    -0x30(%rbp),%r11
mov    -0x14(%rbp),%r10d
mov    -0x14(%rbp),%eax
mov    %r11,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1060 <matrix_mult@plt>
mov    %eax,-0x1c(%rbp)
jmp    131b <lu_psinvert+0x1cb>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    -0x14(%rbp),%r8d
sub    $0x1,%r8d
xor    %ecx,%ecx
mov    %ecx,%esi
call   1070 <free_dmatrix@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
mov    -0x14(%rbp),%r8d
sub    $0x1,%r8d
xor    %ecx,%ecx
mov    %ecx,%esi
call   1070 <free_dmatrix@plt>
mov    -0x1c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lu_psinvert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %edx,%ebx
mov    %rsi,%r13
mov    %rdi,0x10(%rsp)
lea    -0x1(%rbp),%r15d
lea    -0x1(%rbx),%r12d
xor    %edi,%edi
mov    %r15d,%esi
xor    %edx,%edx
mov    %r12d,%ecx
call   1050 <dmatrix@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1040 <matrix_trans@plt>
xor    %edi,%edi
cmp    %ebp,%ebx
jle    1226 <lu_psinvert+0xd6>
mov    %r15d,%esi
xor    %edx,%edx
mov    %r15d,%ecx
call   1050 <dmatrix@plt>
sub    $0x8,%rsp
mov    %rax,0x10(%rsp)
mov    %rax,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %ebp,%r8d
mov    %ebx,%r9d
push   %rbp
push   %rbx
push   %r13
call   1060 <matrix_mult@plt>
add    $0x20,%rsp
mov    %eax,%r13d
test   %eax,%eax
jne    1212 <lu_psinvert+0xc2>
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
call   1030 <lu_invert@plt>
mov    %eax,%r13d
test   %eax,%eax
jne    1212 <lu_psinvert+0xc2>
sub    $0x8,%rsp
mov    0x18(%rsp),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    0x10(%rsp),%rcx
mov    %ebp,%r8d
mov    %ebp,%r9d
push   %rbx
push   %rbp
push   %r14
call   1060 <matrix_mult@plt>
add    $0x20,%rsp
mov    %eax,%r13d
mov    0x8(%rsp),%rdi
xor    %esi,%esi
mov    %r15d,%edx
xor    %ecx,%ecx
mov    %r15d,%r8d
jmp    12aa <lu_psinvert+0x15a>
mov    %r12d,%esi
xor    %edx,%edx
mov    %r12d,%ecx
call   1050 <dmatrix@plt>
sub    $0x8,%rsp
mov    %rax,0x10(%rsp)
mov    %rax,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
mov    %r13,%rcx
mov    %ebx,%r8d
mov    %ebp,%r9d
push   %rbx
push   %rbp
push   %r14
call   1060 <matrix_mult@plt>
add    $0x20,%rsp
mov    %eax,%r13d
test   %eax,%eax
jne    129b <lu_psinvert+0x14b>
mov    0x8(%rsp),%rdi
mov    %ebx,%esi
call   1030 <lu_invert@plt>
mov    %eax,%r13d
test   %eax,%eax
jne    129b <lu_psinvert+0x14b>
sub    $0x8,%rsp
mov    0x18(%rsp),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r14,%rcx
mov    %ebp,%r8d
mov    %ebx,%r9d
push   %rbx
push   %rbx
push   0x20(%rsp)
call   1060 <matrix_mult@plt>
add    $0x20,%rsp
mov    %eax,%r13d
mov    0x8(%rsp),%rdi
xor    %esi,%esi
mov    %r12d,%edx
xor    %ecx,%ecx
mov    %r12d,%r8d
call   1070 <free_dmatrix@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15d,%edx
xor    %ecx,%ecx
mov    %r12d,%r8d
call   1070 <free_dmatrix@plt>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @lu_psinvert(double** %0, double** %1, i32 %2, i32 %3) {
%5 = alloca double**
%6 = alloca double**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double**
%11 = alloca double**
store double** %0, double*** %5
store double** %1, double*** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
%12 = load i32, i32* %8
%13 = sub nsw i32 %12, 1
%14 = load i32, i32* %7
%15 = sub nsw i32 %14, 1
%16 = call double** @dmatrix(i32 0, i32 %13, i32 0, i32 %15)
store double** %16, double*** %10
%17 = load double**, double*** %10
%18 = load double**, double*** %6
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = call i32 @matrix_trans(double** %17, double** %18, i32 %19, i32 %20)
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %66
25: ; preds = %4
%26 = load i32, i32* %8
%27 = sub nsw i32 %26, 1
%28 = load i32, i32* %8
%29 = sub nsw i32 %28, 1
%30 = call double** @dmatrix(i32 0, i32 %27, i32 0, i32 %29)
store double** %30, double*** %11
%31 = load double**, double*** %11
%32 = load i32, i32* %8
%33 = load i32, i32* %8
%34 = load double**, double*** %10
%35 = load i32, i32* %8
%36 = load i32, i32* %7
%37 = load double**, double*** %6
%38 = load i32, i32* %7
%39 = load i32, i32* %8
%40 = call i32 @matrix_mult(double** %31, i32 %32, i32 %33, double** %34, i32 %35, i32 %36, double** %37, i32 %38, i32 %39)
store i32 %40, i32* %9
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %59
42: ; preds = %25
%43 = load double**, double*** %11
%44 = load i32, i32* %8
%45 = call i32 @lu_invert(double** %43, i32 %44)
store i32 %45, i32* %9
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %58
47: ; preds = %42
%48 = load double**, double*** %5
%49 = load i32, i32* %8
%50 = load i32, i32* %7
%51 = load double**, double*** %11
%52 = load i32, i32* %8
%53 = load i32, i32* %8
%54 = load double**, double*** %10
%55 = load i32, i32* %8
%56 = load i32, i32* %7
%57 = call i32 @matrix_mult(double** %48, i32 %49, i32 %50, double** %51, i32 %52, i32 %53, double** %54, i32 %55, i32 %56)
store i32 %57, i32* %9
br label %58
58: ; preds = %47, %42
br label %59
59: ; preds = %58, %25
%60 = load double**, double*** %11
%61 = load i32, i32* %8
%62 = sub nsw i32 %61, 1
%63 = load i32, i32* %8
%64 = sub nsw i32 %63, 1
%65 = call i32 @free_dmatrix(double** %60, i32 0, i32 %62, i32 0, i32 %64)
br label %107
66: ; preds = %4
%67 = load i32, i32* %7
%68 = sub nsw i32 %67, 1
%69 = load i32, i32* %7
%70 = sub nsw i32 %69, 1
%71 = call double** @dmatrix(i32 0, i32 %68, i32 0, i32 %70)
store double** %71, double*** %11
%72 = load double**, double*** %11
%73 = load i32, i32* %7
%74 = load i32, i32* %7
%75 = load double**, double*** %6
%76 = load i32, i32* %7
%77 = load i32, i32* %8
%78 = load double**, double*** %10
%79 = load i32, i32* %8
%80 = load i32, i32* %7
%81 = call i32 @matrix_mult(double** %72, i32 %73, i32 %74, double** %75, i32 %76, i32 %77, double** %78, i32 %79, i32 %80)
store i32 %81, i32* %9
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %100
83: ; preds = %66
%84 = load double**, double*** %11
%85 = load i32, i32* %7
%86 = call i32 @lu_invert(double** %84, i32 %85)
store i32 %86, i32* %9
%87 = icmp eq i32 %86, 0
br i1 %87, label %88, label %99
88: ; preds = %83
%89 = load double**, double*** %5
%90 = load i32, i32* %8
%91 = load i32, i32* %7
%92 = load double**, double*** %10
%93 = load i32, i32* %8
%94 = load i32, i32* %7
%95 = load double**, double*** %11
%96 = load i32, i32* %7
%97 = load i32, i32* %7
%98 = call i32 @matrix_mult(double** %89, i32 %90, i32 %91, double** %92, i32 %93, i32 %94, double** %95, i32 %96, i32 %97)
store i32 %98, i32* %9
br label %99
99: ; preds = %88, %83
br label %100
100: ; preds = %99, %66
%101 = load double**, double*** %11
%102 = load i32, i32* %7
%103 = sub nsw i32 %102, 1
%104 = load i32, i32* %7
%105 = sub nsw i32 %104, 1
%106 = call i32 @free_dmatrix(double** %101, i32 0, i32 %103, i32 0, i32 %105)
br label %107
107: ; preds = %100, %59
%108 = load double**, double*** %10
%109 = load i32, i32* %8
%110 = sub nsw i32 %109, 1
%111 = load i32, i32* %7
%112 = sub nsw i32 %111, 1
%113 = call i32 @free_dmatrix(double** %108, i32 0, i32 %110, i32 0, i32 %112)
%114 = load i32, i32* %9
ret i32 %114
}

LLVM IR (-O2):
define i32 @lu_psinvert(double** %0, double** %1, i32 %2, i32 %3) {
%5 = add nsw i32 %3, -1
%6 = add nsw i32 %2, -1
%7 = tail call double** @dmatrix(i32 0, i32 %5, i32 0, i32 %6)
%8 = tail call i32 @matrix_trans(double** %7, double** %1, i32 %2, i32 %3)
%9 = icmp sgt i32 %2, %3
br i1 %9, label %10, label %22
10: ; preds = %4
%11 = tail call double** @dmatrix(i32 0, i32 %5, i32 0, i32 %5)
%12 = tail call i32 @matrix_mult(double** %11, i32 %3, i32 %3, double** %7, i32 %3, i32 %2, double** %1, i32 %2, i32 %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = tail call i32 @lu_invert(double** %11, i32 %3)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @matrix_mult(double** %0, i32 %3, i32 %2, double** %11, i32 %3, i32 %3, double** %7, i32 %3, i32 %2)
br label %19
19: ; preds = %14, %17, %10
%20 = phi i32 [ %18, %17 ], [ %15, %14 ], [ %12, %10 ]
%21 = tail call i32 @free_dmatrix(double** %11, i32 0, i32 %5, i32 0, i32 %5)
br label %34
22: ; preds = %4
%23 = tail call double** @dmatrix(i32 0, i32 %6, i32 0, i32 %6)
%24 = tail call i32 @matrix_mult(double** %23, i32 %2, i32 %2, double** %1, i32 %2, i32 %3, double** %7, i32 %3, i32 %2)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = tail call i32 @lu_invert(double** %23, i32 %2)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = tail call i32 @matrix_mult(double** %0, i32 %3, i32 %2, double** %7, i32 %3, i32 %2, double** %23, i32 %2, i32 %2)
br label %31
31: ; preds = %26, %29, %22
%32 = phi i32 [ %30, %29 ], [ %27, %26 ], [ %24, %22 ]
%33 = tail call i32 @free_dmatrix(double** %23, i32 0, i32 %6, i32 0, i32 %6)
br label %34
34: ; preds = %31, %19
%35 = phi i32 [ %20, %19 ], [ %32, %31 ]
%36 = tail call i32 @free_dmatrix(double** %7, i32 0, i32 %5, i32 0, i32 %6)
ret i32 %35
}