// File: /workspace/github_c_makefile_star2_O1/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 0x2274a(%rip), %rsi     # 0x29aa4
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 0x25481(%rip), %rdi     # 0x2c810
movq %r14, %rsi
callq 0x50a0
callq 0x586c
movq (%rbx), %rax
cmpb $0x0, (%rax)
leaq 0xed23(%rip), %rsi      # 0x160cc
cmovneq %rax, %rsi
leaq 0x2547c(%rip), %r14     # 0x2c830
movq %r14, %rdi
callq 0x50a0
movq %r14, %rdi
movl $0x2f, %esi
callq 0x5150
testq %rax, %rax
je 0x73e0
incq %rax
leaq 0x25458(%rip), %rdi     # 0x2c830
movq %rax, %rsi
callq 0x50a0
movq (%rbx), %rdi
callq 0xb330
leaq 0x26121(%rip), %rdi     # 0x2d510
movq %rax, %rsi
callq 0xb1df
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x625f
testl %eax, %eax
jne 0x742a
movq 0x20bda(%rip), %rax     # 0x27ff0
movq (%rax), %rdi
xorl %esi, %esi
callq 0x5be5
movl $0x1, %edi
callq 0x5300
leaq 0xeca0(%rip), %rdi      # 0x160d1
callq 0x5040
testq %rax, %rax
je 0x748c
movw $0x20, 0x254f0(%rip)    # 0x2c934
movl $0x6c616370, 0x254e2(%rip) # imm = 0x6C616370
leaq 0x254db(%rip), %r14     # 0x2c930
movq %r14, %rdi
movq %rax, %rsi
callq 0x52e0
leaq 0x256c9(%rip), %r15     # 0x2cb30
movq %r15, %rdi
movq %r14, %rsi
callq 0xa985
leaq 0xec58(%rip), %rdx      # 0x160d1
movq %r15, %rdi
movl $0x4, %esi
xorl %ecx, %ecx
callq 0x625f
testl %eax, %eax
je 0x740f
movq %rbx, %rdi
movl $0x8, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x625f
cmpl $0x0, 0x25220(%rip)     # 0x2c6c4
je 0x74e4
movl 0x25ff0(%rip), %eax     # 0x2d49c
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, 0x25fcb(%rip)     # 0x2d49c
cmpl $0x0, 0x25448(%rip)     # 0x2c920
jne 0x74e4
movl $0x1, 0x25fb0(%rip)     # 0x2d494
movl 0x25faa(%rip), %eax     # 0x2d494
movl 0x25fac(%rip), %ecx     # 0x2d49c
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
movl %eax, 0x260b9(%rip)     # 0x2d5d8
addl 0x25f73(%rip), %ecx     # 0x2d498
movl %ecx, 0x260b1(%rip)     # 0x2d5dc
xorl %r14d, %r14d
movl 0x20d1c(%rip), %eax     # 0x28250
cmpl $0x2, %eax
je 0x756c
cmpl $0x1, %eax
jne 0x766e
leaq 0x181f4(%rip), %rax     # 0x1f73d
movq %rax, (%rsp)
leaq 0xeb8d(%rip), %rdi      # 0x160e1
callq 0x5040
testq %rax, %rax
jne 0x7608
leaq 0x8(%rsp), %rcx
jmp 0x7611
leaq 0xeb6e(%rip), %rdi      # 0x160e1
callq 0x5040
testq %rax, %rax
je 0x7587
movq %rax, (%rsp)
movl $0x1, %r14d
leaq 0xeb74(%rip), %rdi      # 0x16102
callq 0x5040
testq %rax, %rax
je 0x75a2
movl %r14d, %ecx
incl %r14d
movq %rax, (%rsp,%rcx,8)
testl %r14d, %r14d
jne 0x75b8
leaq 0x1818f(%rip), %rax     # 0x1f73d
movq %rax, (%rsp)
movl $0x1, %r14d
movl %r14d, %eax
movq $0x0, (%rsp,%rax,8)
leaq 0x24ce6(%rip), %rdi     # 0x2c2b0
leaq 0xe0f9(%rip), %rsi      # 0x156ca
leaq 0x16f39(%rip), %rcx     # 0x1e511
movq %rsp, %rdx
callq 0x72a8
testq %rax, %rax
jne 0x766b
leaq 0x24cc0(%rip), %rdi     # 0x2c2b0
leaq 0x1cb27(%rip), %rsi     # 0x2411e
leaq 0x16f13(%rip), %rcx     # 0x1e511
movq %rsp, %rdx
callq 0x72a8
jmp 0x766b
leaq 0x10(%rsp), %rcx
movq %rax, -0x8(%rcx)
movq $0x0, (%rcx)
leaq 0x24c91(%rip), %r14     # 0x2c2b0
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x50a0
leaq 0x16edb(%rip), %rcx     # 0x1e511
movq %rsp, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x72a8
testq %rax, %rax
jne 0x766b
movq 0x209a0(%rip), %rax     # 0x27ff0
movq (%rax), %rdi
leaq 0xea90(%rip), %rsi      # 0x160ea
leaq 0x251cf(%rip), %rdx     # 0x2c830
leaq 0x50(%rsp), %rcx
jmp 0x7759
movq %rax, %r14
testq %r14, %r14
jne 0x767c
movb $0x0, 0x24c36(%rip)     # 0x2c2b0
jmp 0x769f
movl 0x25e16(%rip), %eax     # 0x2d498
movl %eax, 0x25f58(%rip)     # 0x2d5e0
leaq 0x24c21(%rip), %rsi     # 0x2c2b0
movq %r14, %rdi
callq 0xb47c
movq %r14, %rdi
callq 0x50e0
movq %rbx, %rdi
movl $0x20, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x625f
cmpl $0x1, 0x223d9(%rip)     # 0x29a90
jne 0x76d3
leaq 0x26154(%rip), %rax     # 0x2d814
movslq (%rax), %rax
leaq 0x24a96(%rip), %rcx     # 0x2c160
movl (%rcx,%rax,4), %eax
movl %eax, 0x24ca9(%rip)     # 0x2c37c
cmpl $-0x1, 0x2505a(%rip)    # 0x2c734
jne 0x76e7
callq 0x138bd
movl %eax, 0x2504d(%rip)     # 0x2c734
movb 0x25da3(%rip), %al      # 0x2d490
movl 0x24fd5(%rip), %ecx     # 0x2c6c8
testl %ecx, %ecx
sete %dl
xorb $0x1, %al
cmpl $0x2, %ecx
sete %cl
testb %dl, %al
jne 0x7708
andb %cl, %al
je 0x770f
movb $0x0, 0x24ee1(%rip)     # 0x2c5f0
cmpb $0x0, 0x24eda(%rip)     # 0x2c5f0
je 0x7765
movq 0x208a1(%rip), %rax     # 0x27fc0
movq (%rax), %rdx
leaq 0x24ec7(%rip), %rdi     # 0x2c5f0
leaq 0x1c36c(%rip), %rsi     # 0x23a9c
callq 0x5180
testq %rax, %rax
jne 0x7765
movq 0x208af(%rip), %rax     # 0x27ff0
movq (%rax), %rdi
leaq 0xe99f(%rip), %rsi      # 0x160ea
leaq 0x250de(%rip), %rdx     # 0x2c830
leaq 0x24e97(%rip), %rcx     # 0x2c5f0
xorl %eax, %eax
callq 0x5210
jmp 0x7420
movl 0x24fbd(%rip), %edi     # 0x2c728
callq 0x615f
movl 0x24f52(%rip), %eax     # 0x2c6c8
cmpl $0x2, %eax
je 0x7787
cmpl $0x1, %eax
jne 0x778e
callq 0x121b3
jmp 0x7799
callq 0x1348d
jmp 0x7799
movl 0x24f44(%rip), %edi     # 0x2c6d8
callq 0xe1de
callq 0xc108
xorl %edi, %edi
callq 0x5300
nopl (%rax)