// File: /workspace/github_c_makefile_star2_O2/mmayer[P]pcal/src/pcal.c
// Function: main
int main (int argc GCC_UNUSED, char **argv)
{
   FILE *dfp = NULL;   /* date file pointer */
   char *p, *pathlist[10];
   char tmp[STRSIZ];
   int n;
   
   /* get version from VERSION_STRING (for PostScript comments and version
    * symbol predefined in init_misc())
    */
   strcpy(tmp, VERSION_STRING + 4);
   p = strchr(tmp, ' ') + 1;   /* skip program name */
   *strchr(p, ' ') = '\0';   /* terminate after version */
   strcpy(version, p);
   
   init_misc();   /* handle initialization warts */
   
   /* extract root program name and program path - note that some systems
    * supply the full pathname and others just the root
    */

   strcpy(progname, **argv ? *argv : "pcal");
   
   if ((p = strrchr(progname, END_PATH)) != NULL) strcpy(progname, ++p);

#ifndef BUILD_ENV_UNIX
   if ((p = strchr(progname, '.')) != NULL) *p = '\0';   /* strip suffix if non-Un*x */
#endif

   mk_path(progpath, find_executable(*argv));

   /*
    * Get the arguments from a) the command line (pre-pass to pick up debug
    * and usage flags), b) the environment variable PCAL_OPTS, c) the first
    * command line pass, d) "opt" lines in the date file, and e) a final
    * command line pass, in that order
    */

   /* Make a preliminary pass to look for the debug flags (to ensure that -ZO
    * will print any flags set in PCAL_OPTS) and the usage flags (-h, -u, and
    * -v).  If none of the latter is specified, this pass will also validate
    * any numeric command-line arguments.
    */
   if (!get_args(argv, P_CMD0, NULL, TRUE)) {
      display_usage(stderr, FALSE);   /* invalid flag or param */
      exit(EXIT_FAILURE);
   }

   /* parse environment variable PCAL_OPTS as a command line */
   
   if ((p = getenv(PCAL_OPTS)) != NULL) {
      strcpy(lbuf, "pcal ");   /* dummy program name */
      strcat(lbuf, p);
      (void) loadwords(words, lbuf);   /* split string into words */
      if (! get_args(words, P_ENV, PCAL_OPTS, FALSE)) {
         display_usage(stderr, FALSE);
         exit(EXIT_FAILURE);
      }
   }
   
   /* parse command-line arguments once to find name of date file, etc. */
   
   (void) get_args(argv, P_CMD1, NULL, FALSE);
   
   /* if in whole-year mode, round number of months up to full year and set
    * default starting month to January of current year
    */
   if (do_whole_year) {
      nmonths = ((nmonths + 11) / 12) * 12;
      if (nargs == 0) init_month = JAN;
   }

   /* recalculate final month and year (latter needed for "year all") */
   final_month = (init_month + (nmonths - 1) - 1) % 12 + 1;
   final_year = init_year + ((nmonths - 1 + init_month - 1) / 12);
   
   /* Attempt to open the date file as specified by the [-e | -f] flags */

   switch (datefile_type) {
   case NO_DATEFILE:
      dfp = NULL;
      break;
      
   case USER_DATEFILE:
      /* Attempt to open user-specified calendar file: search first in the
       * current directory, then in PCAL_DIR (if defined), and finally in the
       * directory where the Pcal executable lives (if SEARCH_PCAL_DIR != 0).
       * It is a fatal error if the user-specified date file cannot be found.
       */
      n = 0;
      pathlist[n++] = "";
      if ((p = getenv(PCAL_DIR)) != NULL) pathlist[n++] = p;

#if (SEARCH_PCAL_DIR != 0)
      pathlist[n++] = progpath;
#endif

      pathlist[n] = NULL;
      
      strcpy(tmp, datefile);   /* save original name for error msg */
      
      if ((dfp = alt_fopen(datefile, tmp, pathlist, "r")) == NULL) {
         fprintf(stderr, E_FOPEN_ERR, progname, tmp);
         exit(EXIT_FAILURE);
      }
      break;

   case SYS_DATEFILE:
      /* Attempt to open system-specified calendar file: search first in
       * PCAL_DIR, then in HOME_DIR (current directory if neither is defined)
       * and finally in the directory where the Pcal executable lives (if
       * SEARCH_PCAL_DIR != 0).  It is not an error if the system-specified
       * date file cannot be opened; Pcal will simply generate an empty
       * calendar.
       */
      n = 0;
      if ((p = getenv(PCAL_DIR)) != NULL) pathlist[n++] = p;
      if ((p = getenv(HOME_DIR)) != NULL) pathlist[n++] = p;
      if (n == 0) pathlist[n++] = "";

#if (SEARCH_PCAL_DIR != 0)
      pathlist[n++] = progpath;
#endif

      pathlist[n] = NULL;
      
      dfp = alt_fopen(datefile, DATEFILE, pathlist, "r");
      
      /* if the date file has not been found and ALT_DATEFILE is defined,
       * search same paths for ALT_DATEFILE before giving up
       */
#ifdef ALT_DATEFILE
      if (!dfp) dfp = alt_fopen(datefile, ALT_DATEFILE, pathlist, "r");
#endif

      break;
   }

   /* read the date file (if any) and build internal data structure */
   
   if (dfp) {
      curr_year = init_year;
      read_datefile(dfp, datefile);
      fclose(dfp);
   } else datefile[0] = '\0';   /* for PostScript comment */

   /* reparse command line - flags there supersede those in date file */
   
   (void) get_args(argv, P_CMD2, NULL, FALSE);
   
   /* if the user has not explicitly selected a mapping, choose one based on
    * the chosen language
    */
   if (map_default == TRUE) mapfonts = lang_mapping[output_language];

   /* fprintf(stderr, "Font mapping is %d\n", mapfonts); */
   
   /* select an appropriate color for holidays if not set explicitly */
   if (holiday_color == HOLIDAY_DEFAULT) holiday_color = select_color();

   /* done with the arguments and flags - try to open the output file */
   
   /* use default output files (cf. pcaldefs.h) if -o flag not used */
   if (!oflag && output_type == OUTPUT_PS) strcpy(outfile, PS_OUTFILE);
   if (!oflag && output_type == OUTPUT_HTML) strcpy(outfile, HTML_OUTFILE);
   
   /* reopen stdout as alternate file if one was specified */
   if (*outfile && freopen(outfile, "w", stdout) == (FILE *) NULL) {
      fprintf(stderr, E_FOPEN_ERR, progname, outfile);
      exit(EXIT_FAILURE);
   }
   
   /* Set up the initial page-related values based on the default paper
    * size.
    */
   recalc_paper_parameters(paper_size);
   
   /* generate the "calendar", HTML, or PostScript code (cf. writefil.c) */
   
   if (output_type == OUTPUT_CAL) write_calfile();
   else if (output_type == OUTPUT_HTML) write_htmlfile();
   else write_psfile(generate_diagonals);
   
   cleanup();   /* free allocated data */
   
   exit(EXIT_SUCCESS);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %rbx
leaq 0x22d46(%rip), %rsi     # 0x29a94
leaq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x50a0
pushq $0x20
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
callq 0x5120
leaq 0x1(%rax), %r14
movq %r14, %rdi
movl %ebp, %esi
callq 0x5120
movb $0x0, (%rax)
leaq 0x25a80(%rip), %rdi     # 0x2c800
movq %r14, %rsi
callq 0x50a0
callq 0x543c
movq (%rbx), %rax
cmpb $0x0, (%rax)
leaq 0xe332(%rip), %rsi      # 0x150cc
cmovneq %rax, %rsi
leaq 0x25a7b(%rip), %r14     # 0x2c820
movq %r14, %rdi
callq 0x50a0
pushq $0x2f
popq %rsi
movq %r14, %rdi
callq 0x5150
testq %rax, %rax
je 0x6dcf
incq %rax
leaq 0x25a59(%rip), %rdi     # 0x2c820
movq %rax, %rsi
callq 0x50a0
movq (%rbx), %rdi
callq 0xa9b8
leaq 0x26722(%rip), %rdi     # 0x2d500
movq %rax, %rsi
callq 0xa8a7
pushq $0x2
popq %rsi
pushq $0x1
popq %rbp
movq %rbx, %rdi
xorl %edx, %edx
movl %ebp, %ecx
callq 0x5d9e
testl %eax, %eax
jne 0x6e15
movq 0x211f5(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
xorl %esi, %esi
callq 0x574c
pushq $0x1
popq %rdi
callq 0x52f0
leaq 0xe2b5(%rip), %rdi      # 0x150d1
callq 0x5040
testq %rax, %rax
je 0x6e75
movw $0x20, 0x25af5(%rip)    # 0x2c924
movl $0x6c616370, 0x25ae7(%rip) # imm = 0x6C616370
leaq 0x25ae0(%rip), %r14     # 0x2c920
movq %r14, %rdi
movq %rax, %rsi
callq 0x52d0
leaq 0x25cce(%rip), %r15     # 0x2cb20
movq %r15, %rdi
movq %r14, %rsi
callq 0xa10d
leaq 0xe26d(%rip), %rdx      # 0x150d1
pushq $0x4
popq %rsi
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x5d9e
testl %eax, %eax
je 0x6dfc
pushq $0x8
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x5d9e
cmpl $0x0, 0x25829(%rip)     # 0x2c6b4
movl 0x265fb(%rip), %ecx     # 0x2d48c
pushq $0xc
popq %rsi
je 0x6eb9
addl $0xb, %ecx
movl %ecx, %eax
cltd
idivl %esi
subl %edx, %ecx
movl %ecx, 0x265e6(%rip)     # 0x2d48c
cmpl $0x0, 0x25a63(%rip)     # 0x2c910
jne 0x6eb9
movl $0x1, 0x265cb(%rip)     # 0x2d484
movl 0x265c5(%rip), %eax     # 0x2d484
addl %ecx, %eax
addl $-0x2, %eax
cltd
idivl %esi
incl %edx
addl 0x265b9(%rip), %eax     # 0x2d488
movl %edx, 0x266f3(%rip)     # 0x2d5c8
movl %eax, 0x266f1(%rip)     # 0x2d5cc
movl 0x2135f(%rip), %eax     # 0x28240
cmpl $0x2, %eax
je 0x6f12
cmpl $0x1, %eax
jne 0x700a
leaq 0x17867(%rip), %rax     # 0x1e75d
movq %rax, (%rsp)
leaq 0xe1e0(%rip), %rdi      # 0x150e1
callq 0x5040
testq %rax, %rax
jne 0x6f57
leaq 0x8(%rsp), %rcx
jmp 0x6f60
leaq 0xe1c8(%rip), %rdi      # 0x150e1
callq 0x5040
movq %rax, %r14
xorl %r15d, %r15d
testq %rax, %rax
je 0x6f30
movq %r14, (%rsp)
movl %ebp, %r15d
leaq 0xe1cb(%rip), %rdi      # 0x15102
callq 0x5040
testq %rax, %rax
jne 0x6fb7
pushq $0x1
popq %r15
testq %r14, %r14
jne 0x6fc1
leaq 0x1780c(%rip), %rax     # 0x1e75d
movq %rax, (%rsp)
jmp 0x6fc1
leaq 0x10(%rsp), %rcx
movq %rax, -0x8(%rcx)
andq $0x0, (%rcx)
leaq 0x25335(%rip), %r14     # 0x2c2a0
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x50a0
leaq 0x165b6(%rip), %rcx     # 0x1d538
movq %rsp, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x6c5c
testq %rax, %rax
jne 0x7013
movq 0x2105c(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0xe144(%rip), %rsi      # 0x150ea
leaq 0x25873(%rip), %rdx     # 0x2c820
leaq 0x50(%rsp), %rcx
jmp 0x70e6
movl %r15d, %ecx
incl %r15d
movq %rax, (%rsp,%rcx,8)
andq $0x0, (%rsp,%r15,8)
leaq 0x252d3(%rip), %rdi     # 0x2c2a0
leaq 0xd6f6(%rip), %rsi      # 0x146ca
leaq 0x1655d(%rip), %rcx     # 0x1d538
movq %rsp, %rdx
callq 0x6c5c
testq %rax, %rax
jne 0x7013
leaq 0x252b1(%rip), %rdi     # 0x2c2a0
leaq 0x1c148(%rip), %rsi     # 0x2313e
leaq 0x1653b(%rip), %rcx     # 0x1d538
movq %rsp, %rdx
callq 0x6c5c
testq %rax, %rax
jne 0x7013
movb $0x0, 0x2528f(%rip)     # 0x2c2a0
jmp 0x7039
movq %rax, %r14
movl 0x2646c(%rip), %eax     # 0x2d488
movl %eax, 0x265ae(%rip)     # 0x2d5d0
leaq 0x25277(%rip), %rsi     # 0x2c2a0
movq %r14, %rdi
callq 0xaaf8
movq %r14, %rdi
callq 0x50e0
pushq $0x20
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x5d9e
cmpl $0x1, 0x22a31(%rip)     # 0x29a80
jne 0x706b
leaq 0x267ac(%rip), %rax     # 0x2d804
movslq (%rax), %rax
leaq 0x250ee(%rip), %rcx     # 0x2c150
movl (%rcx,%rax,4), %eax
movl %eax, 0x25301(%rip)     # 0x2c36c
cmpl $-0x1, 0x256b2(%rip)    # 0x2c724
jne 0x707f
callq 0x12778
movl %eax, 0x256a5(%rip)     # 0x2c724
cmpb $0x0, 0x263fa(%rip)     # 0x2d480
jne 0x709c
movl 0x2562a(%rip), %eax     # 0x2c6b8
andl $-0x3, %eax
jne 0x709c
movb $0x0, 0x25546(%rip)     # 0x2c5e0
jmp 0x70f2
cmpb $0x0, 0x2553d(%rip)     # 0x2c5e0
je 0x70f2
movq 0x20f14(%rip), %rax     # 0x27fc0
movq (%rax), %rdx
leaq 0x2552a(%rip), %rdi     # 0x2c5e0
leaq 0x1b9ff(%rip), %rsi     # 0x22abc
callq 0x5170
testq %rax, %rax
jne 0x70f2
movq 0x20f2a(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0xe012(%rip), %rsi      # 0x150ea
leaq 0x25741(%rip), %rdx     # 0x2c820
leaq 0x254fa(%rip), %rcx     # 0x2c5e0
xorl %eax, %eax
callq 0x5200
jmp 0x6e0d
movl 0x25620(%rip), %edi     # 0x2c718
callq 0x5cc0
movl 0x255b5(%rip), %eax     # 0x2c6b8
cmpl $0x2, %eax
je 0x7114
cmpl $0x1, %eax
jne 0x711b
callq 0x113d4
jmp 0x7126
callq 0x12382
jmp 0x7126
movl 0x255a7(%rip), %edi     # 0x2c6c8
callq 0xd5ca
callq 0xb711
xorl %edi, %edi
callq 0x52f0
nop