// File: /workspace/github_c_makefile_star2_O2/LenShustek[P]miditones/miditones.c
// Function: main
int main (int argc, char *argv[]) {
   int argno;
   char *filebasename;
   int basenamelen;
#define MAXPATH 120
   char filename[MAXPATH];

   printf ("MIDITONES V%s, (C) 2011-2021 Len Shustek\n", VERSION);
   if (argc == 1) {     // no arguments
      SayUsage (argv[0]);
      return 1; }

   argno = HandleOptions (argc, argv); // process options
   if (argno == 0) {
      fprintf (stderr, "\n*** No basefilename given\n\n");
      SayUsage (argv[0]);
      exit (4); }
   filebasename = argv[argno];
   
   // strip off trailing .mid or .MID extension if provided by user
   basenamelen = strlength(filebasename);
   if (basenamelen > 4 &&
         (charcmp (filebasename + basenamelen - 4, ".mid") ||
          charcmp (filebasename + basenamelen - 4, ".MID"))) {
      filebasename[basenamelen - 4] = 0; }

   if (logparse || loggen) { // open the log file
      miditones_strlcpy (filename, filebasename, MAXPATH);
      miditones_strlcat (filename, ".log", MAXPATH);
      logfile = fopen (filename, "w");
      if (!logfile) {
         fprintf (stderr, "Unable to open log file %s\n", filename);
         return 1; }
      fprintf (logfile, "MIDITONES V%s log file\n", VERSION);
      print_command_line(logfile, argc, argv); }
   if (loggen) {
      fprintf(logfile, "\nThere are %d independent time-ordered streams in this log file:\n", logparse ? 3 : 2);
      if (logparse) fprintf(logfile, " - the parsed MIDI events, marked with #\n");
      fprintf(logfile, " - the MIDI play/stop events being queued, announced with ->\n"
              " - the generated bytestream commands pulled from the queue, announced with <-\n\n"); }

   // open the input file
   miditones_strlcpy (filename, filebasename, MAXPATH);
   miditones_strlcat (filename, ".mid", MAXPATH);
   infile = fopen (filename, "rb");
   if (!infile) {
      fprintf (stderr, "Unable to open input file %s\n", filename);
      return 1; }

   // Read the whole input file into memory
   fseek (infile, 0, SEEK_END); // find its size
   buflen = ftell (infile);
   fseek (infile, 0, SEEK_SET);
   buffer = (byte *) malloc (buflen + 1);
   if (!buffer) {
      fprintf (stderr, "Unable to allocate %ld bytes for the file\n", buflen);
      return 1; }
   fread (buffer, buflen, 1, infile);
   fclose (infile);
   if (logparse) fprintf (logfile, "Processing %s, %ld bytes\n", filename, buflen);

   if (!parseonly) { // create the output file
      miditones_strlcpy (filename, filebasename, MAXPATH);
      if (binaryoutput) {
         miditones_strlcat (filename, ".bin", MAXPATH);
         outfile = fopen (filename, "wb"); }
      else {
         miditones_strlcat (filename,  asm_output ? (scorename ? ".inc" : ".asm") : (scorename ? ".h" : ".c"), MAXPATH);
         outfile = fopen (filename, "w"); }
      if (!outfile) {
         fprintf (stderr, "Unable to open output file %s\n", filename);
         return 1; }
      file_header.f1 = (volume_output ? HDR_F1_VOLUME_PRESENT : 0)
                       | (instrumentoutput ? HDR_F1_INSTRUMENTS_PRESENT : 0)
                       | (percussion_translate ? HDR_F1_PERCUSSION_PRESENT : 0);
      file_header.num_tgens = num_tonegens;
      if (!binaryoutput) {      /* create header of C file that initializes score data */
         time_t rawtime;
         time (&rawtime);
         fprintf (outfile, "%s Playtune bytestream for file \"%s.mid\" ", comment, filebasename);
         fprintf (outfile, "created by MIDITONES V%s on %s", VERSION,
                  asctime (localtime (&rawtime)));
         print_command_line (outfile, argc, argv);
         if (channel_mask != 0xffff)
            fprintf (outfile, "%s   Only the masked channels were processed: %04X\n", comment, channel_mask);
         if (keyshift != 0)
            fprintf (outfile, "%s   Keyshift was %d chromatic notes\n", comment, keyshift);
         if (define_progmem) {
            fprintf (outfile, "#ifdef __AVR__\n");
            fprintf (outfile, "#include <avr/pgmspace.h>\n");
            fprintf (outfile, "#else\n");
            fprintf (outfile, "#define PROGMEM\n");
            fprintf (outfile, "#endif\n"); }
         if (asm_output) // create the assembler label for the score
            fprintf(outfile, "\n%s:\n%s", filebasename, byteop);
         else fprintf (outfile, "const unsigned char PROGMEM %s [] = {\n",
                  scorename ? filebasename : "score");
         if (do_header) {       // write the initialization for the file header
            fprintf (outfile, "'P','t', 6, %s%02X, %s%02X, ", hex, file_header.f1, hex, file_header.f2);
            fflush (outfile);
            file_header_num_tgens_position = ftell (outfile);   // remember where the number of tone generators is
            fprintf (outfile, "%2d%s %s (Playtune file header)\n%s", file_header.num_tgens, asm_output ? "" : ",", comment, byteop);
            outfile_bytecount += 6; } }
      else if (do_header) {     // write the binary file header
         int i;
         for (i = 0; i < sizeof (file_header); ++i)
            fputc (((byte *) &file_header)[i], outfile);
         file_header_num_tgens_position = (char *) &file_header.num_tgens - (char *) &file_header;
         outfile_bytecount += sizeof (file_header); } }

   // process the MIDI file header
   hdrptr = buffer;   // point to the file and track headers
   process_file_header ();
   printf ("  Processing %d tracks.\n", num_tracks);
   if (num_tracks > MAX_TRACKS) midi_error ("Too many tracks", buffer);

   // initialize for processing of all the tracks
   tempo = DEFAULT_TEMPO;
   for (int tracknum = 0; tracknum < num_tracks; ++tracknum) {
      track[tracknum].tempo = DEFAULT_TEMPO;
      process_track_header (tracknum);
      find_next_note (tracknum);     /* position to the first note on/off */
      /* if we are in "parse only" mode, do the whole track,
         so we do them one at a time instead of time-synchronized. */
      if (parseonly)
         while (track[tracknum].cmd != CMD_TRACKDONE)
            find_next_note (tracknum); }
#if 0
   // TEMP test queuing routines
   show_queue_cmd(12, CMD_PLAYNOTE, 100);
   show_queue_cmd(12, CMD_PLAYNOTE, 101);
   show_queue_cmd(12, CMD_PLAYNOTE, 103);
   show_queue_cmd(20, CMD_STOPNOTE, 101);
   show_queue_cmd(15, CMD_STOPNOTE, 103);
   show_queue_cmd(21, CMD_PLAYNOTE, 104);
   show_queue_cmd(20, CMD_STOPNOTE, 100);
   show_queue_cmd(20, CMD_STOPNOTE, 104);
   show_queue_cmd(22, CMD_PLAYNOTE, 109);
   flush_queue();
#endif
   if (!parseonly) {

      process_track_data();    // do all the tracks interleaved, like a 1950's multiway merge

      // generate the ending commentary
      if (!binaryoutput) {
         fprintf(outfile, "\n%s This %ld byte score contains %d notes and uses %d tone generator%s.\n",
                 comment, outfile_bytecount, note_on_commands, num_tonegens_used,
                 num_tonegens_used == 1 ? "" : "s");
         fprintf(outfile, "%s It encodes %u.%03u seconds of music with %d tempo change%s.\n",
            comment, (unsigned)(timenow_usec / 1000000), (unsigned)(timenow_usec / 1000 % 1000),
            tempo_changes, tempo_changes == 1 ? "" : "s");
         if (notes_skipped)
            fprintf(outfile, "%s %d notes had to be skipped.\n", comment, notes_skipped); }
      printf("  %s %d tone generators were used.\n",
             num_tonegens_used < num_tonegens ? "Only" : "All", num_tonegens_used);
      if (notes_skipped)
         printf("  %d notes were skipped because there weren't enough tone generators.\n",
                notes_skipped);
      if (consecutive_delays)
         printf("  %d consecutive delays could be eliminated\n", consecutive_delays);
      if (events_delayed)
         printf("  %d \"stop note\" commands were delayed because the %d-element output queue is too small\n",
                events_delayed, QUEUE_SIZE);
      if (noteinfo_overflow + noteinfo_notfound > 0)
         printf("  %d notes couldn't be recorded in the track status, so then %d notes couldn't be found\n"
                "  (Consider recompiling with MAX_TRACKNOTES bigger than %d, to allow more simultaneous notes.)\n",
                noteinfo_overflow, noteinfo_notfound, MAX_CHANNELNOTES);
      printf("  %ld bytes of score data were generated, ", outfile_bytecount);
      printf("encoding %u.%03u seconds of music with %d tempo change%s.\n",
             (unsigned)(timenow_usec / 1000000), (unsigned)(timenow_usec / 1000 % 1000), 
             tempo_changes, tempo_changes == 1 ? "" : "s");
      if (delaymin_usec)
         printf("  %ld delays were removed because the minimum delay of  %u msec caused events to be merged\n",
                delays_saved, (unsigned)(delaymin_usec / 1000));
      if (loggen) {
         fprintf(logfile, "%d note-on commands, %d instrument changes.\n",
                 note_on_commands, instrument_changes);
         fprintf(logfile, "%d stop-notes without start-notes, %d start-notes without stop-notes\n",
                 stopnotes_without_playnotes, playnotes_without_stopnotes);
         if (attacktime_usec > 0) fprintf(logfile, "%d sustain phases done, and %d skipped because the notes were too short\n",
                                             sustainphases_done, sustainphases_skipped); }
      if (0 && do_header) {             // rewrite the file header with the actual number of tone generators used
         if (fseek(outfile, file_header_num_tgens_position, SEEK_SET) != 0)
            fprintf(stderr, "Can't seek to number of tone generators in the header\n");
         else {
            if (binaryoutput)
               putc(num_tonegens_used, outfile);
            else
               fprintf(outfile, "%2d", num_tonegens_used); } }
      fclose(outfile); }

   if (loggen || logparse)
      fclose (logfile);
   printf ("  Done.\n");
   return 0; }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x90, %rsp
