#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, double *);
double calculoCoeficienteLinear(int quantidadeVelas) {
  FILE *arquivo;
  double x[quantidadeVelas], y[quantidadeVelas];
  double soma_x = 0, soma_y = 0;
  double numerador, denominador;
  double variacaoLinear;
  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];
  }
  for (i = 1; i < quantidadeVelas; i++) {
    numerador = x[i] * (y[i] - soma_x / quantidadeVelas);
    denominador = y[i] * (x[i] - soma_y / quantidadeVelas);
  }
  variacaoLinear = numerador / denominador;
  fclose(arquivo);
  return variacaoLinear;
}


x86 assembly (clang, -O0):
<calculoCoeficienteLinear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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,-0x68(%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,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
lea    0xe67(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1236 <calculoCoeficienteLinear+0x106>
mov    -0x68(%rbp),%rdx
mov    -0x10(%rbp),%rdi
movslq -0x54(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe47(%rip),%rsi
call   1040 <fscanf@plt>
mov    -0x60(%rbp),%rdx
mov    -0x10(%rbp),%rdi
movslq -0x54(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe28(%rip),%rsi
call   1040 <fscanf@plt>
mov    -0x68(%rbp),%rcx
mov    -0x60(%rbp),%rax
movsd  -0x30(%rbp),%xmm0
movslq -0x54(%rbp),%rdx
addsd  (%rcx,%rdx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm0
movslq -0x54(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11b0 <calculoCoeficienteLinear+0x80>
movl   $0x1,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12b9 <calculoCoeficienteLinear+0x189>
mov    -0x68(%rbp),%rax
mov    -0x60(%rbp),%rcx
movslq -0x54(%rbp),%rdx
movsd  (%rax,%rdx,8),%xmm0
movslq -0x54(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm1
movsd  -0x30(%rbp),%xmm2
cvtsi2sdl -0x4(%rbp),%xmm3
divsd  %xmm3,%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movslq -0x54(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm0
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x38(%rbp),%xmm2
cvtsi2sdl -0x4(%rbp),%xmm3
divsd  %xmm3,%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    123d <calculoCoeficienteLinear+0x10d>
movsd  -0x40(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movsd  -0x50(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculoCoeficienteLinear>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edi,%r12d
mov    %edi,%r14d
mov    %rsp,%r13
lea    0xf(,%r14,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe94(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r15
cmp    $0x2,%r12d
jl     1244 <calculoCoeficienteLinear+0x114>
mov    %r12,-0x58(%rbp)
mov    %rbx,-0x48(%rbp)
lea    0x8(%rbx),%r12
mov    %r13,-0x50(%rbp)
lea    0x8(%r13),%rbx
add    $0xffffffffffffffff,%r14
xorpd  %xmm2,%xmm2
lea    0xe75(%rip),%r13
nopl   0x0(%rax,%rax,1)
movapd %xmm2,-0x40(%rbp)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
movapd -0x40(%rbp),%xmm2
movsd  (%rbx),%xmm0
movhpd (%r12),%xmm0
addpd  %xmm0,%xmm2
add    $0x8,%r12
add    $0x8,%rbx
add    $0xffffffffffffffff,%r14
jne    11b0 <calculoCoeficienteLinear+0x80>
mov    -0x58(%rbp),%rcx
cmp    $0x2,%ecx
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rsi
jl     1244 <calculoCoeficienteLinear+0x114>
lea    -0x1(%rcx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
unpcklpd %xmm0,%xmm0
divpd  %xmm0,%xmm2
movsd  (%rdx,%rax,8),%xmm3
movsd  (%rsi,%rax,8),%xmm0
movapd %xmm0,%xmm1
unpcklpd %xmm3,%xmm1
subpd  %xmm2,%xmm1
unpcklpd %xmm0,%xmm3
mulpd  %xmm1,%xmm3
movapd %xmm3,%xmm0
unpckhpd %xmm3,%xmm0
divsd  %xmm0,%xmm3
movapd %xmm3,-0x40(%rbp)
mov    %r15,%rdi
call   1030 <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 @calculoCoeficienteLinear(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 double
%11 = alloca double
%12 = alloca i32
store i32 %0, i32* %2
%13 = load i32, i32* %2
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %4
%16 = alloca double, i64 %14
store i64 %14, i64* %5
%17 = load i32, i32* %2
%18 = zext i32 %17 to i64
%19 = alloca double, i64 %18
store i64 %18, i64* %6
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
%20 = 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* %20, i32** %3
store i32 1, i32* %12
br label %21
21: ; preds = %48, %1
%22 = load i32, i32* %12
%23 = load i32, i32* %2
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %51
25: ; preds = %21
%26 = load i32*, i32** %3
%27 = load i32, i32* %12
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %16, i64 %28
%30 = call i32 @fscanf(i32* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %29)
%31 = load i32*, i32** %3
%32 = load i32, i32* %12
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %19, i64 %33
%35 = call i32 @fscanf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %34)
%36 = load double, double* %7
%37 = load i32, i32* %12
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %16, i64 %38
%40 = load double, double* %39
%41 = fadd double %36, %40
store double %41, double* %7
%42 = load double, double* %8
%43 = load i32, i32* %12
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %19, i64 %44
%46 = load double, double* %45
%47 = fadd double %42, %46
store double %47, double* %8
br label %48
48: ; preds = %25
%49 = load i32, i32* %12
%50 = add nsw i32 %49, 1
store i32 %50, i32* %12
br label %21
51: ; preds = %21
store i32 1, i32* %12
br label %52
52: ; preds = %85, %51
%53 = load i32, i32* %12
%54 = load i32, i32* %2
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %88
56: ; preds = %52
%57 = load i32, i32* %12
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %16, i64 %58
%60 = load double, double* %59
%61 = load i32, i32* %12
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %19, i64 %62
%64 = load double, double* %63
%65 = load double, double* %7
%66 = load i32, i32* %2
%67 = sitofp i32 %66 to double
%68 = fdiv double %65, %67
%69 = fsub double %64, %68
%70 = fmul double %60, %69
store double %70, double* %9
%71 = load i32, i32* %12
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %19, i64 %72
%74 = load double, double* %73
%75 = load i32, i32* %12
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %16, i64 %76
%78 = load double, double* %77
%79 = load double, double* %8
%80 = load i32, i32* %2
%81 = sitofp i32 %80 to double
%82 = fdiv double %79, %81
%83 = fsub double %78, %82
%84 = fmul double %74, %83
store double %84, double* %10
br label %85
85: ; preds = %56
%86 = load i32, i32* %12
%87 = add nsw i32 %86, 1
store i32 %87, i32* %12
br label %52
88: ; preds = %52
%89 = load double, double* %9
%90 = load double, double* %10
%91 = fdiv double %89, %90
store double %91, double* %11
%92 = load i32*, i32** %3
%93 = call i32 @fclose(i32* %92)
%94 = load double, double* %11
%95 = load i8*, i8** %4
ret double %94
}

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 @calculoCoeficienteLinear(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 %28, label %42
7: ; preds = %28
br i1 %6, label %8, label %42
8: ; preds = %7
%9 = add nsw i32 %0, -1
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds double, double* %3, i64 %10
%12 = load double, double* %11
%13 = getelementptr inbounds double, double* %4, i64 %10
%14 = load double, double* %13
%15 = sitofp i32 %0 to double
%16 = insertelement <2 x double> poison, double %15, i64 0
%17 = shufflevector <2 x double> %16, <2 x double> poison, <2 x i32> zeroinitializer
%18 = fdiv <2 x double> %39, %17
%19 = insertelement <2 x double> poison, double %14, i64 0
%20 = insertelement <2 x double> %19, double %12, i64 1
%21 = fsub <2 x double> %20, %18
%22 = insertelement <2 x double> poison, double %12, i64 0
%23 = insertelement <2 x double> %22, double %14, i64 1
%24 = fmul <2 x double> %23, %21
%25 = extractelement <2 x double> %24, i64 0
%26 = extractelement <2 x double> %24, i64 1
%27 = fdiv double %25, %26
br label %42
28: ; preds = %1, %28
%29 = phi i64 [ %40, %28 ], [ 1, %1 ]
%30 = phi <2 x double> [ %39, %28 ], [ zeroinitializer, %1 ]
%31 = getelementptr inbounds double, double* %3, i64 %29
%32 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %31)
%33 = getelementptr inbounds double, double* %4, i64 %29
%34 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %33)
%35 = load double, double* %31
%36 = load double, double* %33
%37 = insertelement <2 x double> poison, double %35, i64 0
%38 = insertelement <2 x double> %37, double %36, i64 1
%39 = fadd <2 x double> %30, %38
%40 = add nuw nsw i64 %29, 1
%41 = icmp eq i64 %40, %2
br i1 %41, label %7, label %28
42: ; preds = %1, %8, %7
%43 = phi double [ %27, %8 ], [ undef, %7 ], [ undef, %1 ]
%44 = call i32 @fclose(i32* %5)
ret double %43
}