// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathgps.cpp
// Function: parse_scpi_leaptime()
void parse_scpi_leaptime()
{
char *s;
u32 val;
int yy,mm,dd;
double leap_day;

   // calculates the date of the next leapsecond event
   log_packet_id("scpi leaptime");

   val = 0;

   msg_col = 0;
   if(get_msg_field()) { 
      strupr(msg_field);
      s = strstr(msg_field, "#H");
      if(scpi_type == NORTEL_TYPE) {
         s = "";
         val = atohex(&msg_field[0]);
         goto hex_time;
      }
      else if(s) {  // hex format
         if(s[2] == 0) return;
         val = atohex(s+2);

         hex_time:
         leap_day = (double) (u32) val;
         leap_day /= (24.0*60.0*60.0);
         leap_day += GPS_EPOCH;
         leap_day -= jtime(0,0,utc_offset, 0.0);  // convert GPS to UTC
         leap_day = ((double) (int) leap_day) + 0.50;  // removes time fraction
         leap_day -= jtime(0,0,0, 1.0);  // gets time of leap to 23:59:59
         have_scpi_hex_leap = 1;
//gregorian(0, leap_day);
//sprintf(debug_text2, "hexday:%f utcofs:%d  %04d/%02d/%02d %02d:%02d:%02d", leap_day, utc_offset, g_year,g_month,g_day, g_hours,g_minutes,g_seconds);
      }
      else if(0 && have_scpi_hex_leap) {  // we have leap date from the hex format message
         return;
      }
      else { // yyyy mm dd format  // this message can be wrong on devcices that send both formats
          yy = atoi(msg_field);   // ... might say 30 Sep if leap pending flag
          if(yy < 2016) return;    // ... was broadcast in July
          if(yy > 2100) return;

          if(get_msg_field() == 0) return;
          mm = atoi(msg_field);
          if(mm < 1) return;
          if(mm > 12) return;

          if(get_msg_field() == 0) return;
          dd = atoi(msg_field);
          if(dd < 1) return;
          if(dd > 31) return;

          leap_day = jdate(yy, mm, dd) + jtime(23,59,59,0.0);
          if(dd == 1) leap_day -= 1.0;
          sprintf(out, "%04d/%02d/%02d", yy,mm,dd);
//sprintf(debug_text3, "lday2:%f  %s", leap_day, out);
          s = &out[0];
      }

      leap_day += (double) (rolled * 1024*7);
      jd_leap = leap_day;
      calc_jd_leap(4);
///have_leap_days = 30;
///gregorian(0, leap_day);
//sprintf(plot_title, "rolled:%d  lday:%04d/%02d/%02d  %02d:%02d:%02d  today:%04d/%02d/%02d", rolled, g_year,g_month,g_day, g_hours,g_minutes,g_seconds, year,month,day);
///      today = jdate(year, month, day);
///      leap_days = (int) (leap_day - today);
///      have_leap_days = 3;
///sprintf(debug_text, "leap_day:%f today:%f leap_days:%d  rolled:%d", leap_day,today,leap_days, rolled);

if(debug_file) fprintf(debug_file, "### leaptime:%08X(%u)  leap_day:%f  leap_days:%d  s:%s", val, val, jd_leap, leap_days, s);
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x86f4a(%rip), %rdi     # 0x124ebd
callq 0x58e77
leaq 0x29dcc5(%rip), %rax    # 0x33bc44
movl $0x0, (%rax)
callq 0x811da
testl %eax, %eax
je 0x9e16c
leaq 0x29daa7(%rip), %r14    # 0x33ba40
movq %r14, %rdi
callq 0x9899
leaq 0x86e41(%rip), %rsi     # 0x124de9
movq %r14, %rdi
callq 0x9090
movq %rax, %rbx
leaq 0x17d026(%rip), %rax    # 0x21afe0
cmpl $0x4e, (%rax)
jne 0x9dfc8
leaq 0x939e0(%rip), %rbx     # 0x1319a6
jmp 0x9dfe2
testq %rbx, %rbx
je 0x9e10e
cmpb $0x0, 0x2(%rbx)
je 0x9e16c
movq %rbx, %r14
addq $0x2, %r14
movq %r14, %rdi
callq 0x98c6
movl %eax, %r14d
movl %eax, %eax
cvtsi2sd %rax, %xmm0
divsd 0x6b01c(%rip), %xmm0    # 0x109018
addsd 0x6d884(%rip), %xmm0    # 0x10b888
movapd %xmm0, -0x40(%rbp)
leaq 0x26f718(%rip), %rax    # 0x30d728
movl (%rax), %edx
xorpd %xmm0, %xmm0
xorl %edi, %edi
xorl %esi, %esi
callq 0xd41e0
movapd -0x40(%rbp), %xmm1
subsd %xmm0, %xmm1
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm0
addsd 0x6b030(%rip), %xmm0    # 0x109068
movapd %xmm0, -0x40(%rbp)
movsd 0x6b02b(%rip), %xmm0    # 0x109070
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd41e0
movapd -0x40(%rbp), %xmm1
subsd %xmm0, %xmm1
leaq 0x26f1c4(%rip), %rax    # 0x30d224
movl $0x1, (%rax)
leaq 0x26f3a3(%rip), %rax    # 0x30d410
imull $0x1c00, (%rax), %eax   # imm = 0x1C00
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
addsd %xmm1, %xmm0
leaq 0x26f4ab(%rip), %rax    # 0x30d530
movapd %xmm0, %xmm1
subsd (%rax), %xmm1
xorl %eax, %eax
ucomisd 0x80049(%rip), %xmm1    # 0x11e0e0
setb %al
shll $0x2, %eax
xorl %ecx, %ecx
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
cmovbel %eax, %ecx
leaq 0x26f4af(%rip), %rax    # 0x30d560
movsd %xmm0, (%rax)
leaq 0x26f134(%rip), %rax    # 0x30d1f0
movl %ecx, (%rax)
leaq 0x26f4a3(%rip), %rax    # 0x30d568
movl %ecx, (%rax)
cvttsd2si %xmm1, %r8d
leaq 0x26f119(%rip), %rax    # 0x30d1ec
movl %r8d, (%rax)
leaq 0x1a02b3(%rip), %rax    # 0x23e390
movq (%rax), %rdi
testq %rdi, %rdi
je 0x9e16c
leaq 0x86ddb(%rip), %rsi     # 0x124ecb
movl %r14d, %edx
movl %r14d, %ecx
movq %rbx, %r9
movb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9560
leaq 0x29d92b(%rip), %rdi    # 0x33ba40
callq 0x95e0
movl %eax, %r15d
leal -0x835(%r15), %eax
cmpl $-0x55, %eax
jb 0x9e16c
callq 0x811da
testl %eax, %eax
je 0x9e16c
leaq 0x29d907(%rip), %rdi    # 0x33ba40
callq 0x95e0
movl %eax, %r12d
leal -0xd(%r12), %eax
cmpl $-0xc, %eax
jb 0x9e16c
callq 0x811da
testl %eax, %eax
je 0x9e16c
leaq 0x29d8e5(%rip), %rdi    # 0x33ba40
callq 0x95e0
movl %eax, %r13d
leal -0x20(%r13), %eax
cmpl $-0x1f, %eax
jae 0x9e17b
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r15d, %edi
movl %r12d, %esi
movl %r13d, %edx
callq 0xd4110
movsd %xmm0, -0x40(%rbp)
xorpd %xmm0, %xmm0
movl $0x17, %edi
movl $0x3b, %esi
movl $0x3b, %edx
callq 0xd41e0
addsd -0x40(%rbp), %xmm0
cmpl $0x1, %r13d
jne 0x9e1b9
addsd 0x6af3f(%rip), %xmm0    # 0x1090f8
movapd %xmm0, -0x40(%rbp)
leaq 0x29e05b(%rip), %rbx    # 0x33c220
leaq 0x79316(%rip), %rsi     # 0x1174e2
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r15d, %edx
movl %r12d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x9060
movapd -0x40(%rbp), %xmm1
jmp 0x9e066