#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double calculoCoeficienteLinear(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, double *);
double calculoCoeficienteAngular(int quantidadeVelas) {
  FILE *arquivo;
  double x[quantidadeVelas], y[quantidadeVelas];
  double soma_x = 0, soma_y = 0;
  double variacaoAngular;
  int i;
  arquivo = fopen("dadosMinimosQuadrados.txt", "rt");
  for (i = 1; i < quantidadeVelas; i++) {
    fscanf(arquivo, "%lf", &x[i]);
    fscanf(arquivo, "%lf", &y[i]);
    soma_x = soma_x + x[i];
    soma_y = soma_y + y[i];
  }
  variacaoAngular =
      soma_y / quantidadeVelas -
      (calculoCoeficienteLinear(quantidadeVelas) * soma_x / quantidadeVelas);
  fclose(arquivo);
  return variacaoAngular;
}


x86 assembly (clang, -O0):
<calculoCoeficienteAngular>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
lea    0xe57(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1246 <calculoCoeficienteAngular+0x106>
mov    -0x58(%rbp),%rdx
mov    -0x10(%rbp),%rdi
movslq -0x44(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe37(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x50(%rbp),%rdx
mov    -0x10(%rbp),%rdi
movslq -0x44(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe18(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x58(%rbp),%rcx
mov    -0x50(%rbp),%rax
movsd  -0x30(%rbp),%xmm0
movslq -0x44(%rbp),%rdx
addsd  (%rcx,%rdx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm0
movslq -0x44(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11c0 <calculoCoeficienteAngular+0x80>
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <calculoCoeficienteLinear@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm1
cvtsi2sdl -0x4(%rbp),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculoCoeficienteAngular>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edi,%r13d
mov    %edi,%r14d
mov    %rsp,%r12
lea    0xf(,%r14,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe84(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
mov    %r13d,-0x2c(%rbp)
cmp    $0x2,%r13d
jl     1208 <calculoCoeficienteAngular+0xc8>
add    $0x8,%rbx
add    $0x8,%r12
add    $0xffffffffffffffff,%r14
xorpd  %xmm1,%xmm1
lea    0xe69(%rip),%r13
xorpd  %xmm0,%xmm0
nopl   0x0(%rax,%rax,1)
movapd %xmm1,-0x50(%rbp)
movapd %xmm0,-0x40(%rbp)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
movapd -0x50(%rbp),%xmm1
movapd -0x40(%rbp),%xmm0
addsd  (%r12),%xmm1
addsd  (%rbx),%xmm0
add    $0x8,%rbx
add    $0x8,%r12
add    $0xffffffffffffffff,%r14
jne    11c0 <calculoCoeficienteAngular+0x80>
movapd %xmm1,-0x50(%rbp)
movapd %xmm0,-0x40(%rbp)
mov    -0x2c(%rbp),%edi
cvtsi2sd %edi,%xmm2
movapd %xmm2,-0x60(%rbp)
call   1030 <calculoCoeficienteLinear@plt>
mulsd  -0x50(%rbp),%xmm0
movapd -0x40(%rbp),%xmm1
unpcklpd %xmm0,%xmm1
movapd -0x60(%rbp),%xmm0
unpcklpd %xmm0,%xmm0
divpd  %xmm0,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
subsd  %xmm0,%xmm1
movapd %xmm1,-0x40(%rbp)
mov    %r15,%rdi
call   1040 <fclose@plt>
movaps -0x40(%rbp),%xmm0
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"dadosMinimosQuadrados.txt\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [4 x i8] c"%lf\00"
define double @calculoCoeficienteAngular(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
store i32 %0, i32* %2
%11 = load i32, i32* %2
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca double, i64 %12
store i64 %12, i64* %5
%15 = load i32, i32* %2
%16 = zext i32 %15 to i64
%17 = alloca double, i64 %16
store i64 %16, i64* %6
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
%18 = call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %3
store i32 1, i32* %10
br label %19
19: ; preds = %46, %1
%20 = load i32, i32* %10
%21 = load i32, i32* %2
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %49
23: ; preds = %19
%24 = load i32*, i32** %3
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %14, i64 %26
%28 = call i32 @fscanf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %27)
%29 = load i32*, i32** %3
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %17, i64 %31
%33 = call i32 @fscanf(i32* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %32)
%34 = load double, double* %7
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %14, i64 %36
%38 = load double, double* %37
%39 = fadd double %34, %38
store double %39, double* %7
%40 = load double, double* %8
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %17, i64 %42
%44 = load double, double* %43
%45 = fadd double %40, %44
store double %45, double* %8
br label %46
46: ; preds = %23
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
br label %19
49: ; preds = %19
%50 = load double, double* %8
%51 = load i32, i32* %2
%52 = sitofp i32 %51 to double
%53 = fdiv double %50, %52
%54 = load i32, i32* %2
%55 = call double @calculoCoeficienteLinear(i32 %54)
%56 = load double, double* %7
%57 = fmul double %55, %56
%58 = load i32, i32* %2
%59 = sitofp i32 %58 to double
%60 = fdiv double %57, %59
%61 = fsub double %53, %60
store double %61, double* %9
%62 = load i32*, i32** %3
%63 = call i32 @fclose(i32* %62)
%64 = load double, double* %9
%65 = load i8*, i8** %4
ret double %64
}

LLVM IR (-O2):
@.str = [26 x i8] c"dadosMinimosQuadrados.txt\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [4 x i8] c"%lf\00"
define double @calculoCoeficienteAngular(i32 %0) {
%2 = zext i32 %0 to i64
%3 = alloca double, i64 %2
%4 = alloca double, i64 %2
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %21
7: ; preds = %1, %7
%8 = phi i64 [ %19, %7 ], [ 1, %1 ]
%9 = phi double [ %16, %7 ], [ 0.000000e+00, %1 ]
%10 = phi double [ %18, %7 ], [ 0.000000e+00, %1 ]
%11 = getelementptr inbounds double, double* %3, i64 %8
%12 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %11)
%13 = getelementptr inbounds double, double* %4, i64 %8
%14 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %13)
%15 = load double, double* %11
%16 = fadd double %9, %15
%17 = load double, double* %13
%18 = fadd double %10, %17
%19 = add nuw nsw i64 %8, 1
%20 = icmp eq i64 %19, %2
br i1 %20, label %21, label %7
21: ; preds = %7, %1
%22 = phi double [ 0.000000e+00, %1 ], [ %18, %7 ]
%23 = phi double [ 0.000000e+00, %1 ], [ %16, %7 ]
%24 = sitofp i32 %0 to double
%25 = call double @calculoCoeficienteLinear(i32 %0)
%26 = fmul double %23, %25
%27 = insertelement <2 x double> poison, double %22, i64 0
%28 = insertelement <2 x double> %27, double %26, i64 1
%29 = insertelement <2 x double> poison, double %24, i64 0
%30 = shufflevector <2 x double> %29, <2 x double> poison, <2 x i32> zeroinitializer
%31 = fdiv <2 x double> %28, %30
%32 = shufflevector <2 x double> %31, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%33 = fsub <2 x double> %31, %32
%34 = extractelement <2 x double> %33, i64 0
%35 = call i32 @fclose(i32* %5)
ret double %34
}