#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*/ free_matrix2(double **);
int /*<<< orphan*/ matrix_mult(double **, double **, double **, int, int, int);
int /*<<< orphan*/ matrix_vec_mult(double *, double **, double *, int, int);
double **new_matrix2(int, int);
int /*<<< orphan*/ solve(double *, double **, double *, int);
int /*<<< orphan*/ transpose(double **, double **, int, int);
void linear_regression(double *b, double **X, double *y, int n, int d) {
  double **Xt = new_matrix2(d, n);
  transpose(Xt, X, n, d);
  double **XtX = new_matrix2(d, d);
  matrix_mult(XtX, Xt, X, d, n, d);
  double Xty[d];
  matrix_vec_mult(Xty, Xt, y, d, n);
  solve(b, XtX, Xty, d);
  free_matrix2(Xt);
  free_matrix2(XtX);
}


x86 assembly (clang, -O0):
<linear_regression>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1070 <new_matrix2@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1040 <transpose@plt>
mov    -0x20(%rbp),%esi
mov    %esi,%edi
call   1070 <new_matrix2@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%r9d
mov    -0x1c(%rbp),%r8d
mov    %r9d,%ecx
call   1050 <matrix_mult@plt>
mov    -0x20(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1080 <matrix_vec_mult@plt>
mov    -0x48(%rbp),%rdx
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%ecx
call   1030 <solve@plt>
mov    -0x28(%rbp),%rdi
call   1060 <free_matrix2@plt>
mov    -0x30(%rbp),%rdi
call   1060 <free_matrix2@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linear_regression>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r15d
mov    %ecx,%r12d
mov    %rdx,-0x38(%rbp)
mov    %rsi,%r13
mov    %rdi,-0x40(%rbp)
mov    %r8d,%edi
mov    %ecx,%esi
call   1070 <new_matrix2@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1040 <transpose@plt>
mov    %r15d,%edi
mov    %r15d,%esi
call   1070 <new_matrix2@plt>
mov    %rax,-0x30(%rbp)
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %r15d,%r9d
call   1050 <matrix_mult@plt>
mov    %r15d,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    -0x38(%rbp),%rdx
mov    %r15d,%ecx
mov    %r12d,%r8d
call   1080 <matrix_vec_mult@plt>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%r12
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r15d,%ecx
call   1030 <solve@plt>
mov    %r14,%rdi
call   1060 <free_matrix2@plt>
mov    %r12,%rdi
call   1060 <free_matrix2@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @linear_regression(double* %0, double** %1, double* %2, i32 %3, i32 %4) {
%6 = alloca double*
%7 = alloca double**
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca double**
%12 = alloca double**
%13 = alloca i8*
%14 = alloca i64
store double* %0, double** %6
store double** %1, double*** %7
store double* %2, double** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%15 = load i32, i32* %10
%16 = load i32, i32* %9
%17 = call double** @new_matrix2(i32 %15, i32 %16)
store double** %17, double*** %11
%18 = load double**, double*** %11
%19 = load double**, double*** %7
%20 = load i32, i32* %9
%21 = load i32, i32* %10
%22 = call i32 @transpose(double** %18, double** %19, i32 %20, i32 %21)
%23 = load i32, i32* %10
%24 = load i32, i32* %10
%25 = call double** @new_matrix2(i32 %23, i32 %24)
store double** %25, double*** %12
%26 = load double**, double*** %12
%27 = load double**, double*** %11
%28 = load double**, double*** %7
%29 = load i32, i32* %10
%30 = load i32, i32* %9
%31 = load i32, i32* %10
%32 = call i32 @matrix_mult(double** %26, double** %27, double** %28, i32 %29, i32 %30, i32 %31)
%33 = load i32, i32* %10
%34 = zext i32 %33 to i64
%35 = call i8* @llvm.stacksave()
store i8* %35, i8** %13
%36 = alloca double, i64 %34
store i64 %34, i64* %14
%37 = load double**, double*** %11
%38 = load double*, double** %8
%39 = load i32, i32* %10
%40 = load i32, i32* %9
%41 = call i32 @matrix_vec_mult(double* %36, double** %37, double* %38, i32 %39, i32 %40)
%42 = load double*, double** %6
%43 = load double**, double*** %12
%44 = load i32, i32* %10
%45 = call i32 @solve(double* %42, double** %43, double* %36, i32 %44)
%46 = load double**, double*** %11
%47 = call i32 @free_matrix2(double** %46)
%48 = load double**, double*** %12
%49 = call i32 @free_matrix2(double** %48)
%50 = load i8*, i8** %13
ret void
}

LLVM IR (-O2):
define void @linear_regression(double* %0, double** %1, double* %2, i32 %3, i32 %4) {
%6 = tail call double** @new_matrix2(i32 %4, i32 %3)
%7 = tail call i32 @transpose(double** %6, double** %1, i32 %3, i32 %4)
%8 = tail call double** @new_matrix2(i32 %4, i32 %4)
%9 = tail call i32 @matrix_mult(double** %8, double** %6, double** %1, i32 %4, i32 %3, i32 %4)
%10 = zext i32 %4 to i64
%11 = alloca double, i64 %10
%12 = call i32 @matrix_vec_mult(double* %11, double** %6, double* %2, i32 %4, i32 %3)
%13 = call i32 @solve(double* %0, double** %8, double* %11, i32 %4)
%14 = call i32 @free_matrix2(double** %6)
%15 = call i32 @free_matrix2(double** %8)
ret void
}