// File: jkingan[P]ladyheather/heather.cpp
// Function: trend_value(int, double)
DATA_SIZE trend_value(int plot, double t)
{
double r;
double a0, a1;
double sxx,syy,sxy;

   // calculate linear regression trend line slope and offset

   sxy = resid[plot].sum_xy - ((resid[plot].sum_x*resid[plot].sum_y)/resid[plot].resid_count);
   syy = resid[plot].sum_yy - ((resid[plot].sum_y*resid[plot].sum_y)/resid[plot].resid_count);
   sxx = resid[plot].sum_xx - ((resid[plot].sum_x*resid[plot].sum_x)/resid[plot].resid_count);

   if(sxx == 0.0F) {
      a1 = a0 = 0.0;
   }
   else {
      a1 = (sxy / sxx);
      a0 = (resid[plot].sum_y/resid[plot].resid_count) - (resid[plot].a1*(resid[plot].sum_x/resid[plot].resid_count));
   }

//if(plot == PPS) sprintf(debug_text2, "t:%f  a0:%.12f a1:%.12f", t,a0,a1);

   resid[plot].a0 = a0;
   resid[plot].a1 = a1;

   r = (a0 + (a1 * t));
   return (DATA_SIZE) r;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %edi, -0x4(%rbp)
movsd %xmm0, -0x10(%rbp)
movslq -0x4(%rbp), %rcx
leaq 0x385519(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movslq -0x4(%rbp), %rcx
leaq 0x385502(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
movsd (%rax), %xmm1
movslq -0x4(%rbp), %rcx
leaq 0x3854ec(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
mulsd 0x8(%rax), %xmm1
movslq -0x4(%rbp), %rcx
leaq 0x3854d5(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
divsd 0x38(%rax), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movslq -0x4(%rbp), %rcx
leaq 0x3854b5(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
movsd 0x18(%rax), %xmm0
movslq -0x4(%rbp), %rcx
leaq 0x38549e(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm1
movslq -0x4(%rbp), %rcx
leaq 0x385487(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
mulsd 0x8(%rax), %xmm1
movslq -0x4(%rbp), %rcx
leaq 0x385470(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
divsd 0x38(%rax), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movslq -0x4(%rbp), %rcx
leaq 0x385450(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm0
movslq -0x4(%rbp), %rcx
leaq 0x385439(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
movsd (%rax), %xmm1
movslq -0x4(%rbp), %rcx
leaq 0x385423(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
mulsd (%rax), %xmm1
movslq -0x4(%rbp), %rcx
leaq 0x38540d(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
divsd 0x38(%rax), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x1965d
jp 0x1965d
xorps %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
jmp 0x19702
movsd -0x40(%rbp), %xmm0
divsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movslq -0x4(%rbp), %rcx
leaq 0x3853b9(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm1
movslq -0x4(%rbp), %rcx
leaq 0x3853a2(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
divsd 0x38(%rax), %xmm1
movslq -0x4(%rbp), %rcx
leaq 0x38538b(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
movsd 0x30(%rax), %xmm0
movslq -0x4(%rbp), %rcx
leaq 0x385374(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
movsd (%rax), %xmm2
movslq -0x4(%rbp), %rcx
leaq 0x38535e(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
divsd 0x38(%rax), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
movslq -0x4(%rbp), %rcx
leaq 0x38531e(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
movsd %xmm0, 0x28(%rax)
movsd -0x28(%rbp), %xmm0
movslq -0x4(%rbp), %rcx
leaq 0x385302(%rip), %rax    # 0x39ea30
shlq $0x6, %rcx
addq %rcx, %rax
movsd %xmm0, 0x30(%rax)
movsd -0x20(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
movsd -0x10(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
popq %rbp
retq
nopl (%rax)