#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*/ allocate_double_matrix(double ***, int, int);
int /*<<< orphan*/ allocate_double_vector(double **, int);
int /*<<< orphan*/ dgels_(char *, int *, int *, int *, double *, int *,
                          double *, int *, double *, int *, int *);
int /*<<< orphan*/ free_matrix(void **);
int /*<<< orphan*/ free_vector(double *);
int least_squares(int m, int n, double **matrix) {
  if (m < 1 || n < 1 || n > m)
    return -2;
  int i, j;
  int info, lwork = m * m;
  double *work;
  if (!allocate_double_vector(&work, lwork)) {
    return -1;
  }
  char transa = 'N';
  double **a_matrix;
  if (!allocate_double_matrix(&a_matrix, n, m)) {
    return -1;
  }
  for (i = 0; i < m; i++)
    for (j = 0; j < n; j++)
      a_matrix[j][i] = matrix[j][i];
  double **b_matrix;
  if (!allocate_double_matrix(&b_matrix, m, m)) {
    return -1;
  }
  for (i = 0; i < m; i++)
    for (j = 0; j < m; j++)
      b_matrix[i][j] = (i == j);
  dgels_(&transa, &m, &n, &m, a_matrix[0], &m, b_matrix[0], &m, work, &lwork,
         &info);
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      matrix[i][j] = b_matrix[j][i];
  free_matrix((void **)a_matrix);
  free_matrix((void **)b_matrix);
  free_vector(work);
  return 1;
}


