// File: /workspace/github_c_makefile_star2_O0/mmayer[P]pcal/src/pcalutil.c
// Function: calc_year_day
int calc_year_day (int ord, int wkd, date_str *pdate)
{
   int incr, (*pfcn) (int, int, int);
   date_str date;
   
   if (IS_WILD(wkd)) {   /* "day", "weekday", "workday", or "holiday" */
      pfcn = pdatefcn[wkd - WILD_FIRST];
      
      if (ord < 0) {   /* nth occurrence backwards */
         MAKE_DATE(date, DEC, 31, curr_year);
         ord = -ord;
         incr = -1;
      }
      else {   /* nth occurrence forwards */
         MAKE_DATE(date, JAN, 1, curr_year);
         incr = 1;
      }
      
      /* search for selected occurrence of specified wildcard */
      
      while (date.yy == curr_year && !((*pfcn)(date.mm, date.dd, date.yy) && --ord == 0)) {
         date.dd += incr;
         normalize(&date);
      }
   }
   else {   /* fixed weekday - calculate it */
      if (ord < 0) {
         MAKE_DATE(date, DEC, calc_day(-1, wkd, DEC) + 7 * (ord + 1), curr_year);
      }
      else {
         MAKE_DATE(date, JAN, calc_day(1, wkd, JAN) + 7 * (ord - 1), curr_year);
      }

      normalize(&date);
   }
   
   return date.yy == curr_year ? (*pdate = date, TRUE) : FALSE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
cmpl $0x7, -0x8(%rbp)
jl 0xc30d
cmpl $0x11, -0x8(%rbp)
jg 0xc30d
movl -0x8(%rbp), %eax
subl $0x7, %eax
movslq %eax, %rcx
leaq 0x21f7a(%rip), %rax     # 0x2e1c0
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
cmpl $0x0, -0x4(%rbp)
jge 0xc281
jmp 0xc256
movl $0xc, -0x2c(%rbp)
movl $0x1f, -0x28(%rbp)
leaq 0x273f5(%rip), %rax     # 0x33660
movl (%rax), %eax
movl %eax, -0x24(%rbp)
xorl %eax, %eax
subl -0x4(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0xc2a4
jmp 0xc283
movl $0x1, -0x2c(%rbp)
movl $0x1, -0x28(%rbp)
leaq 0x273c8(%rip), %rax     # 0x33660
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movl $0x1, -0x14(%rbp)
jmp 0xc2a6
movl -0x24(%rbp), %ecx
xorl %eax, %eax
leaq 0x273ae(%rip), %rdx     # 0x33660
cmpl (%rdx), %ecx
movb %al, -0x2d(%rbp)
jne 0xc2ee
movq -0x20(%rbp), %rax
movl -0x2c(%rbp), %edi
movl -0x28(%rbp), %esi
movl -0x24(%rbp), %edx
callq *%rax
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x2e(%rbp)
je 0xc2e6
movl -0x4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4(%rbp)
cmpl $0x0, %eax
sete %al
movb %al, -0x2e(%rbp)
movb -0x2e(%rbp), %al
xorb $-0x1, %al
movb %al, -0x2d(%rbp)
movb -0x2d(%rbp), %al
testb $0x1, %al
jne 0xc2f7
jmp 0xc30b
movl -0x14(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
leaq -0x2c(%rbp), %rdi
callq 0xbb80
jmp 0xc2a6
jmp 0xc387
cmpl $0x0, -0x4(%rbp)
jge 0xc34a
jmp 0xc315
movl $0xc, -0x2c(%rbp)
movl -0x8(%rbp), %esi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0xc, %edx
callq 0xbd90
movl -0x4(%rbp), %ecx
addl $0x1, %ecx
imull $0x7, %ecx, %ecx
addl %ecx, %eax
movl %eax, -0x28(%rbp)
leaq 0x2731d(%rip), %rax     # 0x33660
movl (%rax), %eax
movl %eax, -0x24(%rbp)
jmp 0xc37e
jmp 0xc34c
movl $0x1, -0x2c(%rbp)
movl -0x8(%rbp), %esi
movl $0x1, %edx
movl %edx, %edi
callq 0xbd90
movl -0x4(%rbp), %ecx
subl $0x1, %ecx
imull $0x7, %ecx, %ecx
addl %ecx, %eax
movl %eax, -0x28(%rbp)
leaq 0x272e9(%rip), %rax     # 0x33660
movl (%rax), %eax
movl %eax, -0x24(%rbp)
jmp 0xc37e
leaq -0x2c(%rbp), %rdi
callq 0xbb80
movl -0x24(%rbp), %eax
leaq 0x272cf(%rip), %rcx     # 0x33660
cmpl (%rcx), %eax
jne 0xc3b0
movq -0x10(%rbp), %rax
movq -0x2c(%rbp), %rcx
movq %rcx, (%rax)
movl -0x24(%rbp), %ecx
movl %ecx, 0x8(%rax)
movl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xc3b7
xorl %eax, %eax
movl %eax, -0x34(%rbp)
jmp 0xc3b7
movl -0x34(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq