// File: /workspace/github_c_makefile_star2_O3/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 %r15
pushq %r14
pushq %rbx
subq $0x120, %rsp            # imm = 0x120
movq %rsi, %rbx
leaq 0x231ae(%rip), %rsi     # 0x2aaa4
leaq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x50a0
movq %r14, %rdi
movl $0x20, %esi
callq 0x5120
leaq 0x1(%rax), %r14
movq %r14, %rdi
movl $0x20, %esi
callq 0x5120
movb $0x0, (%rax)
leaq 0x25ee5(%rip), %rdi     # 0x2d810
movq %r14, %rsi
callq 0x50a0
callq 0x580c
movq (%rbx), %rax
cmpb $0x0, (%rax)
leaq 0xf7df(%rip), %rsi      # 0x17124
cmovneq %rax, %rsi
leaq 0x25ee0(%rip), %r14     # 0x2d830
movq %r14, %rdi
callq 0x50a0
movq %r14, %rdi
movl $0x2f, %esi
callq 0x5150
testq %rax, %rax
je 0x797c
incq %rax
leaq 0x25ebc(%rip), %rdi     # 0x2d830
movq %rax, %rsi
callq 0x50a0
movq (%rbx), %rdi
callq 0xb85e
leaq 0x26b85(%rip), %rdi     # 0x2e510
movq %rax, %rsi
callq 0xb74b
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x67d0
testl %eax, %eax
jne 0x79c6
movq 0x2163e(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
xorl %esi, %esi
callq 0x6156
movl $0x1, %edi
callq 0x5300
leaq 0xf75c(%rip), %rdi      # 0x17129
callq 0x5040
testq %rax, %rax
je 0x7a28
movw $0x20, 0x25f54(%rip)    # 0x2d934
movl $0x6c616370, 0x25f46(%rip) # imm = 0x6C616370
leaq 0x25f3f(%rip), %r14     # 0x2d930
movq %r14, %rdi
movq %rax, %rsi
callq 0x52e0
leaq 0x2612d(%rip), %r15     # 0x2db30
movq %r15, %rdi
movq %r14, %rsi
callq 0xaf3b
leaq 0xf714(%rip), %rdx      # 0x17129
movq %r15, %rdi
movl $0x4, %esi
xorl %ecx, %ecx
callq 0x67d0
testl %eax, %eax
je 0x79ab
movq %rbx, %rdi
movl $0x8, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x67d0
cmpl $0x0, 0x25c84(%rip)     # 0x2d6c4
movl 0x26a56(%rip), %eax     # 0x2e49c
je 0x7a80
addl $0xb, %eax
cltq
imulq $0x2aaaaaab, %rax, %rax # imm = 0x2AAAAAAB
movq %rax, %rcx
shrq $0x3f, %rcx
shrq $0x21, %rax
addl %ecx, %eax
shll $0x2, %eax
leal (%rax,%rax,2), %eax
movl %eax, 0x26a2f(%rip)     # 0x2e49c
cmpl $0x0, 0x25eac(%rip)     # 0x2d920
jne 0x7a80
movl $0x1, 0x26a14(%rip)     # 0x2e494
movl 0x26a0e(%rip), %ecx     # 0x2e494
addl %ecx, %eax
addl $-0x2, %eax
cltq
imulq $0x2aaaaaab, %rax, %rcx # imm = 0x2AAAAAAB
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (,%rcx,4), %edx
leal (%rdx,%rdx,2), %edx
subl %edx, %eax
incl %eax
addl 0x269e3(%rip), %ecx     # 0x2e498
movl %eax, 0x26b1d(%rip)     # 0x2e5d8
movl %ecx, 0x26b1b(%rip)     # 0x2e5dc
movl 0x21789(%rip), %eax     # 0x29250
cmpl $0x2, %eax
je 0x7af8
cmpl $0x1, %eax
jne 0x7c15
leaq 0x18cd1(%rip), %rax     # 0x207ad
movq %rax, (%rsp)
leaq 0xf652(%rip), %rdi      # 0x17139
callq 0x5040
testq %rax, %rax
jne 0x7b37
leaq 0x8(%rsp), %rcx
jmp 0x7b40
leaq 0xf63a(%rip), %rdi      # 0x17139
callq 0x5040
testq %rax, %rax
jne 0x7b9e
leaq 0xf646(%rip), %rdi      # 0x1715a
callq 0x5040
testq %rax, %rax
jne 0x7bbf
leaq 0x18c84(%rip), %rax     # 0x207ad
movq %rax, (%rsp)
movl $0x1, %ecx
jmp 0x7bc9
leaq 0x10(%rsp), %rcx
movq %rax, -0x8(%rcx)
movq $0x0, (%rcx)
leaq 0x25762(%rip), %r14     # 0x2d2b0
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x50a0
leaq 0x17a23(%rip), %rcx     # 0x1f588
movq %rsp, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x7840
testq %rax, %rax
jne 0x7c1e
movq 0x2146d(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
leaq 0xf5b5(%rip), %rsi      # 0x17142
leaq 0x25c9c(%rip), %rdx     # 0x2d830
leaq 0x50(%rsp), %rcx
jmp 0x7cf3
movq %rax, (%rsp)
leaq 0xf5b1(%rip), %rdi      # 0x1715a
callq 0x5040
movl $0x1, %ecx
testq %rax, %rax
je 0x7bc9
movl $0x1, %ecx
jmp 0x7bc1
xorl %ecx, %ecx
movl %ecx, %edx
incl %ecx
movq %rax, (%rsp,%rdx,8)
movq $0x0, (%rsp,%rcx,8)
leaq 0x256d8(%rip), %rdi     # 0x2d2b0
leaq 0xeb43(%rip), %rsi      # 0x16722
leaq 0x179a2(%rip), %rcx     # 0x1f588
movq %rsp, %rdx
callq 0x7840
testq %rax, %rax
jne 0x7c1e
leaq 0x256b6(%rip), %rdi     # 0x2d2b0
leaq 0x1d58d(%rip), %rsi     # 0x2518e
leaq 0x17980(%rip), %rcx     # 0x1f588
movq %rsp, %rdx
callq 0x7840
testq %rax, %rax
jne 0x7c1e
movb $0x0, 0x25694(%rip)     # 0x2d2b0
jmp 0x7c44
movq %rax, %r14
movl 0x26871(%rip), %eax     # 0x2e498
movl %eax, 0x269b3(%rip)     # 0x2e5e0
leaq 0x2567c(%rip), %rsi     # 0x2d2b0
movq %r14, %rdi
callq 0xb9a4
movq %r14, %rdi
callq 0x50e0
movq %rbx, %rdi
movl $0x20, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x67d0
cmpl $0x1, 0x22e34(%rip)     # 0x2aa90
jne 0x7c78
leaq 0x26baf(%rip), %rax     # 0x2e814
movslq (%rax), %rax
leaq 0x254f1(%rip), %rcx     # 0x2d160
movl (%rcx,%rax,4), %eax
movl %eax, 0x25704(%rip)     # 0x2d37c
cmpl $-0x1, 0x25ab5(%rip)    # 0x2d734
jne 0x7c8c
callq 0x13d75
movl %eax, 0x25aa8(%rip)     # 0x2d734
cmpb $0x0, 0x267fd(%rip)     # 0x2e490
jne 0x7ca9
movl 0x25a2d(%rip), %eax     # 0x2d6c8
andl $-0x3, %eax
jne 0x7ca9
movb $0x0, 0x25949(%rip)     # 0x2d5f0
jmp 0x7cff
cmpb $0x0, 0x25940(%rip)     # 0x2d5f0
je 0x7cff
movq 0x21307(%rip), %rax     # 0x28fc0
movq (%rax), %rdx
leaq 0x2592d(%rip), %rdi     # 0x2d5f0
leaq 0x1ce42(%rip), %rsi     # 0x24b0c
callq 0x5180
testq %rax, %rax
jne 0x7cff
movq 0x21315(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
leaq 0xf45d(%rip), %rsi      # 0x17142
leaq 0x25b44(%rip), %rdx     # 0x2d830
leaq 0x258fd(%rip), %rcx     # 0x2d5f0
xorl %eax, %eax
callq 0x5210
jmp 0x79bc
movl 0x25a23(%rip), %edi     # 0x2d728
callq 0x66d0
movl 0x259b8(%rip), %eax     # 0x2d6c8
cmpl $0x2, %eax
je 0x7d21
cmpl $0x1, %eax
jne 0x7d28
callq 0x1264d
jmp 0x7d33
callq 0x13942
jmp 0x7d33
movl 0x259aa(%rip), %edi     # 0x2d6d8
callq 0xe69a
callq 0xc5ec
xorl %edi, %edi
callq 0x5300
nop