// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathmsc.cpp
// Function: time_check(int, double, int, int, int, int, int, int, double)
int time_check(int reading_log, DATA_SIZE interval, int yy,int mon,int dd,  int hours,int minutes,int seconds,double frac)
{
double t;
int warn;
COORD row, col;
struct PLOT_Q q;
double nav_step;
double delta;

   // This routine verfies that time stamps are sequential
   // NEW_RCVR
   if(log_errors == 0) return 0;

   t = jdate(yy, mon, dd) - jdate(2012,0,0);
   t += jtime(hours,minutes,seconds,frac);
   t *= (24.0*60.0*60.0*1000.0);
   t = (double) (s64) (t+0.5);

   if(!have_last_stamp) {
      last_stamp = t;
      have_last_stamp = 1;
      return 0;
   }

   // see if we have a skip in the time stamp sequence
   warn = 0;   // assume properly consecutive time stamps

   nav_step = 1000.0;
   if(reading_log && interval) nav_step =  (double) (int) (((DATA_SIZE) 1000.0 * interval)+(DATA_SIZE) 0.50);
   else if(nav_rate) nav_step = (double) (int) ((1000.0 / nav_rate)+0.50);

   delta = fabs((t - last_stamp) - nav_step);

   if((rcvr_type == ACRON_RCVR) && status_second(seconds)) ;  // seconds value is when a long status message is being processed
   else if((rcvr_type == BRANDY_RCVR) && (delta < 800.0)) warn = 0;   // !!!! brandywine receiver can send multiple time stamps per second with millisecond fractions
   else if((rcvr_type == ESIP_RCVR) && (delta < 100.0)) warn = 0;
   else if((rcvr_type == LPFRS_RCVR) && (delta < 1400.0)) warn = 0;
   else if((rcvr_type == SA35_RCVR) && (delta < 1400.0)) warn = 0;
   else if((rcvr_type == RT17_RCVR) && (delta < 100.0)) warn = 0;  // toots
   else if((rcvr_type == SRO_RCVR) && (delta < 1400.0)) warn = 0;
   else if(STARLOC && starloc_skip_delay) --starloc_skip_delay;
   else if(STARLOC && bad_starloc_time && (delta == 1000.0)) warn = 0;
   else if((rcvr_type == TSIP_RCVR) && (tsip_type == SV6_TYPE) && (delta < 1100.0)) warn = 0;
   else if((rcvr_type == TSIP_RCVR) && (res_t == RES_T) && (raw_msg_rate >= 3) && (delta < 2100.0)) warn = 0;
   else if((rcvr_type == Z12_RCVR) && (delta < 750.0)) warn = 0;   // !!!! Z12 can send 0.5 sec backwards time stamps
//OSA   else if((rcvr_type == STAR_RCVR) && (star_type == OSA_TYPE) && (delta < 2200.0)) warn = 0;  // OSA
   else if(rcvr_type == TICC_RCVR) ;
   else if(lte_lite && (have_sawtooth == 0)) ;
   else if(time_checked == 0) warn = 0;   // it's the first time 
   else if((t-last_stamp) == 0.0) {  // duplicate time stamp
      warn = 1;
       if((rcvr_type == STAR_RCVR) && (star_type == OSA_TYPE)) warn = 0;  // OSA
   }
   else if(HIGH_TS_THRESH && (delta < TS_CHECK_THRESHOLD)) { // allow larger time stamp differences
      warn = 0;
   }
   else if(nav_rate && (reading_log == 0) && (delta > 1.0)) {  // more than 1msec err in time stamp sequence
      warn = 2;  // checking live readings
   }
   else if(reading_log && (delta > 1.0)) {  // time stamp sequence error > 1 msec
      warn = 3;   // checking log readings
   }
   bad_starloc_time = 0;

   if(0 && warn) {
      sprintf(debug_text2, "unt:%f step:%f last_stamp:%f  t:%f  delta:%f nav:%f warn:%d", 
      interval, nav_step, last_stamp, t, delta, 1.0/nav_rate, warn);
   }

//if(log_file) fprintf(log_file, "#! (%d) pri=%02d:%02d:%02d  adj:%02d:%02d:%02d\n", warn, pri_hours,pri_minutes,pri_seconds, hours,minutes,seconds);

   if(warn) {  // we have a duplicate or missing time stamp
      q = get_plot_q(plot_q_in);
      q.sat_flags |= TIME_SKIP;  
      put_plot_q(plot_q_in, q);

      if(log_errors && (reading_log == 0)) {
         if     (warn == 1) sprintf(log_text, "#! time stamp duplicated.  t=%.3f last=%.3f  delta=%.1f", t, last_stamp, delta);
         else if(warn == 2) sprintf(log_text, "#! time stamp skipped.  t=%.1f  last=%.1f  err:%.0f ms  %02d:%02d:%02d  delta=%.1f", t, last_stamp, t-last_stamp, hours,minutes,seconds, delta);
         else if(warn == 3) sprintf(log_text, "#! time stamp skipped in log file  delta=%.1f", delta);
         else               sprintf(log_text, "#! time stamp sequence error type: %d  delta=%.1f", warn, delta);
if(debug_file) fprintf(debug_file, "%s\n", log_text);
         write_log_comment(1);
      }

      if(log_comments && reading_log && log_errors) {
         if(text_mode) {
            row = EDIT_ROW;
            col = EDIT_COL;
         }
         else {
            row = PLOT_TEXT_ROW;
            col = PLOT_TEXT_COL;
         }
         sprintf(out, "#! time stamp skip %d in log.  interval=%.3f  step:%.1f  prev=%.3f this=%.3f  ", 
            warn, interval, nav_step, last_stamp, t);
         vidstr(row+4, col, RED, out);
         refresh_page();
      }
   }

   last_stamp = t;
   if(warn) time_checked = 0;
   else     time_checked = have_time;

   return warn;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movsd %xmm0, -0x38(%rbp)
leaq 0x16a8df(%rip), %rax    # 0x23e3fb
xorl %r14d, %r14d
cmpb $0x0, (%rax)
je 0xd4001
movl %r9d, %r12d
movl %r8d, %r15d
movl %edi, %ebx
movl %esi, %edi
movl %edx, %esi
movl %ecx, %edx
movsd %xmm1, -0x30(%rbp)
callq 0xd4110
addsd 0x57b90(%rip), %xmm0    # 0x12b6d8
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
cvtsi2sd %r12d, %xmm2
divsd 0x354ab(%rip), %xmm2    # 0x109008
cvtsi2sdl 0x10(%rbp), %xmm3
addsd %xmm1, %xmm2
addsd -0x30(%rbp), %xmm3
divsd 0x3549d(%rip), %xmm3    # 0x109010
addsd %xmm2, %xmm3
divsd 0x354c1(%rip), %xmm3    # 0x109040
addsd %xmm0, %xmm3
mulsd 0x4a565(%rip), %xmm3    # 0x11e0f0
addsd 0x354d5(%rip), %xmm3    # 0x109068
cvttsd2si %xmm3, %rax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
leaq 0x14fa42(%rip), %rax    # 0x2235e9
cmpb $0x0, (%rax)
je 0xd3be0
testl %ebx, %ebx
movl %r15d, -0x40(%rbp)
je 0xd3bf3
xorpd %xmm0, %xmm0
movsd -0x38(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jne 0xd3bc5
jnp 0xd3bf3
movsd 0x3546b(%rip), %xmm0    # 0x109038
mulsd -0x38(%rbp), %xmm0
addsd 0x3548e(%rip), %xmm0    # 0x109068
cvttpd2dq %xmm0, %xmm0
jmp 0xd3c26
leaq 0x14f9f9(%rip), %rcx    # 0x2235e0
movsd %xmm2, (%rcx)
movb $0x1, (%rax)
jmp 0xd4001
leaq 0x14775e(%rip), %rax    # 0x21b358
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xd3c0e
jnp 0xd3d6c
movsd 0x35422(%rip), %xmm1    # 0x109038
divsd %xmm0, %xmm1
addsd 0x35446(%rip), %xmm1    # 0x109068
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm0
leaq 0x14f9af(%rip), %r15    # 0x2235e0
movapd %xmm2, %xmm3
subsd (%r15), %xmm3
movapd %xmm0, -0x60(%rbp)
subsd %xmm0, %xmm3
andpd 0x35535(%rip), %xmm3    # 0x109180
leaq 0x144c7e(%rip), %r13    # 0x2188d0
cmpq $0x4000, (%r13)         # imm = 0x4000
movsd %xmm2, -0x30(%rbp)
movapd %xmm3, -0x50(%rbp)
jne 0xd3c83
movl 0x10(%rbp), %edi
callq 0x47a31
movapd -0x50(%rbp), %xmm3
movsd -0x30(%rbp), %xmm2
xorl %r14d, %r14d
testl %eax, %eax
jne 0xd3df1
movq (%r13), %rax
xorl %r14d, %r14d
cmpq $0x40000, %rax          # imm = 0x40000
jne 0xd3ca4
movsd 0x57a46(%rip), %xmm0    # 0x12b6e0
ucomisd %xmm3, %xmm0
ja 0xd3df1
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0xd3cc0
movsd 0x353aa(%rip), %xmm0    # 0x109060
ucomisd %xmm3, %xmm0
ja 0xd3df1
movsd 0x35398(%rip), %xmm0    # 0x109060
ucomisd %xmm3, %xmm0
seta %dl
cmpq $0x10000000, %rax       # imm = 0x10000000
sete %sil
movsd 0x57a07(%rip), %xmm0    # 0x12b6e8
ucomisd %xmm3, %xmm0
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
seta %dil
cmpq %rcx, %rax
sete %r8b
orb %sil, %r8b
andb %dil, %r8b
movabsq $0x200000000, %rsi      # imm = 0x200000000
cmpq %rsi, %rax
sete %sil
andb %dl, %sil
orb %r8b, %sil
cmpq $0x8000000, %rax        # imm = 0x8000000
sete %dl
andb %dil, %dl
orb %sil, %dl
jne 0xd3df1
cmpq $0x1, %rax
sete %dil
leaq 0x147299(%rip), %rdx    # 0x21afd4
movl (%rdx), %edx
cmpl $0x53, %edx
sete %sil
andb %dil, %sil
leaq 0x14f89e(%rip), %rdi    # 0x2235ec
movl (%rdi), %r8d
testl %r8d, %r8d
setne %r9b
andb %sil, %r9b
cmpb $0x1, %r9b
jne 0xd3d79
decl %r8d
movl %r8d, (%rdi)
jmp 0xd3df1
movsd 0x352c4(%rip), %xmm0    # 0x109038
jmp 0xd3c2a
leaq 0x14f870(%rip), %rdi    # 0x2235f0
cmpl $0x0, (%rdi)
setne %dil
andb %dil, %sil
cmpb $0x1, %sil
jne 0xd3d9c
ucomisd 0x352a0(%rip), %xmm3    # 0x109038
jne 0xd3d9c
jnp 0xd3df1
cmpq $0x1, %rax
jne 0xd3db5
cmpl $0x36, %edx
jne 0xd3db5
movsd 0x57941(%rip), %xmm0    # 0x12b6f0
ucomisd %xmm3, %xmm0
ja 0xd3df1
cmpq $0x1, %rax
jne 0xd4016
leaq 0x144b3e(%rip), %rdx    # 0x218904
cmpb $0x1, (%rdx)
jne 0xd4016
leaq 0x1475a2(%rip), %rdx    # 0x21b378
cmpl $0x3, (%rdx)
jl 0xd4016
movsd 0x57911(%rip), %xmm0    # 0x12b6f8
ucomisd %xmm3, %xmm0
jbe 0xd4016
leaq 0x14f7f8(%rip), %rax    # 0x2235f0
movl $0x0, (%rax)
testl %r14d, %r14d
je 0xd3ebb
movl %r12d, -0x3c(%rbp)
leaq 0x147516(%rip), %r15    # 0x21b328
movq (%r15), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x10141
leaq -0x1be(%rbp), %rsi
leaq -0x10e(%rbp), %r13
movl $0x400, %r12d           # imm = 0x400
orl -0x2(%rsi), %r12d
movl $0xae, %edx
movq %r13, %rdi
callq 0x92b0
movq (%r15), %rax
leaq 0x16a5ab(%rip), %r15    # 0x23e3fb
movw %r12w, -0x2(%r13)
leaq 0x14f784(%rip), %r12    # 0x2235e0
leaq -0x110(%rbp), %rsi
movl $0x16, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
callq 0x1030d
testl %ebx, %ebx
jne 0xd3f4e
cmpb $0x0, (%r15)
je 0xd3f4e
cmpl $0x2, %r14d
je 0xd3ece
cmpl $0x1, %r14d
movapd -0x50(%rbp), %xmm2
jne 0xd3f07
movsd (%r12), %xmm1
leaq 0x169aba(%rip), %rdi    # 0x23d960
leaq 0x5e9fc(%rip), %rsi     # 0x1328a9
movsd -0x30(%rbp), %xmm0
movb $0x3, %al
callq 0x9060
jmp 0xd3f20
movsd %xmm2, (%r15)
leaq 0x16b015(%rip), %rax    # 0x23eedc
movb (%rax), %al
jmp 0xd3ff8
movsd (%r12), %xmm1
movsd -0x30(%rbp), %xmm0
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
leaq 0x169a78(%rip), %rdi    # 0x23d960
leaq 0x5e9f2(%rip), %rsi     # 0x1328e1
movl -0x40(%rbp), %edx
movl -0x3c(%rbp), %ecx
movl 0x10(%rbp), %r8d
movapd -0x50(%rbp), %xmm3
movb $0x4, %al
callq 0x9060
jmp 0xd3f20
leaq 0x169a52(%rip), %rdi    # 0x23d960
leaq 0x5ea1f(%rip), %rsi     # 0x132934
movapd %xmm2, %xmm0
movb $0x1, %al
callq 0x9060
leaq 0x16a469(%rip), %rax    # 0x23e390
movq (%rax), %rdi
testq %rdi, %rdi
je 0xd3f44
leaq 0x51ac1(%rip), %rsi     # 0x1259f7
leaq 0x169a23(%rip), %rdx    # 0x23d960
xorl %eax, %eax
callq 0x9560
movl $0x1, %edi
callq 0xc3105
testl %ebx, %ebx
je 0xd3feb
leaq 0x16a4b7(%rip), %rax    # 0x23e414
cmpb $0x0, (%rax)
je 0xd3feb
cmpb $0x0, (%r15)
je 0xd3feb
leaq 0x144865(%rip), %rax    # 0x2187d8
cmpl $0x0, (%rax)
leaq 0x26b693(%rip), %rax    # 0x33f610
cmoveq 0x7c04b(%rip), %rax     # 0x14ffd0
leaq 0x26b680(%rip), %rcx    # 0x33f60c
cmoveq 0x7bef4(%rip), %rcx     # 0x14fe88
movl (%rax), %ebx
movl (%rcx), %r15d
movsd (%r12), %xmm2
leaq 0x26827a(%rip), %r12    # 0x33c220
leaq 0x5e9b5(%rip), %rsi     # 0x132962
movq %r12, %rdi
movl %r14d, %edx
movsd -0x38(%rbp), %xmm0
movapd -0x60(%rbp), %xmm1
movsd -0x30(%rbp), %xmm3
movb $0x4, %al
callq 0x9060
addl $0x4, %r15d
movl %r15d, %edi
movl %ebx, %esi
movl $0xc, %edx
movq %r12, %rcx
leaq 0x14f5ff(%rip), %r12    # 0x2235e0
callq 0xe7d0
callq 0xab5f
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r12)
xorl %eax, %eax
leaq 0x14f5e9(%rip), %rcx    # 0x2235e8
movb %al, (%rcx)
movl %r14d, %eax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movabsq $0x100000000, %rdx      # imm = 0x100000000
cmpq %rdx, %rax
sete %dl
movsd 0x576d2(%rip), %xmm0    # 0x12b700
ucomisd %xmm3, %xmm0
seta %sil
cmpq $0x10000, %rax          # imm = 0x10000
je 0xd3df1
andb %sil, %dl
jne 0xd3df1
leaq 0x146f7e(%rip), %rdx    # 0x21afd0
cmpl $0x0, (%rdx)
setne %dl
leaq 0x239365(%rip), %rsi    # 0x30d3c4
cmpl $0x0, (%rsi)
sete %sil
testb %sil, %dl
jne 0xd3df1
leaq 0x14f572(%rip), %rdx    # 0x2235e8
cmpb $0x0, (%rdx)
je 0xd3df1
movsd (%r15), %xmm1
ucomisd %xmm2, %xmm1
jne 0xd40ad
jp 0xd40ad
cmpq $0x1000, %rax           # imm = 0x1000
setne %al
leaq 0x146f4c(%rip), %rcx    # 0x21afe8
cmpl $0x4f, (%rcx)
setne %cl
orb %al, %cl
movzbl %cl, %r14d
jmp 0xd3df1
addq $0x1b880400, %rcx       # imm = 0x1B880400
testq %rcx, %rax
je 0xd40c3
ucomisd %xmm3, %xmm0
ja 0xd3df1
testl %ebx, %ebx
jne 0xd40f2
leaq 0x14728a(%rip), %rax    # 0x21b358
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xd40de
jnp 0xd40f2
movl $0x2, %r14d
ucomisd 0x34f84(%rip), %xmm3    # 0x109070
ja 0xd3df1
ucomisd 0x34f76(%rip), %xmm3    # 0x109070
seta %al
testl %ebx, %ebx
setne %cl
andb %al, %cl
movzbl %cl, %eax
leal (%rax,%rax,2), %r14d
jmp 0xd3df1