// File: 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
subq $0x70, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, 0x2a626b(%rip)    # 0x3d9c74
movl $0x0, 0x2a6259(%rip)    # 0x3d9c6c
movl $0x0, 0x2a6253(%rip)    # 0x3d9c70
movl $0x0, 0x2a6241(%rip)    # 0x3d9c68
movl $0x0, 0x2a6247(%rip)    # 0x3d9c78
leaq 0x238d58(%rip), %rax    # 0x36c790
movl $0x1, (%rax)
movl $0x0, -0x24(%rbp)
leaq 0x239030(%rip), %rax    # 0x36ca7c
cmpl $0x0, (%rax)
jne 0x133a5a
movl -0x24(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x133a6a
movl -0x24(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x133a7f
movl -0x24(%rbp), %eax
orl $0x4, %eax
movl %eax, -0x24(%rbp)
leaq 0x239080(%rip), %rax    # 0x36cb06
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x133a97
movl -0x24(%rbp), %eax
orl $0x8, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x133b1b
callq 0x133d80
movl %eax, %ecx
leaq 0x238fd5(%rip), %rax    # 0x36ca80
movl %ecx, (%rax)
leaq 0x238c5c(%rip), %rax    # 0x36c710
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0x133f80
movaps %xmm0, %xmm1
movsd -0x38(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x2395ce(%rip), %rax    # 0x36d0a8
movsd (%rax), %xmm0
movsd 0x3b54a(%rip), %xmm1    # 0x16f030
divsd %xmm1, %xmm0
xorl %edx, %edx
movl %edx, %edi
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
addsd %xmm1, %xmm0
leaq 0x238c20(%rip), %rax    # 0x36c728
movsd %xmm0, (%rax)
movl $0x1, %edi
callq 0x133fc0
jmp 0x133d6b
movl $0x0, -0x18(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x2, 0x95ce7(%rip)     # 0x1c9828
movq -0x10(%rbp), %rdi
leaq 0x62bec(%rip), %rsi     # 0x196738
leaq -0x14(%rbp), %rdx
leaq -0x1c(%rbp), %rcx
leaq 0x2a6111(%rip), %r8     # 0x3d9c6c
leaq -0x18(%rbp), %r9
leaq -0x20(%rbp), %r11
leaq 0x2a610a(%rip), %r10    # 0x3d9c74
leaq 0x95cb7(%rip), %rax     # 0x1c9828
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x9370
movl 0x2a60e0(%rip), %eax    # 0x3d9c6c
cmpl 0x2a60e2(%rip), %eax    # 0x3d9c74
jle 0x133c21
movl $0x1, 0x2a60d6(%rip)    # 0x3d9c78
movl $0x0, 0x2a60c8(%rip)    # 0x3d9c74
movl $0x0, 0x2a60b6(%rip)    # 0x3d9c6c
movl $0x0, -0x18(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x2, 0x95c4c(%rip)     # 0x1c9828
movq -0x10(%rbp), %rdi
leaq 0x62b51(%rip), %rsi     # 0x196738
leaq -0x18(%rbp), %rdx
leaq -0x20(%rbp), %rcx
leaq 0x2a607e(%rip), %r8     # 0x3d9c74
leaq -0x14(%rbp), %r9
leaq -0x1c(%rbp), %r11
leaq 0x2a6067(%rip), %r10    # 0x3d9c6c
leaq 0x95c1c(%rip), %rax     # 0x1c9828
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x9370
movl -0x14(%rbp), %edi
movl -0x1c(%rbp), %esi
movl 0x2a603f(%rip), %edx    # 0x3d9c6c
movl -0x4(%rbp), %ecx
callq 0x132ae0
movl %eax, 0x2a602d(%rip)    # 0x3d9c68
movl -0x18(%rbp), %edi
movl -0x20(%rbp), %esi
movl 0x2a602d(%rip), %edx    # 0x3d9c74
movl -0x4(%rbp), %ecx
callq 0x132ae0
movl %eax, 0x2a601b(%rip)    # 0x3d9c70
movl -0x4(%rbp), %edi
movl 0x2a600e(%rip), %esi    # 0x3d9c6c
movl 0x2a6004(%rip), %edx    # 0x3d9c68
callq 0x122140
movsd %xmm0, -0x58(%rbp)
movl 0x95bb4(%rip), %edi     # 0x1c9828
xorl %edx, %edx
xorps %xmm0, %xmm0
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0x58(%rbp), %xmm0
addsd %xmm1, %xmm0
leaq 0x238dcd(%rip), %rax    # 0x36ca60
subsd (%rax), %xmm0
leaq 0x238e32(%rip), %rax    # 0x36cad0
movsd %xmm0, (%rax)
movl -0x4(%rbp), %edi
movl 0x2a5fc9(%rip), %esi    # 0x3d9c74
movl 0x2a5fbf(%rip), %edx    # 0x3d9c70
callq 0x122140
movsd %xmm0, -0x50(%rbp)
movl 0x95b67(%rip), %edi     # 0x1c9828
addl $0x1, %edi
xorl %edx, %edx
xorps %xmm0, %xmm0
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0x50(%rbp), %xmm0
addsd %xmm1, %xmm0
leaq 0x238d7d(%rip), %rax    # 0x36ca60
subsd (%rax), %xmm0
leaq 0x238dea(%rip), %rax    # 0x36cad8
movsd %xmm0, (%rax)
callq 0x133d80
movl %eax, %ecx
leaq 0x238d80(%rip), %rax    # 0x36ca80
movl %ecx, (%rax)
leaq 0x238a07(%rip), %rax    # 0x36c710
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
callq 0x133f80
movaps %xmm0, %xmm1
movsd -0x48(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
leaq 0x239379(%rip), %rax    # 0x36d0a8
movsd (%rax), %xmm0
movsd 0x3b2f5(%rip), %xmm1    # 0x16f030
divsd %xmm1, %xmm0
xorl %edx, %edx
movl %edx, %edi
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0x40(%rbp), %xmm0
addsd %xmm1, %xmm0
leaq 0x2389cb(%rip), %rax    # 0x36c728
movsd %xmm0, (%rax)
movl $0x2, %edi
callq 0x133fc0
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)