// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathmsc.cpp
// Function: calc_dst_times(int, char*)
void calc_dst_times(int yy, char *s)
{
int start_n, end_n;
int start_dow, end_dow;
int no_dst;

   // calculate when daylight savings time starts and ends

   dst_start_month = dst_end_month = 0;
   dst_start_day = dst_end_day = 0;
   down_under = 0;
   need_sunrise = 1;

   no_dst = 0;
   if(dst_area == 0) no_dst |= 0x01;       // no dst area set
   if(s == 0) no_dst |= 0x02;              // no dst area definition string
   if(s[0] == 0) no_dst |= 0x04;           // empty dst area definition string
   if(dst_string[0] == 0) no_dst |= 0x08;  // no DST time zone name given

   if(no_dst) {
      dst_ofs = dst_offset();
      jd_local = jd_utc + time_zone() + jtime(0,0,0,TSX_TWEAK);

      #ifdef GREET_STUFF
         setup_calendars(1);   // recalc calendars for the new time zone
      #endif
      return;
   }

   start_n = end_n = 0;
   start_dow = end_dow = 0;
   dst_hour = 2;
   sscanf(s, "%d,%d,%d,%d,%d,%d,%d", &start_n,&start_dow,&dst_start_month,
                                     &end_n,&end_dow,&dst_end_month, &dst_hour);
   if(dst_start_month > dst_end_month) { // start month>end_month means southern hemisphere
      down_under = 1;                    // re-scan the string to swap the values
      dst_start_month = dst_end_month = 0;
      start_n = end_n = 0;
      start_dow = end_dow = 0;
      dst_hour = 2;
      sscanf(s, "%d,%d,%d,%d,%d,%d,%d", &end_n,&end_dow,&dst_end_month,
                                        &start_n,&start_dow,&dst_start_month, &dst_hour);
   }

// yy = pri_year;
// yy = this_year;
   dst_start_day = nth_dow_in(start_n, start_dow, dst_start_month, yy);
   dst_end_day   = nth_dow_in(end_n,   end_dow,   dst_end_month,   yy);

   dst_start_jd = jdate(yy,dst_start_month,dst_start_day) + jtime(dst_hour,0,0,0.0) - tz_adjust;
// dst_end_jd = jdate(yy,dst_end_month,dst_end_day) + jtime(dst_hour,0,0,0.0) - tz_adjust;
   dst_end_jd = jdate(yy,dst_end_month,dst_end_day) + jtime(dst_hour+1,0,0,0.0) - tz_adjust;
   dst_ofs = dst_offset();
   jd_local = jd_utc + time_zone() + jtime(0,0,0,TSX_TWEAK);
///gregorian(0, dst_start_jd);
///sprintf(debug_text2, "dst start: %04d/%02d/%02d  %02d:%02d:%02d", g_year,g_month,g_day, g_hours,g_minutes,g_seconds);
///gregorian(0, dst_end_jd);
///sprintf(debug_text3, "dst end:   %04d/%02d/%02d  %02d:%02d:%02d", g_year,g_month,g_day, g_hours,g_minutes,g_seconds);
///sprintf(debug_text, "dst ofs:%d", dst_ofs);

   #ifdef GREET_STUFF
      setup_calendars(2);   // recalc calendars for the new time zone
   #endif

///sprintf(debug_text6, "DST(%s): %02d/%02d .. (%s) %02d/%02d  invert=%d -> %d.  area=%d: %s", 
///  dst_string, dst_start_month, dst_start_day, std_string, dst_end_month, dst_end_day, down_under, dst_offset(), dst_area, dst_list[dst_area]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
andl $0x0, 0x296802(%rip)    # 0x364a0c
andl $0x0, 0x2967f3(%rip)    # 0x364a04
andl $0x0, 0x2967f0(%rip)    # 0x364a08
andl $0x0, 0x2967e1(%rip)    # 0x364a00
andl $0x0, 0x2967ea(%rip)    # 0x364a10
leaq 0x229383(%rip), %rax    # 0x2f75b0
movl $0x1, (%rax)
leaq 0x2296ee(%rip), %rax    # 0x2f7928
cmpb $0x0, (%rax)
je 0xce46e
movq %rsi, %r14
testq %rsi, %rsi
je 0xce46e
cmpb $0x0, (%r14)
je 0xce46e
leaq 0x22963c(%rip), %rax    # 0x2f789c
cmpl $0x0, (%rax)
je 0xce46e
movl %edi, %ebx
leaq -0x34(%rbp), %r9
andl $0x0, (%r9)
leaq -0x38(%rbp), %rdx
andl $0x0, (%rdx)
leaq -0x2c(%rbp), %r10
andl $0x0, (%r10)
leaq -0x30(%rbp), %r15
andl $0x0, (%r15)
movl $0x2, 0x86590(%rip)     # 0x154824
leaq 0x86589(%rip), %r13     # 0x154824
subq $0x8, %rsp
leaq 0x296766(%rip), %r11    # 0x364a0c
leaq 0x4f843(%rip), %rsi     # 0x11daf0
leaq 0x296750(%rip), %r12    # 0x364a04
movq %r14, %rdi
movq %r15, %rcx
movq %r12, %r8
xorl %eax, %eax
pushq %r13
pushq %r11
pushq %r10
callq 0x9350
addq $0x20, %rsp
movl 0x296730(%rip), %edx    # 0x364a04
cmpl 0x296732(%rip), %edx    # 0x364a0c
jle 0xce344
movl $0x1, 0x29672a(%rip)    # 0x364a10
andl $0x0, 0x29671f(%rip)    # 0x364a0c
leaq 0x296718(%rip), %r8     # 0x364a0c
andl $0x0, 0x296709(%rip)    # 0x364a04
leaq -0x34(%rbp), %rdx
andl $0x0, (%rdx)
leaq -0x38(%rbp), %r9
andl $0x0, (%r9)
leaq -0x2c(%rbp), %rcx
andl $0x0, (%rcx)
andl $0x0, -0x30(%rbp)
movl $0x2, 0x86505(%rip)     # 0x154824
subq $0x8, %rsp
leaq 0x4f7c6(%rip), %rsi     # 0x11daf0
movq %r14, %rdi
xorl %eax, %eax
pushq %r13
pushq %r12
pushq %r15
callq 0x9350
addq $0x20, %rsp
movl 0x2966c0(%rip), %edx    # 0x364a04
movl -0x38(%rbp), %edi
movl -0x30(%rbp), %esi
movl %ebx, %ecx
callq 0xcd819
movl %eax, 0x2966a9(%rip)    # 0x364a00
movl -0x34(%rbp), %edi
movl -0x2c(%rbp), %esi
movl 0x2966a9(%rip), %edx    # 0x364a0c
movl %ebx, %ecx
callq 0xcd819
movl %eax, %r14d
movl %eax, 0x296695(%rip)    # 0x364a08
movl 0x29668b(%rip), %esi    # 0x364a04
movl 0x296681(%rip), %edx    # 0x364a00
movl %ebx, %edi
callq 0xc2f07
movl 0x86497(%rip), %r12d    # 0x154824
cvtsi2sd %r12d, %xmm1
divsd 0x24ca6(%rip), %xmm1    # 0xf3040
addsd %xmm0, %xmm1
leaq 0x2294db(%rip), %r15    # 0x2f7880
movsd (%r15), %xmm0
movsd %xmm0, -0x40(%rbp)
subsd %xmm0, %xmm1
leaq 0x229536(%rip), %rax    # 0x2f78f0
movsd %xmm1, (%rax)
movl 0x296648(%rip), %esi    # 0x364a0c
movl %ebx, %edi
movl %r14d, %edx
callq 0xc2f07
incl %r12d
cvtsi2sd %r12d, %xmm1
divsd 0x24c62(%rip), %xmm1    # 0xf3040
addsd %xmm0, %xmm1
subsd -0x40(%rbp), %xmm1
leaq 0x22950a(%rip), %rax    # 0x2f78f8
movsd %xmm1, (%rax)
callq 0xce4ef
leaq 0x2294a2(%rip), %rcx    # 0x2f78a0
cvtsi2sd %eax, %xmm0
movl %eax, (%rcx)
movsd 0x24c34(%rip), %xmm3    # 0xf3040
divsd %xmm3, %xmm0
addsd (%r15), %xmm0
leaq 0x229114(%rip), %rax    # 0x2f7530
addsd (%rax), %xmm0
leaq 0x229aa1(%rip), %rax    # 0x2f7ec8
movsd (%rax), %xmm1
divsd 0x24c05(%rip), %xmm1    # 0xf3038
xorpd %xmm2, %xmm2
addsd %xmm2, %xmm1
divsd 0x24bcd(%rip), %xmm1    # 0xf3010
addsd %xmm2, %xmm1
divsd %xmm3, %xmm1
addsd %xmm0, %xmm1
leaq 0x2290f2(%rip), %rax    # 0x2f7548
movsd %xmm1, (%rax)
callq 0xce64b
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xce4ef
leaq 0x229426(%rip), %rcx    # 0x2f78a0
movl %eax, (%rcx)
leaq 0x2293fd(%rip), %rcx    # 0x2f7880
cvtsi2sd %eax, %xmm0
movsd 0x24bb1(%rip), %xmm1    # 0xf3040
divsd %xmm1, %xmm0
addsd (%rcx), %xmm0
leaq 0x229092(%rip), %rax    # 0x2f7530
addsd (%rax), %xmm0
leaq 0x229a1f(%rip), %rax    # 0x2f7ec8
movsd (%rax), %xmm2
divsd 0x24b83(%rip), %xmm2    # 0xf3038
xorpd %xmm3, %xmm3
addsd %xmm3, %xmm2
divsd 0x24b4b(%rip), %xmm2    # 0xf3010
addsd %xmm3, %xmm2
divsd %xmm1, %xmm2
addsd %xmm0, %xmm2
leaq 0x229070(%rip), %rax    # 0x2f7548
movsd %xmm2, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xce64b