#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*/ MatrixMult(double *, int, int, double *, int, double *);
int /*<<< orphan*/ MatrixT(double *, int, int, double *);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(double *, double const *, int);
int /*<<< orphan*/ svdcmp(double *, int, int, double, double *, double *);
int MatrixPinv(const double *a, int m, int n, double tol, double *b) {
  int i, j;
  double *u = (double *)malloc(m * n * sizeof(double));
  if (u == NULL) {
    return 1;
  }
  double *w = (double *)malloc(n * sizeof(double));
  if (w == NULL) {
    free(u);
    return 1;
  }
  double *v = (double *)malloc(n * n * sizeof(double));
  if (v == NULL) {
    free(u);
    free(w);
    return 1;
  }
  double *vw = (double *)malloc(n * n * sizeof(double));
  if (vw == NULL) {
    free(u);
    free(w);
    free(v);
    return 1;
  }
  double *uT = (double *)malloc(m * n * sizeof(double));
  if (uT == NULL) {
    free(u);
    free(w);
    free(v);
    free(vw);
    return 1;
  }
  memcpy(u, a, m * n * sizeof(double));
  svdcmp(u, m, n, tol, w, v);
  for (i = 0; i < n; i++) {
    if (w[i] <= tol) {
      w[i] = 0;
    } else {
      w[i] = 1.0 / w[i];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      vw[i * n + j] = v[i * n + j] * w[j];
    }
  }
  MatrixT(u, m, n, uT);
  MatrixMult(vw, n, n, uT, m, b);
  free(u);
  free(w);
  free(v);
  free(vw);
  free(uT);
  return 0;
}


