// File: /workspace/github_cpp_makefile_star2_O3/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 0x86e50(%rip), %rdi     # 0x124f9d
callq 0x58dc2
leaq 0x29daeb(%rip), %rax    # 0x33bc44
movl $0x0, (%rax)
callq 0x810b1
testl %eax, %eax
je 0x9e346
leaq 0x29d8cd(%rip), %r14    # 0x33ba40
movq %r14, %rdi
callq 0x9899
leaq 0x86d47(%rip), %rsi     # 0x124ec9
movq %r14, %rdi
callq 0x9090
movq %rax, %rbx
leaq 0x17ce4c(%rip), %rax    # 0x21afe0
cmpl $0x4e, (%rax)
jne 0x9e1a2
leaq 0x938f6(%rip), %rbx     # 0x131a96
jmp 0x9e1bc
testq %rbx, %rbx
je 0x9e2e8
cmpb $0x0, 0x2(%rbx)
je 0x9e346
movq %rbx, %r14
addq $0x2, %r14
movq %r14, %rdi
callq 0x98c6
movl %eax, %r14d
movl %eax, %eax
cvtsi2sd %rax, %xmm0
divsd 0x6ae42(%rip), %xmm0    # 0x109018
addsd 0x6d6ba(%rip), %xmm0    # 0x10b898
movapd %xmm0, -0x40(%rbp)
leaq 0x26f53e(%rip), %rax    # 0x30d728
movl (%rax), %edx
xorpd %xmm0, %xmm0
xorl %edi, %edi
xorl %esi, %esi
callq 0xd492e
movapd -0x40(%rbp), %xmm1
subsd %xmm0, %xmm1
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm0
addsd 0x6ae56(%rip), %xmm0    # 0x109068
movapd %xmm0, -0x40(%rbp)
movsd 0x6ae51(%rip), %xmm0    # 0x109070
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd492e
movapd -0x40(%rbp), %xmm1
subsd %xmm0, %xmm1
leaq 0x26efea(%rip), %rax    # 0x30d224
movl $0x1, (%rax)
leaq 0x26f1c9(%rip), %rax    # 0x30d410
imull $0x1c00, (%rax), %eax   # imm = 0x1C00
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
addsd %xmm1, %xmm0
leaq 0x26f2d1(%rip), %rax    # 0x30d530
movapd %xmm0, %xmm1
subsd (%rax), %xmm1
xorl %eax, %eax
ucomisd 0x7ff17(%rip), %xmm1    # 0x11e188
setb %al
shll $0x2, %eax
xorl %ecx, %ecx
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
cmovbel %eax, %ecx
leaq 0x26f2d5(%rip), %rax    # 0x30d560
movsd %xmm0, (%rax)
leaq 0x26ef5a(%rip), %rax    # 0x30d1f0
movl %ecx, (%rax)
leaq 0x26f2c9(%rip), %rax    # 0x30d568
movl %ecx, (%rax)
cvttsd2si %xmm1, %r8d
leaq 0x26ef3f(%rip), %rax    # 0x30d1ec
movl %r8d, (%rax)
leaq 0x1a00d9(%rip), %rax    # 0x23e390
movq (%rax), %rdi
testq %rdi, %rdi
je 0x9e346
leaq 0x86ce1(%rip), %rsi     # 0x124fab
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 0x29d751(%rip), %rdi    # 0x33ba40
callq 0x95e0
movl %eax, %r15d
leal -0x835(%r15), %eax
cmpl $-0x55, %eax
jb 0x9e346
callq 0x810b1
testl %eax, %eax
je 0x9e346
leaq 0x29d72d(%rip), %rdi    # 0x33ba40
callq 0x95e0
movl %eax, %r12d
leal -0xd(%r12), %eax
cmpl $-0xc, %eax
jb 0x9e346
callq 0x810b1
testl %eax, %eax
je 0x9e346
leaq 0x29d70b(%rip), %rdi    # 0x33ba40
callq 0x95e0
movl %eax, %r13d
leal -0x20(%r13), %eax
cmpl $-0x1f, %eax
jae 0x9e355
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 0xd485e
movsd %xmm0, -0x40(%rbp)
xorpd %xmm0, %xmm0
movl $0x17, %edi
movl $0x3b, %esi
movl $0x3b, %edx
callq 0xd492e
addsd -0x40(%rbp), %xmm0
cmpl $0x1, %r13d
jne 0x9e393
addsd 0x6ad65(%rip), %xmm0    # 0x1090f8
movapd %xmm0, -0x40(%rbp)
leaq 0x29de81(%rip), %rbx    # 0x33c220
leaq 0x791d0(%rip), %rsi     # 0x117576
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 0x9e240