// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: init_persian(int)
void init_persian(int year)
{
double jd;
int leap;
int mm;

// gregorian(0, spring-365.24238426);    // time of spring in GMT of last year;
// jd = jdate(g_year, g_month, g_day);   // jdate of start of spring
// if((jd - (3.5/24.0) + (12.0/24.0)) > spring) {  // it's after noon in Tehran
//    jd += 1.0;  //!!! kludge - we should be using solar noon in Tehran
// }

   leap = year-621-1;               // start calculating from last year
   leap %= 33;                      // leap years on 33 year cycles
   if     (leap == 1)  leap = 20;   // leap years start on 20 March
   else if(leap == 5)  leap = 20;
   else if(leap == 9)  leap = 20;
   else if(leap == 13) leap = 20;
   else if(leap == 17) leap = 20;
   else if(leap == 22) leap = 20;
   else if(leap == 26) leap = 20;
   else if(leap == 30) leap = 20;
   else                leap = 21;

   jd = jdate(year-1, 3, leap);  // first day of the previous persian year

   ptimes[0] = jd;
   pyears[0] = year-621-1;

   for(mm=0+1; mm<=36; mm++) { // calculate next 36 months
      if     ((mm%12) <= 6)  ptimes[mm] = ptimes[mm-1] + 31.0;
      else if((mm%12) <= 11) ptimes[mm] = ptimes[mm-1] + 30.0;
      if((mm == 12) || (mm == 24) || (mm == 36)) {  // first month of the next year
         if(leap == 20)  ptimes[mm] = ptimes[mm-1] + 30.0;  // set length of the previous month
         else            ptimes[mm] = ptimes[mm-1] + 29.0;
      }
      pyears[mm] = (year-621-1) + (mm/12);
   }
}

// Assembly:
leal -0x26e(%rdi), %esi
movslq %esi, %rax
imulq $0x3e0f83e1, %rax, %rcx # imm = 0x3E0F83E1
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x23, %rcx
addl %edx, %ecx
movl %ecx, %edx
shll $0x5, %edx
addl %ecx, %edx
subl %edx, %eax
cmpl $0x1e, %eax
ja 0xef0fc
movl $0x44422222, %ecx       # imm = 0x44422222
btl %eax, %ecx
jae 0xef0fc
movsd 0x1cb86(%rip), %xmm2    # 0x10bb40
movsd 0x1c93e(%rip), %xmm0    # 0x10b900
pushq %rbp
movq %rsp, %rbp
pushq %rbx
movslq %edi, %rax
leaq -0x1(%rax), %rcx
imulq $0x51eb851f, %rcx, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x25, %rcx
addl %edx, %ecx
movslq %ecx, %rcx
imulq $-0x64, %rcx, %rdx
addq %rdx, %rax
decq %rax
imulq $0x23ab1, %rcx, %rcx    # imm = 0x23AB1
leaq 0x3(%rcx), %rdi
testq %rcx, %rcx
cmovnsq %rcx, %rdi
sarq $0x2, %rdi
imulq $0x8ead, %rax, %rcx     # imm = 0x8EAD
movabsq $-0x5c28f5c28f5c28f5, %rdx # imm = 0xA3D70A3D70A3D70B
movq %rcx, %rax
imulq %rdx
addq %rcx, %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x6, %rdx
addq %rax, %rdx
cvtsi2sd %rdi, %xmm3
addsd 0x3c7ae(%rip), %xmm3    # 0x12b7e8
cvtsi2sd %rdx, %xmm1
addsd %xmm3, %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, 0x28c131(%rip)   # 0x37b180
movl %esi, 0x28c25b(%rip)    # 0x37b2b0
movb $0x1, %al
xorl %r9d, %r9d
leaq 0x3d8cf(%rip), %rcx     # 0x12c930
leaq 0x28c118(%rip), %rdx    # 0x37b180
leaq 0x28c241(%rip), %rdi    # 0x37b2b0
movabsq $0x1001001000, %r8      # imm = 0x1001001000
movq %r9, %r10
movzbl %al, %r9d
imull $0xab, %r9d, %r9d
shrl $0x9, %r9d
andl $-0x4, %r9d
leal (%r9,%r9,2), %r11d
leaq 0x1(%r10), %r9
movl %r10d, %ebx
subl %r11d, %ebx
incb %bl
xorl %r11d, %r11d
cmpb $0x7, %bl
setb %r11b
addsd (%rcx,%r11,8), %xmm1
movsd %xmm1, 0x8(%rdx,%r10,8)
cmpl $0x24, %r9d
ja 0xef0d6
movl %r9d, %r11d
btq %r11, %r8
jae 0xef0d6
movsd (%rdx,%r10,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rdx,%r10,8)
movzbl %r9b, %r11d
imull $0xab, %r11d, %r11d
shrl $0xb, %r11d
movzbl %r11b, %r11d
addl %esi, %r11d
movl %r11d, 0x4(%rdi,%r10,4)
incb %al
cmpq $0x24, %r9
jne 0xef079
popq %rbx
popq %rbp
retq
movsd 0x2f7cc(%rip), %xmm2    # 0x11e8d0
movsd 0x3d4fc(%rip), %xmm0    # 0x12c608
jmp 0xeefc2