// File: /workspace/github_cpp_makefile_star2_O2/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 0x7fc06(%rip), %rdi     # 0x10eee5
callq 0x520bf
leaq 0x296959(%rip), %rax    # 0x325c44
andl $0x0, (%rax)
callq 0x75767
testl %eax, %eax
je 0x8f49d
leaq 0x29673e(%rip), %r14    # 0x325a40
movq %r14, %rdi
callq 0x988f
leaq 0x7fb00(%rip), %rsi     # 0x10ee11
movq %r14, %rdi
callq 0x9090
movq %rax, %rbx
leaq 0x175cbd(%rip), %rax    # 0x204fe0
cmpl $0x4e, (%rax)
jne 0x8f331
leaq 0x8c687(%rip), %rbx     # 0x11b9b6
jmp 0x8f34b
testq %rbx, %rbx
je 0x8f43f
cmpb $0x0, 0x2(%rbx)
je 0x8f49d
movq %rbx, %r14
addq $0x2, %r14
movq %r14, %rdi
callq 0x98b2
movl %eax, %r15d
movl %eax, %eax
cvtsi2sd %rax, %xmm0
divsd 0x63cb3(%rip), %xmm0    # 0xf3018
addsd 0x665a3(%rip), %xmm0    # 0xf5910
movapd %xmm0, -0x40(%rbp)
leaq 0x2683af(%rip), %rax    # 0x2f7728
movl (%rax), %edx
xorpd %xmm0, %xmm0
xorl %edi, %edi
xorl %esi, %esi
callq 0xc2faf
movapd -0x40(%rbp), %xmm1
subsd %xmm0, %xmm1
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm0
addsd 0x63cc7(%rip), %xmm0    # 0xf3068
movapd %xmm0, -0x40(%rbp)
movsd 0x63cc2(%rip), %xmm0    # 0xf3070
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xc2faf
movapd -0x40(%rbp), %xmm1
subsd %xmm0, %xmm1
leaq 0x267e5b(%rip), %rax    # 0x2f7224
movl $0x1, (%rax)
leaq 0x26803a(%rip), %rax    # 0x2f7410
imull $0x1c00, (%rax), %eax   # imm = 0x1C00
cvtsi2sd %eax, %xmm0
addsd %xmm1, %xmm0
leaq 0x268175(%rip), %r14    # 0x2f7560
movsd %xmm0, (%r14)
pushq $0x4
popq %rdi
callq 0x557cf
leaq 0x198f91(%rip), %rax    # 0x228390
movq (%rax), %rdi
testq %rdi, %rdi
je 0x8f49d
movsd (%r14), %xmm0
leaq 0x267dd5(%rip), %rax    # 0x2f71ec
movl (%rax), %r8d
leaq 0x7fad2(%rip), %rsi     # 0x10eef3
movl %r15d, %edx
movl %r15d, %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 0x2965fa(%rip), %rdi    # 0x325a40
callq 0x95e0
movl %eax, %r14d
leal -0x835(%r14), %eax
cmpl $-0x55, %eax
jb 0x8f49d
callq 0x75767
testl %eax, %eax
je 0x8f49d
leaq 0x2965d6(%rip), %rdi    # 0x325a40
callq 0x95e0
movl %eax, %r12d
leal -0xd(%r12), %eax
cmpl $-0xc, %eax
jb 0x8f49d
callq 0x75767
testl %eax, %eax
je 0x8f49d
leaq 0x2965b4(%rip), %rdi    # 0x325a40
callq 0x95e0
movl %eax, %r13d
leal -0x20(%r13), %eax
cmpl $-0x1f, %eax
jae 0x8f4ac
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r14d, %edi
movl %r12d, %esi
movl %r13d, %edx
callq 0xc2f07
movsd %xmm0, -0x40(%rbp)
pushq $0x17
popq %rdi
pushq $0x3b
popq %rdx
xorpd %xmm0, %xmm0
movl %edx, %esi
callq 0xc2faf
addsd -0x40(%rbp), %xmm0
cmpl $0x1, %r13d
jne 0x8f4e3
addsd 0x63c15(%rip), %xmm0    # 0xf30f8
movapd %xmm0, -0x40(%rbp)
leaq 0x296d31(%rip), %rbx    # 0x326220
leaq 0x72100(%rip), %rsi     # 0x1015f6
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r14d, %edx
movl %r12d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x9060
movapd -0x40(%rbp), %xmm1
jmp 0x8f3cf