#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 *calloc(int, int);
int /*<<< orphan*/ dgels_(char *, int *, int *, int *, double *, int *,
                          double *, int *, double *, int *, int *);
int /*<<< orphan*/ free(double *);
double *malloc(int);
double *pseudoinverse(double *a, int size) {
  char trans;
  int i, m, n, nrhs, lda, ldb, lwork, info;
  trans = 'N';
  m = size;
  n = m;
  nrhs = m;
  lda = m;
  ldb = m;
  double *b = calloc(ldb * nrhs, sizeof(double));
  for (i = 0; i < ldb; ++i) {
    b[i * nrhs + i] = 1.;
  }
  lwork = -1;
  double *work = malloc((((1) > (lwork)) ? (1) : (lwork)) * sizeof(double));
  dgels_(&trans, &m, &n, &nrhs, a, &lda, b, &ldb, work, &lwork, &info);
  lwork = (int)work[0];
  free(work);
  work = malloc((((1) > (lwork)) ? (1) : (lwork)) * sizeof(double));
  dgels_(&trans, &m, &n, &nrhs, a, &lda, b, &ldb, work, &lwork, &info);
  free(work);
  return (b);
}


x86 assembly (clang, -O0):
<pseudoinverse>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
movb   $0x4e,-0x1d(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
imul   -0x30(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    11c8 <pseudoinverse+0x88>
mov    -0x48(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x30(%rbp),%ecx
add    -0x24(%rbp),%ecx
movslq %ecx,%rcx
movsd  0xe4b(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1190 <pseudoinverse+0x50>
movl   $0xffffffff,-0x3c(%rbp)
mov    $0x1,%eax
cmp    -0x3c(%rbp),%eax
jle    11ea <pseudoinverse+0xaa>
mov    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11f0 <pseudoinverse+0xb0>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%r8
mov    -0x48(%rbp),%r14
mov    -0x50(%rbp),%r11
lea    -0x1d(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x34(%rbp),%r9
lea    -0x38(%rbp),%rbx
lea    -0x3c(%rbp),%r10
lea    -0x40(%rbp),%rax
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1040 <dgels_@plt>
mov    -0x50(%rbp),%rax
cvttsd2si (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
cmp    -0x3c(%rbp),%eax
jle    127c <pseudoinverse+0x13c>
mov    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1282 <pseudoinverse+0x142>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%r8
mov    -0x48(%rbp),%r14
mov    -0x50(%rbp),%r11
lea    -0x1d(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x34(%rbp),%r9
lea    -0x38(%rbp),%rbx
lea    -0x3c(%rbp),%r10
lea    -0x40(%rbp),%rax
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1040 <dgels_@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<pseudoinverse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %esi,%ebx
mov    %rdi,%r12
movb   $0x4e,0x3(%rsp)
mov    %esi,0x1c(%rsp)
mov    %esi,0x14(%rsp)
mov    %esi,0x10(%rsp)
mov    %esi,0xc(%rsp)
mov    %esi,0x8(%rsp)
mov    %esi,%edi
imul   %esi,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
jle    1276 <pseudoinverse+0x136>
mov    %ebx,%r11d
lea    -0x1(%r11),%rax
mov    %r11,%rcx
and    $0x3,%r11d
xor    %edx,%edx
movabs $0x3ff0000000000000,%r9
cmp    $0x3,%rax
jb     1254 <pseudoinverse+0x114>
mov    %r12,0x28(%rsp)
lea    (%rbx,%rbx,1),%edi
lea    0x0(,%rbx,4),%r10d
lea    (%rbx,%rbx,2),%esi
and    $0xfffffffc,%ecx
neg    %rcx
mov    %rcx,0x30(%rsp)
mov    $0x2,%r12d
mov    $0x1,%r13d
mov    $0x3,%r15d
mov    %rbx,%rcx
xor    %ebx,%ebx
mov    %rcx,0x20(%rsp)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movslq %edi,%rdi
movslq %ecx,%rcx
movslq %edx,%rdx
lea    (%rdx,%rbp,1),%r8
mov    %r9,(%r14,%r8,8)
lea    0x0(%r13,%rcx,1),%rax
mov    %r9,(%r14,%rax,8)
lea    (%r12,%rdi,1),%rax
movslq %esi,%rsi
mov    %r9,(%r14,%rax,8)
lea    (%r15,%rsi,1),%rax
mov    %r9,(%r14,%rax,8)
add    $0x4,%rbp
add    %r10d,%edx
add    $0x4,%r12
add    %r10d,%edi
add    $0x4,%r13
add    %r10d,%ecx
add    $0x4,%r15
add    %r10d,%esi
add    $0xfffffffffffffffc,%rbx
cmp    %rbx,0x30(%rsp)
jne    11f0 <pseudoinverse+0xb0>
neg    %rbx
mov    %rbx,%rdx
mov    0x28(%rsp),%r12
mov    0x20(%rsp),%rbx
test   %r11,%r11
je     1276 <pseudoinverse+0x136>
mov    %ebx,%eax
imul   %edx,%eax
xchg   %ax,%ax
cltq
lea    (%rdx,%rax,1),%rcx
mov    %r9,(%r14,%rcx,8)
add    $0x1,%rdx
add    %ebx,%eax
add    $0xffffffffffffffff,%r11
jne    1260 <pseudoinverse+0x120>
movl   $0xffffffff,0x4(%rsp)
ff
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
sub    $0x8,%rsp
lea    0x20(%rsp),%rbp
lea    0xc(%rsp),%rbx
lea    0x10(%rsp),%rax
lea    0xb(%rsp),%rdi
lea    0x24(%rsp),%r13
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x14(%rsp),%r9
mov    %r13,%rsi
mov    %r12,%r8
push   %rbp
push   %rbx
push   %r15
push   %rax
push   %r14
call   1040 <dgels_@plt>
add    $0x30,%rsp
cvttsd2si (%r15),%ebp
mov    %ebp,0x4(%rsp)
mov    %r15,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
mov    $0x1,%edi
cmovg  %ebp,%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
sub    $0x8,%rsp
lea    0xb(%rsp),%rdi
mov    %r13,%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
mov    %r12,%r8
lea    0x14(%rsp),%r9
lea    0x20(%rsp),%rax
push   %rax
lea    0x14(%rsp),%rax
push   %rax
push   %rbp
lea    0x28(%rsp),%rax
push   %rax
push   %r14
call   1040 <dgels_@plt>
add    $0x30,%rsp
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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