// File: 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
subq $0x1950, %rsp           # imm = 0x1950
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x14(%rbp), %rdi
callq 0x6c30
leaq 0x68cb(%rip), %rsi      # 0xa004
leaq -0x220(%rbp), %rdi
movl $0x8, %edx
callq 0x34e0
jmp 0x374c
movb $0x0, -0x1241(%rbp)
movb $0x0, -0x1242(%rbp)
movb $0x0, -0x1243(%rbp)
movb $0x0, -0x1244(%rbp)
movb $0x0, -0x1245(%rbp)
leaq -0x1448(%rbp), %rdi
callq 0x3480
jmp 0x377d
leaq -0x1469(%rbp), %rdi
movq %rdi, -0x1758(%rbp)
callq 0x34b0
movq -0x1758(%rbp), %rdx
leaq 0x6874(%rip), %rsi      # 0xa012
leaq -0x1468(%rbp), %rdi
callq 0x54b0
jmp 0x37ac
leaq -0x1469(%rbp), %rdi
callq 0x32e0
leaq -0x1490(%rbp), %rdi
callq 0x33a0
leaq -0x14b0(%rbp), %rdi
callq 0x33a0
leaq -0x14d0(%rbp), %rdi
callq 0x33a0
leaq -0x14f0(%rbp), %rdi
callq 0x33a0
leaq -0x1510(%rbp), %rdi
callq 0x33a0
leaq -0x1528(%rbp), %rdi
callq 0x5560
leaq -0x1540(%rbp), %rdi
callq 0x5560
leaq -0x1558(%rbp), %rdi
callq 0x5560
cmpl $0x2, -0x8(%rbp)
jl 0x39d1
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x67f1(%rip), %rsi      # 0xa022
callq 0x33b0
cmpl $0x0, %eax
jne 0x38c8
movb $0x1, -0x1241(%rbp)
movq 0xa77b(%rip), %rdi      # 0xdfc8
leaq 0x67d1(%rip), %rsi      # 0xa025
callq 0x3280
jmp 0x385b
jmp 0x39cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x4c10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x4c04
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x1469(%rbp), %rdi
callq 0x32e0
jmp 0x4bf8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x4b8c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x675b(%rip), %rsi      # 0xa032
callq 0x33b0
cmpl $0x0, %eax
jne 0x3902
movb $0x1, -0x1242(%rbp)
movq 0xa6d9(%rip), %rdi      # 0xdfc8
leaq 0x673f(%rip), %rsi      # 0xa035
callq 0x3280
jmp 0x38fd
jmp 0x39cd
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6732(%rip), %rsi      # 0xa043
callq 0x33b0
cmpl $0x0, %eax
jne 0x39a0
movb $0x1, -0x1243(%rbp)
movq 0xa69b(%rip), %rdi      # 0xdfc8
leaq 0x6712(%rip), %rsi      # 0xa046
callq 0x3280
jmp 0x393b
cmpl $0x3, -0x8(%rbp)
jne 0x3959
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0x1468(%rbp), %rdi
callq 0x3390
jmp 0x3957
jmp 0x3959
leaq -0x1468(%rbp), %rdi
callq 0x30d0
movq %rax, %rsi
leaq -0x1448(%rbp), %rdi
movl $0x10, %edx
callq 0x3040
jmp 0x397b
leaq 0x66cf(%rip), %rsi      # 0xa051
leaq -0x1448(%rbp), %rdi
callq 0x3280
jmp 0x3990
leaq -0x1448(%rbp), %rdi
callq 0x33d0
jmp 0x399e
jmp 0x39cb
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x66b5(%rip), %rsi      # 0xa064
callq 0x33b0
cmpl $0x0, %eax
jne 0x39c2
movb $0x1, -0x1244(%rbp)
jmp 0x39c9
movb $0x1, -0x1245(%rbp)
jmp 0x39cb
jmp 0x39cd
jmp 0x39cf
jmp 0x39d1
leaq 0x668f(%rip), %rsi      # 0xa067
leaq -0x14(%rbp), %rdi
movl $0x1c200, %edx          # imm = 0x1C200
callq 0x6c90
jmp 0x39e8
movq 0xa5d9(%rip), %rdi      # 0xdfc8
leaq 0x667e(%rip), %rsi      # 0xa074
callq 0x3280
jmp 0x39fd
leaq -0x14(%rbp), %rdi
callq 0x7630
jmp 0x3a08
testb $0x1, -0x1245(%rbp)
je 0x3a42
movq 0xa5b0(%rip), %rdi      # 0xdfc8
leaq 0x6679(%rip), %rsi      # 0xa098
callq 0x3280
jmp 0x3a26
jmp 0x4a95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x489b
testb $0x1, -0x1241(%rbp)
je 0x3c60
movq 0xa572(%rip), %rdi      # 0xdfc8
leaq 0x666f(%rip), %rsi      # 0xa0cc
callq 0x3280
jmp 0x3a64
movq 0xa55d(%rip), %rdi      # 0xdfc8
leaq 0x666e(%rip), %rsi      # 0xa0e0
callq 0x3280
jmp 0x3a79
movq 0xa560(%rip), %rdi      # 0xdfe0
leaq -0x14f0(%rbp), %rsi
callq 0x3370
jmp 0x3a8e
jmp 0x3a90
leaq 0x6683(%rip), %rsi      # 0xa11a
leaq -0x14f0(%rbp), %rdi
callq 0x5580
movb %al, -0x1759(%rbp)
jmp 0x3aab
movb -0x1759(%rbp), %al
testb $0x1, %al
jne 0x3aba
jmp 0x3c5b
leaq -0x14f0(%rbp), %rdi
movl $0xa, %esi
callq 0x31a0
jmp 0x3acd
leaq -0x14f0(%rbp), %rdi
callq 0x30d0
movq %rax, %rsi
leaq -0x14(%rbp), %rdi
callq 0x6f30
jmp 0x3ae7
movq 0xa4da(%rip), %rdi      # 0xdfc8
leaq 0x662a(%rip), %rsi      # 0xa11f
callq 0x3280
movq %rax, -0x1768(%rbp)
jmp 0x3b03
movq -0x1768(%rbp), %rdi
leaq -0x14f0(%rbp), %rsi
callq 0x3250
jmp 0x3b18
movl $0x1, %edi
callq 0x3200
jmp 0x3b24
leaq -0x14(%rbp), %rdi
leaq -0x1230(%rbp), %rsi
movl $0xa, %edx
movl $0x1000, %ecx           # imm = 0x1000
movl $0x1388, %r8d           # imm = 0x1388
callq 0x7320
jmp 0x3b46
leaq -0x1579(%rbp), %rdi
movq %rdi, -0x1770(%rbp)
callq 0x34b0
movq -0x1770(%rbp), %rdx
leaq -0x1578(%rbp), %rdi
leaq -0x1230(%rbp), %rsi
callq 0x54b0
jmp 0x3b75
leaq -0x14f0(%rbp), %rdi
movq %rdi, -0x1778(%rbp)
leaq -0x1578(%rbp), %rsi
movq %rsi, -0x1780(%rbp)
callq 0x3340
movq -0x1780(%rbp), %rdi
callq 0x3190
leaq -0x1579(%rbp), %rdi
callq 0x32e0
movq -0x1778(%rbp), %rdi
callq 0x4c30
jmp 0x3bbc
movq 0xa405(%rip), %rdi      # 0xdfc8
movq 0xa3e6(%rip), %rsi      # 0xdfb0
callq 0x32c0
movq %rax, -0x1788(%rbp)
jmp 0x3bd8
movq -0x1788(%rbp), %rdi
leaq -0x14f0(%rbp), %rsi
callq 0x3250
movq %rax, -0x1790(%rbp)
jmp 0x3bf4
movq -0x1790(%rbp), %rdi
movq 0xa3ae(%rip), %rsi      # 0xdfb0
callq 0x32c0
jmp 0x3c09
movq 0xa3b8(%rip), %rdi      # 0xdfc8
leaq 0x651a(%rip), %rsi      # 0xa131
callq 0x3280
jmp 0x3c1e
movq 0xa3bb(%rip), %rdi      # 0xdfe0
leaq -0x14f0(%rbp), %rsi
callq 0x3370
jmp 0x3c33
jmp 0x3a90
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x1579(%rbp), %rdi
callq 0x32e0
jmp 0x489b
jmp 0x4a93
testb $0x1, -0x1244(%rbp)
je 0x3d05
movq 0xa354(%rip), %rdi      # 0xdfc8
leaq 0x64c5(%rip), %rsi      # 0xa140
callq 0x3280
jmp 0x3c82
movq 0xa33f(%rip), %rdi      # 0xdfc8
leaq 0x6555(%rip), %rsi      # 0xa1e5
callq 0x3280
jmp 0x3c97
movq 0xa32a(%rip), %rdi      # 0xdfc8
leaq 0x655e(%rip), %rsi      # 0xa203
callq 0x3280
jmp 0x3cac
movq 0xa315(%rip), %rdi      # 0xdfc8
leaq 0x65bf(%rip), %rsi      # 0xa279
callq 0x3280
jmp 0x3cc1
movq 0xa300(%rip), %rdi      # 0xdfc8
leaq 0x6619(%rip), %rsi      # 0xa2e8
callq 0x3280
jmp 0x3cd6
movq 0xa2eb(%rip), %rdi      # 0xdfc8
leaq 0x66ab(%rip), %rsi      # 0xa38f
callq 0x3280
jmp 0x3ceb
movq 0xa2d6(%rip), %rdi      # 0xdfc8
leaq 0x66dc(%rip), %rsi      # 0xa3d5
callq 0x3280
jmp 0x3d00
jmp 0x4a91
leaq -0x1598(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x4ca0
jmp 0x3d1a
leaq -0x1528(%rbp), %rdi
leaq -0x1598(%rbp), %rsi
movq %rsi, -0x1798(%rbp)
callq 0x55b0
movq -0x1798(%rbp), %rdi
callq 0x55e0
movq 0xa281(%rip), %rdi      # 0xdfc8
leaq 0x672c(%rip), %rsi      # 0xa47a
callq 0x3280
jmp 0x3d55
movq $0x0, -0x15a0(%rbp)
movq -0x15a0(%rbp), %rax
movq %rax, -0x17a0(%rbp)
leaq -0x1528(%rbp), %rdi
callq 0x5640
movq %rax, %rcx
movq -0x17a0(%rbp), %rax
cmpq %rcx, %rax
jae 0x4a06
movq 0xa234(%rip), %rdi      # 0xdfc8
leaq 0x66f6(%rip), %rsi      # 0xa491
callq 0x3280
movq %rax, -0x17a8(%rbp)
jmp 0x3da9
movq -0x15a0(%rbp), %rsi
leaq -0x1528(%rbp), %rdi
callq 0x5660
movq -0x17a8(%rbp), %rdi
movq %rax, %rsi
callq 0x3250
movq %rax, -0x17b0(%rbp)
jmp 0x3dd4
movq -0x17b0(%rbp), %rdi
movq 0xa1ce(%rip), %rsi      # 0xdfb0
callq 0x32c0
jmp 0x3de9
movq -0x15a0(%rbp), %rsi
leaq -0x1528(%rbp), %rdi
callq 0x5660
movq %rax, %rsi
leaq -0x15c0(%rbp), %rdi
callq 0x30e0
jmp 0x3e0d
leaq -0x15c0(%rbp), %rdi
callq 0x4ee0
movb %al, -0x17b1(%rbp)
jmp 0x3e21
leaq -0x15c0(%rbp), %rdi
callq 0x3190
movb -0x17b1(%rbp), %al
testb $0x1, %al
jne 0x3e3c
jmp 0x4556
leaq -0x15f0(%rbp), %rdi
leaq -0x1528(%rbp), %rsi
callq 0x5680
jmp 0x3e51
movq -0x15a0(%rbp), %rdx
leaq -0x15d8(%rbp), %rdi
leaq -0x15f0(%rbp), %rsi
callq 0x5050
jmp 0x3e6d
leaq -0x1540(%rbp), %rdi
movq %rdi, -0x17c0(%rbp)
leaq -0x15d8(%rbp), %rsi
movq %rsi, -0x17c8(%rbp)
callq 0x55b0
movq -0x17c8(%rbp), %rdi
callq 0x55e0
leaq -0x15f0(%rbp), %rdi
callq 0x55e0
movq -0x17c0(%rbp), %rsi
leaq -0x1620(%rbp), %rdi
callq 0x5680
jmp 0x3ebb
leaq -0x1608(%rbp), %rdi
leaq -0x1620(%rbp), %rsi
callq 0x8f80
jmp 0x3ed0
leaq -0x1558(%rbp), %rdi
leaq -0x1608(%rbp), %rsi
movq %rsi, -0x17d0(%rbp)
callq 0x55b0
movq -0x17d0(%rbp), %rdi
callq 0x55e0
leaq -0x1620(%rbp), %rdi
callq 0x55e0
movq 0xa0bf(%rip), %rdi      # 0xdfc8
leaq 0x6593(%rip), %rsi      # 0xa4a3
callq 0x3280
jmp 0x3f17
movq $0x0, -0x1628(%rbp)
movq -0x1628(%rbp), %rax
movq %rax, -0x17d8(%rbp)
leaq -0x1558(%rbp), %rdi
callq 0x5640
movq %rax, %rcx
movq -0x17d8(%rbp), %rax
cmpq %rcx, %rax
jae 0x451e
movq -0x1628(%rbp), %rsi
leaq -0x1558(%rbp), %rdi
callq 0x5660
movq %rax, %rdi
movl $0xa, %esi
callq 0x31a0
jmp 0x3f71
testb $0x1, -0x1242(%rbp)
je 0x40a4
movq 0xa043(%rip), %rdi      # 0xdfc8
leaq 0x6533(%rip), %rsi      # 0xa4bf
callq 0x3280
movq %rax, -0x17e0(%rbp)
jmp 0x3f9a
movq -0x17e0(%rbp), %rdi
movq -0x1628(%rbp), %rsi
callq 0x34d0
movq %rax, -0x17e8(%rbp)
jmp 0x3fb6
movq -0x17e8(%rbp), %rdi
leaq 0x6510(%rip), %rsi      # 0xa4d4
callq 0x3280
movq %rax, -0x17f0(%rbp)
jmp 0x3fd2
leaq -0x1558(%rbp), %rdi
callq 0x5640
movq -0x17f0(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x3060
movq %rax, -0x17f8(%rbp)
jmp 0x3ff9
movq -0x17f8(%rbp), %rdi
leaq 0x64cf(%rip), %rsi      # 0xa4d6
callq 0x3280
movq %rax, -0x1800(%rbp)
jmp 0x4015
movq -0x1628(%rbp), %rsi
leaq -0x1558(%rbp), %rdi
callq 0x5660
movq -0x1800(%rbp), %rdi
movq %rax, %rsi
callq 0x3250
jmp 0x4039
jmp 0x40a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x15c0(%rbp), %rdi
callq 0x3190
jmp 0x489b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x15f0(%rbp), %rdi
callq 0x55e0
jmp 0x489b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x1620(%rbp), %rdi
callq 0x55e0
jmp 0x489b
movq -0x1628(%rbp), %rsi
leaq -0x1558(%rbp), %rdi
callq 0x5660
movq %rax, %rdi
callq 0x30d0
movq %rax, %rsi
leaq -0x14(%rbp), %rdi
callq 0x6f30
jmp 0x40cd
movq -0x1628(%rbp), %rsi
leaq -0x1558(%rbp), %rdi
callq 0x5660
movq %rax, %rdi
leaq 0x5f78(%rip), %rsi      # 0xa062
callq 0x5580
movb %al, -0x1801(%rbp)
jmp 0x40f7
movb -0x1801(%rbp), %al
testb $0x1, %al
jne 0x4106
jmp 0x4288
jmp 0x4108
leaq -0x14(%rbp), %rdi
leaq -0x1230(%rbp), %rsi
movl $0xa, %edx
movl $0xbebc200, %ecx        # imm = 0xBEBC200
movl $0x1388, %r8d           # imm = 0x1388
callq 0x7320
movl %eax, -0x1808(%rbp)
jmp 0x4130
movl -0x1808(%rbp), %eax
movl %eax, -0x230(%rbp)
leaq -0x1649(%rbp), %rdi
movq %rdi, -0x1810(%rbp)
callq 0x34b0
movq -0x1810(%rbp), %rdx
leaq -0x1648(%rbp), %rdi
leaq -0x1230(%rbp), %rsi
callq 0x54b0
jmp 0x416b
leaq -0x1510(%rbp), %rdi
movq %rdi, -0x1818(%rbp)
leaq -0x1648(%rbp), %rsi
movq %rsi, -0x1820(%rbp)
callq 0x3340
movq -0x1820(%rbp), %rdi
callq 0x3190
leaq -0x1649(%rbp), %rdi
callq 0x32e0
movq -0x1818(%rbp), %rdi
callq 0x4c30
jmp 0x41b2
leaq -0x1690(%rbp), %rdi
leaq -0x1510(%rbp), %rsi
callq 0x30e0
jmp 0x41c7
leaq -0x1670(%rbp), %rdi
leaq -0x1690(%rbp), %rsi
callq 0x5360
jmp 0x41dc
leaq -0x14d0(%rbp), %rdi
leaq -0x1670(%rbp), %rsi
callq 0x3340
leaq -0x1670(%rbp), %rdi
callq 0x3190
leaq -0x1690(%rbp), %rdi
callq 0x3190
movq -0x1628(%rbp), %rsi
leaq -0x1558(%rbp), %rdi
callq 0x5660
movq %rax, %rdi
leaq -0x14d0(%rbp), %rsi
callq 0x3030
movl %eax, -0x1824(%rbp)
jmp 0x4231
movl -0x1824(%rbp), %eax
cmpl $0x1, %eax
jne 0x4108
jmp 0x4288
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x1649(%rbp), %rdi
callq 0x32e0
jmp 0x489b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x1690(%rbp), %rdi
callq 0x3190
jmp 0x489b
testb $0x1, -0x1242(%rbp)
jne 0x4343
movq 0x9d2c(%rip), %rdi      # 0xdfc8
leaq 0x6237(%rip), %rsi      # 0xa4da
callq 0x3280
movq %rax, -0x1830(%rbp)
jmp 0x42b1
movq -0x1830(%rbp), %rdi
movq -0x1628(%rbp), %rsi
callq 0x34d0
movq %rax, -0x1838(%rbp)
jmp 0x42cd
movq -0x1838(%rbp), %rdi
leaq 0x61f9(%rip), %rsi      # 0xa4d4
callq 0x3280
movq %rax, -0x1840(%rbp)
jmp 0x42e9
leaq -0x1558(%rbp), %rdi
callq 0x5640
movq -0x1840(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x3060
movq %rax, -0x1848(%rbp)
jmp 0x4310
movq -0x1848(%rbp), %rdi
leaq 0x61c9(%rip), %rsi      # 0xa4e7
callq 0x3280
movq %rax, -0x1850(%rbp)
jmp 0x432c
movq -0x1850(%rbp), %rdi
movq 0x9c96(%rip), %rsi      # 0xdfd0
callq 0x32c0
jmp 0x4341
jmp 0x4343
testb $0x1, -0x1242(%rbp)
je 0x441a
movq 0x9c71(%rip), %rdi      # 0xdfc8
leaq 0x618b(%rip), %rsi      # 0xa4e9
callq 0x3280
movq %rax, -0x1858(%rbp)
jmp 0x436c
movq -0x1858(%rbp), %rdi
movq -0x1628(%rbp), %rsi
callq 0x34d0
movq %rax, -0x1860(%rbp)
jmp 0x4388
movq -0x1860(%rbp), %rdi
leaq 0x613e(%rip), %rsi      # 0xa4d4
callq 0x3280
movq %rax, -0x1868(%rbp)
jmp 0x43a4
leaq -0x1558(%rbp), %rdi
callq 0x5640
movq -0x1868(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x3060
movq %rax, -0x1870(%rbp)
jmp 0x43cb
movq -0x1870(%rbp), %rdi
leaq 0x612d(%rip), %rsi      # 0xa506
callq 0x3280
movq %rax, -0x1878(%rbp)
jmp 0x43e7
movq -0x1878(%rbp), %rdi
leaq -0x1510(%rbp), %rsi
callq 0x3250
movq %rax, -0x1880(%rbp)
jmp 0x4403
movq -0x1880(%rbp), %rdi
leaq 0x60fa(%rip), %rsi      # 0xa50b
callq 0x3280
jmp 0x4418
jmp 0x441a
testb $0x1, -0x1243(%rbp)
je 0x4505
leaq -0x1468(%rbp), %rdi
callq 0x30d0
movq %rax, %rsi
leaq -0x1448(%rbp), %rdi
movl $0x1, %edx
callq 0x3040
jmp 0x4449
leaq 0x60be(%rip), %rsi      # 0xa50e
leaq -0x1448(%rbp), %rdi
callq 0x3280
movq %rax, -0x1888(%rbp)
jmp 0x4465
movq -0x1888(%rbp), %rdi
movq -0x1628(%rbp), %rsi
callq 0x34d0
movq %rax, -0x1890(%rbp)
jmp 0x4481
movq -0x1890(%rbp), %rdi
leaq 0x6045(%rip), %rsi      # 0xa4d4
callq 0x3280
movq %rax, -0x1898(%rbp)
jmp 0x449d
leaq -0x1558(%rbp), %rdi
callq 0x5640
movq -0x1898(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x3060
movq %rax, -0x18a0(%rbp)
jmp 0x44c4
movq -0x18a0(%rbp), %rdi
leaq 0x5b90(%rip), %rsi      # 0xa062
callq 0x3280
movq %rax, -0x18a8(%rbp)
jmp 0x44e0
movq -0x18a8(%rbp), %rdi
leaq -0x1510(%rbp), %rsi
callq 0x3250
jmp 0x44f5
leaq -0x1448(%rbp), %rdi
callq 0x33d0
jmp 0x4503
jmp 0x4505
jmp 0x4507
movq -0x1628(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1628(%rbp)
jmp 0x3f22
movq 0x9aa3(%rip), %rdi      # 0xdfc8
leaq 0x5ff9(%rip), %rsi      # 0xa525
callq 0x3280
jmp 0x4533
leaq -0x1540(%rbp), %rdi
callq 0x5640
subq $0x1, %rax
addq -0x15a0(%rbp), %rax
movq %rax, -0x15a0(%rbp)
jmp 0x49ed
movq -0x15a0(%rbp), %rsi
leaq -0x1528(%rbp), %rdi
callq 0x5660
movq %rax, %rsi
leaq -0x16d0(%rbp), %rdi
callq 0x30e0
jmp 0x457a
leaq -0x16b0(%rbp), %rdi
leaq -0x16d0(%rbp), %rsi
callq 0x7ae0
jmp 0x458f
leaq -0x14b0(%rbp), %rdi
movq %rdi, -0x18b8(%rbp)
leaq -0x16b0(%rbp), %rsi
movq %rsi, -0x18c0(%rbp)
callq 0x3340
movq -0x18c0(%rbp), %rdi
callq 0x3190
leaq -0x16d0(%rbp), %rdi
callq 0x3190
movq -0x18b8(%rbp), %rdi
leaq 0x5a8d(%rip), %rsi      # 0xa063
callq 0x5580
movb %al, -0x18a9(%rbp)
jmp 0x45e3
movb -0x18a9(%rbp), %al
testb $0x1, %al
jne 0x45ef
jmp 0x4661
movq 0x99d2(%rip), %rdi      # 0xdfc8
leaq 0x5f46(%rip), %rsi      # 0xa543
callq 0x3280
movq %rax, -0x18c8(%rbp)
jmp 0x460b
movq -0x18c8(%rbp), %rdi
leaq -0x14b0(%rbp), %rsi
callq 0x3250
movq %rax, -0x18d0(%rbp)
jmp 0x4627
movq -0x18d0(%rbp), %rdi
movq 0x997b(%rip), %rsi      # 0xdfb0
callq 0x32c0
jmp 0x463c
jmp 0x4661
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x16d0(%rbp), %rdi
callq 0x3190
jmp 0x489b
leaq -0x14b0(%rbp), %rdi
movl $0xa, %esi
callq 0x31a0
jmp 0x4674
leaq -0x14b0(%rbp), %rdi
callq 0x30d0
movq %rax, %rsi
leaq -0x14(%rbp), %rdi
callq 0x6f30
jmp 0x468e
movl $0x1, %edi
callq 0x3200
jmp 0x469a
leaq 0x59c1(%rip), %rsi      # 0xa062
leaq -0x14b0(%rbp), %rdi
callq 0x5580
movb %al, -0x18d1(%rbp)
jmp 0x46b5
movb -0x18d1(%rbp), %al
testb $0x1, %al
jne 0x46c4
jmp 0x49eb
jmp 0x46c6
leaq -0x14(%rbp), %rdi
leaq -0x1230(%rbp), %rsi
movl $0xa, %edx
movl $0xbebc200, %ecx        # imm = 0xBEBC200
movl $0x1388, %r8d           # imm = 0x1388
callq 0x7320
movl %eax, -0x18d8(%rbp)
jmp 0x46ee
movl -0x18d8(%rbp), %eax
movl %eax, -0x230(%rbp)
leaq -0x16f1(%rbp), %rdi
movq %rdi, -0x18e0(%rbp)
callq 0x34b0
movq -0x18e0(%rbp), %rdx
leaq -0x16f0(%rbp), %rdi
leaq -0x1230(%rbp), %rsi
callq 0x54b0
jmp 0x4729
leaq -0x1510(%rbp), %rdi
movq %rdi, -0x18e8(%rbp)
leaq -0x16f0(%rbp), %rsi
movq %rsi, -0x18f0(%rbp)
callq 0x3340
movq -0x18f0(%rbp), %rdi
callq 0x3190
leaq -0x16f1(%rbp), %rdi
callq 0x32e0
movq -0x18e8(%rbp), %rdi
callq 0x4c30
jmp 0x4770
leaq -0x1738(%rbp), %rdi
leaq -0x1510(%rbp), %rsi
callq 0x30e0
jmp 0x4785
leaq -0x1718(%rbp), %rdi
leaq -0x1738(%rbp), %rsi
callq 0x5360
jmp 0x479a
leaq -0x14d0(%rbp), %rdi
leaq -0x1718(%rbp), %rsi
callq 0x3340
leaq -0x1718(%rbp), %rdi
callq 0x3190
leaq -0x1738(%rbp), %rdi
callq 0x3190
leaq -0x14b0(%rbp), %rdi
leaq -0x14d0(%rbp), %rsi
callq 0x3030
movl %eax, -0x18f4(%rbp)
jmp 0x47e0
movl -0x18f4(%rbp), %eax
cmpl $0x1, %eax
jne 0x46c6
movq 0x97d2(%rip), %rdi      # 0xdfc8
leaq 0x5d60(%rip), %rsi      # 0xa55d
callq 0x3280
movq %rax, -0x1900(%rbp)
jmp 0x480b
movq -0x1900(%rbp), %rdi
movq 0x9797(%rip), %rsi      # 0xdfb0
callq 0x32c0
movq %rax, -0x1908(%rbp)
jmp 0x4827
movq -0x1908(%rbp), %rdi
leaq -0x1510(%rbp), %rsi
callq 0x3250
movq %rax, -0x1910(%rbp)
jmp 0x4843
movq -0x1910(%rbp), %rdi
movq 0x975f(%rip), %rsi      # 0xdfb0
callq 0x32c0
jmp 0x4858
jmp 0x49eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x16f1(%rbp), %rdi
callq 0x32e0
jmp 0x489b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x1738(%rbp), %rdi
callq 0x3190
movl -0x22c(%rbp), %eax
movl %eax, -0x1914(%rbp)
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x4951
movq -0x228(%rbp), %rdi
callq 0x30c0
movq %rax, -0x1750(%rbp)
movq 0x96fa(%rip), %rdi      # 0xdfc8
leaq 0x5cee(%rip), %rsi      # 0xa5c3
callq 0x3280
movq %rax, -0x1920(%rbp)
jmp 0x48e3
movq -0x1750(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0x1920(%rbp), %rdi
movq %rax, %rsi
callq 0x3280
movq %rax, -0x1928(%rbp)
jmp 0x490b
movq -0x1928(%rbp), %rdi
movq 0x9697(%rip), %rsi      # 0xdfb0
callq 0x32c0
jmp 0x4920
leaq -0x14(%rbp), %rdi
callq 0x7630
jmp 0x492b
leaq -0x14(%rbp), %rdi
callq 0x6c70
jmp 0x4936
movl $0x1, -0x4(%rbp)
movl $0x1, -0x1744(%rbp)
callq 0x3450
jmp 0x4ad0
movl -0x1914(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x4b8c
movq -0x228(%rbp), %rdi
callq 0x30c0
movq %rax, -0x1740(%rbp)
movq 0x964a(%rip), %rdi      # 0xdfc8
leaq 0x5c29(%rip), %rsi      # 0xa5ae
callq 0x3280
movq %rax, -0x1930(%rbp)
jmp 0x4993
movq -0x1740(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0x1930(%rbp), %rdi
movq %rax, %rsi
callq 0x3280
movq %rax, -0x1938(%rbp)
jmp 0x49bb
movq -0x1938(%rbp), %rdi
movq 0x95e7(%rip), %rsi      # 0xdfb0
callq 0x32c0
jmp 0x49d0
movl $0x1, -0x4(%rbp)
movl $0x1, -0x1744(%rbp)
callq 0x3450
jmp 0x4ab0
jmp 0x49ed
jmp 0x49ef
movq -0x15a0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x15a0(%rbp)
jmp 0x3d60
movq 0x95bb(%rip), %rdi      # 0xdfc8
leaq 0x5b5a(%rip), %rsi      # 0xa56e
callq 0x3280
movq %rax, -0x1940(%rbp)
jmp 0x4a22
movq -0x1940(%rbp), %rdi
movq 0x9580(%rip), %rsi      # 0xdfb0
callq 0x32c0
jmp 0x4a37
testb $0x1, -0x1243(%rbp)
je 0x4a8f
movq 0x9581(%rip), %rdi      # 0xdfc8
leaq 0x5b32(%rip), %rsi      # 0xa580
callq 0x3280
movq %rax, -0x1948(%rbp)
jmp 0x4a5c
movq -0x1948(%rbp), %rdi
leaq -0x1468(%rbp), %rsi
callq 0x3250
movq %rax, -0x1950(%rbp)
jmp 0x4a78
movq -0x1950(%rbp), %rdi
leaq 0x560f(%rip), %rsi      # 0xa095
callq 0x3280
jmp 0x4a8d
jmp 0x4a8f
jmp 0x4a91
jmp 0x4a93
jmp 0x4a95
jmp 0x4ad7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
callq 0x3450
jmp 0x4ab2
jmp 0x4af3
jmp 0x4b8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
callq 0x3450
jmp 0x4ad2
jmp 0x4af3
jmp 0x4b8c
leaq -0x14(%rbp), %rdi
callq 0x6c70
jmp 0x4ae2
movl $0x0, -0x4(%rbp)
movl $0x1, -0x1744(%rbp)
leaq -0x1558(%rbp), %rdi
callq 0x55e0
leaq -0x1540(%rbp), %rdi
callq 0x55e0
leaq -0x1528(%rbp), %rdi
callq 0x55e0
leaq -0x1510(%rbp), %rdi
callq 0x3190
leaq -0x14f0(%rbp), %rdi
callq 0x3190
leaq -0x14d0(%rbp), %rdi
callq 0x3190
leaq -0x14b0(%rbp), %rdi
callq 0x3190
leaq -0x1490(%rbp), %rdi
callq 0x3190
leaq -0x1468(%rbp), %rdi
callq 0x3190
leaq -0x1448(%rbp), %rdi
callq 0x3400
leaq -0x220(%rbp), %rdi
callq 0x3070
leaq -0x14(%rbp), %rdi
callq 0x6c40
movl -0x4(%rbp), %eax
addq $0x1950, %rsp           # imm = 0x1950
popq %rbp
retq
leaq -0x1558(%rbp), %rdi
callq 0x55e0
leaq -0x1540(%rbp), %rdi
callq 0x55e0
leaq -0x1528(%rbp), %rdi
callq 0x55e0
leaq -0x1510(%rbp), %rdi
callq 0x3190
leaq -0x14f0(%rbp), %rdi
callq 0x3190
leaq -0x14d0(%rbp), %rdi
callq 0x3190
leaq -0x14b0(%rbp), %rdi
callq 0x3190
leaq -0x1490(%rbp), %rdi
callq 0x3190
leaq -0x1468(%rbp), %rdi
callq 0x3190
leaq -0x1448(%rbp), %rdi
callq 0x3400
leaq -0x220(%rbp), %rdi
callq 0x3070
leaq -0x14(%rbp), %rdi
callq 0x6c40
movq -0x228(%rbp), %rdi
callq 0x34a0
movq %rax, %rdi
callq 0x5770
nopl (%rax)