#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 */
struct CircularBuffer {
  int dummy;
};

/* Variables and functions */
int bufferLength(struct CircularBuffer *);
double getBufferValue(struct CircularBuffer *, int);
double getTime(struct CircularBuffer *, int);
double slope(struct CircularBuffer *buf) {
  double sumX = 0.0, sumY = 0.0, sumXY = 0.0;
  double sumXsquared = 0.0, sumYsquared = 0.0;
  int n = bufferLength(buf) - 1;
  double t0 = getTime(buf, n);
  int i = 0;
  for (i = n - 1; i > 0; i--) {
    double y = getBufferValue(buf, i) - getBufferValue(buf, n);
    double x = getTime(buf, i) - t0;
    sumX += x;
    sumY += y;
    sumXsquared += x * x;
    sumYsquared += y * y;
    sumXY += x * y;
  }
  double denom = (double)n * sumXsquared - sumX * sumX;
  double m = 0.0;
  if (denom != 0.0)
    m = ((double)n * sumXY - sumX * sumY) / denom;
  return m;
}


x86 assembly (clang, -O0):
<slope>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <bufferLength@plt>
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1050 <getTime@plt>
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jle    1262 <slope+0x132>
mov    -0x8(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1040 <getBufferValue@plt>
movsd  %xmm0,-0x70(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1040 <getBufferValue@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1050 <getTime@plt>
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x44(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
jmp    1194 <slope+0x64>
cvtsi2sdl -0x34(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12bf <slope+0x18f>
jp     12bf <slope+0x18f>
jmp    12fc <slope+0x1cc>
cvtsi2sdl -0x34(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slope>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%rbx
call   1030 <bufferLength@plt>
mov    %eax,%ebp
lea    -0x1(%rbp),%r14d
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <getTime@plt>
movapd %xmm0,%xmm2
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
xorpd  %xmm5,%xmm5
xorpd  %xmm6,%xmm6
cmp    $0x3,%ebp
jl     1208 <slope+0xd8>
xorpd  %xmm0,%xmm0
mov    %r14d,%ebp
xorpd  %xmm6,%xmm6
movapd %xmm2,(%rsp)
xchg   %ax,%ax
movapd %xmm6,0x40(%rsp)
movapd %xmm0,0x30(%rsp)
add    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <getBufferValue@plt>
movapd %xmm0,0x20(%rsp)
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <getBufferValue@plt>
movapd %xmm0,0x10(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <getTime@plt>
movapd 0x30(%rsp),%xmm3
movapd (%rsp),%xmm1
movapd 0x40(%rsp),%xmm6
unpcklpd 0x20(%rsp),%xmm0
unpcklpd 0x10(%rsp),%xmm1
subpd  %xmm1,%xmm0
addpd  %xmm0,%xmm6
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
mulpd  %xmm0,%xmm1
movapd %xmm1,%xmm0
addpd  %xmm3,%xmm0
cmp    $0x1,%ebp
ja     1180 <slope+0x50>
movapd %xmm6,%xmm5
unpckhpd %xmm6,%xmm5
addpd  %xmm3,%xmm1
xorpd  %xmm0,%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %r14d,%xmm2
movapd %xmm6,%xmm4
mulsd  %xmm6,%xmm4
movapd %xmm2,%xmm3
mulsd  %xmm1,%xmm3
subsd  %xmm4,%xmm3
ucomisd %xmm0,%xmm3
jne    122c <slope+0xfc>
jnp    124c <slope+0x11c>
xorpd  0xdcc(%rip),%xmm6
mulsd  %xmm6,%xmm5
unpckhpd %xmm1,%xmm1
mulsd  %xmm1,%xmm2
addsd  %xmm5,%xmm2
divsd  %xmm3,%xmm2
movapd %xmm2,%xmm0
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.CircularBuffer = type { i32 }
define double @slope(%struct.CircularBuffer* %0) {
%2 = alloca %struct.CircularBuffer*
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store %struct.CircularBuffer* %0, %struct.CircularBuffer** %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
%15 = load %struct.CircularBuffer*, %struct.CircularBuffer** %2
%16 = call i32 @bufferLength(%struct.CircularBuffer* %15)
%17 = sub nsw i32 %16, 1
store i32 %17, i32* %8
%18 = load %struct.CircularBuffer*, %struct.CircularBuffer** %2
%19 = load i32, i32* %8
%20 = call double @getTime(%struct.CircularBuffer* %18, i32 %19)
store double %20, double* %9
store i32 0, i32* %10
%21 = load i32, i32* %8
%22 = sub nsw i32 %21, 1
store i32 %22, i32* %10
br label %23
23: ; preds = %57, %1
%24 = load i32, i32* %10
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %60
26: ; preds = %23
%27 = load %struct.CircularBuffer*, %struct.CircularBuffer** %2
%28 = load i32, i32* %10
%29 = call double @getBufferValue(%struct.CircularBuffer* %27, i32 %28)
%30 = load %struct.CircularBuffer*, %struct.CircularBuffer** %2
%31 = load i32, i32* %8
%32 = call double @getBufferValue(%struct.CircularBuffer* %30, i32 %31)
%33 = fsub double %29, %32
store double %33, double* %11
%34 = load %struct.CircularBuffer*, %struct.CircularBuffer** %2
%35 = load i32, i32* %10
%36 = call double @getTime(%struct.CircularBuffer* %34, i32 %35)
%37 = load double, double* %9
%38 = fsub double %36, %37
store double %38, double* %12
%39 = load double, double* %12
%40 = load double, double* %3
%41 = fadd double %40, %39
store double %41, double* %3
%42 = load double, double* %11
%43 = load double, double* %4
%44 = fadd double %43, %42
store double %44, double* %4
%45 = load double, double* %12
%46 = load double, double* %12
%47 = load double, double* %6
%48 = call double @llvm.fmuladd.f64(double %45, double %46, double %47)
store double %48, double* %6
%49 = load double, double* %11
%50 = load double, double* %11
%51 = load double, double* %7
%52 = call double @llvm.fmuladd.f64(double %49, double %50, double %51)
store double %52, double* %7
%53 = load double, double* %12
%54 = load double, double* %11
%55 = load double, double* %5
%56 = call double @llvm.fmuladd.f64(double %53, double %54, double %55)
store double %56, double* %5
br label %57
57: ; preds = %26
%58 = load i32, i32* %10
%59 = add nsw i32 %58, -1
store i32 %59, i32* %10
br label %23
60: ; preds = %23
%61 = load i32, i32* %8
%62 = sitofp i32 %61 to double
%63 = load double, double* %6
%64 = load double, double* %3
%65 = load double, double* %3
%66 = fmul double %64, %65
%67 = fneg double %66
%68 = call double @llvm.fmuladd.f64(double %62, double %63, double %67)
store double %68, double* %13
store double 0.000000e+00, double* %14
%69 = load double, double* %13
%70 = fcmp une double %69, 0.000000e+00
br i1 %70, label %71, label %82
71: ; preds = %60
%72 = load i32, i32* %8
%73 = sitofp i32 %72 to double
%74 = load double, double* %5
%75 = load double, double* %3
%76 = load double, double* %4
%77 = fmul double %75, %76
%78 = fneg double %77
%79 = call double @llvm.fmuladd.f64(double %73, double %74, double %78)
%80 = load double, double* %13
%81 = fdiv double %79, %80
store double %81, double* %14
br label %82
82: ; preds = %71, %60
%83 = load double, double* %14
ret double %83
}

LLVM IR (-O2):
%struct.CircularBuffer = type { i32 }
define double @slope(%struct.CircularBuffer* %0) {
%2 = tail call i32 @bufferLength(%struct.CircularBuffer* %0)
%3 = add nsw i32 %2, -1
%4 = tail call double @getTime(%struct.CircularBuffer* %0, i32 %3)
%5 = icmp sgt i32 %2, 2
br i1 %5, label %6, label %29
6: ; preds = %1
%7 = add nsw i32 %2, -2
%8 = insertelement <2 x double> poison, double %4, i64 0
br label %9
9: ; preds = %6, %9
%10 = phi i32 [ %23, %9 ], [ %7, %6 ]
%11 = phi <2 x double> [ %22, %9 ], [ zeroinitializer, %6 ]
%12 = phi <2 x double> [ %20, %9 ], [ zeroinitializer, %6 ]
%13 = tail call double @getBufferValue(%struct.CircularBuffer* %0, i32 %10)
%14 = tail call double @getBufferValue(%struct.CircularBuffer* %0, i32 %3)
%15 = tail call double @getTime(%struct.CircularBuffer* %0, i32 %10)
%16 = insertelement <2 x double> poison, double %15, i64 0
%17 = insertelement <2 x double> %16, double %13, i64 1
%18 = insertelement <2 x double> %8, double %14, i64 1
%19 = fsub <2 x double> %17, %18
%20 = fadd <2 x double> %12, %19
%21 = shufflevector <2 x double> %19, <2 x double> undef, <2 x i32> zeroinitializer
%22 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %21, <2 x double> %19, <2 x double> %11)
%23 = add nsw i32 %10, -1
%24 = icmp ugt i32 %10, 1
br i1 %24, label %9, label %25
25: ; preds = %9
%26 = extractelement <2 x double> %20, i64 1
%27 = extractelement <2 x double> %20, i64 0
%28 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %21, <2 x double> %19, <2 x double> %11)
br label %29
29: ; preds = %25, %1
%30 = phi double [ 0.000000e+00, %1 ], [ %26, %25 ]
%31 = phi double [ 0.000000e+00, %1 ], [ %27, %25 ]
%32 = phi <2 x double> [ zeroinitializer, %1 ], [ %28, %25 ]
%33 = sitofp i32 %3 to double
%34 = fneg double %31
%35 = fmul double %31, %34
%36 = extractelement <2 x double> %32, i64 0
%37 = tail call double @llvm.fmuladd.f64(double %33, double %36, double %35)
%38 = fcmp une double %37, 0.000000e+00
br i1 %38, label %39, label %44
39: ; preds = %29
%40 = fmul double %30, %34
%41 = extractelement <2 x double> %32, i64 1
%42 = tail call double @llvm.fmuladd.f64(double %33, double %41, double %40)
%43 = fdiv double %42, %37
br label %44
44: ; preds = %39, %29
%45 = phi double [ %43, %39 ], [ 0.000000e+00, %29 ]
ret double %45
}