// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heather.cpp
// Function: remove_trend(int, int, double, double)
DATA_SIZE remove_trend(int id, int phase_flag, double jd, DATA_SIZE val)
{
double jd0;
DATA_SIZE r;
double a0, a1;

   // remove linear regression trend line value from reading

   if(id <= 0) return val;
   if(id >= (NUM_PLOTS+DERIVED_PLOTS)) return val;

   if(plot[id].show_deriv) return val;       // plot derivative enabled
   if(plot[id].show_freq) return val;        // plot frequency enabled
   if(plot[id].drift_rate == 0) return val;  // trend removal not active for the plot

   if(phase_flag && phase_plot(id)) {  // it's a TICC_RCVR phase plot
      if(id == ONE) {
         jd0 = jd - pps_adev_jd0;    // time of first queue entry
         jd0 *= (24.0*60.0*60.0);
         r = trend_value(PPS, jd0);
//r -= resid[PPS].a0;    // for better match with TimeLab zero-based values
         val = val - r;
      }
      else if(id == TWO) {
         jd0 = jd - osc_adev_jd0;
         jd0 *= (24.0*60.0*60.0);
         r = trend_value(OSC, jd0);
//r -= resid[OSC].a0;
         val = val - r;
      }
      else if(id == THREE) {
         jd0 = jd - chc_adev_jd0;
         jd0 *= (24.0*60.0*60.0);
         r = trend_value(CHC, jd0);
//r -= resid[CHC].a0;
         val = val - r;
      }
      else if(id == FOUR) {
         jd0 = jd - chd_adev_jd0;
         jd0 *= (24.0*60.0*60.0);
         r = trend_value(CHD, jd0);
//r -= resid[CHD].a0;
         val = val - r;
      }
   }
   else {
      if(dynamic_trend_line) {   // dynamic trend removal
         a1 = plot[id].a1;
         a0 = plot[id].a0;
      }
      else {                     // static trend removal
         a1 = plot[id].drift_rate;
         a0 = 0.0;
      }
      val -= (DATA_SIZE) (a0 + (a1 * jd));
   }

   return val;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movapd %xmm1, %xmm3
leal -0x14(%rdi), %eax
cmpl $-0x13, %eax
jb 0x13e89
movl %edi, %eax
imulq $0xe8, %rax, %rcx
leaq 0x149fab(%rip), %rax    # 0x15dd30
cmpl $0x0, 0xcc(%rcx,%rax)
jne 0x13e89
addq %rcx, %rax
cmpl $0x0, 0xd0(%rax)
jne 0x13e89
movsd 0xa0(%rax), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0x13dbb
jnp 0x13e89
testl %esi, %esi
je 0x13e0b
movl %edi, %ecx
andl $0x1c, %ecx
cmpl $0x4, %ecx
jne 0x13e0b
cmpq $0x10000, 0x204afc(%rip) # imm = 0x10000
jne 0x13e0b
addl $-0x4, %edi
cmpl $0x3, %edi
ja 0x13e89
movsd %xmm3, -0x8(%rbp)
leaq 0xf5646(%rip), %rax     # 0x109434
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
subsd 0x228e99(%rip), %xmm0   # 0x23cc98
mulsd 0xf5211(%rip), %xmm0    # 0x109018
xorl %edi, %edi
jmp 0x13e7b
cmpl $0x0, 0x32bf5a(%rip)    # 0x33fd6c
je 0x13e24
movsd 0x90(%rax), %xmm1
addq $0x98, %rax
jmp 0x13e2e
addq $0xa0, %rax
xorpd %xmm1, %xmm1
mulsd (%rax), %xmm0
addsd %xmm1, %xmm0
jmp 0x13e85
subsd 0x228e68(%rip), %xmm0   # 0x23cca8
mulsd 0xf51d0(%rip), %xmm0    # 0x109018
movl $0xa, %edi
jmp 0x13e7b
subsd 0x228e59(%rip), %xmm0   # 0x23ccb0
mulsd 0xf51b9(%rip), %xmm0    # 0x109018
movl $0xb, %edi
jmp 0x13e7b
subsd 0x228e32(%rip), %xmm0   # 0x23cca0
mulsd 0xf51a2(%rip), %xmm0    # 0x109018
movl $0x1, %edi
callq 0x13c43
movsd -0x8(%rbp), %xmm3
subsd %xmm0, %xmm3
movapd %xmm3, %xmm0
addq $0x10, %rsp
popq %rbp
retq