// File: /workspace/github_cpp_makefile_star2_O3/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, 0x2996cd(%rip)    # 0x37aa0c
movl %eax, 0x2996bf(%rip)    # 0x37aa04
movl %eax, 0x2996bd(%rip)    # 0x37aa08
movl %eax, 0x2996af(%rip)    # 0x37aa00
movl %eax, 0x2996b9(%rip)    # 0x37aa10
leaq 0x22c252(%rip), %rax    # 0x30d5b0
movl $0x1, (%rax)
leaq 0x22c5bd(%rip), %rax    # 0x30d928
cmpb $0x0, (%rax)
je 0xe15af
movq %rsi, %r14
testq %rsi, %rsi
je 0xe15af
cmpb $0x0, (%r14)
je 0xe15af
leaq 0x22c50b(%rip), %rax    # 0x30d89c
cmpl $0x0, (%rax)
je 0xe15af
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, 0x8945f(%rip)     # 0x16a824
leaq 0x89458(%rip), %r12     # 0x16a824
subq $0x8, %rsp
leaq 0x299635(%rip), %r11    # 0x37aa0c
leaq 0x527f2(%rip), %rsi     # 0x133bd0
leaq 0x29961f(%rip), %r8     # 0x37aa04
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
pushq %r12
pushq %r11
pushq %r10
callq 0x9360
addq $0x20, %rsp
movl 0x299602(%rip), %edx    # 0x37aa04
cmpl 0x299604(%rip), %edx    # 0x37aa0c
jle 0xe147f
movl $0x1, 0x2995fc(%rip)    # 0x37aa10
movl %r13d, 0x2995f1(%rip)   # 0x37aa0c
leaq 0x2995ea(%rip), %r8     # 0x37aa0c
movl %r13d, 0x2995db(%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, 0x893d8(%rip)     # 0x16a824
subq $0x8, %rsp
leaq 0x52779(%rip), %rsi     # 0x133bd0
movq %r14, %rdi
xorl %eax, %eax
leaq 0x893c1(%rip), %r10     # 0x16a824
pushq %r10
leaq 0x299598(%rip), %r10    # 0x37aa04
pushq %r10
pushq %r15
callq 0x9360
addq $0x20, %rsp
movl 0x299585(%rip), %edx    # 0x37aa04
movl -0x38(%rbp), %edi
movl -0x30(%rbp), %esi
movl %ebx, %ecx
callq 0xe085c
movl %eax, 0x29956e(%rip)    # 0x37aa00
movl -0x34(%rbp), %edi
movl -0x2c(%rbp), %esi
movl 0x29956e(%rip), %edx    # 0x37aa0c
movl %ebx, %ecx
callq 0xe085c
movl %eax, %r14d
movl %eax, 0x29955a(%rip)    # 0x37aa08
movl 0x299550(%rip), %esi    # 0x37aa04
movl 0x299546(%rip), %edx    # 0x37aa00
movl %ebx, %edi
callq 0xd485e
movl 0x8935c(%rip), %r12d    # 0x16a824
cvtsi2sd %r12d, %xmm1
divsd 0x27b6b(%rip), %xmm1    # 0x109040
addsd %xmm0, %xmm1
leaq 0x22c3a0(%rip), %r15    # 0x30d880
movsd (%r15), %xmm0
movsd %xmm0, -0x40(%rbp)
subsd %xmm0, %xmm1
leaq 0x22c3fb(%rip), %rax    # 0x30d8f0
movsd %xmm1, (%rax)
movl 0x29950d(%rip), %esi    # 0x37aa0c
movl %ebx, %edi
movl %r14d, %edx
callq 0xd485e
incl %r12d
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
divsd 0x27b24(%rip), %xmm1    # 0x109040
addsd %xmm0, %xmm1
subsd -0x40(%rbp), %xmm1
leaq 0x22c3cc(%rip), %rax    # 0x30d8f8
movsd %xmm1, (%rax)
callq 0xe1630
leaq 0x22c364(%rip), %rcx    # 0x30d8a0
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movl %eax, (%rcx)
movsd 0x27af3(%rip), %xmm3    # 0x109040
divsd %xmm3, %xmm0
addsd (%r15), %xmm0
leaq 0x22bfd3(%rip), %rax    # 0x30d530
addsd (%rax), %xmm0
leaq 0x22c960(%rip), %rax    # 0x30dec8
movsd (%rax), %xmm1
divsd 0x27ac4(%rip), %xmm1    # 0x109038
xorpd %xmm2, %xmm2
addsd %xmm2, %xmm1
divsd 0x27a8c(%rip), %xmm1    # 0x109010
addsd %xmm2, %xmm1
divsd %xmm3, %xmm1
addsd %xmm0, %xmm1
leaq 0x22bfb1(%rip), %rax    # 0x30d548
movsd %xmm1, (%rax)
callq 0xe178e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xe1630
leaq 0x22c2e5(%rip), %rcx    # 0x30d8a0
movl %eax, (%rcx)
leaq 0x22c2bc(%rip), %rcx    # 0x30d880
cvtsi2sd %eax, %xmm0
movsd 0x27a70(%rip), %xmm1    # 0x109040
divsd %xmm1, %xmm0
addsd (%rcx), %xmm0
leaq 0x22bf51(%rip), %rax    # 0x30d530
addsd (%rax), %xmm0
leaq 0x22c8de(%rip), %rax    # 0x30dec8
movsd (%rax), %xmm2
divsd 0x27a42(%rip), %xmm2    # 0x109038
xorpd %xmm3, %xmm3
addsd %xmm3, %xmm2
divsd 0x27a0a(%rip), %xmm2    # 0x109010
addsd %xmm3, %xmm2
divsd %xmm1, %xmm2
addsd %xmm0, %xmm2
leaq 0x22bf2f(%rip), %rax    # 0x30d548
movsd %xmm2, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe178e