// File: /workspace/github_cpp_makefile_star2_O1/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
xorl %eax, %eax
movl %eax, 0x29a18b(%rip)    # 0x37aa0c
movl %eax, 0x29a17d(%rip)    # 0x37aa04
movl %eax, 0x29a17b(%rip)    # 0x37aa08
movl %eax, 0x29a16d(%rip)    # 0x37aa00
movl %eax, 0x29a177(%rip)    # 0x37aa10
leaq 0x22cd10(%rip), %rax    # 0x30d5b0
movl $0x1, (%rax)
leaq 0x22d07b(%rip), %rax    # 0x30d928
cmpb $0x0, (%rax)
je 0xe0a71
movq %rsi, %r14
testq %rsi, %rsi
je 0xe0a71
cmpb $0x0, (%r14)
je 0xe0a71
leaq 0x22cfc9(%rip), %rax    # 0x30d89c
cmpl $0x0, (%rax)
je 0xe0a71
movl %edi, %ebx
xorl %r13d, %r13d
leaq -0x34(%rbp), %r9
movl %r13d, (%r9)
leaq -0x38(%rbp), %rdx
movl %r13d, (%rdx)
leaq -0x2c(%rbp), %r10
movl %r13d, (%r10)
leaq -0x30(%rbp), %r15
movl %r13d, (%r15)
movl $0x2, 0x89f1d(%rip)     # 0x16a824
leaq 0x89f16(%rip), %r12     # 0x16a824
subq $0x8, %rsp
leaq 0x29a0f3(%rip), %r11    # 0x37aa0c
leaq 0x531c0(%rip), %rsi     # 0x133ae0
leaq 0x29a0dd(%rip), %r8     # 0x37aa04
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
pushq %r12
pushq %r11
pushq %r10
callq 0x9360
addq $0x20, %rsp
movl 0x29a0c0(%rip), %eax    # 0x37aa04
cmpl 0x29a0c2(%rip), %eax    # 0x37aa0c
jle 0xe09bb
movl $0x1, 0x29a0ba(%rip)    # 0x37aa10
movl %r13d, 0x29a0af(%rip)   # 0x37aa0c
leaq 0x29a0a8(%rip), %r8     # 0x37aa0c
movl %r13d, 0x29a099(%rip)   # 0x37aa04
leaq -0x34(%rbp), %rdx
movl %r13d, (%rdx)
leaq -0x38(%rbp), %r9
movl %r13d, (%r9)
leaq -0x2c(%rbp), %rcx
movl %r13d, (%rcx)
movl %r13d, -0x30(%rbp)
movl $0x2, 0x89e96(%rip)     # 0x16a824
subq $0x8, %rsp
leaq 0x53147(%rip), %rsi     # 0x133ae0
movq %r14, %rdi
xorl %eax, %eax
leaq 0x89e7f(%rip), %r10     # 0x16a824
pushq %r10
leaq 0x29a056(%rip), %r10    # 0x37aa04
pushq %r10
pushq %r15
callq 0x9360
addq $0x20, %rsp
movl -0x38(%rbp), %edi
movl -0x30(%rbp), %esi
movl 0x29a03d(%rip), %edx    # 0x37aa04
movl %ebx, %ecx
callq 0xdfd9e
movl %eax, 0x29a02c(%rip)    # 0x37aa00
movl -0x34(%rbp), %edi
movl -0x2c(%rbp), %esi
movl 0x29a02c(%rip), %edx    # 0x37aa0c
movl %ebx, %ecx
callq 0xdfd9e
movl %eax, %r14d
movl %eax, 0x29a018(%rip)    # 0x37aa08
movl 0x29a00e(%rip), %esi    # 0x37aa04
movl 0x29a004(%rip), %edx    # 0x37aa00
movl %ebx, %edi
callq 0xd4110
movl 0x89e1a(%rip), %r15d    # 0x16a824
cvtsi2sd %r15d, %xmm1
divsd 0x28629(%rip), %xmm1    # 0x109040
addsd %xmm0, %xmm1
leaq 0x22ce5e(%rip), %rax    # 0x30d880
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
subsd %xmm0, %xmm1
leaq 0x22ceba(%rip), %rax    # 0x30d8f0
movsd %xmm1, (%rax)
movl 0x299fcc(%rip), %esi    # 0x37aa0c
movl %ebx, %edi
movl %r14d, %edx
callq 0xd4110
incl %r15d
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
divsd 0x285e3(%rip), %xmm1    # 0x109040
addsd %xmm0, %xmm1
subsd -0x40(%rbp), %xmm1
leaq 0x22ce8b(%rip), %rax    # 0x30d8f8
movsd %xmm1, (%rax)
callq 0xe0af6
leaq 0x22ce23(%rip), %rcx    # 0x30d8a0
movl %eax, (%rcx)
leaq 0x22cdfa(%rip), %rcx    # 0x30d880
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x285ab(%rip), %xmm1    # 0x109040
divsd %xmm1, %xmm0
addsd (%rcx), %xmm0
leaq 0x22ca8c(%rip), %rax    # 0x30d530
addsd (%rax), %xmm0
leaq 0x22d419(%rip), %rax    # 0x30dec8
movsd (%rax), %xmm2
divsd 0x2857d(%rip), %xmm2    # 0x109038
xorpd %xmm3, %xmm3
addsd %xmm3, %xmm2
divsd 0x28545(%rip), %xmm2    # 0x109010
addsd %xmm3, %xmm2
divsd %xmm1, %xmm2
addsd %xmm0, %xmm2
leaq 0x22ca6a(%rip), %rax    # 0x30d548
movsd %xmm2, (%rax)
callq 0xe0c54
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq