// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x4(%rbp)
movl -0x4(%rbp), %eax
subl $0x26d, %eax            # imm = 0x26D
subl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl $0x21, %ecx
cltd
idivl %ecx
movl %edx, -0x14(%rbp)
cmpl $0x1, -0x14(%rbp)
jne 0x147d96
movl $0x14, -0x14(%rbp)
jmp 0x147e14
cmpl $0x5, -0x14(%rbp)
jne 0x147da5
movl $0x14, -0x14(%rbp)
jmp 0x147e12
cmpl $0x9, -0x14(%rbp)
jne 0x147db4
movl $0x14, -0x14(%rbp)
jmp 0x147e10
cmpl $0xd, -0x14(%rbp)
jne 0x147dc3
movl $0x14, -0x14(%rbp)
jmp 0x147e0e
cmpl $0x11, -0x14(%rbp)
jne 0x147dd2
movl $0x14, -0x14(%rbp)
jmp 0x147e0c
cmpl $0x16, -0x14(%rbp)
jne 0x147de1
movl $0x14, -0x14(%rbp)
jmp 0x147e0a
cmpl $0x1a, -0x14(%rbp)
jne 0x147df0
movl $0x14, -0x14(%rbp)
jmp 0x147e08
cmpl $0x1e, -0x14(%rbp)
jne 0x147dff
movl $0x14, -0x14(%rbp)
jmp 0x147e06
movl $0x15, -0x14(%rbp)
jmp 0x147e08
jmp 0x147e0a
jmp 0x147e0c
jmp 0x147e0e
jmp 0x147e10
jmp 0x147e12
jmp 0x147e14
movl -0x4(%rbp), %edi
subl $0x1, %edi
movl -0x14(%rbp), %edx
movl $0x3, %esi
callq 0x122140
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, 0x2925a7(%rip)   # 0x3da3e0
movl -0x4(%rbp), %eax
subl $0x26d, %eax            # imm = 0x26D
subl $0x1, %eax
movl %eax, 0x2926c6(%rip)    # 0x3da510
movl $0x1, -0x18(%rbp)
cmpl $0x24, -0x18(%rbp)
jg 0x147f89
movl -0x18(%rbp), %eax
movl $0xc, %ecx
cltd
idivl %ecx
cmpl $0x6, %edx
jg 0x147e9a
movl -0x18(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
movsd 0x4694c(%rip), %xmm0    # 0x18e7c8
leaq 0x29255d(%rip), %rax    # 0x3da3e0
addsd (%rax,%rcx,8), %xmm0
movslq -0x18(%rbp), %rcx
leaq 0x29254d(%rip), %rax    # 0x3da3e0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x147ed9
movl -0x18(%rbp), %eax
movl $0xc, %ecx
cltd
idivl %ecx
cmpl $0xb, %edx
jg 0x147ed7
movl -0x18(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
movsd 0x297c5(%rip), %xmm0    # 0x171680
leaq 0x29251e(%rip), %rax    # 0x3da3e0
addsd (%rax,%rcx,8), %xmm0
movslq -0x18(%rbp), %rcx
leaq 0x29250e(%rip), %rax    # 0x3da3e0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x147ed9
cmpl $0xc, -0x18(%rbp)
je 0x147eeb
cmpl $0x18, -0x18(%rbp)
je 0x147eeb
cmpl $0x24, -0x18(%rbp)
jne 0x147f4f
cmpl $0x14, -0x14(%rbp)
jne 0x147f20
movl -0x18(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
movsd 0x2977e(%rip), %xmm0    # 0x171680
leaq 0x2924d7(%rip), %rax    # 0x3da3e0
addsd (%rax,%rcx,8), %xmm0
movslq -0x18(%rbp), %rcx
leaq 0x2924c7(%rip), %rax    # 0x3da3e0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x147f4d
movl -0x18(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
movsd 0x467e7(%rip), %xmm0    # 0x18e718
leaq 0x2924a8(%rip), %rax    # 0x3da3e0
addsd (%rax,%rcx,8), %xmm0
movslq -0x18(%rbp), %rcx
leaq 0x292498(%rip), %rax    # 0x3da3e0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x147f4f
movl -0x4(%rbp), %eax
subl $0x26d, %eax            # imm = 0x26D
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
movl $0xc, %ecx
cltd
idivl %ecx
movl -0x1c(%rbp), %edx
addl %eax, %edx
movslq -0x18(%rbp), %rcx
leaq 0x292598(%rip), %rax    # 0x3da510
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x147e51
addq $0x20, %rsp
popq %rbp
retq
nop