// File: /workspace/github_cpp_makefile_star2_O1/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 0x556c
leaq 0x39fa(%rip), %rsi      # 0x7020
leaq -0x660(%rbp), %rdi
movl $0x8, %edx
callq 0x3400
leaq -0x458(%rbp), %rdi
callq 0x33c0
leaq -0x158(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x39d9(%rip), %rsi      # 0x702e
leaq 0x39e1(%rip), %rdx      # 0x703d
leaq -0x168(%rbp), %rdi
callq 0x51c0
leaq -0x218(%rbp), %rax
movq %rax, -0x10(%rax)
xorl %r15d, %r15d
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq -0x100(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq -0x178(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq -0xe0(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq -0xa0(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
movq %r15, -0xc0(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xd0(%rbp)
movq %r15, -0x120(%rbp)
movaps %xmm0, -0x130(%rbp)
movq %r15, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
movl $0x0, %eax
movq %rax, -0x58(%rbp)
movl $0x0, %eax
movq %rax, -0x90(%rbp)
movl $0x0, %r12d
movl $0x0, %r13d
cmpl $0x2, %r14d
jl 0x37e0
movq 0x8(%rbx), %r15
leaq 0x391c(%rip), %rsi      # 0x703e
movq %r15, %rdi
callq 0x32f0
testl %eax, %eax
je 0x3789
leaq 0x3919(%rip), %rsi      # 0x704e
movq %r15, %rdi
callq 0x32f0
testl %eax, %eax
je 0x37ae
leaq 0x3917(%rip), %rsi      # 0x705f
movq %r15, %rdi
callq 0x32f0
testl %eax, %eax
je 0x4703
leaq 0x3921(%rip), %rsi      # 0x7080
movq %r15, %rdi
callq 0x32f0
testl %eax, %eax
sete %r12b
setne %r13b
xorl %r15d, %r15d
movq $0x0, -0x58(%rbp)
movq $0x0, -0x90(%rbp)
jmp 0x37e0
movq 0x6838(%rip), %rdi      # 0x9fc8
leaq 0x38aa(%rip), %rsi      # 0x7041
movl $0xc, %edx
callq 0x32a0
movb $0x1, %r15b
movq $0x0, -0x58(%rbp)
jmp 0x37cf
movq 0x6813(%rip), %rdi      # 0x9fc8
leaq 0x3895(%rip), %rsi      # 0x7051
movl $0xd, %edx
callq 0x32a0
movb $0x1, %al
movq %rax, -0x58(%rbp)
xorl %r15d, %r15d
movq $0x0, -0x90(%rbp)
xorl %r12d, %r12d
xorl %r13d, %r13d
leaq 0x389c(%rip), %rsi      # 0x7083
leaq -0x2c(%rbp), %rdi
movl $0x1c200, %edx          # imm = 0x1C200
callq 0x5594
movq 0x67cc(%rip), %rbx      # 0x9fc8
leaq 0x388d(%rip), %rsi      # 0x7090
movl $0x23, %edx
movq %rbx, %rdi
callq 0x32a0
leaq -0x2c(%rbp), %rdi
callq 0x5bfa
testb %r13b, %r13b
je 0x398d
movl $0x33, %edx
leaq 0x3886(%rip), %rsi      # 0x70b4
movq %rbx, %rdi
callq 0x32a0
xorl %ebx, %ebx
leaq -0x2c(%rbp), %rdi
callq 0x5588
leaq -0x50(%rbp), %rdi
callq 0x4fce
leaq -0x130(%rbp), %rdi
callq 0x4fce
leaq -0xd0(%rbp), %rdi
callq 0x4fce
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x3884
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x38a6
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x188(%rbp), %rdi
leaq -0x178(%rbp), %rax
cmpq %rax, %rdi
je 0x38c8
movq -0x178(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x38ea
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x228(%rbp), %rdi
leaq -0x218(%rbp), %rax
cmpq %rax, %rdi
je 0x390c
movq -0x218(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x168(%rbp), %rdi
leaq -0x158(%rbp), %rax
cmpq %rax, %rdi
je 0x392e
movq -0x158(%rbp), %rsi
incq %rsi
callq 0x3250
movq 0x6683(%rip), %rax      # 0x9fb8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x450(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x458(%rbp,%rcx)
callq 0x31e0
leaq -0x360(%rbp), %rdi
callq 0x30a0
leaq -0x660(%rbp), %rdi
callq 0x3060
leaq -0x2c(%rbp), %rdi
callq 0x5572
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 0x3b70
movq 0x662b(%rip), %rdi      # 0x9fc8
leaq 0x3744(%rip), %rsi      # 0x70e8
movl $0x13, %edx
callq 0x32a0
movq 0x6613(%rip), %rbx      # 0x9fc8
leaq 0x3740(%rip), %rsi      # 0x70fc
movl $0x39, %edx
movq %rbx, %rdi
callq 0x32a0
movq 0x6608(%rip), %rdi      # 0x9fd8
leaq -0xf0(%rbp), %rsi
callq 0x32e0
leaq -0xf0(%rbp), %r15
leaq -0x1660(%rbp), %r13
leaq -0x80(%rbp), %r14
movq %r15, %rdi
leaq 0x373e(%rip), %rsi      # 0x7136
callq 0x3080
testl %eax, %eax
je 0x3836
movq %r15, %rdi
movl $0xa, %esi
callq 0x31f0
movq -0xf0(%rbp), %rsi
leaq -0x2c(%rbp), %rdi
callq 0x57c6
movl $0x11, %edx
movq %rbx, %rdi
leaq 0x370a(%rip), %rsi      # 0x713b
callq 0x32a0
movq -0xf0(%rbp), %rsi
movq -0xe8(%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 0x5a0a
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 0x51c0
movq %r15, %rdi
movq %r14, %rsi
callq 0x32c0
movq -0x80(%rbp), %rdi
cmpq %r12, %rdi
je 0x3ab8
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3250
cmpq $0x0, -0xe8(%rbp)
je 0x3ae1
xorl %eax, %eax
movq -0xf0(%rbp), %rcx
cmpb $0x9, (%rcx,%rax)
jne 0x3ad5
movb $0xa, (%rcx,%rax)
incq %rax
cmpq %rax, -0xe8(%rbp)
ja 0x3ac4
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 -0xf0(%rbp), %rsi
movq -0xe8(%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 0x35f6(%rip), %rsi      # 0x714d
callq 0x32a0
movq 0x6475(%rip), %rdi      # 0x9fd8
movq %r15, %rsi
callq 0x32e0
jmp 0x39ee
testb %r12b, %r12b
je 0x3c19
movq 0x6448(%rip), %rdi      # 0x9fc8
leaq 0x35d5(%rip), %rsi      # 0x715c
movl $0xa4, %edx
callq 0x32a0
movq 0x6430(%rip), %rdi      # 0x9fc8
leaq 0x3662(%rip), %rsi      # 0x7201
movl $0x1d, %edx
callq 0x32a0
movq 0x6418(%rip), %rdi      # 0x9fc8
leaq 0x3668(%rip), %rsi      # 0x721f
movl $0x75, %edx
callq 0x32a0
movq 0x6400(%rip), %rdi      # 0x9fc8
leaq 0x36c6(%rip), %rsi      # 0x7295
movl $0x6e, %edx
callq 0x32a0
movq 0x63e8(%rip), %rbx      # 0x9fc8
leaq 0x371d(%rip), %rsi      # 0x7304
movl $0xa6, %edx
movq %rbx, %rdi
callq 0x32a0
leaq 0x37b0(%rip), %rsi      # 0x73ab
movl $0x45, %edx
movq %rbx, %rdi
callq 0x32a0
movl $0xa4, %edx
leaq 0x37dd(%rip), %rsi      # 0x73f1
jmp 0x382e
leaq -0x148(%rbp), %rdi
leaq -0x660(%rbp), %rsi
callq 0x4ad3
xorps %xmm0, %xmm0
leaq -0x80(%rbp), %rdi
movaps %xmm0, (%rdi)
movaps -0xd0(%rbp), %xmm0
movq -0xc0(%rbp), %rax
leaq -0x148(%rbp), %rbx
movups (%rbx), %xmm1
movaps %xmm1, -0xd0(%rbp)
movq 0x10(%rbx), %rcx
movq %rcx, -0xc0(%rbp)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
movups %xmm1, (%rbx)
movq $0x0, 0x10(%rbx)
callq 0x4fce
movq %rbx, %rdi
callq 0x4fce
movq 0x633f(%rip), %rdi      # 0x9fc8
leaq 0x3806(%rip), %rsi      # 0x7496
movl $0x16, %edx
callq 0x32a0
movq -0xc8(%rbp), %rax
cmpq -0xd0(%rbp), %rax
je 0x466a
leaq -0x70(%rbp), %r15
movq $0x0, -0x88(%rbp)
leaq -0x80(%rbp), %r13
leaq -0x1660(%rbp), %r14
movl $0x11, %edx
movq 0x62f4(%rip), %rdi      # 0x9fc8
leaq 0x37d2(%rip), %rsi      # 0x74ad
callq 0x32a0
movq -0xd0(%rbp), %rax
movq -0x88(%rbp), %r12
shlq $0x5, %r12
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
movq 0x62c6(%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 -0xd0(%rbp), %rax
leaq -0x198(%rbp), %rcx
movq %rcx, -0x1a8(%rbp)
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
addq %rsi, %rdx
leaq -0x1a8(%rbp), %rdi
callq 0x5126
leaq -0x1a8(%rbp), %rdi
callq 0x4c14
movl %eax, %ebx
movq -0x1a8(%rbp), %rdi
leaq -0x198(%rbp), %rax
cmpq %rax, %rdi
je 0x3d8e
movq -0x198(%rbp), %rsi
incq %rsi
callq 0x3250
testb %bl, %bl
je 0x430c
leaq -0x258(%rbp), %rbx
movq %rbx, %rdi
leaq -0xd0(%rbp), %rsi
callq 0x5038
leaq -0x148(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq -0x88(%rbp), %rdx
callq 0x4d5b
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
movaps -0x130(%rbp), %xmm0
movq -0x120(%rbp), %rax
movups -0x148(%rbp), %xmm1
movaps %xmm1, -0x130(%rbp)
movq -0x138(%rbp), %rcx
movq %rcx, -0x120(%rbp)
movaps -0x80(%rbp), %xmm1
movaps %xmm0, -0x80(%rbp)
movq %rax, -0x70(%rbp)
movups %xmm1, -0x148(%rbp)
movq $0x0, -0x138(%rbp)
movq %r13, %rdi
callq 0x4fce
movq %r12, %rdi
callq 0x4fce
movq %rbx, %rdi
callq 0x4fce
leaq -0x240(%rbp), %rbx
movq %rbx, %rdi
leaq -0x130(%rbp), %rsi
callq 0x5038
movq %r12, %rdi
movq %rbx, %rsi
callq 0x697d
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
movaps -0x50(%rbp), %xmm0
movq -0x40(%rbp), %rax
movups -0x148(%rbp), %xmm1
movaps %xmm1, -0x50(%rbp)
movq -0x138(%rbp), %rcx
movq %rcx, -0x40(%rbp)
movaps -0x80(%rbp), %xmm1
movaps %xmm0, -0x80(%rbp)
movq %rax, -0x70(%rbp)
movups %xmm1, -0x148(%rbp)
movq $0x0, -0x138(%rbp)
movq %r13, %rdi
callq 0x4fce
movq %r12, %rdi
callq 0x4fce
movq %rbx, %rdi
callq 0x4fce
movl $0x1b, %edx
movq 0x6114(%rip), %rdi      # 0x9fc8
leaq 0x3604(%rip), %rsi      # 0x74bf
callq 0x32a0
movq -0x50(%rbp), %rdi
cmpq %rdi, -0x48(%rbp)
je 0x42c9
xorl %r12d, %r12d
movq %r12, -0xb8(%rbp)
shlq $0x5, %r12
addq %r12, %rdi
movl $0xa, %esi
callq 0x31f0
cmpb $0x0, -0x58(%rbp)
je 0x3f78
movl $0x14, %edx
movq 0x60c9(%rip), %rdi      # 0x9fc8
leaq 0x35d5(%rip), %rsi      # 0x74db
callq 0x32a0
movq 0x60b6(%rip), %rdi      # 0x9fc8
movq -0xb8(%rbp), %rsi
callq 0x3210
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x35c0(%rip), %rsi      # 0x74f0
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 0x3594(%rip), %rsi      # 0x74f2
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 0x57c6
movq -0x50(%rbp), %rdi
addq %r12, %rdi
leaq 0x30e7(%rip), %rsi      # 0x707e
callq 0x3080
testl %eax, %eax
je 0x40ca
leaq -0x2c(%rbp), %rdi
movq %r14, %rsi
movl $0xa, %edx
movl $0xbebc200, %ecx        # imm = 0xBEBC200
movl $0x1388, %r8d           # imm = 0x1388
callq 0x5a0a
movq %r15, -0x80(%rbp)
movq %r14, %rdi
callq 0x30e0
leaq (%rax,%rbp), %rdx
addq $-0x1660, %rdx          # imm = 0xE9A0
movq %r13, %rdi
movq %r14, %rsi
callq 0x51c0
leaq -0xb0(%rbp), %rdi
movq %r13, %rsi
callq 0x32c0
movq -0x80(%rbp), %rdi
cmpq %r15, %rdi
je 0x4006
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3250
cmpq $0x0, -0xa8(%rbp)
je 0x402f
xorl %eax, %eax
movq -0xb0(%rbp), %rcx
cmpb $0x9, (%rcx,%rax)
jne 0x4023
movb $0xa, (%rcx,%rax)
incq %rax
cmpq %rax, -0xa8(%rbp)
ja 0x4012
leaq -0x1f8(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
addq %rsi, %rdx
leaq -0x208(%rbp), %rbx
movq %rbx, %rdi
callq 0x5126
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4ee3
leaq -0x188(%rbp), %rdi
movq %r13, %rsi
callq 0x32c0
movq -0x80(%rbp), %rdi
cmpq %r15, %rdi
je 0x408c
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x208(%rbp), %rdi
leaq -0x1f8(%rbp), %rax
cmpq %rax, %rdi
je 0x40ae
movq -0x1f8(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x50(%rbp), %rdi
addq %r12, %rdi
leaq -0x188(%rbp), %rsi
callq 0x3040
cmpl $0x1, %eax
jne 0x3fa4
cmpb $0x0, -0x58(%rbp)
jne 0x4156
movl $0xc, %edx
movq 0x5ee8(%rip), %rdi      # 0x9fc8
leaq 0x340f(%rip), %rsi      # 0x74f6
callq 0x32a0
movq 0x5ed5(%rip), %rdi      # 0x9fc8
movq -0xb8(%rbp), %rsi
callq 0x3210
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x33df(%rip), %rsi      # 0x74f0
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 0x33c4(%rip), %rsi      # 0x7503
callq 0x32a0
movq %rbx, %rdi
callq 0x3180
cmpb $0x0, -0x58(%rbp)
je 0x41f0
movl $0x1c, %edx
movq 0x5e66(%rip), %rdi      # 0x9fc8
leaq 0x339c(%rip), %rsi      # 0x7505
callq 0x32a0
movq 0x5e53(%rip), %rdi      # 0x9fc8
movq -0xb8(%rbp), %rsi
callq 0x3210
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x335d(%rip), %rsi      # 0x74f0
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 0x3361(%rip), %rsi      # 0x7522
callq 0x32a0
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq %rbx, %rdi
callq 0x32a0
movl $0x2, %edx
movq %rax, %rdi
leaq 0x333c(%rip), %rsi      # 0x7527
callq 0x32a0
cmpb $0x0, -0x90(%rbp)
je 0x42a7
movq -0x168(%rbp), %rsi
leaq -0x458(%rbp), %rdi
movl $0x1, %edx
callq 0x3050
movl $0x16, %edx
leaq -0x458(%rbp), %rdi
leaq 0x3302(%rip), %rsi      # 0x752a
callq 0x32a0
leaq -0x458(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0x3210
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x329e(%rip), %rsi      # 0x74f0
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 0x2dfe(%rip), %rsi      # 0x707e
callq 0x32a0
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq %rbx, %rdi
callq 0x32a0
leaq -0x458(%rbp), %rdi
callq 0x3310
movq -0xb8(%rbp), %r12
incq %r12
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %rax, %r12
jb 0x3ed1
movl $0x1d, %edx
movq 0x5cf3(%rip), %rdi      # 0x9fc8
leaq 0x3265(%rip), %rsi      # 0x7541
callq 0x32a0
movq -0x128(%rbp), %rax
subq -0x130(%rbp), %rax
sarq $0x5, %rax
movq -0x88(%rbp), %rcx
addq %rax, %rcx
decq %rcx
movq %rcx, -0x88(%rbp)
jmp 0x463e
movq -0xd0(%rbp), %rax
leaq -0x1d8(%rbp), %rcx
movq %rcx, -0x1e8(%rbp)
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
addq %rsi, %rdx
leaq -0x1e8(%rbp), %rbx
movq %rbx, %rdi
callq 0x5126
movq %r13, %rdi
movq %rbx, %rsi
callq 0x5d58
leaq -0x110(%rbp), %rdi
movq %r13, %rsi
callq 0x32c0
movq -0x80(%rbp), %rdi
cmpq %r15, %rdi
je 0x436b
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x1e8(%rbp), %rdi
leaq -0x1d8(%rbp), %rax
cmpq %rax, %rdi
je 0x438d
movq -0x1d8(%rbp), %rsi
incq %rsi
callq 0x3250
leaq -0x110(%rbp), %rdi
leaq 0x2ce4(%rip), %rsi      # 0x707f
callq 0x3080
testl %eax, %eax
je 0x4400
movl $0x19, %edx
movq 0x5c18(%rip), %rdi      # 0x9fc8
leaq 0x31a8(%rip), %rsi      # 0x755f
callq 0x32a0
movq -0x110(%rbp), %rsi
movq -0x108(%rbp), %rdx
movq 0x5bf7(%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 -0x110(%rbp), %rdi
movl $0xa, %esi
callq 0x31f0
movq -0x110(%rbp), %rsi
leaq -0x2c(%rbp), %rdi
callq 0x57c6
movl $0x1, %edi
callq 0x31b0
leaq -0x110(%rbp), %rdi
leaq 0x2c45(%rip), %rsi      # 0x707e
callq 0x3080
testl %eax, %eax
je 0x463e
leaq -0x2c(%rbp), %rdi
movq %r14, %rsi
movl $0xa, %edx
movl $0xbebc200, %ecx        # imm = 0xBEBC200
movl $0x1388, %r8d           # imm = 0x1388
callq 0x5a0a
movq %r15, -0x80(%rbp)
movq %r14, %rdi
callq 0x30e0
leaq (%rax,%rbp), %rdx
addq $-0x1660, %rdx          # imm = 0xE9A0
movq %r13, %rdi
movq %r14, %rsi
callq 0x51c0
leaq -0xb0(%rbp), %rdi
movq %r13, %rsi
callq 0x32c0
movq -0x80(%rbp), %rdi
cmpq %r15, %rdi
je 0x44a8
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3250
cmpq $0x0, -0xa8(%rbp)
je 0x44d1
xorl %eax, %eax
movq -0xb0(%rbp), %rcx
cmpb $0x9, (%rcx,%rax)
jne 0x44c5
movb $0xa, (%rcx,%rax)
incq %rax
cmpq %rax, -0xa8(%rbp)
ja 0x44b4
leaq -0x1b8(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
addq %rsi, %rdx
leaq -0x1c8(%rbp), %rbx
movq %rbx, %rdi
callq 0x5126
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4ee3
leaq -0x188(%rbp), %rdi
movq %r13, %rsi
callq 0x32c0
movq -0x80(%rbp), %rdi
cmpq %r15, %rdi
je 0x452e
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x1c8(%rbp), %rdi
leaq -0x1b8(%rbp), %rax
cmpq %rax, %rdi
je 0x4550
movq -0x1b8(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x108(%rbp), %rbx
movq -0x180(%rbp), %r12
cmpq %rbx, %r12
movq %rbx, %rdx
cmovbq %r12, %rdx
testq %rdx, %rdx
je 0x4582
movq -0x188(%rbp), %rsi
movq -0x110(%rbp), %rdi
callq 0x30f0
jmp 0x4584
xorl %eax, %eax
testl %eax, %eax
jne 0x45ab
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 0x4446
movl $0x10, %edx
movq 0x5a08(%rip), %rdi      # 0x9fc8
leaq 0x2fb2(%rip), %rsi      # 0x7579
callq 0x32a0
movq 0x59f5(%rip), %rcx      # 0x9fc8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq 0x59d7(%rip), %rdi      # 0x9fc8
callq 0x3030
movq %rax, %rdi
callq 0x3180
movq -0xb0(%rbp), %rsi
movq -0xa8(%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 -0x88(%rbp), %rdx
incq %rdx
movq -0xc8(%rbp), %rax
subq -0xd0(%rbp), %rax
sarq $0x5, %rax
movq %rdx, -0x88(%rbp)
cmpq %rax, %rdx
jb 0x3cc8
movq 0x5957(%rip), %rbx      # 0x9fc8
leaq 0x2f12(%rip), %rsi      # 0x758a
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 0x5925(%rip), %rdi      # 0x9fc8
callq 0x3030
movq %rax, %rdi
callq 0x3180
cmpb $0x0, -0x90(%rbp)
je 0x3836
movq 0x5904(%rip), %rdi      # 0x9fc8
leaq 0x2ed1(%rip), %rsi      # 0x759c
movl $0x2d, %edx
callq 0x32a0
movq -0x168(%rbp), %rsi
movq -0x160(%rbp), %rdx
movq 0x58de(%rip), %rdi      # 0x9fc8
callq 0x32a0
movq %rax, %rbx
movl $0x2, %edx
leaq 0x29b3(%rip), %rsi      # 0x70b1
jmp 0x382e
movq 0x58be(%rip), %rdi      # 0x9fc8
leaq 0x2951(%rip), %rsi      # 0x7062
movl $0xa, %edx
callq 0x32a0
cmpl $0x3, %r14d
jne 0x474b
movq 0x10(%rbx), %rbx
leaq -0x168(%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 0x3380
movq -0x168(%rbp), %rsi
leaq -0x458(%rbp), %rdi
movl $0x10, %edx
callq 0x3050
leaq 0x2903(%rip), %rsi      # 0x706d
leaq -0x458(%rbp), %rdi
movl $0x12, %edx
callq 0x32a0
leaq -0x458(%rbp), %rdi
callq 0x3310
movb $0x1, %al
movq %rax, -0x90(%rbp)
xorl %r15d, %r15d
movq $0x0, -0x58(%rbp)
jmp 0x37da
jmp 0x49b6
movq %rax, %rbx
jmp 0x490b
movq %rax, %rbx
jmp 0x4917
movq %rax, %rbx
jmp 0x4923
movq %rdx, %r14
movq %rax, %rbx
leaq -0x240(%rbp), %rdi
jmp 0x4811
movq %rdx, %r14
movq %rax, %rbx
movq -0x1e8(%rbp), %rdi
leaq -0x1d8(%rbp), %rax
cmpq %rax, %rdi
je 0x49bc
movq -0x1d8(%rbp), %rsi
jmp 0x49aa
jmp 0x49b6
jmp 0x49b6
jmp 0x49b6
movq %rdx, %r14
movq %rax, %rbx
leaq -0x258(%rbp), %rdi
callq 0x4fce
jmp 0x49bc
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x4fce
leaq -0x130(%rbp), %rdi
callq 0x4fce
leaq -0xd0(%rbp), %rdi
callq 0x4fce
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x4861
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x4883
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x188(%rbp), %rdi
leaq -0x178(%rbp), %rax
cmpq %rax, %rdi
je 0x48a5
movq -0x178(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x48c7
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x228(%rbp), %rdi
leaq -0x218(%rbp), %rax
cmpq %rax, %rdi
je 0x48e9
movq -0x218(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x168(%rbp), %rdi
leaq -0x158(%rbp), %rax
cmpq %rax, %rdi
je 0x490b
movq -0x158(%rbp), %rsi
incq %rsi
callq 0x3250
leaq -0x458(%rbp), %rdi
callq 0x3350
leaq -0x660(%rbp), %rdi
callq 0x3060
leaq -0x2c(%rbp), %rdi
callq 0x5572
movq %rbx, %rdi
callq 0x33e0
movq %rdx, %r14
movq %rax, %rbx
movq -0x1a8(%rbp), %rdi
leaq -0x198(%rbp), %rax
cmpq %rax, %rdi
je 0x49bc
movq -0x198(%rbp), %rsi
jmp 0x49aa
jmp 0x49b6
jmp 0x49b6
jmp 0x49b6
jmp 0x49b6
movq %rdx, %r14
movq %rax, %rbx
movq -0x1c8(%rbp), %rdi
leaq -0x1b8(%rbp), %rax
cmpq %rax, %rdi
je 0x49bc
movq -0x1b8(%rbp), %rsi
jmp 0x49aa
jmp 0x49b6
jmp 0x49b6
jmp 0x49b6
jmp 0x49b6
jmp 0x49b6
movq %rdx, %r14
movq %rax, %rbx
movq -0x208(%rbp), %rdi
leaq -0x1f8(%rbp), %rax
cmpq %rax, %rdi
je 0x49bc
movq -0x1f8(%rbp), %rsi
incq %rsi
callq 0x3250
jmp 0x49bc
jmp 0x49b6
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x2, %r14d
jne 0x4a26
movq %rbx, %rdi
callq 0x30d0
movq %rax, %rbx
movq 0x55f4(%rip), %rdi      # 0x9fc8
leaq 0x2c04(%rip), %rsi      # 0x75df
movl $0x13, %edx
callq 0x32a0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x55d3(%rip), %rdi      # 0x9fc8
movq %rax, %rsi
callq 0x3230
movq %rax, %rdi
callq 0x3100
leaq -0x2c(%rbp), %rdi
callq 0x5bfa
leaq -0x2c(%rbp), %rdi
callq 0x5588
movl $0x1, %ebx
callq 0x33a0
jmp 0x3841
cmpl $0x1, %r14d
jne 0x481e
movq %rbx, %rdi
callq 0x30d0
movq %rax, %rbx
movq 0x5586(%rip), %rdi      # 0x9fc8
leaq 0x2b81(%rip), %rsi      # 0x75ca
movl $0x14, %edx
callq 0x32a0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x5565(%rip), %rdi      # 0x9fc8
movq %rax, %rsi
callq 0x3230
movq %rax, %rdi
callq 0x3100
movl $0x1, %ebx
callq 0x33a0
jmp 0x3841
jmp 0x481b
jmp 0x481b
movq %rax, %rbx
callq 0x33a0
jmp 0x481e
movq %rax, %rbx
callq 0x33a0
jmp 0x481e
movq %rax, %rdi
callq 0x50cc