#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 *allocateDoubleVector(int);
double *gaussianElimination(int, double **, double *);
double *matrixToVector(double **, int, int);
double **multiplyMatrix(double **, double **, int, int, int);
double **trasposeMatrix(double **, int, int);
double **vectorToMatrix(double *, int, int);
double *multipleLinearRegression(double **X, double *y, int n, int m) {
  double **A, **XT, **B, *b, *x, **Y;
  Y = vectorToMatrix(y, m, 1);
  x = allocateDoubleVector(n);
  XT = trasposeMatrix(X, n, m);
  A = multiplyMatrix(XT, X, m, n, n);
  B = multiplyMatrix(XT, Y, m, n, 1);
  b = matrixToVector(B, n, 1);
  x = gaussianElimination(n, A, b);
  return x;
}


x86 assembly (clang, -O0):
<multipleLinearRegression>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x1,%edx
call   1070 <vectorToMatrix@plt>
mov    %rax,-0x48(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <allocateDoubleVector@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1060 <trasposeMatrix@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1080 <multiplyMatrix@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    $0x1,%r8d
call   1080 <multiplyMatrix@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1030 <matrixToVector@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <gaussianElimination@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multipleLinearRegression>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %edx,%ebx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %ecx,%esi
mov    $0x1,%edx
call   1070 <vectorToMatrix@plt>
mov    %rax,%r15
mov    %ebx,%edi
call   1040 <allocateDoubleVector@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1060 <trasposeMatrix@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %ebx,%r8d
call   1080 <multiplyMatrix@plt>
mov    %rax,%r14
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    $0x1,%r8d
call   1080 <multiplyMatrix@plt>
mov    %rax,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
call   1030 <matrixToVector@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %rax,%rdx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <gaussianElimination@plt>

LLVM IR (-O0):
define double* @multipleLinearRegression(double** %0, double* %1, i32 %2, i32 %3) {
%5 = alloca double**
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double**
%10 = alloca double**
%11 = alloca double**
%12 = alloca double*
%13 = alloca double*
%14 = alloca double**
store double** %0, double*** %5
store double* %1, double** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%15 = load double*, double** %6
%16 = load i32, i32* %8
%17 = call double** @vectorToMatrix(double* %15, i32 %16, i32 1)
store double** %17, double*** %14
%18 = load i32, i32* %7
%19 = call double* @allocateDoubleVector(i32 %18)
store double* %19, double** %13
%20 = load double**, double*** %5
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = call double** @trasposeMatrix(double** %20, i32 %21, i32 %22)
store double** %23, double*** %10
%24 = load double**, double*** %10
%25 = load double**, double*** %5
%26 = load i32, i32* %8
%27 = load i32, i32* %7
%28 = load i32, i32* %7
%29 = call double** @multiplyMatrix(double** %24, double** %25, i32 %26, i32 %27, i32 %28)
store double** %29, double*** %9
%30 = load double**, double*** %10
%31 = load double**, double*** %14
%32 = load i32, i32* %8
%33 = load i32, i32* %7
%34 = call double** @multiplyMatrix(double** %30, double** %31, i32 %32, i32 %33, i32 1)
store double** %34, double*** %11
%35 = load double**, double*** %11
%36 = load i32, i32* %7
%37 = call double* @matrixToVector(double** %35, i32 %36, i32 1)
store double* %37, double** %12
%38 = load i32, i32* %7
%39 = load double**, double*** %9
%40 = load double*, double** %12
%41 = call double* @gaussianElimination(i32 %38, double** %39, double* %40)
store double* %41, double** %13
%42 = load double*, double** %13
ret double* %42
}

LLVM IR (-O2):
define double* @multipleLinearRegression(double** %0, double* %1, i32 %2, i32 %3) {
%5 = tail call double** @vectorToMatrix(double* %1, i32 %3, i32 1)
%6 = tail call double* @allocateDoubleVector(i32 %2)
%7 = tail call double** @trasposeMatrix(double** %0, i32 %2, i32 %3)
%8 = tail call double** @multiplyMatrix(double** %7, double** %0, i32 %3, i32 %2, i32 %2)
%9 = tail call double** @multiplyMatrix(double** %7, double** %5, i32 %3, i32 %2, i32 1)
%10 = tail call double* @matrixToVector(double** %9, i32 %2, i32 1)
%11 = tail call double* @gaussianElimination(i32 %2, double** %8, double* %10)
ret double* %11
}