// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathmsc.cpp
// Function: adjust_tz(int)
int adjust_tz(int why)
{
double st;
double jd;
int round_time;
static int last_why;

   // This routine adjusts the receiver time for the time zone and
   // various astronomical time scales. It sets the pri_xxxx variables to
   // the desired local time / astronomical time.
   //
//jd_utc = jdate(1873,12,29) + 0.50;
//jd_gps = jd_utc + jtime(0,0,utc_offset,0.0);


// dst_ofs = 0;
   jd = 0.0;
   round_time = 0;
   have_local_time = 0;

   jd_astro = jd_display = jd_local;
   if(use_gmst || use_lmst || use_merc || use_msd || use_pluto || use_ven || use_bessel) {
      if(use_msd) {
         st = jd_astro = mars_date(jd_tt);
         st = st - (int) st;
         st *= 24.0;
      }
      else if(use_ven || use_merc || use_pluto) {
         st = jd_astro = planet_date(jd_gps+jtime(0,0,0,TSX_TWEAK));
         st = st - (int) st;
         st *= 24.0;
      }
      else if(use_bessel) {
         st = bessel_date(jd_utc);  // bessel_date returns bessel date offset by year 1900
         jd_astro = 1900.0 + st;    // true bessel date

         st = st - (int) st;
         gregorian(0, jd_utc);
         st = jdate(g_year, 1, 1) + (st * 365.242198781);

         st = st - (int) st;
         st *= 24.0;
      }
      else if(use_gmst) st = gmst(jd_utc+jtime(0,0,0,TSX_TWEAK), use_gmst-1);
      else              st = lmst(jd_utc+jtime(0,0,0,TSX_TWEAK), use_lmst-1);

      pri_hours = (int) st;
      st = (st - pri_hours);       // decimal hour
      st *= 60.0;

      pri_minutes = (int) st;
      st = (st - pri_minutes);     // decimal minutes
      st *= 60.0;

      pri_seconds = (int) st;
      st = (st - pri_seconds);     // decimal seconds
      st_secs = st;                // remainder seconds

      pri_frac = st_secs;

      strcpy(tz_string, std_string);
      round_time = 1;
   }
   else {
//pri_year = 2006;  // Astronomical time scale test data from SOFA
//pri_month= 1;
//pri_day= 15;
//pri_hours = 21;
//pri_minutes = 24;
//pri_seconds = 37+14;
//pri_frac = 0.50;
      if(use_tai) {
         jd = tai_time(jd_gps);
         strcpy(tz_string, std_string);
      }
      else if(use_tt) {
         jd = jd_tt;  // TT is 51.184 seconds ahead of GPS
         strcpy(tz_string, std_string);
         round_time = 1;
      }
      else if(use_ut1) {
         delta_ut1 = (jtime(0, 0, 51+utc_offset, 0.184) - utc_delta_t());
//sprintf(debug_text3, "delta_ut1:%f", delta_ut1*24.0*3600.0);
         jd = jd_utc + delta_ut1;
         strcpy(tz_string, std_string);
         round_time = 1;
      }
      else if(use_tcg) {
         jd = tcg_time(jd_tt);
         strcpy(tz_string, std_string);
         round_time = 1;
      }
      else if(use_tdb) {  // accurate to < 50 uS
         jd = tdb_time(jd_tt);
         strcpy(tz_string, std_string);
         round_time = 1;
      }
      else if(use_tcb) {
         jd = tcb_time(jd_tt);

//jd = jd + (1.550519768e-8*(now - 2443144.5003725)*86400.0 + (-6.55e-5)); // calc TCB
         strcpy(tz_string, std_string);
         round_time = 1;
      }
      else if(use_hjd) {
         jd = jd_astro = get_hjd(jd_utc+jtime(0,0,0,TSX_TWEAK));
         strcpy(tz_string, std_string);
         round_time = 1;
      }
      else if(use_loran) {
         jd = loran_time(jd_gps);
         strcpy(tz_string, std_string);
         have_local_time = 1;
      }
      else if(use_gps) {
         jd = jd_gps;
         strcpy(tz_string, std_string);
         have_local_time = 2;
      }
      else if(use_utc) {
         jd = jd_utc;
         strcpy(tz_string, std_string);
         have_local_time = 3;
      }
      else if(solar_time) {
         jd = jd_utc + jtime(0,0,0,TSX_TWEAK);  // adjust time for receiver message delays
         jd += (eot(jd_utc) / (24.0*60.0));
         round_time = 1;
      }
      else {
         if(time_flags & TFLAGS_UTC) jd = jd_utc;  // we want UTC based times
         else                        jd = jd_gps;  // displaying GPS based times

         if((leap_time || leap_sixty) && (TSX_TWEAK < 0.0)) ;  // negative TSX_TWEAK would mess up leap second display
         else jd += jtime(0,0,0,TSX_TWEAK);    // adjust time for receiver message delays

         if(!solar_time) jd += time_zone();    // adjust time for the time zone

         have_local_time = 4;
      }


      if(leap_sixty) {  // receiver sent a time of xx:59:60
         gregorian(0, jd - jtime(0,0,1,0.0));   // convert adjusted Julian back to Gregorian
         g_seconds = 60;  // display leapsecond time to xx:59:60
      }
      else {
         gregorian(0, jd);
      }

round_time = 0;  // we no longer do time rounding
      if(round_time) {       // round time up to nearest second;
         jd += jtime(0,0,0, 0.5);
      }

      jd_display = jd;
      pri_day = g_day;         // set local time values to the adjusted time
      pri_month = g_month;
      pri_year = g_year;
      pri_hours = g_hours;        
      pri_minutes = g_minutes;
      pri_seconds = g_seconds;
      pri_frac = g_frac;       // note: usually 1msec fast due to rounding compensation in gregorian(0, )
      if(round_time) {
         pri_frac = g_frac = 0;
      }
   }

   last_why = why;
   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
leaq 0x2283a0(%rip), %r14    # 0x2f764c
andl $0x0, (%r14)
leaq 0x228291(%rip), %rax    # 0x2f7548
movsd (%rax), %xmm0
leaq 0x22828e(%rip), %rbx    # 0x2f7550
movsd %xmm0, (%rbx)
leaq 0x22828b(%rip), %r15    # 0x2f7558
movsd %xmm0, (%r15)
leaq 0x228627(%rip), %rax    # 0x2f7900
movzbl (%rax), %edi
leaq 0x22861e(%rip), %rax    # 0x2f7901
movb (%rax), %al
movl %edi, %edx
orb %al, %dl
leaq 0x22861d(%rip), %rcx    # 0x2f790d
movb (%rcx), %cl
leaq 0x228613(%rip), %rsi    # 0x2f790c
movb (%rsi), %sil
movl %ecx, %r8d
orb %sil, %r8b
orb %dl, %r8b
leaq 0x228603(%rip), %rdx    # 0x2f790f
movb (%rdx), %dl
leaq 0x2285f9(%rip), %r9     # 0x2f790e
movb (%r9), %r9b
movl %edx, %r10d
orb %r9b, %r10b
orb %r8b, %r10b
leaq 0x2285e8(%rip), %r8     # 0x2f7910
movb (%r8), %r8b
orb %r8b, %r10b
je 0xcf382
testb %sil, %sil
je 0xcf3da
leaq 0x228200(%rip), %rax    # 0x2f7540
movsd (%rax), %xmm2
addsd 0x466f4(%rip), %xmm2    # 0x115a40
divsd 0x466f4(%rip), %xmm2    # 0x115a48
addsd 0x466f4(%rip), %xmm2    # 0x115a50
addsd 0x466f4(%rip), %xmm2    # 0x115a58
cvttpd2dq %xmm2, %xmm0
cvtdq2pd %xmm0, %xmm0
movsd %xmm2, (%r15)
subsd %xmm0, %xmm2
mulsd 0x23cc3(%rip), %xmm2    # 0xf3040
jmp 0xcf6b9
leaq 0x22857a(%rip), %rax    # 0x2f7903
cmpb $0x0, (%rax)
je 0xcf446
leaq 0x22819f(%rip), %rax    # 0x2f7538
leaq 0x228b28(%rip), %rcx    # 0x2f7ec8
movsd (%rcx), %xmm0
divsd 0x23c8c(%rip), %xmm0    # 0xf3038
addsd 0x46724(%rip), %xmm0    # 0x115ad8
divsd 0x23c54(%rip), %xmm0    # 0xf3010
xorpd %xmm1, %xmm1
addsd %xmm0, %xmm1
divsd 0x23c74(%rip), %xmm1    # 0xf3040
addsd (%rax), %xmm1
movsd %xmm1, -0x30(%rbp)
jmp 0xcf466
orb %cl, %r9b
orb %dl, %r9b
je 0xcf547
leaq 0x228adb(%rip), %rax    # 0x2f7ec8
movsd (%rax), %xmm2
divsd 0x23c3f(%rip), %xmm2    # 0xf3038
xorpd %xmm0, %xmm0
addsd %xmm0, %xmm2
divsd 0x23c07(%rip), %xmm2    # 0xf3010
leaq 0x228128(%rip), %rax    # 0x2f7538
addsd %xmm0, %xmm2
movsd 0x23c24(%rip), %xmm0    # 0xf3040
divsd %xmm0, %xmm2
addsd (%rax), %xmm2
addsd 0x46634(%rip), %xmm2    # 0x115a60
movsd %xmm2, (%r15)
cvttpd2dq %xmm2, %xmm1
cvtdq2pd %xmm1, %xmm1
subsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
jmp 0xcf6b9
leaq 0x2284b7(%rip), %rax    # 0x2f7904
cmpb $0x0, (%rax)
je 0xcf5c9
leaq 0x2280e3(%rip), %rax    # 0x2f7540
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x2284c3(%rip), %rdi    # 0x2f7930
leaq 0x2284ac(%rip), %rsi    # 0x2f7920
callq 0x9330
leaq 0x227da8(%rip), %rax    # 0x2f7228
cmpl $0x0, (%rax)
je 0xcf4ab
movsd 0x46693(%rip), %xmm0    # 0x115b20
addsd -0x30(%rbp), %xmm0
xorl %edi, %edi
callq 0xbfac2
leaq 0x228210(%rip), %rax    # 0x2f76b0
movl $0x3c, (%rax)
pushq $0x3c
popq %rax
jmp 0xcf4c0
xorl %edi, %edi
movsd -0x30(%rbp), %xmm0
callq 0xbfac2
leaq 0x2281f2(%rip), %rax    # 0x2f76b0
movl (%rax), %eax
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rbx)
leaq 0x2281d0(%rip), %rcx    # 0x2f76a0
movl (%rcx), %ecx
leaq 0x228033(%rip), %rdx    # 0x2f750c
movl %ecx, (%rdx)
leaq 0x2281ba(%rip), %rcx    # 0x2f769c
movl (%rcx), %ecx
leaq 0x228025(%rip), %rdx    # 0x2f7510
movl %ecx, (%rdx)
leaq 0x2281b0(%rip), %rcx    # 0x2f76a4
movl (%rcx), %ecx
leaq 0x228017(%rip), %rdx    # 0x2f7514
movl %ecx, (%rdx)
leaq 0x2281a2(%rip), %rcx    # 0x2f76a8
movl (%rcx), %ecx
leaq 0x227ff9(%rip), %rdx    # 0x2f7508
movl %ecx, (%rdx)
leaq 0x228194(%rip), %rcx    # 0x2f76ac
movl (%rcx), %ecx
leaq 0x227fe3(%rip), %rdx    # 0x2f7504
movl %ecx, (%rdx)
leaq 0x227fd6(%rip), %rcx    # 0x2f7500
movl %eax, (%rcx)
leaq 0x228185(%rip), %rax    # 0x2f76b8
movsd (%rax), %xmm0
leaq 0x227fda(%rip), %rax    # 0x2f7518
movsd %xmm0, (%rax)
jmp 0xcf73d
leaq 0x227fe2(%rip), %rcx    # 0x2f7530
movsd (%rcx), %xmm0
testb %r8b, %r8b
je 0xcf633
movsd 0x46505(%rip), %xmm3    # 0x115a68
addsd %xmm0, %xmm3
divsd 0x46501(%rip), %xmm3    # 0x115a70
movsd 0x465b1(%rip), %xmm1    # 0x115b28
addsd %xmm3, %xmm1
cvttpd2dq %xmm3, %xmm2
movsd %xmm1, (%r15)
cvtdq2pd %xmm2, %xmm1
subsd %xmm1, %xmm3
movapd %xmm3, -0x30(%rbp)
xorl %edi, %edi
callq 0xbfac2
leaq 0x228105(%rip), %rax    # 0x2f76a4
movl (%rax), %edi
pushq $0x1
popq %rdx
movl %edx, %esi
callq 0xc2f07
movapd -0x30(%rbp), %xmm2
mulsd 0x464b8(%rip), %xmm2    # 0x115a70
addsd %xmm0, %xmm2
cvttpd2dq %xmm2, %xmm0
cvtdq2pd %xmm0, %xmm0
jmp 0xcf371
leaq 0x228332(%rip), %rax    # 0x2f7902
cmpb $0x0, (%rax)
je 0xcf673
leaq 0x228148(%rip), %rax    # 0x2f7728
movl (%rax), %eax
addl $0x33, %eax
cvtsi2sd %eax, %xmm0
addsd 0x460bf(%rip), %xmm0    # 0x1156b0
divsd 0x23a17(%rip), %xmm0    # 0xf3010
xorpd %xmm1, %xmm1
addsd %xmm0, %xmm1
divsd 0x23a37(%rip), %xmm1    # 0xf3040
movsd %xmm1, -0x30(%rbp)
callq 0xbcc92
movsd -0x30(%rbp), %xmm1
subsd %xmm0, %xmm1
leaq 0x227ed5(%rip), %rax    # 0x2f74f8
movsd %xmm1, (%rax)
leaq 0x227f02(%rip), %rax    # 0x2f7530
jmp 0xcf3cc
leaq 0x22888e(%rip), %rcx    # 0x2f7ec8
movsd (%rcx), %xmm1
divsd 0x239f2(%rip), %xmm1    # 0xf3038
xorpd %xmm2, %xmm2
addsd %xmm2, %xmm1
divsd 0x239ba(%rip), %xmm1    # 0xf3010
addsd %xmm2, %xmm1
divsd 0x239de(%rip), %xmm1    # 0xf3040
addsd %xmm1, %xmm0
testl %edi, %edi
je 0xcf6ab
decl %edi
callq 0xceefc
jmp 0xcf6b5
leaq 0x22828b(%rip), %rax    # 0x2f7905
cmpb $0x0, (%rax)
je 0xcf74b
leaq 0x227eb6(%rip), %rax    # 0x2f7540
movsd (%rax), %xmm0
movsd 0x4644a(%rip), %xmm1    # 0x115ae0
addsd %xmm0, %xmm1
mulsd 0x46446(%rip), %xmm1    # 0x115ae8
addsd %xmm0, %xmm1
jmp 0xcf3d0
movzbl %al, %edi
decl %edi
callq 0xcf057
movapd %xmm0, %xmm2
cvttsd2si %xmm2, %eax
leaq 0x227e44(%rip), %rcx    # 0x2f7508
movl %eax, (%rcx)
cvttpd2dq %xmm2, %xmm0
cvtdq2pd %xmm0, %xmm0
subsd %xmm0, %xmm2
movsd 0x2392e(%rip), %xmm0    # 0xf3008
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %eax
leaq 0x227e1b(%rip), %rcx    # 0x2f7504
cvttpd2dq %xmm2, %xmm1
cvtdq2pd %xmm1, %xmm1
subsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %edx
movl %eax, (%rcx)
leaq 0x227dfa(%rip), %rax    # 0x2f7500
cvttpd2dq %xmm2, %xmm0
movl %edx, (%rax)
cvtdq2pd %xmm0, %xmm0
subsd %xmm0, %xmm2
leaq 0x2281fd(%rip), %rax    # 0x2f7918
movsd %xmm2, (%rax)
leaq 0x227df2(%rip), %rax    # 0x2f7518
movsd %xmm2, (%rax)
leaq 0x2281ff(%rip), %rdi    # 0x2f7930
leaq 0x2281e8(%rip), %rsi    # 0x2f7920
callq 0x9330
pushq $0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2281b4(%rip), %rax    # 0x2f7906
cmpb $0x0, (%rax)
je 0xcf76c
leaq 0x227de2(%rip), %rax    # 0x2f7540
movsd (%rax), %xmm0
callq 0xcf137
jmp 0xcf461
leaq 0x228194(%rip), %rax    # 0x2f7907
cmpb $0x0, (%rax)
je 0xcf78d
leaq 0x227dc1(%rip), %rax    # 0x2f7540
movsd (%rax), %xmm0
callq 0xcf1bd
jmp 0xcf461
leaq 0x228174(%rip), %rax    # 0x2f7908
cmpb $0x0, (%rax)
je 0xcf7e7
leaq 0x227d90(%rip), %rax    # 0x2f7530
leaq 0x228721(%rip), %rcx    # 0x2f7ec8
movsd (%rcx), %xmm0
divsd 0x23885(%rip), %xmm0    # 0xf3038
xorpd %xmm1, %xmm1
addsd %xmm1, %xmm0
divsd 0x2384d(%rip), %xmm0    # 0xf3010
addsd %xmm1, %xmm0
divsd 0x23871(%rip), %xmm0    # 0xf3040
addsd (%rax), %xmm0
callq 0xcedfb
movsd %xmm0, -0x30(%rbp)
movsd %xmm0, (%r15)
jmp 0xcf466
leaq 0x22811b(%rip), %rax    # 0x2f7909
cmpb $0x0, (%rax)
je 0xcf855
leaq 0x227d3e(%rip), %rax    # 0x2f7538
leaq 0x2286c7(%rip), %rcx    # 0x2f7ec8
movsd (%rcx), %xmm0
divsd 0x2382b(%rip), %xmm0    # 0xf3038
addsd 0x38f6b(%rip), %xmm0    # 0x108780
divsd 0x237f3(%rip), %xmm0    # 0xf3010
xorpd %xmm1, %xmm1
addsd %xmm0, %xmm1
divsd 0x23813(%rip), %xmm1    # 0xf3040
addsd (%rax), %xmm1
movsd %xmm1, -0x30(%rbp)
leaq 0x2280f3(%rip), %rdi    # 0x2f7930
leaq 0x2280dc(%rip), %rsi    # 0x2f7920
callq 0x9330
movl $0x1, (%r14)
jmp 0xcf479
leaq 0x2280ae(%rip), %rax    # 0x2f790a
cmpb $0x0, (%rax)
je 0xcf890
leaq 0x227cd0(%rip), %rax    # 0x2f7538
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x2280b8(%rip), %rdi    # 0x2f7930
leaq 0x2280a1(%rip), %rsi    # 0x2f7920
callq 0x9330
movl $0x2, (%r14)
jmp 0xcf479
leaq 0x228074(%rip), %rax    # 0x2f790b
cmpb $0x0, (%rax)
je 0xcf8cb
leaq 0x227c8d(%rip), %rax    # 0x2f7530
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x22807d(%rip), %rdi    # 0x2f7930
leaq 0x228066(%rip), %rsi    # 0x2f7920
callq 0x9330
movl $0x3, (%r14)
jmp 0xcf479
leaq 0x22803f(%rip), %rax    # 0x2f7911
cmpb $0x0, (%rax)
je 0xcf936
leaq 0x227c52(%rip), %rax    # 0x2f7530
movsd (%rax), %xmm0
leaq 0x2285df(%rip), %rax    # 0x2f7ec8
movsd (%rax), %xmm2
divsd 0x23743(%rip), %xmm2    # 0xf3038
xorpd %xmm1, %xmm1
addsd %xmm1, %xmm2
divsd 0x2370b(%rip), %xmm2    # 0xf3010
addsd %xmm1, %xmm2
divsd 0x2372f(%rip), %xmm2    # 0xf3040
addsd %xmm0, %xmm2
movsd %xmm2, -0x30(%rbp)
callq 0xce933
divsd 0x23851(%rip), %xmm0    # 0xf3178
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0xcf479
leaq 0x227b67(%rip), %rax    # 0x2f74a4
testb $0x1, (%rax)
jne 0xcf94b
leaq 0x227bef(%rip), %rax    # 0x2f7538
jmp 0xcf952
leaq 0x227bde(%rip), %rax    # 0x2f7530
leaq 0x227af7(%rip), %rcx    # 0x2f7450
cmpb $0x0, (%rcx)
setne %cl
leaq 0x2278c2(%rip), %rdx    # 0x2f7228
cmpl $0x0, (%rdx)
movsd (%rax), %xmm0
setne %al
orb %cl, %al
leaq 0x22854f(%rip), %rcx    # 0x2f7ec8
movsd (%rcx), %xmm1
divsd 0x236b3(%rip), %xmm1    # 0xf3038
cmpb $0x1, %al
jne 0xcf993
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
ja 0xcf9b3
xorpd %xmm2, %xmm2
addsd %xmm2, %xmm1
divsd 0x2366d(%rip), %xmm1    # 0xf3010
addsd %xmm2, %xmm1
divsd 0x23691(%rip), %xmm1    # 0xf3040
addsd %xmm1, %xmm0
leaq 0x227ec6(%rip), %rax    # 0x2f7880
leaq 0x227edf(%rip), %rcx    # 0x2f78a0
cvtsi2sdl (%rcx), %xmm1
divsd 0x23673(%rip), %xmm1    # 0xf3040
addsd (%rax), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
movl $0x4, (%r14)
jmp 0xcf479