// File: jkingan[P]ladyheather/heathgps.cpp
// Function: ticc_phase(char*, int, double, double)
double ticc_phase(char *id, int ticc_mode, double val, double last_val)
{
   // convert TICC/counter readings to phase values

   if((ticc_mode == 'T') || (ticc_mode == 'D') || (ticc_mode == 'L')) { // TICC is in a timestamp mode
      if((TS_WRAP_INTERVAL != 0.0) && (timestamp_wrap == 0.0)) {   // limit time stamps to TS_WRAP_INTERVAL (100.0) seconds
         val = fmod(val, TS_WRAP_INTERVAL);
         last_val = fmod(last_val, TS_WRAP_INTERVAL);
      }

      val -= last_val;     // convert consecutive time stamps to time interval
      if(val <= 0.0) {     // time stamps wrapped, adjust the interval
         if(timestamp_wrap == 0.0) val += TS_WRAP_INTERVAL;  // !!!!! what if still negative? 
         else                      val += timestamp_wrap; //       ... looping could take forever on a bogus value
      }
   }
   else if(ticc_mode == 'P') {  // time interval between samples on same channel
   }
   else if(ticc_mode == 'H') {  // phase
   }
   else if(ticc_mode == 'I') {  // time interval between two channels
      val -= last_val;
   }
   else if(ticc_mode == 'F') {  // frequency counter
      if(nominal_cha_freq <= 0.0) nominal_cha_freq = NOMINAL_FREQ;
      val = ((val - nominal_cha_freq) / nominal_cha_freq) * pps_adev_period;
   }

   return val;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x20(%rbp)
cmpl $0x54, -0xc(%rbp)
je 0xeba9f
cmpl $0x44, -0xc(%rbp)
je 0xeba9f
cmpl $0x4c, -0xc(%rbp)
jne 0xebb46
leaq 0x280132(%rip), %rax    # 0x36bbd8
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xebae3
jp 0xebae3
movsd -0x18(%rbp), %xmm0
movsd 0x8358e(%rip), %xmm1    # 0x16f050
callq 0x94d0
movsd %xmm0, -0x18(%rbp)
movsd -0x20(%rbp), %xmm0
movsd 0x83577(%rip), %xmm1    # 0x16f050
callq 0x94d0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm1
movsd -0x18(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x18(%rbp), %xmm0
jb 0xebb41
leaq 0x2800d1(%rip), %rax    # 0x36bbd8
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xebb2a
jp 0xebb2a
movsd 0x83532(%rip), %xmm0    # 0x16f050
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xebb3f
leaq 0x2800a7(%rip), %rax    # 0x36bbd8
movsd (%rax), %xmm0
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xebb41
jmp 0xebbcd
cmpl $0x50, -0xc(%rbp)
jne 0xebb4e
jmp 0xebbcb
cmpl $0x48, -0xc(%rbp)
jne 0xebb56
jmp 0xebbc9
cmpl $0x49, -0xc(%rbp)
jne 0xebb71
movsd -0x20(%rbp), %xmm1
movsd -0x18(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xebbc7
cmpl $0x46, -0xc(%rbp)
jne 0xebbc5
xorps %xmm0, %xmm0
leaq 0x27ffc7(%rip), %rax    # 0x36bb48
ucomisd (%rax), %xmm0
jb 0xebb9a
leaq 0x27ffba(%rip), %rax    # 0x36bb48
movsd 0x8361a(%rip), %xmm0    # 0x16f1b0
movsd %xmm0, (%rax)
movsd -0x18(%rbp), %xmm0
leaq 0x27ffa2(%rip), %rax    # 0x36bb48
subsd (%rax), %xmm0
leaq 0x27ff97(%rip), %rax    # 0x36bb48
divsd (%rax), %xmm0
leaq 0x1b0324(%rip), %rax    # 0x29bee0
mulsd (%rax), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0xebbc7
jmp 0xebbc9
jmp 0xebbcb
jmp 0xebbcd
movsd -0x18(%rbp), %xmm0
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)