x86 assembly (clang, -O0):
<least_squares>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %edi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %rdx,-0x28(%rbp)
cmpl   $0x1,-0x18(%rbp)
jl     1185 <least_squares+0x35>
cmpl   $0x1,-0x1c(%rbp)
jl     1185 <least_squares+0x35>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1191 <least_squares+0x41>
movl   $0xfffffffe,-0x14(%rbp)
jmp    13c6 <least_squares+0x276>
mov    -0x18(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%esi
lea    -0x40(%rbp),%rdi
call   1060 <allocate_double_vector@plt>
cmp    $0x0,%eax
jne    11bc <least_squares+0x6c>
movl   $0xffffffff,-0x14(%rbp)
jmp    13c6 <least_squares+0x276>
movb   $0x4e,-0x41(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    -0x50(%rbp),%rdi
call   1070 <allocate_double_matrix@plt>
cmp    $0x0,%eax
jne    11e4 <least_squares+0x94>
movl   $0xffffffff,-0x14(%rbp)
jmp    13c6 <least_squares+0x276>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1255 <least_squares+0x105>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1242 <least_squares+0xf2>
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x50(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11fe <least_squares+0xae>
jmp    1247 <least_squares+0xf7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11eb <least_squares+0x9b>
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    -0x58(%rbp),%rdi
call   1070 <allocate_double_matrix@plt>
cmp    $0x0,%eax
jne    1279 <least_squares+0x129>
movl   $0xffffffff,-0x14(%rbp)
jmp    13c6 <least_squares+0x276>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12e7 <least_squares+0x197>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12d4 <least_squares+0x184>
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cvtsi2sd %eax,%xmm0
mov    -0x58(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1293 <least_squares+0x143>
jmp    12d9 <least_squares+0x189>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1280 <least_squares+0x130>
mov    -0x50(%rbp),%rax
mov    (%rax),%r8
mov    -0x58(%rbp),%rax
mov    (%rax),%r14
mov    -0x40(%rbp),%r11
lea    -0x41(%rbp),%rdi
lea    -0x18(%rbp),%rbx
lea    -0x1c(%rbp),%rdx
lea    -0x38(%rbp),%r10
lea    -0x34(%rbp),%rax
mov    %rbx,%rsi
mov    %rbx,%rcx
mov    %rbx,%r9
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
call   1040 <dgels_@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    13a4 <least_squares+0x254>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1391 <least_squares+0x241>
mov    -0x58(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    134d <least_squares+0x1fd>
jmp    1396 <least_squares+0x246>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    133a <least_squares+0x1ea>
mov    -0x50(%rbp),%rdi
call   1030 <free_matrix@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free_matrix@plt>
mov    -0x40(%rbp),%rdi
call   1050 <free_vector@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<least_squares>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %edi,0x14(%rsp)
mov    %esi,0x10(%rsp)
mov    $0xfffffffe,%eax
cmp    %edi,%esi
jg     14bf <least_squares+0x36f>
mov    %edi,%r14d
test   %edi,%edi
jle    14bf <least_squares+0x36f>
mov    %esi,%ebp
test   %esi,%esi
jle    14bf <least_squares+0x36f>
mov    %rdx,%r12
mov    %r14d,%esi
imul   %r14d,%esi
mov    %esi,0x2c(%rsp)
lea    0x30(%rsp),%rdi
call   1060 <allocate_double_vector@plt>
test   %eax,%eax
je     137b <least_squares+0x22b>
movb   $0x4e,0xf(%rsp)
lea    0x20(%rsp),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1070 <allocate_double_matrix@plt>
test   %eax,%eax
je     137b <least_squares+0x22b>
mov    0x20(%rsp),%rax
mov    %r14d,%r15d
mov    %ebp,%r9d
lea    -0x1(%r9),%r8
mov    %r9d,%esi
and    $0x3,%esi
and    $0xfffffffc,%r9d
xor    %edi,%edi
jmp    11ed <least_squares+0x9d>
nop
add    $0x1,%rdi
cmp    %r15,%rdi
je     1291 <least_squares+0x141>
xor    %ebp,%ebp
cmp    $0x3,%r8
jb     1257 <least_squares+0x107>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12,%rbp,8),%rcx
movsd  (%rcx,%rdi,8),%xmm0
mov    (%rax,%rbp,8),%rcx
movsd  %xmm0,(%rcx,%rdi,8)
mov    0x8(%r12,%rbp,8),%rcx
movsd  (%rcx,%rdi,8),%xmm0
mov    0x8(%rax,%rbp,8),%rcx
movsd  %xmm0,(%rcx,%rdi,8)
mov    0x10(%r12,%rbp,8),%rcx
movsd  (%rcx,%rdi,8),%xmm0
mov    0x10(%rax,%rbp,8),%rcx
movsd  %xmm0,(%rcx,%rdi,8)
mov    0x18(%r12,%rbp,8),%rcx
movsd  (%rcx,%rdi,8),%xmm0
mov    0x18(%rax,%rbp,8),%rcx
movsd  %xmm0,(%rcx,%rdi,8)
add    $0x4,%rbp
cmp    %rbp,%r9
jne    1200 <least_squares+0xb0>
test   %rsi,%rsi
je     11e0 <least_squares+0x90>
lea    (%rax,%rbp,8),%rdx
lea    (%r12,%rbp,8),%rbp
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%rbp,%rcx,8),%rbx
movsd  (%rbx,%rdi,8),%xmm0
mov    (%rdx,%rcx,8),%rbx
movsd  %xmm0,(%rbx,%rdi,8)
add    $0x1,%rcx
cmp    %rcx,%rsi
jne    1270 <least_squares+0x120>
jmp    11e0 <least_squares+0x90>
lea    0x18(%rsp),%rdi
mov    %r14d,%esi
mov    %r14d,%edx
call   1070 <allocate_double_matrix@plt>
test   %eax,%eax
je     137b <least_squares+0x22b>
mov    0x18(%rsp),%r8
lea    -0x1(%r15),%r9
mov    %r15d,%edx
and    $0x3,%edx
mov    %r15d,%esi
and    $0xfffffffc,%esi
xor    %edi,%edi
movsd  0xd38(%rip),%xmm0
jmp    12dd <least_squares+0x18d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rdi
cmp    %r15,%rdi
je     1385 <least_squares+0x235>
mov    (%r8,%rdi,8),%rbp
xor    %eax,%eax
cmp    $0x3,%r9
jae    132f <least_squares+0x1df>
test   %rdx,%rdx
je     12d0 <least_squares+0x180>
lea    0x0(%rbp,%rax,8),%rbp
mov    %rdi,%rcx
sub    %rax,%rcx
xor    %eax,%eax
jmp    130f <least_squares+0x1bf>
nopl   (%rax)
movsd  %xmm1,0x0(%rbp,%rax,8)
add    $0x1,%rax
cmp    %rax,%rdx
je     12d0 <least_squares+0x180>
movaps %xmm0,%xmm1
cmp    %rax,%rcx
je     1300 <least_squares+0x1b0>
xorps  %xmm1,%xmm1
jmp    1300 <least_squares+0x1b0>
nopl   0x0(%rax)
movsd  %xmm1,0x18(%rbp,%rax,8)
add    $0x4,%rax
cmp    %rsi,%rax
je     12e9 <least_squares+0x199>
movaps %xmm0,%xmm1
cmp    %rax,%rdi
je     133a <least_squares+0x1ea>
xorps  %xmm1,%xmm1
movsd  %xmm1,0x0(%rbp,%rax,8)
lea    0x1(%rax),%rcx
movaps %xmm0,%xmm1
cmp    %rcx,%rdi
je     134f <least_squares+0x1ff>
xorps  %xmm1,%xmm1
movsd  %xmm1,0x8(%rbp,%rax,8)
lea    0x2(%rax),%rcx
movaps %xmm0,%xmm1
cmp    %rcx,%rdi
je     1364 <least_squares+0x214>
xorps  %xmm1,%xmm1
movsd  %xmm1,0x10(%rbp,%rax,8)
lea    0x3(%rax),%rcx
movaps %xmm0,%xmm1
cmp    %rcx,%rdi
je     1320 <least_squares+0x1d0>
xorps  %xmm1,%xmm1
jmp    1320 <least_squares+0x1d0>
mov    $0xffffffff,%eax
jmp    14bf <least_squares+0x36f>
mov    0x20(%rsp),%rax
mov    (%rax),%r8
mov    0x18(%rsp),%rax
sub    $0x8,%rsp
lea    0x44(%rsp),%rbp
lea    0x34(%rsp),%rbx
lea    0x1c(%rsp),%rcx
lea    0x17(%rsp),%rdi
lea    0x18(%rsp),%rdx
mov    %rcx,%rsi
mov    %rcx,%r9
push   %rbp
push   %rbx
push   0x48(%rsp)
push   %rcx
push   (%rax)
call   1040 <dgels_@plt>
add    $0x30,%rsp
mov    0x10(%rsp),%r9d
test   %r9d,%r9d
jle    149c <least_squares+0x34c>
mov    0x14(%rsp),%r10d
mov    0x18(%rsp),%rdx
mov    %r10,%r8
add    $0xffffffffffffffff,%r8
mov    %r10d,%edi
and    $0x3,%edi
mov    %r10d,%r11d
and    $0xfffffffc,%r11d
xor    %ebp,%ebp
jmp    140d <least_squares+0x2bd>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %r9,%rbp
je     149c <least_squares+0x34c>
test   %r10d,%r10d
jle    1400 <least_squares+0x2b0>
mov    (%r12,%rbp,8),%rax
xor    %esi,%esi
cmp    $0x3,%r8
jb     1467 <least_squares+0x317>
xchg   %ax,%ax
mov    (%rdx,%rsi,8),%rcx
movsd  (%rcx,%rbp,8),%xmm0
movsd  %xmm0,(%rax,%rsi,8)
mov    0x8(%rdx,%rsi,8),%rcx
movsd  (%rcx,%rbp,8),%xmm0
movsd  %xmm0,0x8(%rax,%rsi,8)
mov    0x10(%rdx,%rsi,8),%rcx
movsd  (%rcx,%rbp,8),%xmm0
movsd  %xmm0,0x10(%rax,%rsi,8)
mov    0x18(%rdx,%rsi,8),%rcx
movsd  (%rcx,%rbp,8),%xmm0
movsd  %xmm0,0x18(%rax,%rsi,8)
add    $0x4,%rsi
cmp    %rsi,%r11
jne    1420 <least_squares+0x2d0>
test   %rdi,%rdi
je     1400 <least_squares+0x2b0>
lea    (%rax,%rsi,8),%rax
lea    (%rdx,%rsi,8),%rsi
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
mov    (%rsi,%rcx,8),%rbx
movsd  (%rbx,%rbp,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rdi
jne    1480 <least_squares+0x330>
jmp    1400 <least_squares+0x2b0>
mov    0x20(%rsp),%rdi
call   1030 <free_matrix@plt>
mov    0x18(%rsp),%rdi
call   1030 <free_matrix@plt>
mov    0x30(%rsp),%rdi
call   1050 <free_vector@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @least_squares(i32 %0, i32 %1, double** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double*
%13 = alloca i8
%14 = alloca double**
%15 = alloca double**
store i32 %0, i32* %5
store i32 %1, i32* %6
store double** %2, double*** %7
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 1
br i1 %17, label %25, label %18
18: ; preds = %3
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 1
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* %6
%23 = load i32, i32* %5
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21, %18, %3
store i32 -2, i32* %4
br label %164
26: ; preds = %21
%27 = load i32, i32* %5
%28 = load i32, i32* %5
%29 = mul nsw i32 %27, %28
store i32 %29, i32* %11
%30 = load i32, i32* %11
%31 = call i32 @allocate_double_vector(double** %12, i32 %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %26
store i32 -1, i32* %4
br label %164
34: ; preds = %26
store i8 78, i8* %13
%35 = load i32, i32* %6
%36 = load i32, i32* %5
%37 = call i32 @allocate_double_matrix(double*** %14, i32 %35, i32 %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %34
store i32 -1, i32* %4
br label %164
40: ; preds = %34
store i32 0, i32* %8
br label %41
41: ; preds = %72, %40
%42 = load i32, i32* %8
%43 = load i32, i32* %5
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %75
45: ; preds = %41
store i32 0, i32* %9
br label %46
46: ; preds = %68, %45
%47 = load i32, i32* %9
%48 = load i32, i32* %6
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %71
50: ; preds = %46
%51 = load double**, double*** %7
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double*, double** %51, i64 %53
%55 = load double*, double** %54
%56 = load i32, i32* %8
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
%60 = load double**, double*** %14
%61 = load i32, i32* %9
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double*, double** %60, i64 %62
%64 = load double*, double** %63
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %64, i64 %66
store double %59, double* %67
br label %68
68: ; preds = %50
%69 = load i32, i32* %9
%70 = add nsw i32 %69, 1
store i32 %70, i32* %9
br label %46
71: ; preds = %46
br label %72
72: ; preds = %71
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 1
store i32 %74, i32* %8
br label %41
75: ; preds = %41
%76 = load i32, i32* %5
%77 = load i32, i32* %5
%78 = call i32 @allocate_double_matrix(double*** %15, i32 %76, i32 %77)
%79 = icmp ne i32 %78, 0
br i1 %79, label %81, label %80
80: ; preds = %75
store i32 -1, i32* %4
br label %164
81: ; preds = %75
store i32 0, i32* %8
br label %82
82: ; preds = %109, %81
%83 = load i32, i32* %8
%84 = load i32, i32* %5
%85 = icmp slt i32 %83, %84
br i1 %85, label %86, label %112
86: ; preds = %82
store i32 0, i32* %9
br label %87
87: ; preds = %105, %86
%88 = load i32, i32* %9
%89 = load i32, i32* %5
%90 = icmp slt i32 %88, %89
br i1 %90, label %91, label %108
91: ; preds = %87
%92 = load i32, i32* %8
%93 = load i32, i32* %9
%94 = icmp eq i32 %92, %93
%95 = zext i1 %94 to i32
%96 = sitofp i32 %95 to double
%97 = load double**, double*** %15
%98 = load i32, i32* %8
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds double*, double** %97, i64 %99
%101 = load double*, double** %100
%102 = load i32, i32* %9
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds double, double* %101, i64 %103
store double %96, double* %104
br label %105
105: ; preds = %91
%106 = load i32, i32* %9
%107 = add nsw i32 %106, 1
store i32 %107, i32* %9
br label %87
108: ; preds = %87
br label %109
109: ; preds = %108
%110 = load i32, i32* %8
%111 = add nsw i32 %110, 1
store i32 %111, i32* %8
br label %82
112: ; preds = %82
%113 = load double**, double*** %14
%114 = getelementptr inbounds double*, double** %113, i64 0
%115 = load double*, double** %114
%116 = load double**, double*** %15
%117 = getelementptr inbounds double*, double** %116, i64 0
%118 = load double*, double** %117
%119 = load double*, double** %12
%120 = call i32 @dgels_(i8* %13, i32* %5, i32* %6, i32* %5, double* %115, i32* %5, double* %118, i32* %5, double* %119, i32* %11, i32* %10)
store i32 0, i32* %8
br label %121
121: ; preds = %152, %112
%122 = load i32, i32* %8
%123 = load i32, i32* %6
%124 = icmp slt i32 %122, %123
br i1 %124, label %125, label %155
125: ; preds = %121
store i32 0, i32* %9
br label %126
126: ; preds = %148, %125
%127 = load i32, i32* %9
%128 = load i32, i32* %5
%129 = icmp slt i32 %127, %128
br i1 %129, label %130, label %151
130: ; preds = %126
%131 = load double**, double*** %15
%132 = load i32, i32* %9
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds double*, double** %131, i64 %133
%135 = load double*, double** %134
%136 = load i32, i32* %8
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds double, double* %135, i64 %137
%139 = load double, double* %138
%140 = load double**, double*** %7
%141 = load i32, i32* %8
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds double*, double** %140, i64 %142
%144 = load double*, double** %143
%145 = load i32, i32* %9
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds double, double* %144, i64 %146
store double %139, double* %147
br label %148
148: ; preds = %130
%149 = load i32, i32* %9
%150 = add nsw i32 %149, 1
store i32 %150, i32* %9
br label %126
151: ; preds = %126
br label %152
152: ; preds = %151
%153 = load i32, i32* %8
%154 = add nsw i32 %153, 1
store i32 %154, i32* %8
br label %121
155: ; preds = %121
%156 = load double**, double*** %14
%157 = bitcast double** %156 to i8**
%158 = call i32 @free_matrix(i8** %157)
%159 = load double**, double*** %15
%160 = bitcast double** %159 to i8**
%161 = call i32 @free_matrix(i8** %160)
%162 = load double*, double** %12
%163 = call i32 @free_vector(double* %162)
store i32 1, i32* %4
br label %164
164: ; preds = %155, %80, %39, %33, %25
%165 = load i32, i32* %4
ret i32 %165
}

LLVM IR (-O2):
define i32 @least_squares(i32 %0, i32 %1, double** nocapture %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double*
%9 = alloca i8
%10 = alloca double**
%11 = alloca double**
store i32 %0, i32* %4
store i32 %1, i32* %5
%12 = icmp slt i32 %0, 1
%13 = icmp slt i32 %1, 1
%14 = or i1 %12, %13
%15 = icmp sgt i32 %1, %0
%16 = or i1 %15, %14
br i1 %16, label %230, label %17
17: ; preds = %3
%18 = bitcast i32* %6 to i8*
%19 = bitcast i32* %7 to i8*
%20 = mul nsw i32 %0, %0
store i32 %20, i32* %7
%21 = bitcast double** %8 to i8*
%22 = call i32 @allocate_double_vector(double** %8, i32 %20)
%23 = icmp eq i32 %22, 0
br i1 %23, label %228, label %24
24: ; preds = %17
store i8 78, i8* %9
%25 = bitcast double*** %10 to i8*
%26 = call i32 @allocate_double_matrix(double*** %10, i32 %1, i32 %0)
%27 = icmp eq i32 %26, 0
br i1 %27, label %226, label %28
28: ; preds = %24
%29 = load double**, double*** %10
%30 = zext i32 %0 to i64
%31 = zext i32 %1 to i64
%32 = add nsw i64 %31, -1
%33 = and i64 %31, 3
%34 = icmp ult i64 %32, 3
%35 = and i64 %31, 4294967292
%36 = icmp eq i64 %33, 0
br label %37
37: ; preds = %28, %91
%38 = phi i64 [ 0, %28 ], [ %92, %91 ]
br i1 %34, label %76, label %39
39: ; preds = %37, %39
%40 = phi i64 [ %73, %39 ], [ 0, %37 ]
%41 = phi i64 [ %74, %39 ], [ 0, %37 ]
%42 = getelementptr inbounds double*, double** %2, i64 %40
%43 = load double*, double** %42
%44 = getelementptr inbounds double, double* %43, i64 %38
%45 = load double, double* %44
%46 = getelementptr inbounds double*, double** %29, i64 %40
%47 = load double*, double** %46
%48 = getelementptr inbounds double, double* %47, i64 %38
store double %45, double* %48
%49 = or i64 %40, 1
%50 = getelementptr inbounds double*, double** %2, i64 %49
%51 = load double*, double** %50
%52 = getelementptr inbounds double, double* %51, i64 %38
%53 = load double, double* %52
%54 = getelementptr inbounds double*, double** %29, i64 %49
%55 = load double*, double** %54
%56 = getelementptr inbounds double, double* %55, i64 %38
store double %53, double* %56
%57 = or i64 %40, 2
%58 = getelementptr inbounds double*, double** %2, i64 %57
%59 = load double*, double** %58
%60 = getelementptr inbounds double, double* %59, i64 %38
%61 = load double, double* %60
%62 = getelementptr inbounds double*, double** %29, i64 %57
%63 = load double*, double** %62
%64 = getelementptr inbounds double, double* %63, i64 %38
store double %61, double* %64
%65 = or i64 %40, 3
%66 = getelementptr inbounds double*, double** %2, i64 %65
%67 = load double*, double** %66
%68 = getelementptr inbounds double, double* %67, i64 %38
%69 = load double, double* %68
%70 = getelementptr inbounds double*, double** %29, i64 %65
%71 = load double*, double** %70
%72 = getelementptr inbounds double, double* %71, i64 %38
store double %69, double* %72
%73 = add nuw nsw i64 %40, 4
%74 = add i64 %41, 4
%75 = icmp eq i64 %74, %35
br i1 %75, label %76, label %39
76: ; preds = %39, %37
%77 = phi i64 [ 0, %37 ], [ %73, %39 ]
br i1 %36, label %91, label %78
78: ; preds = %76, %78
%79 = phi i64 [ %88, %78 ], [ %77, %76 ]
%80 = phi i64 [ %89, %78 ], [ 0, %76 ]
%81 = getelementptr inbounds double*, double** %2, i64 %79
%82 = load double*, double** %81
%83 = getelementptr inbounds double, double* %82, i64 %38
%84 = load double, double* %83
%85 = getelementptr inbounds double*, double** %29, i64 %79
%86 = load double*, double** %85
%87 = getelementptr inbounds double, double* %86, i64 %38
store double %84, double* %87
%88 = add nuw nsw i64 %79, 1
%89 = add i64 %80, 1
%90 = icmp eq i64 %89, %33
br i1 %90, label %91, label %78
91: ; preds = %78, %76
%92 = add nuw nsw i64 %38, 1
%93 = icmp eq i64 %92, %30
br i1 %93, label %94, label %37
94: ; preds = %91
%95 = bitcast double*** %11 to i8*
%96 = call i32 @allocate_double_matrix(double*** %11, i32 %0, i32 %0)
%97 = icmp eq i32 %96, 0
br i1 %97, label %224, label %98
98: ; preds = %94
%99 = load double**, double*** %11
%100 = zext i32 %0 to i64
%101 = add nsw i64 %30, -1
%102 = and i64 %30, 3
%103 = icmp ult i64 %101, 3
%104 = and i64 %30, 4294967292
%105 = icmp eq i64 %102, 0
br label %106
106: ; preds = %142, %98
%107 = phi i64 [ 0, %98 ], [ %143, %142 ]
%108 = getelementptr inbounds double*, double** %99, i64 %107
%109 = load double*, double** %108
br i1 %103, label %131, label %110
110: ; preds = %106, %110
%111 = phi i64 [ %128, %110 ], [ 0, %106 ]
%112 = phi i64 [ %129, %110 ], [ 0, %106 ]
%113 = icmp eq i64 %107, %111
%114 = uitofp i1 %113 to double
%115 = getelementptr inbounds double, double* %109, i64 %111
store double %114, double* %115
%116 = or i64 %111, 1
%117 = icmp eq i64 %107, %116
%118 = uitofp i1 %117 to double
%119 = getelementptr inbounds double, double* %109, i64 %116
store double %118, double* %119
%120 = or i64 %111, 2
%121 = icmp eq i64 %107, %120
%122 = uitofp i1 %121 to double
%123 = getelementptr inbounds double, double* %109, i64 %120
store double %122, double* %123
%124 = or i64 %111, 3
%125 = icmp eq i64 %107, %124
%126 = uitofp i1 %125 to double
%127 = getelementptr inbounds double, double* %109, i64 %124
store double %126, double* %127
%128 = add nuw nsw i64 %111, 4
%129 = add i64 %112, 4
%130 = icmp eq i64 %129, %104
br i1 %130, label %131, label %110
131: ; preds = %110, %106
%132 = phi i64 [ 0, %106 ], [ %128, %110 ]
br i1 %105, label %142, label %133
133: ; preds = %131, %133
%134 = phi i64 [ %139, %133 ], [ %132, %131 ]
%135 = phi i64 [ %140, %133 ], [ 0, %131 ]
%136 = icmp eq i64 %107, %134
%137 = uitofp i1 %136 to double
%138 = getelementptr inbounds double, double* %109, i64 %134
store double %137, double* %138
%139 = add nuw nsw i64 %134, 1
%140 = add i64 %135, 1
%141 = icmp eq i64 %140, %102
br i1 %141, label %142, label %133
142: ; preds = %133, %131
%143 = add nuw nsw i64 %107, 1
%144 = icmp eq i64 %143, %100
br i1 %144, label %145, label %106
145: ; preds = %142
%146 = load double**, double*** %10
%147 = load double*, double** %146
%148 = load double**, double*** %11
%149 = load double*, double** %148
%150 = load double*, double** %8
%151 = call i32 @dgels_(i8* %9, i32* %4, i32* %5, i32* %4, double* %147, i32* %4, double* %149, i32* %4, double* %150, i32* %7, i32* %6)
%152 = load i32, i32* %5
%153 = icmp sgt i32 %152, 0
br i1 %153, label %154, label %215
154: ; preds = %145
%155 = load i32, i32* %4
%156 = icmp sgt i32 %155, 0
%157 = load double**, double*** %11
%158 = zext i32 %152 to i64
%159 = zext i32 %155 to i64
%160 = add nsw i64 %159, -1
%161 = and i64 %159, 3
%162 = icmp ult i64 %160, 3
%163 = and i64 %159, 4294967292
%164 = icmp eq i64 %161, 0
br label %165
165: ; preds = %154, %212
%166 = phi i64 [ 0, %154 ], [ %213, %212 ]
br i1 %156, label %167, label %212
167: ; preds = %165
%168 = getelementptr inbounds double*, double** %2, i64 %166
%169 = load double*, double** %168
br i1 %162, label %199, label %170
170: ; preds = %167, %170
%171 = phi i64 [ %196, %170 ], [ 0, %167 ]
%172 = phi i64 [ %197, %170 ], [ 0, %167 ]
%173 = getelementptr inbounds double*, double** %157, i64 %171
%174 = load double*, double** %173
%175 = getelementptr inbounds double, double* %174, i64 %166
%176 = load double, double* %175
%177 = getelementptr inbounds double, double* %169, i64 %171
store double %176, double* %177
%178 = or i64 %171, 1
%179 = getelementptr inbounds double*, double** %157, i64 %178
%180 = load double*, double** %179
%181 = getelementptr inbounds double, double* %180, i64 %166
%182 = load double, double* %181
%183 = getelementptr inbounds double, double* %169, i64 %178
store double %182, double* %183
%184 = or i64 %171, 2
%185 = getelementptr inbounds double*, double** %157, i64 %184
%186 = load double*, double** %185
%187 = getelementptr inbounds double, double* %186, i64 %166
%188 = load double, double* %187
%189 = getelementptr inbounds double, double* %169, i64 %184
store double %188, double* %189
%190 = or i64 %171, 3
%191 = getelementptr inbounds double*, double** %157, i64 %190
%192 = load double*, double** %191
%193 = getelementptr inbounds double, double* %192, i64 %166
%194 = load double, double* %193
%195 = getelementptr inbounds double, double* %169, i64 %190
store double %194, double* %195
%196 = add nuw nsw i64 %171, 4
%197 = add i64 %172, 4
%198 = icmp eq i64 %197, %163
br i1 %198, label %199, label %170
199: ; preds = %170, %167
%200 = phi i64 [ 0, %167 ], [ %196, %170 ]
br i1 %164, label %212, label %201
201: ; preds = %199, %201
%202 = phi i64 [ %209, %201 ], [ %200, %199 ]
%203 = phi i64 [ %210, %201 ], [ 0, %199 ]
%204 = getelementptr inbounds double*, double** %157, i64 %202
%205 = load double*, double** %204
%206 = getelementptr inbounds double, double* %205, i64 %166
%207 = load double, double* %206
%208 = getelementptr inbounds double, double* %169, i64 %202
store double %207, double* %208
%209 = add nuw nsw i64 %202, 1
%210 = add i64 %203, 1
%211 = icmp eq i64 %210, %161
br i1 %211, label %212, label %201
212: ; preds = %199, %201, %165
%213 = add nuw nsw i64 %166, 1
%214 = icmp eq i64 %213, %158
br i1 %214, label %215, label %165
215: ; preds = %212, %145
%216 = bitcast double*** %10 to i8***
%217 = load i8**, i8*** %216
%218 = call i32 @free_matrix(i8** %217)
%219 = bitcast double*** %11 to i8***
%220 = load i8**, i8*** %219
%221 = call i32 @free_matrix(i8** %220)
%222 = load double*, double** %8
%223 = call i32 @free_vector(double* %222)
br label %224
224: ; preds = %94, %215
%225 = phi i32 [ 1, %215 ], [ -1, %94 ]
br label %226
226: ; preds = %24, %224
%227 = phi i32 [ %225, %224 ], [ -1, %24 ]
br label %228
228: ; preds = %17, %226
%229 = phi i32 [ %227, %226 ], [ -1, %17 ]
br label %230
230: ; preds = %3, %228
%231 = phi i32 [ %229, %228 ], [ -2, %3 ]
ret i32 %231
}