// File: /workspace/github_c_makefile_star2_O0/mmayer[P]pcal/src/pcalutil.c
// Function: calc_day
int calc_day (int ord, int wkd, int mm)
{
   int first, last, day, (*pfcn) (int, int, int);
   
   if (IS_WILD(wkd)) {   /* "day", "weekday", "workday", or "holiday" */
      pfcn = pdatefcn[wkd - WILD_FIRST];
      last = LENGTH_OF(mm, curr_year);
      
      if (ord < 0) {   /* search backwards */
         for (day = last; 
              day >= 1 && !((*pfcn)(mm, day, curr_year) && ++ord == 0);
              day--)
            ;
      }
      else {   /* search forwards */
         for (day = 1; 
              day <= last && !((*pfcn)(mm, day, curr_year) && --ord == 0);
              day++) 
            ;
      }
      return is_valid(mm, day, curr_year) ? day : 0; 
   }
   else {   /* fixed weekday - calculate it */
      first = (wkd - FIRST_OF(mm, curr_year) + 7) % 7 + 1;
      if (ord < 0) {   /* get last (try 5th, then 4th) */
         if (!is_valid(mm, last = first + 28, curr_year)) last -= 7;
         if (!is_valid(mm, day = last + 7 * (ord + 1), curr_year)) day = 0;
      }
      else {
         if (!is_valid(mm, day = first + 7 * (ord - 1), curr_year)) day = 0;
      }
      return day;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
cmpl $0x7, -0xc(%rbp)
jl 0xbf60
cmpl $0x11, -0xc(%rbp)
jg 0xbf60
movl -0xc(%rbp), %eax
subl $0x7, %eax
movslq %eax, %rcx
leaq 0x223fb(%rip), %rax     # 0x2e1c0
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movl -0x10(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x223b3(%rip), %rax     # 0x2e190
movsbl (%rax,%rcx), %eax
movl %eax, -0x30(%rbp)
xorl %eax, %eax
cmpl $0x2, -0x10(%rbp)
movb %al, -0x29(%rbp)
jne 0xbe4b
leaq 0x2786a(%rip), %rax     # 0x33660
movl (%rax), %eax
movl $0x4, %ecx
cltd
idivl %ecx
xorl %eax, %eax
cmpl $0x0, %edx
movb %al, -0x31(%rbp)
jne 0xbe45
leaq 0x2784f(%rip), %rax     # 0x33660
movl (%rax), %eax
movl $0x64, %ecx
cltd
idivl %ecx
movb $0x1, %al
cmpl $0x0, %edx
movb %al, -0x32(%rbp)
jne 0xbe3f
leaq 0x27834(%rip), %rax     # 0x33660
movl (%rax), %eax
movl $0x190, %ecx            # imm = 0x190
cltd
idivl %ecx
cmpl $0x0, %edx
sete %al
movb %al, -0x32(%rbp)
movb -0x32(%rbp), %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
movb %al, -0x29(%rbp)
movl -0x30(%rbp), %eax
movb -0x29(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl %ecx, %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x8(%rbp)
jge 0xbec6
movl -0x18(%rbp), %eax
movl %eax, -0x1c(%rbp)
xorl %eax, %eax
cmpl $0x1, -0x1c(%rbp)
movb %al, -0x33(%rbp)
jl 0xbeae
movq -0x28(%rbp), %rax
movl -0x10(%rbp), %edi
movl -0x1c(%rbp), %esi
leaq 0x277dc(%rip), %rcx     # 0x33660
movl (%rcx), %edx
callq *%rax
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x34(%rbp)
je 0xbea6
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
cmpl $0x0, %eax
sete %al
movb %al, -0x34(%rbp)
movb -0x34(%rbp), %al
xorb $-0x1, %al
movb %al, -0x33(%rbp)
movb -0x33(%rbp), %al
testb $0x1, %al
jne 0xbeb7
jmp 0xbec4
jmp 0xbeb9
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xbe68
jmp 0xbf2d
movl $0x1, -0x1c(%rbp)
movl -0x1c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x18(%rbp), %ecx
movb %al, -0x35(%rbp)
jg 0xbf15
movq -0x28(%rbp), %rax
movl -0x10(%rbp), %edi
movl -0x1c(%rbp), %esi
leaq 0x27775(%rip), %rcx     # 0x33660
movl (%rcx), %edx
callq *%rax
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x36(%rbp)
je 0xbf0d
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
cmpl $0x0, %eax
sete %al
movb %al, -0x36(%rbp)
movb -0x36(%rbp), %al
xorb $-0x1, %al
movb %al, -0x35(%rbp)
movb -0x35(%rbp), %al
testb $0x1, %al
jne 0xbf1e
jmp 0xbf2b
jmp 0xbf20
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xbecd
jmp 0xbf2d
movl -0x10(%rbp), %edi
movl -0x1c(%rbp), %esi
leaq 0x27726(%rip), %rax     # 0x33660
movl (%rax), %edx
callq 0xc040
cmpl $0x0, %eax
je 0xbf4e
movl -0x1c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0xbf55
xorl %eax, %eax
movl %eax, -0x3c(%rbp)
jmp 0xbf55
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xc028
movl -0xc(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x10(%rbp), %edi
leaq 0x276f0(%rip), %rax     # 0x33660
movl (%rax), %edx
movl $0x1, %esi
callq 0xc110
movl %eax, %ecx
movl -0x40(%rbp), %eax
subl %ecx, %eax
addl $0x7, %eax
movl $0x7, %ecx
cltd
idivl %ecx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
cmpl $0x0, -0x8(%rbp)
jge 0xbff2
movl -0x10(%rbp), %edi
movl -0x14(%rbp), %esi
addl $0x1c, %esi
movl %esi, -0x18(%rbp)
leaq 0x276b3(%rip), %rax     # 0x33660
movl (%rax), %edx
callq 0xc040
cmpl $0x0, %eax
jne 0xbfc2
movl -0x18(%rbp), %eax
subl $0x7, %eax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %edi
movl -0x18(%rbp), %esi
movl -0x8(%rbp), %eax
addl $0x1, %eax
imull $0x7, %eax, %eax
addl %eax, %esi
movl %esi, -0x1c(%rbp)
leaq 0x27683(%rip), %rax     # 0x33660
movl (%rax), %edx
callq 0xc040
cmpl $0x0, %eax
jne 0xbff0
movl $0x0, -0x1c(%rbp)
jmp 0xc022
movl -0x10(%rbp), %edi
movl -0x14(%rbp), %esi
movl -0x8(%rbp), %eax
subl $0x1, %eax
imull $0x7, %eax, %eax
addl %eax, %esi
movl %esi, -0x1c(%rbp)
leaq 0x27653(%rip), %rax     # 0x33660
movl (%rax), %edx
callq 0xc040
cmpl $0x0, %eax
jne 0xc020
movl $0x0, -0x1c(%rbp)
jmp 0xc022
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)