// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xf8, %rsp
movl $0x0, 0xf4(%rsp)
movl %edi, 0xf0(%rsp)
movq %rsi, 0xe8(%rsp)
leaq 0x32d0(%rip), %rdi      # 0x86d8
leaq 0x32f3(%rip), %rsi      # 0x8702
movb $0x0, %al
callq 0x1070
cmpl $0x1, 0xf0(%rsp)
jne 0x5440
movq 0xe8(%rsp), %rax
movq (%rax), %rdi
callq 0x14e0
movl $0x1, 0xf4(%rsp)
jmp 0x6037
movl 0xf0(%rsp), %edi
movq 0xe8(%rsp), %rsi
callq 0x1540
movl %eax, 0xe4(%rsp)
cmpl $0x0, 0xe4(%rsp)
jne 0x5497
movq 0x5b8c(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x3290(%rip), %rsi      # 0x8706
movb $0x0, %al
callq 0x10a0
movq 0xe8(%rsp), %rax
movq (%rax), %rdi
callq 0x14e0
movl $0x4, %edi
callq 0x1140
movq 0xe8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0xd8(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x1e10
movl %eax, 0xd4(%rsp)
cmpl $0x4, 0xd4(%rsp)
jle 0x553a
movq 0xd8(%rsp), %rdi
movslq 0xd4(%rsp), %rax
addq %rax, %rdi
addq $-0x4, %rdi
leaq 0x1dcf(%rip), %rsi      # 0x72be
callq 0x2070
cmpl $0x0, %eax
jne 0x5521
movq 0xd8(%rsp), %rdi
movslq 0xd4(%rsp), %rax
addq %rax, %rdi
addq $-0x4, %rdi
leaq 0x320c(%rip), %rsi      # 0x8723
callq 0x2070
cmpl $0x0, %eax
je 0x553a
movq 0xd8(%rsp), %rax
movl 0xd4(%rsp), %ecx
subl $0x4, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
testb $0x1, 0x5dc4(%rip)      # 0xb305
jne 0x5550
testb $0x1, 0x5db9(%rip)      # 0xb303
je 0x5603
leaq 0x50(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movl $0x78, %edx
callq 0x1e50
leaq 0x50(%rsp), %rdi
leaq 0x1db3(%rip), %rsi      # 0x7326
movl $0x78, %edx
callq 0x1f20
leaq 0x50(%rsp), %rdi
leaq 0x319f(%rip), %rsi      # 0x8728
callq 0x1120
movq %rax, 0x5d83(%rip)      # 0xb318
cmpq $0x0, 0x5d7b(%rip)      # 0xb318
jne 0x55cc
movq 0x5a52(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x50(%rsp), %rdx
leaq 0x3175(%rip), %rsi      # 0x872a
movb $0x0, %al
callq 0x10a0
movl $0x1, 0xf4(%rsp)
jmp 0x6037
movq 0x5d45(%rip), %rdi      # 0xb318
leaq 0x316c(%rip), %rsi      # 0x8746
leaq 0x3121(%rip), %rdx      # 0x8702
movb $0x0, %al
callq 0x10a0
movq 0x5d29(%rip), %rdi      # 0xb318
movl 0xf0(%rsp), %esi
movq 0xe8(%rsp), %rdx
callq 0x1be0
testb $0x1, 0x5cf9(%rip)      # 0xb303
je 0x566a
movq 0x5d05(%rip), %rdi      # 0xb318
movb 0x5cec(%rip), %cl       # 0xb305
movl $0x2, %edx
movl $0x3, %eax
testb $0x1, %cl
cmovnel %eax, %edx
leaq 0x312e(%rip), %rsi      # 0x875e
movb $0x0, %al
callq 0x10a0
testb $0x1, 0x5cc7(%rip)      # 0xb305
je 0x5655
movq 0x5cd1(%rip), %rdi      # 0xb318
leaq 0x3152(%rip), %rsi      # 0x87a0
movb $0x0, %al
callq 0x10a0
movq 0x5cbc(%rip), %rdi      # 0xb318
leaq 0x3167(%rip), %rsi      # 0x87ca
movb $0x0, %al
callq 0x10a0
leaq 0x50(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movl $0x78, %edx
callq 0x1e50
leaq 0x50(%rsp), %rdi
leaq 0x1c31(%rip), %rsi      # 0x72be
movl $0x78, %edx
callq 0x1f20
leaq 0x50(%rsp), %rdi
leaq 0x31b4(%rip), %rsi      # 0x8857
callq 0x1120
movq %rax, 0x8799(%rip)      # 0xde48
cmpq $0x0, 0x8791(%rip)      # 0xde48
jne 0x56e6
movq 0x5938(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x50(%rsp), %rdx
leaq 0x318b(%rip), %rsi      # 0x885a
movb $0x0, %al
callq 0x10a0
movl $0x1, 0xf4(%rsp)
jmp 0x6037
movq 0x875b(%rip), %rdi      # 0xde48
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x1110
movq 0x8746(%rip), %rdi      # 0xde48
callq 0x10b0
movq %rax, 0x5c1a(%rip)      # 0xb328
movq 0x8733(%rip), %rdi      # 0xde48
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1110
movq 0x5c01(%rip), %rdi      # 0xb328
addq $0x1, %rdi
callq 0x10e0
movq %rax, 0x5be9(%rip)      # 0xb320
cmpq $0x0, 0x5be1(%rip)      # 0xb320
jne 0x5770
movq 0x58b0(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq 0x5bd6(%rip), %rdx      # 0xb328
leaq 0x311f(%rip), %rsi      # 0x8878
movb $0x0, %al
callq 0x10a0
movl $0x1, 0xf4(%rsp)
jmp 0x6037
movq 0x5ba9(%rip), %rdi      # 0xb320
movq 0x5baa(%rip), %rsi      # 0xb328
movq 0x86c3(%rip), %rcx      # 0xde48
movl $0x1, %edx
callq 0x1040
movq 0x86b2(%rip), %rdi      # 0xde48
callq 0x1050
testb $0x1, 0x5b63(%rip)      # 0xb305
je 0x57c5
movq 0x5b6d(%rip), %rdi      # 0xb318
leaq 0x50(%rsp), %rdx
movq 0x5b71(%rip), %rcx      # 0xb328
leaq 0x30e5(%rip), %rsi      # 0x88a3
movb $0x0, %al
callq 0x10a0
testb $0x1, 0x5b3a(%rip)      # 0xb306
jne 0x5c31
leaq 0x50(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movl $0x78, %edx
callq 0x1e50
testb $0x1, 0x5b10(%rip)      # 0xb300
je 0x5825
leaq 0x50(%rsp), %rdi
leaq 0x30bf(%rip), %rsi      # 0x88bd
movl $0x78, %edx
callq 0x1f20
leaq 0x50(%rsp), %rdi
leaq 0x30ae(%rip), %rsi      # 0x88c2
callq 0x1120
movq %rax, 0x5b10(%rip)      # 0xb330
jmp 0x58a6
leaq 0x50(%rsp), %rax
movq %rax, 0x38(%rsp)
testb $0x1, 0x5ad4(%rip)      # 0xb30a
je 0x585a
movb 0x5ad0(%rip), %dl       # 0xb30e
leaq 0x3080(%rip), %rax      # 0x88c5
leaq 0x1ab3(%rip), %rcx      # 0x72ff
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, 0x30(%rsp)
jmp 0x587a
movb 0x5aae(%rip), %dl       # 0xb30e
leaq 0x3066(%rip), %rax      # 0x88cd
leaq 0x305c(%rip), %rcx      # 0x88ca
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
movl $0x78, %edx
callq 0x1f20
leaq 0x50(%rsp), %rdi
leaq 0x2e8e(%rip), %rsi      # 0x8728
callq 0x1120
movq %rax, 0x5a8a(%rip)      # 0xb330
cmpq $0x0, 0x5a82(%rip)      # 0xb330
jne 0x58dd
movq 0x5741(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x50(%rsp), %rdx
leaq 0x300a(%rip), %rsi      # 0x88d0
movb $0x0, %al
callq 0x10a0
movl $0x1, 0xf4(%rsp)
jmp 0x6037
movb 0x5a28(%rip), %dl       # 0xb30b
xorl %eax, %eax
movl $0x80, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb 0x5a0d(%rip), %sil      # 0xb304
xorl %ecx, %ecx
movl $0x40, %edx
testb $0x1, %sil
cmovnel %edx, %ecx
orl %ecx, %eax
movb 0x59fa(%rip), %sil      # 0xb308
xorl %ecx, %ecx
movl $0x20, %edx
testb $0x1, %sil
cmovnel %edx, %ecx
orl %ecx, %eax
movb %al, 0x57df(%rip)       # 0xb103
movl 0x57b2(%rip), %eax      # 0xb0dc
movb %al, 0x57d5(%rip)       # 0xb105
testb $0x1, 0x59c9(%rip)      # 0xb300
jne 0x5bbe
leaq 0x48(%rsp), %rdi
callq 0x10c0
movq 0x59e2(%rip), %rdi      # 0xb330
movq 0x576b(%rip), %rdx      # 0xb0c0
movq 0xd8(%rsp), %rcx
leaq 0x2f8b(%rip), %rsi      # 0x88ef
movb $0x0, %al
callq 0x10a0
movq 0x59be(%rip), %rax      # 0xb330
movq %rax, 0x28(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1060
movq 0x28(%rsp), %rdi
movq %rax, %rcx
leaq 0x2f81(%rip), %rsi      # 0x8919
leaq 0x2d63(%rip), %rdx      # 0x8702
movb $0x0, %al
callq 0x10a0
movq 0x5983(%rip), %rdi      # 0xb330
movl 0xf0(%rsp), %esi
movq 0xe8(%rsp), %rdx
callq 0x1be0
cmpl $0xffff, 0x5715(%rip)   # imm = 0xFFFF
je 0x59ef
movq 0x595c(%rip), %rdi      # 0xb330
movq 0x56e5(%rip), %rdx      # 0xb0c0
movl 0x56ff(%rip), %ecx      # 0xb0e0
leaq 0x2f50(%rip), %rsi      # 0x8938
movb $0x0, %al
callq 0x10a0
cmpl $0x0, 0x58b6(%rip)      # 0xb2ac
je 0x5a1a
movq 0x5931(%rip), %rdi      # 0xb330
movq 0x56ba(%rip), %rdx      # 0xb0c0
movl 0x58a0(%rip), %ecx      # 0xb2ac
leaq 0x2f59(%rip), %rsi      # 0x896c
movb $0x0, %al
callq 0x10a0
testb $0x1, 0x58e1(%rip)      # 0xb302
je 0x5a8c
movq 0x5906(%rip), %rdi      # 0xb330
leaq 0x2f61(%rip), %rsi      # 0x8992
movb $0x0, %al
callq 0x10a0
movq 0x58f1(%rip), %rdi      # 0xb330
leaq 0x2f5c(%rip), %rsi      # 0x89a2
movb $0x0, %al
callq 0x10a0
movq 0x58dc(%rip), %rdi      # 0xb330
leaq 0x2f62(%rip), %rsi      # 0x89bd
movb $0x0, %al
callq 0x10a0
movq 0x58c7(%rip), %rdi      # 0xb330
leaq 0x2f54(%rip), %rsi      # 0x89c4
movb $0x0, %al
callq 0x10a0
movq 0x58b2(%rip), %rdi      # 0xb330
leaq 0x2f50(%rip), %rsi      # 0x89d5
movb $0x0, %al
callq 0x10a0
testb $0x1, 0x5877(%rip)      # 0xb30a
je 0x5abb
movq 0x5894(%rip), %rdi      # 0xb330
movq 0xd8(%rsp), %rdx
movq 0x5625(%rip), %rcx      # 0xb0d0
leaq 0x2f2b(%rip), %rsi      # 0x89dd
movb $0x0, %al
callq 0x10a0
jmp 0x5b05
movq 0x586e(%rip), %rax      # 0xb330
movq %rax, 0x20(%rsp)
testb $0x1, 0x5840(%rip)      # 0xb30e
je 0x5adf
movq 0xd8(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0x5aed
leaq 0x2f26(%rip), %rax      # 0x8a0c
movq %rax, 0x18(%rsp)
jmp 0x5aed
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rdx
leaq 0x2ee7(%rip), %rsi      # 0x89e5
movb $0x0, %al
callq 0x10a0
testb $0x1, 0x57f5(%rip)      # 0xb301
je 0x5bbc
movq 0x5817(%rip), %rdi      # 0xb330
movq 0x55a8(%rip), %rdx      # 0xb0c8
movzbl 0x55dc(%rip), %ecx      # 0xb103
movq 0x559a(%rip), %r8       # 0xb0c8
movzbl 0x55ce(%rip), %r9d      # 0xb104
leaq 0x2ed5(%rip), %rsi      # 0x8a12
movb $0x0, %al
callq 0x10a0
movq 0x57e5(%rip), %rdi      # 0xb330
callq 0x10f0
movq 0x57d9(%rip), %rdi      # 0xb330
callq 0x10b0
movq %rax, 0x82ed(%rip)      # 0xde50
movq 0x57c6(%rip), %rdi      # 0xb330
movzbl 0x5594(%rip), %edx      # 0xb105
movb 0x5792(%rip), %sil      # 0xb30a
leaq 0x2ed3(%rip), %rcx      # 0x8a52
leaq 0x2cd0(%rip), %rax      # 0x8856
testb $0x1, %sil
cmovneq %rax, %rcx
movq 0x552b(%rip), %r8       # 0xb0c0
movq 0x5534(%rip), %r9       # 0xb0d0
leaq 0x2e8c(%rip), %rsi      # 0x8a2f
movb $0x0, %al
callq 0x10a0
movq 0x5717(%rip), %rax      # 0xb2c8
addq $0x6, %rax
movq %rax, 0x570c(%rip)      # 0xb2c8
jmp 0x5c2f
testb $0x1, 0x573c(%rip)      # 0xb301
je 0x5c2d
movl $0x0, 0x44(%rsp)
movslq 0x44(%rsp), %rax
cmpq $0x6, %rax
jae 0x5c03
movslq 0x44(%rsp), %rcx
leaq 0x551a(%rip), %rax      # 0xb100
movzbl (%rax,%rcx), %edi
movq 0x573f(%rip), %rsi      # 0xb330
callq 0x1080
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x5bcf
leaq 0x54f6(%rip), %rcx      # 0xb100
movq %rcx, %rax
addq $0x5, %rax
subq %rcx, %rax
movq %rax, 0x8235(%rip)      # 0xde50
movq 0x56a6(%rip), %rax      # 0xb2c8
addq $0x6, %rax
movq %rax, 0x569b(%rip)      # 0xb2c8
jmp 0x5c2f
jmp 0x5c31
movq 0x56e8(%rip), %rax      # 0xb320
movq %rax, 0x81f1(%rip)      # 0xde30
callq 0x3c70
movl 0x81ee(%rip), %esi      # 0xde38
leaq 0x2e03(%rip), %rdi      # 0x8a54
movb $0x0, %al
callq 0x1070
cmpl $0x18, 0x81d9(%rip)     # 0xde38
jle 0x5c74
movq 0x56b8(%rip), %rsi      # 0xb320
leaq 0x2dfe(%rip), %rdi      # 0x8a6d
callq 0x1ce0
movq $0x7a120, 0x81c1(%rip) # imm = 0x7A120
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x81a7(%rip), %eax      # 0xde38
jge 0x5d05
movslq 0x40(%rsp), %rcx
leaq 0x5861(%rip), %rax      # 0xb500
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq $0x7a120, 0x18(%rax)    # imm = 0x7A120
movl 0x40(%rsp), %edi
callq 0x3e00
movl 0x40(%rsp), %edi
callq 0x3f90
testb $0x1, 0x563f(%rip)      # 0xb306
je 0x5cf6
jmp 0x5ccb
movslq 0x40(%rsp), %rcx
leaq 0x5829(%rip), %rax      # 0xb500
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movzbl 0x24(%rax), %eax
cmpl $0xff, %eax
je 0x5cf4
movl 0x40(%rsp), %edi
callq 0x3f90
jmp 0x5ccb
jmp 0x5cf6
jmp 0x5cf8
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x5c87
testb $0x1, 0x55fa(%rip)      # 0xb306
jne 0x6000
callq 0x4bf0
testb $0x1, 0x55e2(%rip)      # 0xb300
jne 0x5e1d
movq 0x5605(%rip), %rdi      # 0xb330
movq 0x538e(%rip), %rdx      # 0xb0c0
movq 0x558f(%rip), %rcx      # 0xb2c8
movl 0x5540(%rip), %r8d      # 0xb280
movl 0x5531(%rip), %r9d      # 0xb278
movl 0x552a(%rip), %r10d     # 0xb278
leaq 0x2cfb(%rip), %rax      # 0x8a50
leaq 0x2afa(%rip), %rsi      # 0x8856
cmpl $0x1, %r10d
cmoveq %rsi, %rax
leaq 0x2d12(%rip), %rsi      # 0x8a7d
movq %rax, (%rsp)
movb $0x0, %al
callq 0x10a0
movq 0x55b3(%rip), %rdi      # 0xb330
movq 0x533c(%rip), %rax      # 0xb0c0
movq %rax, 0x10(%rsp)
movl 0x5549(%rip), %eax      # 0xb2d8
movl $0xf4240, %ecx          # imm = 0xF4240
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movl 0x5538(%rip), %eax      # 0xb2d8
movl $0x3e8, %esi            # imm = 0x3E8
xorl %edx, %edx
divl %esi
movl $0x3e8, %esi            # imm = 0x3E8
xorl %edx, %edx
divl %esi
movl %edx, %r8d
movq 0x10(%rsp), %rdx
movl 0x552f(%rip), %r9d      # 0xb2f0
movl 0x5528(%rip), %r10d     # 0xb2f0
leaq 0x2c81(%rip), %rax      # 0x8a50
leaq 0x2a80(%rip), %rsi      # 0x8856
cmpl $0x1, %r10d
cmoveq %rsi, %rax
leaq 0x2ce1(%rip), %rsi      # 0x8ac6
movq %rax, (%rsp)
movb $0x0, %al
callq 0x10a0
cmpl $0x0, 0x548d(%rip)      # 0xb284
je 0x5e1b
movq 0x5530(%rip), %rdi      # 0xb330
movq 0x52b9(%rip), %rdx      # 0xb0c0
movl 0x5477(%rip), %ecx      # 0xb284
leaq 0x2cf2(%rip), %rsi      # 0x8b06
movb $0x0, %al
callq 0x10a0
jmp 0x5e1d
movl 0x5455(%rip), %ecx      # 0xb278
movl 0x52b3(%rip), %edx      # 0xb0dc
leaq 0x2d1f(%rip), %rsi      # 0x8b4f
leaq 0x2d13(%rip), %rax      # 0x8b4a
cmpl %edx, %ecx
cmovlq %rax, %rsi
movl 0x5435(%rip), %edx      # 0xb278
leaq 0x2cdc(%rip), %rdi      # 0x8b26
movb $0x0, %al
callq 0x1070
cmpl $0x0, 0x542c(%rip)      # 0xb284
je 0x5e6e
movl 0x5424(%rip), %esi      # 0xb284
leaq 0x2cec(%rip), %rdi      # 0x8b53
movb $0x0, %al
callq 0x1070
cmpl $0x0, 0x5427(%rip)      # 0xb29c
je 0x5e8b
movl 0x541f(%rip), %esi      # 0xb29c
leaq 0x2d16(%rip), %rdi      # 0x8b9a
movb $0x0, %al
callq 0x1070
cmpl $0x0, 0x53f6(%rip)      # 0xb288
je 0x5ead
movl 0x53ee(%rip), %esi      # 0xb288
leaq 0x2d26(%rip), %rdi      # 0x8bc7
movl $0x64, %edx
movb $0x0, %al
callq 0x1070
movl 0x53f1(%rip), %eax      # 0xb2a4
addl 0x53ef(%rip), %eax      # 0xb2a8
cmpl $0x0, %eax
jle 0x5edd
movl 0x53e0(%rip), %esi      # 0xb2a4
movl 0x53de(%rip), %edx      # 0xb2a8
leaq 0x2d4f(%rip), %rdi      # 0x8c20
movl $0x10, %ecx
movb $0x0, %al
callq 0x1070
movq 0x53e4(%rip), %rsi      # 0xb2c8
leaq 0x2ded(%rip), %rdi      # 0x8cd8
movb $0x0, %al
callq 0x1070
movl 0x53e0(%rip), %eax      # 0xb2d8
movl $0xf4240, %ecx          # imm = 0xF4240
xorl %edx, %edx
divl %ecx
movl %eax, %esi
movl 0x53cf(%rip), %eax      # 0xb2d8
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl 0x53cf(%rip), %ecx      # 0xb2f0
movl 0x53c9(%rip), %edi      # 0xb2f0
leaq 0x2b22(%rip), %r8       # 0x8a50
leaq 0x2921(%rip), %rax      # 0x8856
cmpl $0x1, %edi
cmoveq %rax, %r8
leaq 0x2dc0(%rip), %rdi      # 0x8d03
movb $0x0, %al
callq 0x1070
cmpq $0x0, 0x535e(%rip)      # 0xb2b0
je 0x5f7c
movq 0x539d(%rip), %rsi      # 0xb2f8
movq 0x534e(%rip), %rax      # 0xb2b0
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
movl %eax, %edx
leaq 0x2dc9(%rip), %rdi      # 0x8d3e
movb $0x0, %al
callq 0x1070
testb $0x1, 0x5380(%rip)      # 0xb303
je 0x5ff4
movq 0x538c(%rip), %rdi      # 0xb318
movl 0x52ee(%rip), %edx      # 0xb280
movl 0x52e4(%rip), %ecx      # 0xb27c
leaq 0x2dfb(%rip), %rsi      # 0x8d9a
movb $0x0, %al
callq 0x10a0
movq 0x536b(%rip), %rdi      # 0xb318
movl 0x52d9(%rip), %edx      # 0xb28c
movl 0x52d7(%rip), %ecx      # 0xb290
leaq 0x2e07(%rip), %rsi      # 0x8dc7
movb $0x0, %al
callq 0x10a0
cmpq $0x0, 0x52f1(%rip)      # 0xb2c0
jbe 0x5ff2
movq 0x5340(%rip), %rdi      # 0xb318
movl 0x52ba(%rip), %edx      # 0xb298
movl 0x52b0(%rip), %ecx      # 0xb294
leaq 0x2e22(%rip), %rsi      # 0x8e0d
movb $0x0, %al
callq 0x10a0
jmp 0x5ff4
movq 0x5335(%rip), %rdi      # 0xb330
callq 0x1050
testb $0x1, 0x52fc(%rip)      # 0xb303
jne 0x6012
testb $0x1, 0x52f5(%rip)      # 0xb305
je 0x601e
movq 0x52ff(%rip), %rdi      # 0xb318
callq 0x1050
leaq 0x2e31(%rip), %rdi      # 0x8e56
movb $0x0, %al
callq 0x1070
movl $0x0, 0xf4(%rsp)
movl 0xf4(%rsp), %eax
addq $0xf8, %rsp
retq