x86 assembly (clang, -O0):
<MatrixPinv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11aa <MatrixPinv+0x4a>
movl   $0x1,-0x4(%rbp)
jmp    144e <MatrixPinv+0x2ee>
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11dd <MatrixPinv+0x7d>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    144e <MatrixPinv+0x2ee>
mov    -0x18(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    121e <MatrixPinv+0xbe>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    144e <MatrixPinv+0x2ee>
mov    -0x18(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1268 <MatrixPinv+0x108>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    144e <MatrixPinv+0x2ee>
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    12bb <MatrixPinv+0x15b>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    144e <MatrixPinv+0x2ee>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
movsd  -0x20(%rbp),%xmm0
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
call   1040 <svdcmp@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    136c <MatrixPinv+0x20c>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1337 <MatrixPinv+0x1d7>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1359 <MatrixPinv+0x1f9>
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  0xcb9(%rip),%xmm0
divsd  (%rax,%rcx,8),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    135e <MatrixPinv+0x1fe>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12fa <MatrixPinv+0x19a>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    13ec <MatrixPinv+0x28c>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    13d9 <MatrixPinv+0x279>
mov    -0x48(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    -0x30(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x30(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x50(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    -0x30(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1386 <MatrixPinv+0x226>
jmp    13de <MatrixPinv+0x27e>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1373 <MatrixPinv+0x213>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x58(%rbp),%rcx
call   1080 <MatrixT@plt>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x58(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    -0x28(%rbp),%r9
call   1060 <MatrixMult@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MatrixPinv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rcx,%r14
movapd %xmm0,0x20(%rsp)
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%r13
mov    %esi,%ebp
imul   %edx,%ebp
shl    $0x3,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1263 <MatrixPinv+0x103>
mov    %rax,%r12
mov    %r13,0x10(%rsp)
mov    %ebx,0xc(%rsp)
mov    %r15,%r13
lea    0x0(,%r15,8),%r15d
mov    %r15d,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     126d <MatrixPinv+0x10d>
mov    %rax,%rbx
mov    %r14,0x68(%rsp)
mov    %r13,0x18(%rsp)
imul   %r13d,%r15d
mov    %r15d,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     127a <MatrixPinv+0x11a>
mov    %rax,%r14
mov    %r12,(%rsp)
mov    %r15d,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1287 <MatrixPinv+0x127>
mov    %rax,%r12
mov    %ebp,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     129b <MatrixPinv+0x13b>
mov    %rax,0x40(%rsp)
mov    (%rsp),%r15
mov    %r15,%rdi
mov    0x10(%rsp),%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
mov    %r15,%rdi
mov    0xc(%rsp),%esi
mov    0x18(%rsp),%r15
mov    %r15d,%edx
movapd 0x20(%rsp),%xmm0
mov    %rbx,%rcx
mov    %r14,%r8
call   1040 <svdcmp@plt>
test   %r15d,%r15d
jle    15db <MatrixPinv+0x47b>
mov    %r15d,%eax
cmp    $0x1,%r15d
jne    12b2 <MatrixPinv+0x152>
xor    %ecx,%ecx
movapd 0x20(%rsp),%xmm5
jmp    164d <MatrixPinv+0x4ed>
mov    $0x1,%ebp
jmp    163c <MatrixPinv+0x4dc>
mov    $0x1,%ebp
mov    %r12,%r15
jmp    1634 <MatrixPinv+0x4d4>
mov    $0x1,%ebp
mov    %rbx,%r15
jmp    162c <MatrixPinv+0x4cc>
mov    %r14,%r15
mov    $0x1,%ebp
mov    (%rsp),%r14
mov    %rbx,%r12
jmp    1624 <MatrixPinv+0x4c4>
mov    %r12,%r15
mov    %r14,%r12
mov    %rbx,%r14
mov    $0x1,%ebp
mov    (%rsp),%rbx
jmp    161c <MatrixPinv+0x4bc>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
movapd 0x20(%rsp),%xmm5
movapd %xmm5,%xmm0
unpcklpd %xmm5,%xmm0
lea    -0x2(%rcx),%rdx
mov    %rdx,%rsi
shr    %rsi
add    $0x1,%rsi
test   %rdx,%rdx
je     1334 <MatrixPinv+0x1d4>
mov    %rsi,%rdi
and    $0xfffffffffffffffe,%rdi
xor    %edx,%edx
movapd 0xd17(%rip),%xmm1
nopl   0x0(%rax)
movupd (%rbx,%rdx,8),%xmm2
movupd 0x10(%rbx,%rdx,8),%xmm3
movapd %xmm1,%xmm4
divpd  %xmm2,%xmm4
cmpnlepd %xmm0,%xmm2
andpd  %xmm4,%xmm2
movupd %xmm2,(%rbx,%rdx,8)
movapd %xmm1,%xmm2
divpd  %xmm3,%xmm2
cmpnlepd %xmm0,%xmm3
andpd  %xmm2,%xmm3
movupd %xmm3,0x10(%rbx,%rdx,8)
add    $0x4,%rdx
add    $0xfffffffffffffffe,%rdi
jne    12f0 <MatrixPinv+0x190>
jmp    1336 <MatrixPinv+0x1d6>
xor    %edx,%edx
test   $0x1,%sil
je     135b <MatrixPinv+0x1fb>
movupd (%rbx,%rdx,8),%xmm1
movapd 0xcb7(%rip),%xmm2
divpd  %xmm1,%xmm2
cmpnlepd %xmm0,%xmm1
andpd  %xmm2,%xmm1
movupd %xmm1,(%rbx,%rdx,8)
cmp    %rax,%rcx
jne    164d <MatrixPinv+0x4ed>
test   %r15d,%r15d
jle    15db <MatrixPinv+0x47b>
lea    (%rbx,%rax,8),%rcx
mov    %rcx,0x70(%rsp)
mov    %eax,%ecx
and    $0xfffffffc,%ecx
mov    %rcx,0x60(%rsp)
add    $0xfffffffffffffffc,%rcx
mov    %rcx,0x58(%rsp)
mov    %rcx,%rdx
shr    $0x2,%rdx
add    $0x1,%rdx
mov    %rdx,%rcx
mov    %rdx,0x50(%rsp)
and    $0xfffffffffffffffe,%rdx
mov    %rdx,0x48(%rsp)
mov    %rax,%rcx
neg    %rcx
mov    %rcx,0x10(%rsp)
lea    0x30(%r12),%rsi
lea    0x0(,%rax,8),%rcx
mov    %rcx,0x20(%rsp)
lea    0x30(%r14),%rcx
lea    0x8(%r14),%rdx
lea    0x8(%r12),%r8
xor    %r9d,%r9d
mov    %r12,0x38(%rsp)
jmp    13fe <MatrixPinv+0x29e>
nopl   0x0(%rax)
add    $0x1,%r9
mov    0x20(%rsp),%rdi
add    %rdi,%rsi
add    %rdi,%rcx
add    %rdi,%rdx
add    %rdi,%r8
cmp    %rax,%r9
je     15db <MatrixPinv+0x47b>
mov    %r9,%r10
imul   %rax,%r10
cmp    $0x4,%r15d
jae    1480 <MatrixPinv+0x320>
xor    %edi,%edi
mov    %rdi,%rbp
test   $0x1,%al
je     142f <MatrixPinv+0x2cf>
add    %rdi,%r10
movsd  (%r14,%r10,8),%xmm0
mulsd  (%rbx,%rdi,8),%xmm0
movsd  %xmm0,(%r12,%r10,8)
mov    %rdi,%rbp
or     $0x1,%rbp
not    %rdi
cmp    0x10(%rsp),%rdi
je     13e0 <MatrixPinv+0x280>
nopl   0x0(%rax)
movsd  -0x8(%rdx,%rbp,8),%xmm0
mulsd  (%rbx,%rbp,8),%xmm0
movsd  %xmm0,-0x8(%r8,%rbp,8)
movsd  (%rdx,%rbp,8),%xmm0
mulsd  0x8(%rbx,%rbp,8),%xmm0
movsd  %xmm0,(%r8,%rbp,8)
add    $0x2,%rbp
cmp    %rbp,%rax
jne    1440 <MatrixPinv+0x2e0>
jmp    13e0 <MatrixPinv+0x280>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r9,%rdi
imul   %rax,%rdi
lea    (%rdi,%rax,1),%rbp
lea    (%r12,%rdi,8),%r11
lea    (%r12,%rbp,8),%r13
lea    (%r14,%rbp,8),%rbp
mov    %r14,%r15
lea    (%r14,%rdi,8),%rdi
cmp    %rbp,%r11
setb   %r12b
cmp    %r13,%rdi
setb   %dil
cmp    0x70(%rsp),%r11
setb   %r11b
cmp    %r13,%rbx
setb   %bpl
test   %dil,%r12b
jne    15bb <MatrixPinv+0x45b>
mov    $0x0,%edi
and    %bpl,%r11b
mov    0x38(%rsp),%r12
mov    %r15,%r14
mov    0x18(%rsp),%r15
jne    140d <MatrixPinv+0x2ad>
cmpq   $0x0,0x58(%rsp)
je     15cf <MatrixPinv+0x46f>
mov    0x48(%rsp),%r13
xor    %r11d,%r11d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movupd -0x30(%rcx,%r11,8),%xmm0
movupd -0x20(%rcx,%r11,8),%xmm1
movupd (%rbx,%r11,8),%xmm2
mulpd  %xmm0,%xmm2
movupd 0x10(%rbx,%r11,8),%xmm0
mulpd  %xmm1,%xmm0
movupd %xmm2,-0x30(%rsi,%r11,8)
movupd %xmm0,-0x20(%rsi,%r11,8)
movupd -0x10(%rcx,%r11,8),%xmm0
movupd (%rcx,%r11,8),%xmm1
movupd 0x20(%rbx,%r11,8),%xmm2
mulpd  %xmm0,%xmm2
movupd 0x30(%rbx,%r11,8),%xmm0
mulpd  %xmm1,%xmm0
movupd %xmm2,-0x10(%rsi,%r11,8)
movupd %xmm0,(%rsi,%r11,8)
add    $0x8,%r11
add    $0xfffffffffffffffe,%r13
jne    1500 <MatrixPinv+0x3a0>
testb  $0x1,0x50(%rsp)
je     15a5 <MatrixPinv+0x445>
lea    (%r11,%r10,1),%rdi
movupd (%r14,%rdi,8),%xmm0
movupd 0x10(%r14,%rdi,8),%xmm1
movupd (%rbx,%r11,8),%xmm2
mulpd  %xmm0,%xmm2
movupd 0x10(%rbx,%r11,8),%xmm0
mulpd  %xmm1,%xmm0
movupd %xmm2,(%r12,%rdi,8)
movupd %xmm0,0x10(%r12,%rdi,8)
mov    0x60(%rsp),%rbp
mov    %rbp,%rdi
cmp    %rax,%rbp
je     13e0 <MatrixPinv+0x280>
jmp    140d <MatrixPinv+0x2ad>
xor    %edi,%edi
mov    0x38(%rsp),%r12
mov    %r15,%r14
mov    0x18(%rsp),%r15
jmp    140d <MatrixPinv+0x2ad>
xor    %r11d,%r11d
testb  $0x1,0x50(%rsp)
jne    1572 <MatrixPinv+0x412>
jmp    15a5 <MatrixPinv+0x445>
mov    (%rsp),%rdi
mov    0xc(%rsp),%ebp
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r15,%r13
mov    0x40(%rsp),%r15
mov    %r15,%rcx
call   1080 <MatrixT@plt>
mov    %r12,%rdi
mov    %r13d,%esi
mov    %r13d,%edx
mov    %r15,%rcx
mov    %ebp,%r8d
mov    0x68(%rsp),%r9
call   1060 <MatrixMult@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movsd  0x9bb(%rip),%xmm0
jmp    1672 <MatrixPinv+0x512>
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
je     1364 <MatrixPinv+0x204>
movsd  (%rbx,%rcx,8),%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm2,%xmm5
jae    1660 <MatrixPinv+0x500>
movapd %xmm0,%xmm1
divsd  %xmm2,%xmm1
jmp    1660 <MatrixPinv+0x500>

LLVM IR (-O0):
define i32 @MatrixPinv(double* %0, i32 %1, i32 %2, double %3, double* %4) {
%6 = alloca i32
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double*
%12 = alloca i32
%13 = alloca i32
%14 = alloca double*
%15 = alloca double*
%16 = alloca double*
%17 = alloca double*
%18 = alloca double*
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
%19 = load i32, i32* %8
%20 = load i32, i32* %9
%21 = mul nsw i32 %19, %20
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 8
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to double*
store double* %26, double** %14
%27 = load double*, double** %14
%28 = icmp eq double* %27, null
br i1 %28, label %29, label %30
29: ; preds = %5
store i32 1, i32* %6
br label %209
30: ; preds = %5
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = mul i64 %32, 8
%34 = trunc i64 %33 to i32
%35 = call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to double*
store double* %36, double** %15
%37 = load double*, double** %15
%38 = icmp eq double* %37, null
br i1 %38, label %39, label %42
39: ; preds = %30
%40 = load double*, double** %14
%41 = call i32 @free(double* %40)
store i32 1, i32* %6
br label %209
42: ; preds = %30
%43 = load i32, i32* %9
%44 = load i32, i32* %9
%45 = mul nsw i32 %43, %44
%46 = sext i32 %45 to i64
%47 = mul i64 %46, 8
%48 = trunc i64 %47 to i32
%49 = call i64 @malloc(i32 %48)
%50 = inttoptr i64 %49 to double*
store double* %50, double** %16
%51 = load double*, double** %16
%52 = icmp eq double* %51, null
br i1 %52, label %53, label %58
53: ; preds = %42
%54 = load double*, double** %14
%55 = call i32 @free(double* %54)
%56 = load double*, double** %15
%57 = call i32 @free(double* %56)
store i32 1, i32* %6
br label %209
58: ; preds = %42
%59 = load i32, i32* %9
%60 = load i32, i32* %9
%61 = mul nsw i32 %59, %60
%62 = sext i32 %61 to i64
%63 = mul i64 %62, 8
%64 = trunc i64 %63 to i32
%65 = call i64 @malloc(i32 %64)
%66 = inttoptr i64 %65 to double*
store double* %66, double** %17
%67 = load double*, double** %17
%68 = icmp eq double* %67, null
br i1 %68, label %69, label %76
69: ; preds = %58
%70 = load double*, double** %14
%71 = call i32 @free(double* %70)
%72 = load double*, double** %15
%73 = call i32 @free(double* %72)
%74 = load double*, double** %16
%75 = call i32 @free(double* %74)
store i32 1, i32* %6
br label %209
76: ; preds = %58
%77 = load i32, i32* %8
%78 = load i32, i32* %9
%79 = mul nsw i32 %77, %78
%80 = sext i32 %79 to i64
%81 = mul i64 %80, 8
%82 = trunc i64 %81 to i32
%83 = call i64 @malloc(i32 %82)
%84 = inttoptr i64 %83 to double*
store double* %84, double** %18
%85 = load double*, double** %18
%86 = icmp eq double* %85, null
br i1 %86, label %87, label %96
87: ; preds = %76
%88 = load double*, double** %14
%89 = call i32 @free(double* %88)
%90 = load double*, double** %15
%91 = call i32 @free(double* %90)
%92 = load double*, double** %16
%93 = call i32 @free(double* %92)
%94 = load double*, double** %17
%95 = call i32 @free(double* %94)
store i32 1, i32* %6
br label %209
96: ; preds = %76
%97 = load double*, double** %14
%98 = load double*, double** %7
%99 = load i32, i32* %8
%100 = load i32, i32* %9
%101 = mul nsw i32 %99, %100
%102 = sext i32 %101 to i64
%103 = mul i64 %102, 8
%104 = trunc i64 %103 to i32
%105 = call i32 @memcpy(double* %97, double* %98, i32 %104)
%106 = load double*, double** %14
%107 = load i32, i32* %8
%108 = load i32, i32* %9
%109 = load double, double* %10
%110 = load double*, double** %15
%111 = load double*, double** %16
%112 = call i32 @svdcmp(double* %106, i32 %107, i32 %108, double %109, double* %110, double* %111)
store i32 0, i32* %12
br label %113
113: ; preds = %142, %96
%114 = load i32, i32* %12
%115 = load i32, i32* %9
%116 = icmp slt i32 %114, %115
br i1 %116, label %117, label %145
117: ; preds = %113
%118 = load double*, double** %15
%119 = load i32, i32* %12
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds double, double* %118, i64 %120
%122 = load double, double* %121
%123 = load double, double* %10
%124 = fcmp ole double %122, %123
br i1 %124, label %125, label %130
125: ; preds = %117
%126 = load double*, double** %15
%127 = load i32, i32* %12
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds double, double* %126, i64 %128
store double 0.000000e+00, double* %129
br label %141
130: ; preds = %117
%131 = load double*, double** %15
%132 = load i32, i32* %12
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds double, double* %131, i64 %133
%135 = load double, double* %134
%136 = fdiv double 1.000000e+00, %135
%137 = load double*, double** %15
%138 = load i32, i32* %12
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds double, double* %137, i64 %139
store double %136, double* %140
br label %141
141: ; preds = %130, %125
br label %142
142: ; preds = %141
%143 = load i32, i32* %12
%144 = add nsw i32 %143, 1
store i32 %144, i32* %12
br label %113
145: ; preds = %113
store i32 0, i32* %12
br label %146
146: ; preds = %183, %145
%147 = load i32, i32* %12
%148 = load i32, i32* %9
%149 = icmp slt i32 %147, %148
br i1 %149, label %150, label %186
150: ; preds = %146
store i32 0, i32* %13
br label %151
151: ; preds = %179, %150
%152 = load i32, i32* %13
%153 = load i32, i32* %9
%154 = icmp slt i32 %152, %153
br i1 %154, label %155, label %182
155: ; preds = %151
%156 = load double*, double** %16
%157 = load i32, i32* %12
%158 = load i32, i32* %9
%159 = mul nsw i32 %157, %158
%160 = load i32, i32* %13
%161 = add nsw i32 %159, %160
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds double, double* %156, i64 %162
%164 = load double, double* %163
%165 = load double*, double** %15
%166 = load i32, i32* %13
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds double, double* %165, i64 %167
%169 = load double, double* %168
%170 = fmul double %164, %169
%171 = load double*, double** %17
%172 = load i32, i32* %12
%173 = load i32, i32* %9
%174 = mul nsw i32 %172, %173
%175 = load i32, i32* %13
%176 = add nsw i32 %174, %175
%177 = sext i32 %176 to i64
%178 = getelementptr inbounds double, double* %171, i64 %177
store double %170, double* %178
br label %179
179: ; preds = %155
%180 = load i32, i32* %13
%181 = add nsw i32 %180, 1
store i32 %181, i32* %13
br label %151
182: ; preds = %151
br label %183
183: ; preds = %182
%184 = load i32, i32* %12
%185 = add nsw i32 %184, 1
store i32 %185, i32* %12
br label %146
186: ; preds = %146
%187 = load double*, double** %14
%188 = load i32, i32* %8
%189 = load i32, i32* %9
%190 = load double*, double** %18
%191 = call i32 @MatrixT(double* %187, i32 %188, i32 %189, double* %190)
%192 = load double*, double** %17
%193 = load i32, i32* %9
%194 = load i32, i32* %9
%195 = load double*, double** %18
%196 = load i32, i32* %8
%197 = load double*, double** %11
%198 = call i32 @MatrixMult(double* %192, i32 %193, i32 %194, double* %195, i32 %196, double* %197)
%199 = load double*, double** %14
%200 = call i32 @free(double* %199)
%201 = load double*, double** %15
%202 = call i32 @free(double* %201)
%203 = load double*, double** %16
%204 = call i32 @free(double* %203)
%205 = load double*, double** %17
%206 = call i32 @free(double* %205)
%207 = load double*, double** %18
%208 = call i32 @free(double* %207)
store i32 0, i32* %6
br label %209
209: ; preds = %186, %87, %69, %53, %39, %29
%210 = load i32, i32* %6
ret i32 %210
}

LLVM IR (-O2):
define i32 @MatrixPinv(double* %0, i32 %1, i32 %2, double %3, double* %4) {
%6 = shl i32 %1, 3
%7 = mul i32 %6, %2
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double*
%10 = icmp eq i64 %8, 0
br i1 %10, label %262, label %11
11: ; preds = %5
%12 = shl i32 %2, 3
%13 = tail call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to double*
%15 = inttoptr i64 %13 to i8*
%16 = icmp eq i64 %13, 0
br i1 %16, label %258, label %17
17: ; preds = %11
%18 = mul i32 %12, %2
%19 = tail call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to double*
%21 = icmp eq i64 %19, 0
br i1 %21, label %253, label %22
22: ; preds = %17
%23 = tail call i64 @malloc(i32 %18)
%24 = inttoptr i64 %23 to double*
%25 = icmp eq i64 %23, 0
br i1 %25, label %247, label %26
26: ; preds = %22
%27 = tail call i64 @malloc(i32 %7)
%28 = inttoptr i64 %27 to double*
%29 = icmp eq i64 %27, 0
br i1 %29, label %240, label %30
30: ; preds = %26
%31 = tail call i32 @memcpy(double* %9, double* %0, i32 %7)
%32 = tail call i32 @svdcmp(double* %9, i32 %1, i32 %2, double %3, double* %14, double* %20)
%33 = icmp sgt i32 %2, 0
br i1 %33, label %34, label %236
34: ; preds = %30
%35 = zext i32 %2 to i64
%36 = icmp eq i32 %2, 1
br i1 %36, label %82, label %37
37: ; preds = %34
%38 = and i64 %35, 4294967294
%39 = insertelement <2 x double> poison, double %3, i64 0
%40 = shufflevector <2 x double> %39, <2 x double> poison, <2 x i32> zeroinitializer
%41 = add nsw i64 %38, -2
%42 = lshr exact i64 %41, 1
%43 = add nuw i64 %42, 1
%44 = and i64 %43, 1
%45 = icmp eq i64 %41, 0
br i1 %45, label %69, label %46
46: ; preds = %37
%47 = and i64 %43, -2
br label %48
48: ; preds = %48, %46
%49 = phi i64 [ 0, %46 ], [ %66, %48 ]
%50 = phi i64 [ 0, %46 ], [ %67, %48 ]
%51 = getelementptr inbounds double, double* %14, i64 %49
%52 = bitcast double* %51 to <2 x double>*
%53 = load <2 x double>, <2 x double>* %52
%54 = fcmp ugt <2 x double> %53, %40
%55 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %53
%56 = select <2 x i1> %54, <2 x double> %55, <2 x double> zeroinitializer
%57 = bitcast double* %51 to <2 x double>*
store <2 x double> %56, <2 x double>* %57
%58 = or i64 %49, 2
%59 = getelementptr inbounds double, double* %14, i64 %58
%60 = bitcast double* %59 to <2 x double>*
%61 = load <2 x double>, <2 x double>* %60
%62 = fcmp ugt <2 x double> %61, %40
%63 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %61
%64 = select <2 x i1> %62, <2 x double> %63, <2 x double> zeroinitializer
%65 = bitcast double* %59 to <2 x double>*
store <2 x double> %64, <2 x double>* %65
%66 = add nuw i64 %49, 4
%67 = add nuw i64 %50, 2
%68 = icmp eq i64 %67, %47
br i1 %68, label %69, label %48
69: ; preds = %48, %37
%70 = phi i64 [ 0, %37 ], [ %66, %48 ]
%71 = icmp eq i64 %44, 0
br i1 %71, label %80, label %72
72: ; preds = %69
%73 = getelementptr inbounds double, double* %14, i64 %70
%74 = bitcast double* %73 to <2 x double>*
%75 = load <2 x double>, <2 x double>* %74
%76 = fcmp ugt <2 x double> %75, %40
%77 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %75
%78 = select <2 x i1> %76, <2 x double> %77, <2 x double> zeroinitializer
%79 = bitcast double* %73 to <2 x double>*
store <2 x double> %78, <2 x double>* %79
br label %80
80: ; preds = %69, %72
%81 = icmp eq i64 %38, %35
br i1 %81, label %84, label %82
82: ; preds = %34, %80
%83 = phi i64 [ 0, %34 ], [ %38, %80 ]
br label %103
84: ; preds = %103, %80
br i1 %33, label %85, label %236
85: ; preds = %84
%86 = zext i32 %2 to i64
%87 = zext i32 %2 to i64
%88 = getelementptr double, double* %14, i64 %35
%89 = and i64 %35, 4294967292
%90 = add nsw i64 %89, -4
%91 = lshr exact i64 %90, 2
%92 = add nuw nsw i64 %91, 1
%93 = icmp ult i32 %2, 4
%94 = and i64 %35, 4294967292
%95 = and i64 %92, 1
%96 = icmp eq i64 %90, 0
%97 = and i64 %92, 9223372036854775806
%98 = icmp eq i64 %95, 0
%99 = icmp eq i64 %94, %35
%100 = and i64 %35, 1
%101 = icmp eq i64 %100, 0
%102 = sub nsw i64 0, %35
br label %112
103: ; preds = %82, %103
%104 = phi i64 [ %110, %103 ], [ %83, %82 ]
%105 = getelementptr inbounds double, double* %14, i64 %104
%106 = load double, double* %105
%107 = fcmp ugt double %106, %3
%108 = fdiv double 1.000000e+00, %106
%109 = select i1 %107, double %108, double 0.000000e+00
store double %109, double* %105
%110 = add nuw nsw i64 %104, 1
%111 = icmp eq i64 %110, %35
br i1 %111, label %84, label %103
112: ; preds = %233, %85
%113 = phi i64 [ 0, %85 ], [ %234, %233 ]
%114 = mul i64 %113, %35
%115 = getelementptr double, double* %24, i64 %114
%116 = add i64 %114, %35
%117 = getelementptr double, double* %24, i64 %116
%118 = mul nsw i64 %113, %86
br i1 %93, label %199, label %119
119: ; preds = %112
%120 = bitcast double* %117 to i8*
%121 = getelementptr double, double* %20, i64 %116
%122 = getelementptr double, double* %20, i64 %114
%123 = icmp ult double* %115, %121
%124 = icmp ult double* %122, %117
%125 = and i1 %123, %124
%126 = icmp ult double* %115, %88
%127 = icmp ult i8* %15, %120
%128 = and i1 %126, %127
%129 = or i1 %125, %128
br i1 %129, label %199, label %130
130: ; preds = %119
br i1 %96, label %176, label %131
131: ; preds = %130, %131
%132 = phi i64 [ %173, %131 ], [ 0, %130 ]
%133 = phi i64 [ %174, %131 ], [ 0, %130 ]
%134 = add nuw nsw i64 %132, %118
%135 = getelementptr inbounds double, double* %20, i64 %134
%136 = bitcast double* %135 to <2 x double>*
%137 = load <2 x double>, <2 x double>* %136
%138 = getelementptr inbounds double, double* %135, i64 2
%139 = bitcast double* %138 to <2 x double>*
%140 = load <2 x double>, <2 x double>* %139
%141 = getelementptr inbounds double, double* %14, i64 %132
%142 = bitcast double* %141 to <2 x double>*
%143 = load <2 x double>, <2 x double>* %142
%144 = getelementptr inbounds double, double* %141, i64 2
%145 = bitcast double* %144 to <2 x double>*
%146 = load <2 x double>, <2 x double>* %145
%147 = fmul <2 x double> %137, %143
%148 = fmul <2 x double> %140, %146
%149 = getelementptr inbounds double, double* %24, i64 %134
%150 = bitcast double* %149 to <2 x double>*
store <2 x double> %147, <2 x double>* %150
%151 = getelementptr inbounds double, double* %149, i64 2
%152 = bitcast double* %151 to <2 x double>*
store <2 x double> %148, <2 x double>* %152
%153 = or i64 %132, 4
%154 = add nuw nsw i64 %153, %118
%155 = getelementptr inbounds double, double* %20, i64 %154
%156 = bitcast double* %155 to <2 x double>*
%157 = load <2 x double>, <2 x double>* %156
%158 = getelementptr inbounds double, double* %155, i64 2
%159 = bitcast double* %158 to <2 x double>*
%160 = load <2 x double>, <2 x double>* %159
%161 = getelementptr inbounds double, double* %14, i64 %153
%162 = bitcast double* %161 to <2 x double>*
%163 = load <2 x double>, <2 x double>* %162
%164 = getelementptr inbounds double, double* %161, i64 2
%165 = bitcast double* %164 to <2 x double>*
%166 = load <2 x double>, <2 x double>* %165
%167 = fmul <2 x double> %157, %163
%168 = fmul <2 x double> %160, %166
%169 = getelementptr inbounds double, double* %24, i64 %154
%170 = bitcast double* %169 to <2 x double>*
store <2 x double> %167, <2 x double>* %170
%171 = getelementptr inbounds double, double* %169, i64 2
%172 = bitcast double* %171 to <2 x double>*
store <2 x double> %168, <2 x double>* %172
%173 = add nuw i64 %132, 8
%174 = add i64 %133, 2
%175 = icmp eq i64 %174, %97
br i1 %175, label %176, label %131
176: ; preds = %131, %130
%177 = phi i64 [ 0, %130 ], [ %173, %131 ]
br i1 %98, label %198, label %178
178: ; preds = %176
%179 = add nuw nsw i64 %177, %118
%180 = getelementptr inbounds double, double* %20, i64 %179
%181 = bitcast double* %180 to <2 x double>*
%182 = load <2 x double>, <2 x double>* %181
%183 = getelementptr inbounds double, double* %180, i64 2
%184 = bitcast double* %183 to <2 x double>*
%185 = load <2 x double>, <2 x double>* %184
%186 = getelementptr inbounds double, double* %14, i64 %177
%187 = bitcast double* %186 to <2 x double>*
%188 = load <2 x double>, <2 x double>* %187
%189 = getelementptr inbounds double, double* %186, i64 2
%190 = bitcast double* %189 to <2 x double>*
%191 = load <2 x double>, <2 x double>* %190
%192 = fmul <2 x double> %182, %188
%193 = fmul <2 x double> %185, %191
%194 = getelementptr inbounds double, double* %24, i64 %179
%195 = bitcast double* %194 to <2 x double>*
store <2 x double> %192, <2 x double>* %195
%196 = getelementptr inbounds double, double* %194, i64 2
%197 = bitcast double* %196 to <2 x double>*
store <2 x double> %193, <2 x double>* %197
br label %198
198: ; preds = %176, %178
br i1 %99, label %233, label %199
199: ; preds = %119, %112, %198
%200 = phi i64 [ 0, %119 ], [ 0, %112 ], [ %94, %198 ]
%201 = xor i64 %200, -1
br i1 %101, label %211, label %202
202: ; preds = %199
%203 = add nuw nsw i64 %200, %118
%204 = getelementptr inbounds double, double* %20, i64 %203
%205 = load double, double* %204
%206 = getelementptr inbounds double, double* %14, i64 %200
%207 = load double, double* %206
%208 = fmul double %205, %207
%209 = getelementptr inbounds double, double* %24, i64 %203
store double %208, double* %209
%210 = or i64 %200, 1
br label %211
211: ; preds = %202, %199
%212 = phi i64 [ %200, %199 ], [ %210, %202 ]
%213 = icmp eq i64 %201, %102
br i1 %213, label %233, label %214
214: ; preds = %211, %214
%215 = phi i64 [ %231, %214 ], [ %212, %211 ]
%216 = add nuw nsw i64 %215, %118
%217 = getelementptr inbounds double, double* %20, i64 %216
%218 = load double, double* %217
%219 = getelementptr inbounds double, double* %14, i64 %215
%220 = load double, double* %219
%221 = fmul double %218, %220
%222 = getelementptr inbounds double, double* %24, i64 %216
store double %221, double* %222
%223 = add nuw nsw i64 %215, 1
%224 = add nuw nsw i64 %223, %118
%225 = getelementptr inbounds double, double* %20, i64 %224
%226 = load double, double* %225
%227 = getelementptr inbounds double, double* %14, i64 %223
%228 = load double, double* %227
%229 = fmul double %226, %228
%230 = getelementptr inbounds double, double* %24, i64 %224
store double %229, double* %230
%231 = add nuw nsw i64 %215, 2
%232 = icmp eq i64 %231, %87
br i1 %232, label %233, label %214
233: ; preds = %211, %214, %198
%234 = add nuw nsw i64 %113, 1
%235 = icmp eq i64 %234, %87
br i1 %235, label %236, label %112
236: ; preds = %233, %30, %84
%237 = tail call i32 @MatrixT(double* %9, i32 %1, i32 %2, double* %28)
%238 = tail call i32 @MatrixMult(double* %24, i32 %2, i32 %2, double* %28, i32 %1, double* %4)
%239 = tail call i32 @free(double* %9)
br label %240
240: ; preds = %26, %236
%241 = phi double* [ %14, %236 ], [ %9, %26 ]
%242 = phi double* [ %20, %236 ], [ %14, %26 ]
%243 = phi double* [ %24, %236 ], [ %20, %26 ]
%244 = phi double* [ %28, %236 ], [ %24, %26 ]
%245 = phi i32 [ 0, %236 ], [ 1, %26 ]
%246 = tail call i32 @free(double* %241)
br label %247
247: ; preds = %240, %22
%248 = phi double* [ %9, %22 ], [ %242, %240 ]
%249 = phi double* [ %14, %22 ], [ %243, %240 ]
%250 = phi double* [ %20, %22 ], [ %244, %240 ]
%251 = phi i32 [ 1, %22 ], [ %245, %240 ]
%252 = tail call i32 @free(double* %248)
br label %253
253: ; preds = %247, %17
%254 = phi double* [ %9, %17 ], [ %249, %247 ]
%255 = phi double* [ %14, %17 ], [ %250, %247 ]
%256 = phi i32 [ 1, %17 ], [ %251, %247 ]
%257 = tail call i32 @free(double* %254)
br label %258
258: ; preds = %253, %11
%259 = phi double* [ %9, %11 ], [ %255, %253 ]
%260 = phi i32 [ 1, %11 ], [ %256, %253 ]
%261 = tail call i32 @free(double* %259)
br label %262
262: ; preds = %258, %5
%263 = phi i32 [ 1, %5 ], [ %260, %258 ]
ret i32 %263
}