#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 */
float mean(int *, int);
float square_sum_dev(int *, int, int *, int);
float *lin_reg(int x_vals[], int x_vals_size, int y_vals[], int y_vals_size) {
  static float coeffs[2];
  coeffs[0] = square_sum_dev(x_vals, x_vals_size, y_vals, y_vals_size) /
              square_sum_dev(x_vals, x_vals_size, x_vals, x_vals_size);
  coeffs[1] = mean(y_vals, y_vals_size) - coeffs[0] * mean(x_vals, x_vals_size);
  return coeffs;
}


x86 assembly (clang, -O0):
<lin_reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <square_sum_dev@plt>
movss  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
call   1030 <square_sum_dev@plt>
movaps %xmm0,%xmm1
movss  -0x28(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,0x2ebf(%rip)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <mean@plt>
movss  %xmm0,-0x24(%rbp)
movss  0x2ea6(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <mean@plt>
movss  -0x24(%rbp),%xmm1
movaps %xmm0,%xmm2
movss  -0x20(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,0x2e6f(%rip)
lea    0x2e64(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lin_reg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%rbp
call   1030 <square_sum_dev@plt>
movss  %xmm0,0x8(%rsp)
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
mov    %ebx,%ecx
call   1030 <square_sum_dev@plt>
movss  0x8(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x2ed1(%rip)
lea    0x2eca(%rip),%r12
mov    %r15,%rdi
mov    %r14d,%esi
call   1040 <mean@plt>
movss  %xmm0,0x8(%rsp)
movss  0x2eb1(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
mov    %rbp,%rdi
mov    %ebx,%esi
call   1040 <mean@plt>
mulss  0xc(%rsp),%xmm0
movss  0x8(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,0x2e8d(%rip)
mov    %r12,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@lin_reg.coeffs = internal global [2 x float] zeroinitializer
define float* @lin_reg(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%9 = load i32*, i32** %5
%10 = load i32, i32* %6
%11 = load i32*, i32** %7
%12 = load i32, i32* %8
%13 = call float @square_sum_dev(i32* %9, i32 %10, i32* %11, i32 %12)
%14 = load i32*, i32** %5
%15 = load i32, i32* %6
%16 = load i32*, i32** %5
%17 = load i32, i32* %6
%18 = call float @square_sum_dev(i32* %14, i32 %15, i32* %16, i32 %17)
%19 = fdiv float %13, %18
store float %19, float* getelementptr inbounds ([2 x float], [2 x float]* @lin_reg.coeffs, i64 0, i64 0)
%20 = load i32*, i32** %7
%21 = load i32, i32* %8
%22 = call float @mean(i32* %20, i32 %21)
%23 = load float, float* getelementptr inbounds ([2 x float], [2 x float]* @lin_reg.coeffs, i64 0, i64 0)
%24 = load i32*, i32** %5
%25 = load i32, i32* %6
%26 = call float @mean(i32* %24, i32 %25)
%27 = fneg float %23
%28 = call float @llvm.fmuladd.f32(float %27, float %26, float %22)
store float %28, float* getelementptr inbounds ([2 x float], [2 x float]* @lin_reg.coeffs, i64 0, i64 1)
ret float* getelementptr inbounds ([2 x float], [2 x float]* @lin_reg.coeffs, i64 0, i64 0)
}

LLVM IR (-O2):
@lin_reg.coeffs = internal global [2 x float] zeroinitializer
define float* @lin_reg(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = tail call float @square_sum_dev(i32* %0, i32 %1, i32* %2, i32 %3)
%6 = tail call float @square_sum_dev(i32* %0, i32 %1, i32* %0, i32 %1)
%7 = fdiv float %5, %6
store float %7, float* getelementptr inbounds ([2 x float], [2 x float]* @lin_reg.coeffs, i64 0, i64 0)
%8 = tail call float @mean(i32* %2, i32 %3)
%9 = load float, float* getelementptr inbounds ([2 x float], [2 x float]* @lin_reg.coeffs, i64 0, i64 0)
%10 = tail call float @mean(i32* %0, i32 %1)
%11 = fneg float %9
%12 = tail call float @llvm.fmuladd.f32(float %11, float %10, float %8)
store float %12, float* getelementptr inbounds ([2 x float], [2 x float]* @lin_reg.coeffs, i64 0, i64 1)
ret float* getelementptr inbounds ([2 x float], [2 x float]* @lin_reg.coeffs, i64 0, i64 0)
}