// File: /workspace/github_cpp_makefile_star2_O3/mattdibi[P]Programmatore-JTAG-per-Xilinx/main.cpp
// Function: main
int main(int argc, char* argv[])
{
   Serial serialPort;
   ifstream svf_file(INPUT_FILE, fstream::in);
   unsigned ret;
   
   char buffer[BUFFER_SIZE];
   char* instruction_buffer;
   long int ib_length;

   bool manual_mode = false;
   bool verbose_mode = false;
   bool file_mode = false;
   bool help_mode = false;
   bool wrong_argument = false;

   ofstream outputFile;
   string fileName = "arduino_log.txt";

   string instruction, decodedInstruction, inputArduino, s, s_tmp;
   vector<string> instructionsFile, bitstream, decodedBitstream;

   if(argc >= 2)
   {
      if(!strcmp(argv[1], "-m"))
      {
            manual_mode = true;
            cout << "MANUAL MODE\n";
      }
      else if(!strcmp(argv[1], "-v"))
      {
            verbose_mode = true;
            cout << "VERBOSE MODE\n";
      }
      else if(!strcmp(argv[1], "-f"))
      {
            file_mode = true;
            cout << "FILE MODE\n";

            if(argc == 3)
                  fileName = argv[2];

            outputFile.open(fileName.c_str());
            outputFile << "Arduino output: \n\n";
            outputFile.close();
      }
      else if(!strcmp(argv[1], "-h"))
      {
            help_mode = true;
      }
      else
      {
            wrong_argument = true;
      }
   }
   try
   {
      serialPort.Open(DEVICE_PORT,115200);
      cout << "Porta seriale aperta con successo!\n";
      serialPort.FlushReceiver();

      if(wrong_argument)
      {
         cout << "\nArgomento non riconosciuto. Digita -h per aiuto.\n\n";
      }
      else if(manual_mode)
      {
         cout << "Modalità manuale.\n";
         cout << "Inserire comando da inviare (digitare 'quit' per uscire):";
         cin >> s;
         while(s != "quit")
         {
            s += '\n'; //richiesto dalla seriale
            serialPort.WriteString(s.c_str());

            cout << "Comando immesso: " << s;
            sleep(1);

            // Leggiamo da seriale
            serialPort.ReadString(buffer, '\n', BUFFER_SIZE, 5000);
            s = string(buffer);
            SanitizeInput(s);
            // Stampiamo risposta
            cout << endl << s << endl;

            cout << "Nuovo comando:";
            cin >> s;
         }
      }
      else if(help_mode)
      {
            cout << "\n******************************************************************************************************************************************************************\n";
            cout << "HELP  Modalità disponibili:\n";
            cout << "             - Modalità normale: prevede il minimo output su terminale possibile. Modalità di esecuzione standard.\n";
            cout << "-v           - Modalità verbosa: prevede un output su terminale più verboso durante l'upload del bitstream.\n";
            cout << "-f [fileName]- Modalità su file: prevede che l'output della modalità verbosa venga scritto su file. è possibile specificare il nome del file come terzo argomento.\n";
            cout << "-h           - Modalità di aiuto: stampa su terminale questo aiuto.\n";
            cout << "******************************************************************************************************************************************************************\n\n";
      }
      else
      {
         instructionsFile = ExtractInstruction(svf_file);

         cout << "Entrato nel ciclo for\n";
         
         for(long int i = 0; i < instructionsFile.size(); i++)
         {
            cout << "Stringa da file: " << instructionsFile[i] << endl;

            // Rileviamo se stiamo prendendo il bitstream
            if( isBitStreamInstruction(instructionsFile[i]) )
            {
                  // Estraiamo vettore di stringhe
                  bitstream = ExtractBitstream(instructionsFile,i);

                  // Decodifica del bitstream
                  decodedBitstream = GenerateBITSTREAMOutput(bitstream);

                  cout << "Upload bitstream in corso:\n";

                   // Ciclo di stampa sulla seriale
                  for(long int j = 0; j < decodedBitstream.size(); j++)
                  {     
                        decodedBitstream[j] += '\n'; //richiesto dalla seriale

                        // Printa l'istruzione decodificata
                        if(verbose_mode)
                              cout << "Decoded instruction[" << j << "/" << (decodedBitstream.size() - 1) << "]: " << decodedBitstream[j];

                        serialPort.WriteString(decodedBitstream[j].c_str());

                        // Leggiamo cosa risponde la seriale se la decodedInstruction è diversa da stringa vuota
                        if (decodedBitstream[j] != "\n")
                        {
                              // Ciclo di sincronizzazione
                              do {
                                    // Leggiamo da seriale
                                    ret = serialPort.ReadString(buffer,'\n', BUFFER_MAX_SIZE, 5000);
                                    s_tmp = string(buffer);
                                    SanitizeInput(s_tmp);

                                    // Ricaviamo la risposta dell'arduino
                                    inputArduino = ExtractAnswer(s_tmp);
                              } while (decodedBitstream[j].compare(inputArduino) != 1); // Continua finchè le stringhe non sono uguali
                        }

                        // Printa il progresso dell'upload
                        if(!verbose_mode)
                              cout << " Progresso: " << j << "/" << decodedBitstream.size()-1 << "\r" << flush;

                        // Printa la risposta dell'Arduino
                        if(verbose_mode)
                              cout << "Risposta arduino istruzione "<< j << "/" << (decodedBitstream.size() - 1) << ":\n<\n" << s_tmp << ">\n";
                        
                        if(file_mode)
                        {
                              outputFile.open(fileName.c_str(), ios::app);
                              outputFile << "Risposta arduino riga "<< j << "/" << (decodedBitstream.size() - 1) << "\n" << s_tmp;
                              outputFile.close();
                        }
                  }

                  cout << "\nUpload bitstream completato.";

                  // Aggiorniamo l'indice "i" in modo che salti tutto il bitstream nel vettore di stringhe
                  i += (bitstream.size() - 1);
            }
            else
            {
                  // Decodifica dell'istruzione
                  decodedInstruction = DecodeInstruction(instructionsFile[i]);

                  if (decodedInstruction != "")
                        cout << "Istruzione decodificata: " << decodedInstruction << endl;

                  decodedInstruction += '\n'; //richiesto dalla seriale

                  serialPort.WriteString(decodedInstruction.c_str());
                  sleep(1);
                  
                  // Leggiamo cosa risponde la seriale se la decodedInstruction è diversa da stringa vuota
                  if (decodedInstruction != "\n")
                  {
                        // Ciclo di sincronizzazione
                        do {
                              // Leggiamo da seriale
                              ret = serialPort.ReadString(buffer,'\n', BUFFER_MAX_SIZE, 5000);
                              s_tmp = string(buffer);
                              SanitizeInput(s_tmp);

                              // Ricaviamo la risposta dell'arduino
                              inputArduino = ExtractAnswer(s_tmp);
                        } while (decodedInstruction.compare(inputArduino) != 1); // Continua finchè le stringhe non sono uguali

                        // Printa la risposta dell'Arduino
                        cout << "Output seriale: " << endl << s_tmp << endl;
                  }
            }

         }
         cout << "Update completato" << endl;

         if(file_mode)
            cout << "File di log creato nella cartella. Controlla " << fileName << "!\n";
      }
   }
   catch(TimeoutException& e)
   {
      cout << "Timeout exception: " << e.what() << endl;
      serialPort.FlushReceiver();
      serialPort.Close();
      return EXIT_FAILURE;
   }
   catch(exception& e)
   {
      cout << "Standard exception: " << e.what() << endl;
      return EXIT_FAILURE;
   }
   serialPort.Close();
   return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1638, %rsp           # imm = 0x1638
movq %rsi, %rbx
movl %edi, %r14d
leaq -0x2c(%rbp), %rdi
callq 0x54d8
leaq 0x3a0a(%rip), %rsi      # 0x7020
leaq -0x658(%rbp), %rdi
movl $0x8, %edx
callq 0x33f0
leaq -0x450(%rbp), %rdi
callq 0x33b0
leaq -0x150(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x39e9(%rip), %rsi      # 0x702e
leaq 0x39f1(%rip), %rdx      # 0x703d
leaq -0x160(%rbp), %rdi
callq 0x514e
leaq -0x210(%rbp), %rax
movq %rax, -0x10(%rax)
xorl %r15d, %r15d
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq -0xf0(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq -0x170(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq -0xd0(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq -0x90(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
movq %r15, -0xb0(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xc0(%rbp)
movq %r15, -0x130(%rbp)
movaps %xmm0, -0x140(%rbp)
movq %r15, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, %r12d
movl $0x0, %r13d
cmpl $0x2, %r14d
jl 0x384a
movq 0x8(%rbx), %rax
cmpb $0x2d, (%rax)
jne 0x3741
cmpb $0x6d, 0x1(%rax)
jne 0x3715
cmpb $0x0, 0x2(%rax)
je 0x3761
cmpb $0x76, 0x1(%rax)
jne 0x3721
cmpb $0x0, 0x2(%rax)
je 0x3785
cmpb $0x66, 0x1(%rax)
jne 0x3731
cmpb $0x0, 0x2(%rax)
je 0x37b1
cmpb $0x68, 0x1(%rax)
jne 0x3741
cmpb $0x0, 0x2(%rax)
sete %r12b
jmp 0x3744
xorl %r12d, %r12d
movl %r12d, %r13d
xorb $0x1, %r13b
xorl %r15d, %r15d
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
jmp 0x384a
movq 0x6860(%rip), %rdi      # 0x9fc8
leaq 0x38cf(%rip), %rsi      # 0x703e
movl $0xc, %edx
callq 0x32a0
movb $0x1, %r15b
movl $0x0, -0x34(%rbp)
jmp 0x37a5
movq 0x683c(%rip), %rdi      # 0x9fc8
leaq 0x38b8(%rip), %rsi      # 0x704b
movl $0xd, %edx
callq 0x32a0
movb $0x1, %al
movl %eax, -0x34(%rbp)
xorl %r15d, %r15d
movl $0x0, -0x30(%rbp)
jmp 0x3844
movq 0x6810(%rip), %rdi      # 0x9fc8
leaq 0x389a(%rip), %rsi      # 0x7059
movl $0xa, %edx
callq 0x32a0
cmpl $0x3, %r14d
jne 0x37f9
movq 0x10(%rbx), %rbx
leaq -0x160(%rbp), %r14
movq 0x8(%r14), %r15
movq %rbx, %rdi
callq 0x30e0
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x3370
movq -0x160(%rbp), %rsi
leaq -0x450(%rbp), %rdi
movl $0x10, %edx
callq 0x3050
leaq 0x384c(%rip), %rsi      # 0x7064
leaq -0x450(%rbp), %rdi
movl $0x12, %edx
callq 0x32a0
leaq -0x450(%rbp), %rdi
callq 0x3300
movb $0x1, %al
movl %eax, -0x30(%rbp)
xorl %r15d, %r15d
movl $0x0, -0x34(%rbp)
xorl %r12d, %r12d
xorl %r13d, %r13d
leaq 0x3826(%rip), %rsi      # 0x7077
leaq -0x2c(%rbp), %rdi
movl $0x1c200, %edx          # imm = 0x1C200
callq 0x5500
movq 0x6762(%rip), %rbx      # 0x9fc8
leaq 0x3817(%rip), %rsi      # 0x7084
movl $0x23, %edx
movq %rbx, %rdi
callq 0x32a0
leaq -0x2c(%rbp), %rdi
callq 0x5b60
testb %r13b, %r13b
je 0x39f7
movl $0x33, %edx
leaq 0x3810(%rip), %rsi      # 0x70a8
movq %rbx, %rdi
callq 0x32a0
xorl %ebx, %ebx
leaq -0x2c(%rbp), %rdi
callq 0x54f4
leaq -0x50(%rbp), %rdi
callq 0x4f54
leaq -0x140(%rbp), %rdi
callq 0x4f54
leaq -0xc0(%rbp), %rdi
callq 0x4f54
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x38ee
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x3910
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x180(%rbp), %rdi
leaq -0x170(%rbp), %rax
cmpq %rax, %rdi
je 0x3932
movq -0x170(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
cmpq %rax, %rdi
je 0x3954
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x220(%rbp), %rdi
leaq -0x210(%rbp), %rax
cmpq %rax, %rdi
je 0x3976
movq -0x210(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x160(%rbp), %rdi
leaq -0x150(%rbp), %rax
cmpq %rax, %rdi
je 0x3998
movq -0x150(%rbp), %rsi
incq %rsi
callq 0x3250
movq 0x6619(%rip), %rax      # 0x9fb8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x448(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x450(%rbp,%rcx)
callq 0x31e0
leaq -0x358(%rbp), %rdi
callq 0x30a0
leaq -0x658(%rbp), %rdi
callq 0x3060
leaq -0x2c(%rbp), %rdi
callq 0x54de
movl %ebx, %eax
addq $0x1638, %rsp           # imm = 0x1638
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb %r15b, %r15b
je 0x3bdf
movq 0x65c1(%rip), %rdi      # 0x9fc8
leaq 0x36ce(%rip), %rsi      # 0x70dc
movl $0x13, %edx
callq 0x32a0
movq 0x65a9(%rip), %rbx      # 0x9fc8
leaq 0x36ca(%rip), %rsi      # 0x70f0
movl $0x39, %edx
movq %rbx, %rdi
callq 0x32a0
movq 0x659e(%rip), %rdi      # 0x9fd8
leaq -0xe0(%rbp), %rsi
callq 0x32e0
leaq -0xe0(%rbp), %r15
leaq -0x1660(%rbp), %r13
leaq -0x80(%rbp), %r14
movq %r15, %rdi
leaq 0x36c8(%rip), %rsi      # 0x712a
callq 0x3080
testl %eax, %eax
je 0x38a0
movq %r15, %rdi
movl $0xa, %esi
callq 0x31f0
movq -0xe0(%rbp), %rsi
leaq -0x2c(%rbp), %rdi
callq 0x5732
movl $0x11, %edx
movq %rbx, %rdi
leaq 0x3694(%rip), %rsi      # 0x712f
callq 0x32a0
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movq %rbx, %rdi
callq 0x32a0
movl $0x1, %edi
callq 0x31b0
leaq -0x2c(%rbp), %rdi
movq %r13, %rsi
movl $0xa, %edx
movl $0x1000, %ecx           # imm = 0x1000
movl $0x1388, %r8d           # imm = 0x1388
callq 0x5976
leaq -0x70(%rbp), %r12
movq %r12, -0x80(%rbp)
movq %r13, %rdi
callq 0x30e0
leaq (%rax,%rbp), %rdx
addq $-0x1660, %rdx          # imm = 0xE9A0
movq %r14, %rdi
movq %r13, %rsi
callq 0x514e
movq %r15, %rdi
movq %r14, %rsi
callq 0x32c0
movq -0x80(%rbp), %rdi
cmpq %r12, %rdi
je 0x3b22
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0xd8(%rbp), %rax
testq %rax, %rax
je 0x3b50
xorl %ecx, %ecx
movq -0xe0(%rbp), %rdx
cmpb $0x9, (%rdx,%rcx)
jne 0x3b48
movb $0xa, (%rdx,%rcx)
movq -0xd8(%rbp), %rax
incq %rcx
cmpq %rcx, %rax
ja 0x3b30
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3180
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movq %rax, %rdi
callq 0x32a0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3180
movl $0xe, %edx
movq %rbx, %rdi
leaq 0x357b(%rip), %rsi      # 0x7141
callq 0x32a0
movq 0x6406(%rip), %rdi      # 0x9fd8
movq %r15, %rsi
callq 0x32e0
jmp 0x3a58
testb %r12b, %r12b
je 0x3c88
movq 0x63d9(%rip), %rdi      # 0x9fc8
leaq 0x355a(%rip), %rsi      # 0x7150
movl $0xa4, %edx
callq 0x32a0
movq 0x63c1(%rip), %rdi      # 0x9fc8
leaq 0x35e7(%rip), %rsi      # 0x71f5
movl $0x1d, %edx
callq 0x32a0
movq 0x63a9(%rip), %rdi      # 0x9fc8
leaq 0x35ed(%rip), %rsi      # 0x7213
movl $0x75, %edx
callq 0x32a0
movq 0x6391(%rip), %rdi      # 0x9fc8
leaq 0x364b(%rip), %rsi      # 0x7289
movl $0x6e, %edx
callq 0x32a0
movq 0x6379(%rip), %rbx      # 0x9fc8
leaq 0x36a2(%rip), %rsi      # 0x72f8
movl $0xa6, %edx
movq %rbx, %rdi
callq 0x32a0
leaq 0x3735(%rip), %rsi      # 0x739f
movl $0x45, %edx
movq %rbx, %rdi
callq 0x32a0
movl $0xa4, %edx
leaq 0x3762(%rip), %rsi      # 0x73e5
jmp 0x3898
leaq -0x120(%rbp), %rdi
leaq -0x658(%rbp), %rsi
callq 0x4a5f
movaps -0xc0(%rbp), %xmm0
movq -0xb0(%rbp), %rax
leaq -0x120(%rbp), %rbx
movaps (%rbx), %xmm1
movaps %xmm1, -0xc0(%rbp)
movq 0x10(%rbx), %rcx
movq %rcx, -0xb0(%rbp)
leaq -0x80(%rbp), %rdi
movups %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
callq 0x4f54
movq %rbx, %rdi
callq 0x4f54
movq 0x62d6(%rip), %rdi      # 0x9fc8
leaq 0x3791(%rip), %rsi      # 0x748a
movl $0x16, %edx
callq 0x32a0
movq -0xb8(%rbp), %rax
cmpq -0xc0(%rbp), %rax
je 0x4691
leaq -0x70(%rbp), %r14
movq $0x0, -0x58(%rbp)
leaq -0x80(%rbp), %r13
leaq -0x1660(%rbp), %r15
movl $0x11, %edx
movq 0x628e(%rip), %rdi      # 0x9fc8
leaq 0x3760(%rip), %rsi      # 0x74a1
callq 0x32a0
movq -0xc0(%rbp), %rax
movq -0x58(%rbp), %r12
shlq $0x5, %r12
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
movq 0x6263(%rip), %rdi      # 0x9fc8
callq 0x32a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3180
movq -0xc0(%rbp), %rax
leaq -0x190(%rbp), %rcx
movq %rcx, -0x1a0(%rbp)
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
addq %rsi, %rdx
leaq -0x1a0(%rbp), %rdi
callq 0x50b0
leaq -0x1a0(%rbp), %rdi
callq 0x4ba0
movl %eax, %ebx
movq -0x1a0(%rbp), %rdi
leaq -0x190(%rbp), %rax
cmpq %rax, %rdi
je 0x3df1
movq -0x190(%rbp), %rsi
incq %rsi
callq 0x3250
testb %bl, %bl
je 0x433b
leaq -0x250(%rbp), %rbx
movq %rbx, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x4fc2
leaq -0x120(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq -0x58(%rbp), %rdx
callq 0x4ce7
movaps -0x140(%rbp), %xmm0
movq -0x130(%rbp), %rax
movaps -0x120(%rbp), %xmm1
movaps %xmm1, -0x140(%rbp)
movq -0x110(%rbp), %rcx
movq %rcx, -0x130(%rbp)
movups %xmm0, -0x80(%rbp)
movq %rax, -0x70(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x120(%rbp)
movq $0x0, -0x110(%rbp)
movq %r13, %rdi
callq 0x4f54
movq %r12, %rdi
callq 0x4f54
movq %rbx, %rdi
callq 0x4f54
leaq -0x238(%rbp), %rbx
movq %rbx, %rdi
leaq -0x140(%rbp), %rsi
callq 0x4fc2
movq %r12, %rdi
movq %rbx, %rsi
callq 0x68e8
movaps -0x50(%rbp), %xmm0
movq -0x40(%rbp), %rax
movaps -0x120(%rbp), %xmm1
movaps %xmm1, -0x50(%rbp)
movq -0x110(%rbp), %rcx
movq %rcx, -0x40(%rbp)
movups %xmm0, -0x80(%rbp)
movq %rax, -0x70(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x120(%rbp)
movq $0x0, -0x110(%rbp)
movq %r13, %rdi
callq 0x4f54
movq %r12, %rdi
callq 0x4f54
movq %rbx, %rdi
callq 0x4f54
movl $0x1b, %edx
movq 0x60c4(%rip), %rdi      # 0x9fc8
leaq 0x35a8(%rip), %rsi      # 0x74b3
callq 0x32a0
movq -0x50(%rbp), %rdi
cmpq %rdi, -0x48(%rbp)
je 0x42fe
xorl %r12d, %r12d
movq %r12, -0x60(%rbp)
shlq $0x5, %r12
addq %r12, %rdi
movl $0xa, %esi
callq 0x31f0
cmpb $0x0, -0x34(%rbp)
je 0x3fc2
movl $0x14, %edx
movq 0x607c(%rip), %rdi      # 0x9fc8
leaq 0x357c(%rip), %rsi      # 0x74cf
callq 0x32a0
movq 0x6069(%rip), %rdi      # 0x9fc8
movq -0x60(%rbp), %rsi
callq 0x3210
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x356a(%rip), %rsi      # 0x74e4
callq 0x32a0
movq -0x48(%rbp), %rsi
subq -0x50(%rbp), %rsi
sarq $0x5, %rsi
decq %rsi
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x353e(%rip), %rsi      # 0x74e6
callq 0x32a0
movq -0x50(%rbp), %rax
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
movq %rbx, %rdi
callq 0x32a0
movq -0x50(%rbp), %rax
movq (%rax,%r12), %rsi
leaq -0x2c(%rbp), %rdi
callq 0x5732
movq -0x50(%rbp), %rdi
addq %r12, %rdi
leaq 0x3094(%rip), %rsi      # 0x7075
callq 0x3080
testl %eax, %eax
je 0x4116
leaq -0x2c(%rbp), %rdi
movq %r15, %rsi
movl $0xa, %edx
movl $0xbebc200, %ecx        # imm = 0xBEBC200
movl $0x1388, %r8d           # imm = 0x1388
callq 0x5976
movq %r14, -0x80(%rbp)
movq %r15, %rdi
callq 0x30e0
leaq (%rax,%rbp), %rdx
addq $-0x1660, %rdx          # imm = 0xE9A0
movq %r13, %rdi
movq %r15, %rsi
callq 0x514e
leaq -0xa0(%rbp), %rdi
movq %r13, %rsi
callq 0x32c0
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x4050
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x98(%rbp), %rdx
testq %rdx, %rdx
je 0x4080
xorl %eax, %eax
movq -0xa0(%rbp), %rcx
cmpb $0x9, (%rcx,%rax)
jne 0x4076
movb $0xa, (%rcx,%rax)
movq -0x98(%rbp), %rdx
incq %rax
cmpq %rax, %rdx
ja 0x405e
jmp 0x4082
xorl %edx, %edx
leaq -0x1f0(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0xa0(%rbp), %rsi
addq %rsi, %rdx
leaq -0x200(%rbp), %rbx
movq %rbx, %rdi
callq 0x50b0
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4e68
leaq -0x180(%rbp), %rdi
movq %r13, %rsi
callq 0x32c0
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x40d8
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x200(%rbp), %rdi
leaq -0x1f0(%rbp), %rax
cmpq %rax, %rdi
je 0x40fa
movq -0x1f0(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x50(%rbp), %rdi
addq %r12, %rdi
leaq -0x180(%rbp), %rsi
callq 0x3040
cmpl $0x1, %eax
jne 0x3fee
cmpb $0x0, -0x34(%rbp)
je 0x41b9
movl $0x1c, %edx
movq 0x5e9c(%rip), %rdi      # 0x9fc8
leaq 0x33c6(%rip), %rsi      # 0x74f9
callq 0x32a0
movq 0x5e89(%rip), %rdi      # 0x9fc8
movq -0x60(%rbp), %rsi
callq 0x3210
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x338a(%rip), %rsi      # 0x74e4
callq 0x32a0
movq -0x48(%rbp), %rsi
subq -0x50(%rbp), %rsi
sarq $0x5, %rsi
decq %rsi
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
movl $0x4, %edx
movq %rax, %rdi
leaq 0x338e(%rip), %rsi      # 0x7516
callq 0x32a0
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq %rbx, %rdi
callq 0x32a0
movl $0x2, %edx
movq %rax, %rdi
leaq 0x3369(%rip), %rsi      # 0x751b
callq 0x32a0
jmp 0x422e
movl $0xc, %edx
movq 0x5e03(%rip), %rdi      # 0x9fc8
leaq 0x331e(%rip), %rsi      # 0x74ea
callq 0x32a0
movq 0x5df0(%rip), %rdi      # 0x9fc8
movq -0x60(%rbp), %rsi
callq 0x3210
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x32f1(%rip), %rsi      # 0x74e4
callq 0x32a0
movq -0x48(%rbp), %rsi
subq -0x50(%rbp), %rsi
sarq $0x5, %rsi
decq %rsi
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x32d6(%rip), %rsi      # 0x74f7
callq 0x32a0
movq %rbx, %rdi
callq 0x3180
cmpb $0x0, -0x30(%rbp)
je 0x42df
movq -0x160(%rbp), %rsi
leaq -0x450(%rbp), %rdi
movl $0x1, %edx
callq 0x3050
movl $0x16, %edx
leaq -0x450(%rbp), %rdi
leaq 0x32bb(%rip), %rsi      # 0x751e
callq 0x32a0
leaq -0x450(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x3210
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x325a(%rip), %rsi      # 0x74e4
callq 0x32a0
movq -0x48(%rbp), %rsi
subq -0x50(%rbp), %rsi
sarq $0x5, %rsi
decq %rsi
movq %rbx, %rdi
callq 0x3170
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2dbd(%rip), %rsi      # 0x7075
callq 0x32a0
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq %rbx, %rdi
callq 0x32a0
leaq -0x450(%rbp), %rdi
callq 0x3300
movq -0x60(%rbp), %r12
incq %r12
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %rax, %r12
jb 0x3f21
movl $0x1d, %edx
movq 0x5cbe(%rip), %rdi      # 0x9fc8
leaq 0x3224(%rip), %rsi      # 0x7535
callq 0x32a0
movq -0x138(%rbp), %rax
subq -0x140(%rbp), %rax
sarq $0x5, %rax
movq -0x58(%rbp), %rcx
addq %rax, %rcx
decq %rcx
movq %rcx, -0x58(%rbp)
jmp 0x466b
movq -0xc0(%rbp), %rax
leaq -0x1d0(%rbp), %rcx
movq %rcx, -0x1e0(%rbp)
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
addq %rsi, %rdx
leaq -0x1e0(%rbp), %rbx
movq %rbx, %rdi
callq 0x50b0
movq %r13, %rdi
movq %rbx, %rsi
callq 0x5cc0
leaq -0x100(%rbp), %rdi
movq %r13, %rsi
callq 0x32c0
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x439a
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x1e0(%rbp), %rdi
leaq -0x1d0(%rbp), %rax
cmpq %rax, %rdi
je 0x43bc
movq -0x1d0(%rbp), %rsi
incq %rsi
callq 0x3250
leaq -0x100(%rbp), %rdi
leaq 0x2cac(%rip), %rsi      # 0x7076
callq 0x3080
testl %eax, %eax
je 0x442f
movl $0x19, %edx
movq 0x5be9(%rip), %rdi      # 0x9fc8
leaq 0x316d(%rip), %rsi      # 0x7553
callq 0x32a0
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rdx
movq 0x5bc8(%rip), %rdi      # 0x9fc8
callq 0x32a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3180
leaq -0x100(%rbp), %rdi
movl $0xa, %esi
callq 0x31f0
movq -0x100(%rbp), %rsi
leaq -0x2c(%rbp), %rdi
callq 0x5732
movl $0x1, %edi
callq 0x31b0
leaq -0x100(%rbp), %rdi
leaq 0x2c0d(%rip), %rsi      # 0x7075
callq 0x3080
testl %eax, %eax
je 0x466b
leaq -0x2c(%rbp), %rdi
movq %r15, %rsi
movl $0xa, %edx
movl $0xbebc200, %ecx        # imm = 0xBEBC200
movl $0x1388, %r8d           # imm = 0x1388
callq 0x5976
movq %r14, -0x80(%rbp)
movq %r15, %rdi
callq 0x30e0
leaq (%rax,%rbp), %rdx
addq $-0x1660, %rdx          # imm = 0xE9A0
movq %r13, %rdi
movq %r15, %rsi
callq 0x514e
leaq -0xa0(%rbp), %rdi
movq %r13, %rsi
callq 0x32c0
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x44d7
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x98(%rbp), %rdx
testq %rdx, %rdx
je 0x4507
xorl %eax, %eax
movq -0xa0(%rbp), %rcx
cmpb $0x9, (%rcx,%rax)
jne 0x44fd
movb $0xa, (%rcx,%rax)
movq -0x98(%rbp), %rdx
incq %rax
cmpq %rax, %rdx
ja 0x44e5
jmp 0x4509
xorl %edx, %edx
leaq -0x1b0(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq -0xa0(%rbp), %rsi
addq %rsi, %rdx
leaq -0x1c0(%rbp), %rbx
movq %rbx, %rdi
callq 0x50b0
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4e68
leaq -0x180(%rbp), %rdi
movq %r13, %rsi
callq 0x32c0
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x455f
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x1c0(%rbp), %rdi
leaq -0x1b0(%rbp), %rax
cmpq %rax, %rdi
je 0x4581
movq -0x1b0(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0xf8(%rbp), %rbx
movq -0x178(%rbp), %r12
cmpq %rbx, %r12
movq %rbx, %rdx
cmovbq %r12, %rdx
testq %rdx, %rdx
je 0x45b5
movq -0x180(%rbp), %rsi
movq -0x100(%rbp), %rdi
callq 0x30f0
testl %eax, %eax
jne 0x45d8
subq %r12, %rbx
cmpq $-0x7fffffff, %rbx      # imm = 0x80000001
movq $-0x80000000, %rax      # imm = 0x80000000
cmovlq %rax, %rbx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rbx
cmovgeq %rax, %rbx
movl %ebx, %eax
cmpl $0x1, %eax
jne 0x4475
movl $0x10, %edx
movq 0x59db(%rip), %rdi      # 0x9fc8
leaq 0x2f79(%rip), %rsi      # 0x756d
callq 0x32a0
movq 0x59c8(%rip), %rcx      # 0x9fc8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq 0x59aa(%rip), %rdi      # 0x9fc8
callq 0x3030
movq %rax, %rdi
callq 0x3180
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq %rax, %rdi
callq 0x32a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3180
movq -0x58(%rbp), %rdx
incq %rdx
movq -0xb8(%rbp), %rax
subq -0xc0(%rbp), %rax
sarq $0x5, %rax
movq %rdx, -0x58(%rbp)
cmpq %rax, %rdx
jb 0x3d2e
movq 0x5930(%rip), %rbx      # 0x9fc8
leaq 0x2edf(%rip), %rsi      # 0x757e
movl $0x11, %edx
movq %rbx, %rdi
callq 0x32a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq 0x58fe(%rip), %rdi      # 0x9fc8
callq 0x3030
movq %rax, %rdi
callq 0x3180
cmpb $0x0, -0x30(%rbp)
je 0x38a0
movq 0x58e0(%rip), %rdi      # 0x9fc8
leaq 0x2ea1(%rip), %rsi      # 0x7590
movl $0x2d, %edx
callq 0x32a0
movq -0x160(%rbp), %rsi
movq -0x158(%rbp), %rdx
movq 0x58ba(%rip), %rdi      # 0x9fc8
callq 0x32a0
movq %rax, %rbx
movl $0x2, %edx
leaq 0x2983(%rip), %rsi      # 0x70a5
jmp 0x3898
jmp 0x493d
movq %rax, %rbx
jmp 0x4892
movq %rax, %rbx
jmp 0x489e
movq %rax, %rbx
jmp 0x48aa
movq %rdx, %r14
movq %rax, %rbx
leaq -0x250(%rbp), %rdi
jmp 0x4760
movq %rdx, %r14
movq %rax, %rbx
leaq -0x238(%rbp), %rdi
callq 0x4f54
jmp 0x4943
movq %rdx, %r14
movq %rax, %rbx
movq -0x1e0(%rbp), %rdi
leaq -0x1d0(%rbp), %rax
cmpq %rax, %rdi
je 0x4943
movq -0x1d0(%rbp), %rsi
jmp 0x4933
jmp 0x493d
jmp 0x493d
jmp 0x493d
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x4f54
leaq -0x140(%rbp), %rdi
callq 0x4f54
leaq -0xc0(%rbp), %rdi
callq 0x4f54
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x47e8
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x480a
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x180(%rbp), %rdi
leaq -0x170(%rbp), %rax
cmpq %rax, %rdi
je 0x482c
movq -0x170(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
cmpq %rax, %rdi
je 0x484e
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x220(%rbp), %rdi
leaq -0x210(%rbp), %rax
cmpq %rax, %rdi
je 0x4870
movq -0x210(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x160(%rbp), %rdi
leaq -0x150(%rbp), %rax
cmpq %rax, %rdi
je 0x4892
movq -0x150(%rbp), %rsi
incq %rsi
callq 0x3250
leaq -0x450(%rbp), %rdi
callq 0x3340
leaq -0x658(%rbp), %rdi
callq 0x3060
leaq -0x2c(%rbp), %rdi
callq 0x54de
movq %rbx, %rdi
callq 0x33d0
movq %rdx, %r14
movq %rax, %rbx
movq -0x1a0(%rbp), %rdi
leaq -0x190(%rbp), %rax
cmpq %rax, %rdi
je 0x4943
movq -0x190(%rbp), %rsi
jmp 0x4933
jmp 0x493d
jmp 0x493d
jmp 0x493d
jmp 0x493d
movq %rdx, %r14
movq %rax, %rbx
movq -0x1c0(%rbp), %rdi
leaq -0x1b0(%rbp), %rax
cmpq %rax, %rdi
je 0x4943
movq -0x1b0(%rbp), %rsi
jmp 0x4933
jmp 0x493d
jmp 0x493d
jmp 0x493d
jmp 0x493d
jmp 0x493d
jmp 0x493d
movq %rdx, %r14
movq %rax, %rbx
movq -0x200(%rbp), %rdi
leaq -0x1f0(%rbp), %rax
cmpq %rax, %rdi
je 0x4943
movq -0x1f0(%rbp), %rsi
incq %rsi
callq 0x3250
jmp 0x4943
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x2, %r14d
jne 0x49ad
movq %rbx, %rdi
callq 0x30d0
movq %rax, %rbx
movq 0x566d(%rip), %rdi      # 0x9fc8
leaq 0x2c71(%rip), %rsi      # 0x75d3
movl $0x13, %edx
callq 0x32a0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x564c(%rip), %rdi      # 0x9fc8
movq %rax, %rsi
callq 0x3230
movq %rax, %rdi
callq 0x3100
leaq -0x2c(%rbp), %rdi
callq 0x5b60
leaq -0x2c(%rbp), %rdi
callq 0x54f4
movl $0x1, %ebx
callq 0x3390
jmp 0x38ab
cmpl $0x1, %r14d
jne 0x47a5
movq %rbx, %rdi
callq 0x30d0
movq %rax, %rbx
movq 0x55ff(%rip), %rdi      # 0x9fc8
leaq 0x2bee(%rip), %rsi      # 0x75be
movl $0x14, %edx
callq 0x32a0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x55de(%rip), %rdi      # 0x9fc8
movq %rax, %rsi
callq 0x3230
movq %rax, %rdi
callq 0x3100
movl $0x1, %ebx
callq 0x3390
jmp 0x38ab
jmp 0x47a2
jmp 0x47a2
movq %rax, %rbx
callq 0x3390
jmp 0x47a5
movq %rax, %rbx
callq 0x3390
jmp 0x47a5
movq %rax, %rdi
callq 0x5056