movq %rsi, %r14
movl %edi, %ebp
leaq 0x27d4(%rip), %rdi      # 0x650c
leaq 0x27f7(%rip), %rsi      # 0x6536
xorl %eax, %eax
callq 0x1080
cmpl $0x1, %ebp
jne 0x3d58
callq 0x13f9
pushq $0x1
popq %rax
jmp 0x4635
movl %ebp, %edi
movq %r14, %rsi
callq 0x1445
testl %eax, %eax
je 0x46a3
cltq
movq (%r14,%rax,8), %rbx
movq %rbx, %rdi
callq 0x1ae1
cmpl $0x5, %eax
jl 0x3db1
movl %eax, %eax
leaq (%rbx,%rax), %r15
addq $-0x4, %r15
leaq 0x137c(%rip), %rsi      # 0x510a
movq %r15, %rdi
callq 0x1b9b
testl %eax, %eax
jne 0x3dad
leaq 0x27b6(%rip), %rsi      # 0x6557
movq %r15, %rdi
callq 0x1b9b
testl %eax, %eax
je 0x3db1
movb $0x0, (%r15)
cmpb $0x0, 0x540d(%rip)      # 0x91c5
jne 0x3dc4
movb 0x5403(%rip), %al       # 0x91c3
cmpb $0x1, %al
jne 0x3e3b
leaq 0x10(%rsp), %r15
pushq $0x78
popq %r12
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x1af0
leaq 0x1390(%rip), %rsi      # 0x5172
movq %r15, %rdi
movq %r12, %rdx
callq 0x1b37
leaq 0x2768(%rip), %rsi      # 0x655c
movq %r15, %rdi
callq 0x1120
movq %rax, 0x53d5(%rip)      # 0x91d8
testq %rax, %rax
je 0x466e
leaq 0x2767(%rip), %rsi      # 0x657a
leaq 0x271c(%rip), %rdx      # 0x6536
movq %rax, %rdi
xorl %eax, %eax
callq 0x10b0
movq 0x53ad(%rip), %rdi      # 0x91d8
movl %ebp, %esi
movq %r14, %rdx
callq 0x1987
movb 0x5388(%rip), %al       # 0x91c3
testb $0x1, %al
je 0x3e9b
movq 0x5392(%rip), %rdi      # 0x91d8
movzbl 0x5378(%rip), %edx      # 0x91c5
orl $0x2, %edx
leaq 0x273b(%rip), %rsi      # 0x6592
xorl %eax, %eax
callq 0x10b0
cmpb $0x1, 0x5360(%rip)      # 0x91c5
jne 0x3e80
movq 0x536a(%rip), %rcx      # 0x91d8
leaq 0x275f(%rip), %rdi      # 0x65d4
pushq $0x29
popq %rsi
pushq $0x1
popq %rdx
callq 0x1150
movq 0x5351(%rip), %rcx      # 0x91d8
leaq 0x2770(%rip), %rdi      # 0x65fe
pushq $0x1
popq %rdx
movl $0x8c, %esi
callq 0x1150
leaq 0x10(%rsp), %r15
pushq $0x78
popq %r12
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x1af0
leaq 0x1251(%rip), %rsi      # 0x510a
movq %r15, %rdi
movq %r12, %rdx
callq 0x1b37
leaq 0x27c0(%rip), %rsi      # 0x668b
movq %r15, %rdi
callq 0x1120
movq %rax, 0x7e2e(%rip)      # 0xbd08
testq %rax, %rax
je 0x4645
pushq $0x2
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x1110
movq 0x7e11(%rip), %rdi      # 0xbd08
callq 0x10c0
movq %rax, 0x52e5(%rip)      # 0x91e8
movq 0x7dfe(%rip), %rdi      # 0xbd08
xorl %esi, %esi
xorl %edx, %edx
callq 0x1110
movq 0x52ce(%rip), %r15      # 0x91e8
leaq 0x1(%r15), %rdi
callq 0x10e0
movq %rax, 0x52b6(%rip)      # 0x91e0
testq %rax, %rax
je 0x4658
movq 0x7dce(%rip), %rcx      # 0xbd08
pushq $0x1
popq %rdx
movq %rax, %rdi
movq %r15, %rsi
callq 0x1050
movq 0x7db9(%rip), %rdi      # 0xbd08
callq 0x1060
cmpb $0x1, 0x526a(%rip)      # 0x91c5
jne 0x3f7e
movq 0x5274(%rip), %rdi      # 0x91d8
movq 0x527d(%rip), %rcx      # 0x91e8
leaq 0x2765(%rip), %rsi      # 0x66d7
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x10b0
cmpb $0x0, 0x5241(%rip)      # 0x91c6
jne 0x42d8
leaq 0x10(%rsp), %rdi
pushq $0x78
popq %rdx
movq %rbx, %rsi
callq 0x1af0
cmpb $0x0, 0x521e(%rip)      # 0x91c0
je 0x3fb4
leaq 0x274b(%rip), %r15      # 0x66f6
leaq 0x273f(%rip), %rsi      # 0x66f1
jmp 0x3ff1
leaq 0x1190(%rip), %rax      # 0x514b
leaq 0x2737(%rip), %rcx      # 0x66f9
testb $0x1, 0x5205(%rip)      # 0x91ce
cmovneq %rax, %rcx
leaq 0x272a(%rip), %rax      # 0x66fe
leaq 0x2726(%rip), %rsi      # 0x6701
cmovneq %rax, %rsi
cmpb $0x0, 0x51e4(%rip)      # 0x91ca
cmovneq %rcx, %rsi
leaq 0x256b(%rip), %r15      # 0x655c
leaq 0x10(%rsp), %r12
pushq $0x78
popq %rdx
movq %r12, %rdi
callq 0x1b37
movq %r12, %rdi
movq %r15, %rsi
callq 0x1120
movq %rax, 0x51dd(%rip)      # 0x91f0
testq %rax, %rax
je 0x4681
movb 0x51a9(%rip), %al       # 0x91cb
shlb $0x7, %al
movb 0x5199(%rip), %cl       # 0x91c4
shlb $0x6, %cl
orb %al, %cl
movb 0x5192(%rip), %al       # 0x91c8
shlb $0x5, %al
orb %cl, %al
movb %al, 0x50d2(%rip)       # 0x9113
movb 0x50a5(%rip), %al       # 0x90ec
movb %al, 0x50c8(%rip)       # 0x9115
cmpb $0x0, 0x516c(%rip)      # 0x91c0
je 0x408c
cmpb $0x1, 0x5164(%rip)      # 0x91c1
jne 0x42d8
xorl %ebx, %ebx
leaq 0x50a4(%rip), %r14      # 0x9110
cmpq $0x6, %rbx
je 0x4203
movzbl (%rbx,%r14), %edi
movq 0x516e(%rip), %rsi      # 0x91f0
callq 0x1090
incq %rbx
jmp 0x406c
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x10d0
movq 0x5150(%rip), %rdi      # 0x91f0
movq 0x5029(%rip), %rdx      # 0x90d0
leaq 0x2675(%rip), %rsi      # 0x6723
movq %rbx, %rcx
xorl %eax, %eax
callq 0x10b0
movq 0x5131(%rip), %r12      # 0x91f0
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1070
leaq 0x2677(%rip), %rsi      # 0x674d
leaq 0x2459(%rip), %rdx      # 0x6536
movq %r12, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x10b0
movq 0x50ff(%rip), %rdi      # 0x91f0
movl %ebp, %esi
movq %r14, %rdx
callq 0x1987
movl 0x4fef(%rip), %ecx      # 0x90f0
cmpl $0xffff, %ecx           # imm = 0xFFFF
je 0x4125
movq 0x50e0(%rip), %rdi      # 0x91f0
movq 0x4fb9(%rip), %rdx      # 0x90d0
leaq 0x264e(%rip), %rsi      # 0x676c
xorl %eax, %eax
callq 0x10b0
movl 0x5041(%rip), %ecx      # 0x916c
testl %ecx, %ecx
je 0x414b
movq 0x50ba(%rip), %rdi      # 0x91f0
movq 0x4f93(%rip), %rdx      # 0x90d0
leaq 0x265c(%rip), %rsi      # 0x67a0
xorl %eax, %eax
callq 0x10b0
cmpb $0x1, 0x5070(%rip)      # 0x91c2
jne 0x41d9
movq 0x5091(%rip), %rcx      # 0x91f0
leaq 0x2660(%rip), %rdi      # 0x67c6
pushq $0xf
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
callq 0x1150
movq 0x5074(%rip), %rcx      # 0x91f0
leaq 0x2653(%rip), %rdi      # 0x67d6
pushq $0x1a
popq %rsi
movq %r14, %rdx
callq 0x1150
movq 0x505b(%rip), %rcx      # 0x91f0
leaq 0x2655(%rip), %rdi      # 0x67f1
pushq $0x6
popq %rsi
movq %r14, %rdx
callq 0x1150
movq 0x5042(%rip), %rcx      # 0x91f0
leaq 0x2643(%rip), %rdi      # 0x67f8
pushq $0x10
popq %rsi
movq %r14, %rdx
callq 0x1150
movq 0x5029(%rip), %rcx      # 0x91f0
leaq 0x263b(%rip), %rdi      # 0x6809
pushq $0x7
popq %rsi
movq %r14, %rdx
callq 0x1150
movq 0x5010(%rip), %rdi      # 0x91f0
cmpb $0x1, 0x4fe3(%rip)      # 0x91ca
jne 0x4213
movq 0x4ef0(%rip), %rcx      # 0x90e0
leaq 0x261a(%rip), %rsi      # 0x6811
movq %rbx, %rdx
xorl %eax, %eax
callq 0x10b0
jmp 0x4233
movq $0x5, 0x7b02(%rip) # 0xbd10
jmp 0x42d0
leaq 0x2626(%rip), %rdx      # 0x6840
cmpb $0x0, 0x4fad(%rip)      # 0x91ce
cmovneq %rbx, %rdx
leaq 0x25ed(%rip), %rsi      # 0x6819
xorl %eax, %eax
callq 0x10b0
cmpb $0x1, 0x4f87(%rip)      # 0x91c1
jne 0x42d8
movq 0x4fa9(%rip), %rdi      # 0x91f0
movq 0x4e8a(%rip), %rdx      # 0x90d8
movzbl 0x4ebe(%rip), %ecx      # 0x9113
movzbl 0x4eb7(%rip), %r9d      # 0x9114
leaq 0x25e2(%rip), %rsi      # 0x6846
movq %rdx, %r8
xorl %eax, %eax
callq 0x10b0
movq 0x4f7b(%rip), %rdi      # 0x91f0
callq 0x10f0
movq 0x4f6f(%rip), %rdi      # 0x91f0
callq 0x10c0
movq %rax, 0x7a83(%rip)      # 0xbd10
movq 0x4f5c(%rip), %rdi      # 0x91f0
movzbl 0x4e7a(%rip), %edx      # 0x9115
leaq 0x23e8(%rip), %rax      # 0x668a
leaq 0x25dd(%rip), %rcx      # 0x6886
cmpb $0x0, 0x4f1a(%rip)      # 0x91ca
cmovneq %rax, %rcx
movq 0x4e15(%rip), %r8       # 0x90d0
movq 0x4e1e(%rip), %r9       # 0x90e0
leaq 0x259a(%rip), %rsi      # 0x6863
xorl %eax, %eax
callq 0x10b0
addq $0x6, 0x4eb0(%rip)      # 0x9188
movq 0x4f01(%rip), %rax      # 0x91e0
movq %rax, 0x7a0a(%rip)      # 0xbcf0
callq 0x2dba
movl 0x7a07(%rip), %esi      # 0xbcf8
leaq 0x2590(%rip), %rdi      # 0x6888
xorl %eax, %eax
callq 0x1080
movl 0x79f3(%rip), %eax      # 0xbcf8
cmpl $0x19, %eax
jge 0x46cc
movq $0x7a120, 0x79e7(%rip) # imm = 0x7A120
xorl %ebx, %ebx
leaq 0x509e(%rip), %r14      # 0x93c0
cltq
cmpq %rax, %rbx
jge 0x436b
imulq $0x30, %rbx, %r15
movq $0x7a120, 0x18(%r15,%r14) # imm = 0x7A120
movl %ebx, %edi
callq 0x2ee7
movl %ebx, %edi
callq 0x2fc2
cmpb $0x1, 0x4e7b(%rip)      # 0x91c6
jne 0x4360
addq %r14, %r15
cmpb $-0x1, 0x24(%r15)
je 0x4360
movl %ebx, %edi
callq 0x2fc2
jmp 0x4350
incq %rbx
movl 0x798f(%rip), %eax      # 0xbcf8
jmp 0x4322
cmpb $0x0, 0x4e54(%rip)      # 0x91c6
jne 0x4609
callq 0x3837
cmpb $0x0, 0x4e3c(%rip)      # 0x91c0
jne 0x4460
movq 0x4e5f(%rip), %rdi      # 0x91f0
movq 0x4d38(%rip), %rdx      # 0x90d0
movq 0x4de9(%rip), %rcx      # 0x9188
movl 0x4d9a(%rip), %r8d      # 0x9140
movl 0x4d8b(%rip), %r9d      # 0x9138
cmpl $0x1, %r9d
leaq 0x22d2(%rip), %r14      # 0x668a
leaq 0x24c5(%rip), %rbx      # 0x6884
movq %rbx, %rax
cmoveq %r14, %rax
movq %rax, (%rsp)
leaq 0x24e0(%rip), %rsi      # 0x68b1
xorl %eax, %eax
callq 0x10b0
movq 0x4e11(%rip), %rdi      # 0x91f0
movq 0x4cea(%rip), %rcx      # 0x90d0
movl 0x4dac(%rip), %esi      # 0x9198
movl $0xf4240, %r8d          # imm = 0xF4240
movl %esi, %eax
xorl %edx, %edx
divl %r8d
movl %eax, %r8d
movl $0x3e8, %r9d            # imm = 0x3E8
movl %esi, %eax
xorl %edx, %edx
divl %r9d
xorl %edx, %edx
divl %r9d
movl %edx, %eax
movl 0x4d99(%rip), %r9d      # 0x91b0
cmpl $0x1, %r9d
cmoveq %r14, %rbx
movq %rbx, (%rsp)
leaq 0x24d0(%rip), %rsi      # 0x68fa
movq %rcx, %rdx
movl %r8d, %ecx
movl %eax, %r8d
xorl %eax, %eax
callq 0x10b0
movl 0x4d04(%rip), %ecx      # 0x9144
testl %ecx, %ecx
je 0x4460
movq 0x4da5(%rip), %rdi      # 0x91f0
movq 0x4c7e(%rip), %rdx      # 0x90d0
leaq 0x24e1(%rip), %rsi      # 0x693a
xorl %eax, %eax
callq 0x10b0
movl 0x4cd2(%rip), %edx      # 0x9138
cmpl 0x4c80(%rip), %edx      # 0x90ec
leaq 0x250b(%rip), %rax      # 0x697e
leaq 0x2509(%rip), %rsi      # 0x6983
cmovlq %rax, %rsi
leaq 0x24d5(%rip), %rdi      # 0x695a
xorl %eax, %eax
callq 0x1080
movl 0x4cb2(%rip), %esi      # 0x9144
testl %esi, %esi
je 0x44a4
leaq 0x24ea(%rip), %rdi      # 0x6987
xorl %eax, %eax
callq 0x1080
movl 0x4cb2(%rip), %esi      # 0x915c
testl %esi, %esi
je 0x44bc
leaq 0x2519(%rip), %rdi      # 0x69ce
xorl %eax, %eax
callq 0x1080
movl 0x4c86(%rip), %esi      # 0x9148
testl %esi, %esi
je 0x44d7
leaq 0x252e(%rip), %rdi      # 0x69fb
pushq $0x64
popq %rdx
xorl %eax, %eax
callq 0x1080
movl 0x4c87(%rip), %esi      # 0x9164
movl 0x4c85(%rip), %edx      # 0x9168
movl %edx, %eax
addl %esi, %eax
jle 0x44fa
leaq 0x2564(%rip), %rdi      # 0x6a54
pushq $0x10
popq %rcx
xorl %eax, %eax
callq 0x1080
movq 0x4c87(%rip), %rsi      # 0x9188
leaq 0x2604(%rip), %rdi      # 0x6b0c
xorl %eax, %eax
callq 0x1080
movl 0x4c83(%rip), %ecx      # 0x9198
movl $0xf4240, %esi          # imm = 0xF4240
movl %ecx, %eax
xorl %edx, %edx
divl %esi
movl %eax, %esi
movl $0x3e8, %edi            # imm = 0x3E8
movl %ecx, %eax
xorl %edx, %edx
divl %edi
xorl %edx, %edx
divl %edi
movl 0x4c79(%rip), %ecx      # 0x91b0
cmpl $0x1, %ecx
leaq 0x2149(%rip), %rax      # 0x668a
leaq 0x233c(%rip), %r8       # 0x6884
cmoveq %rax, %r8
leaq 0x25e4(%rip), %rdi      # 0x6b37
xorl %eax, %eax
callq 0x1080
movq 0x4c0f(%rip), %rax      # 0x9170
testq %rax, %rax
je 0x4587
movq 0x4c4b(%rip), %rsi      # 0x91b8
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
leaq 0x25f4(%rip), %rdi      # 0x6b72
movl %eax, %edx
xorl %eax, %eax
callq 0x1080
cmpb $0x1, 0x4c35(%rip)      # 0x91c3
jne 0x45fd
movq 0x4c41(%rip), %rdi      # 0x91d8
movl 0x4ba3(%rip), %edx      # 0x9140
movl 0x4b99(%rip), %ecx      # 0x913c
leaq 0x2624(%rip), %rsi      # 0x6bce
xorl %eax, %eax
callq 0x10b0
movq 0x4c20(%rip), %rdi      # 0x91d8
movl 0x4b8e(%rip), %edx      # 0x914c
movl 0x4b8c(%rip), %ecx      # 0x9150
leaq 0x2630(%rip), %rsi      # 0x6bfb
xorl %eax, %eax
callq 0x10b0
cmpq $0x0, 0x4ba6(%rip)      # 0x9180
je 0x45fd
movq 0x4bf5(%rip), %rdi      # 0x91d8
movl 0x4b6f(%rip), %edx      # 0x9158
movl 0x4b65(%rip), %ecx      # 0x9154
leaq 0x264b(%rip), %rsi      # 0x6c41
xorl %eax, %eax
callq 0x10b0
movq 0x4bec(%rip), %rdi      # 0x91f0
callq 0x1060
cmpb $0x0, 0x4bb3(%rip)      # 0x91c3
jne 0x461b
cmpb $0x1, 0x4bac(%rip)      # 0x91c5
jne 0x4627
movq 0x4bb6(%rip), %rdi      # 0x91d8
callq 0x1060
leaq 0x265c(%rip), %rdi      # 0x6c8a
callq 0x1040
xorl %eax, %eax
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x49ac(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x2038(%rip), %rsi      # 0x668e
jmp 0x4692
movq 0x4999(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x2043(%rip), %rsi      # 0x66ac
movq %r15, %rdx
jmp 0x4697
movq 0x4983(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x1edf(%rip), %rsi      # 0x655e
jmp 0x4692
movq 0x4970(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x2072(%rip), %rsi      # 0x6704
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x10b0
jmp 0x3d50
movq 0x494e(%rip), %rax      # 0x8ff8
movq (%rax), %rcx
leaq 0x1e86(%rip), %rdi      # 0x653a
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
callq 0x1150
callq 0x13f9
pushq $0x4
popq %rdi
callq 0x1140
movq 0x4b0d(%rip), %rsi      # 0x91e0
leaq 0x21c7(%rip), %rdi      # 0x68a1
callq 0x1a3a