// File: /workspace/github_cpp_makefile_star2_O2/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 $0x1618, %rsp           # imm = 0x1618
movq %rsi, %rbx
movl %edi, %r14d
leaq -0x2c(%rbp), %rdi
callq 0x4bf0
leaq 0x2a2e(%rip), %rsi      # 0x6004
leaq -0x638(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x33b0
leaq -0x430(%rbp), %rdi
callq 0x3370
leaq 0x2a1a(%rip), %rsi      # 0x6012
leaq -0xe0(%rbp), %rdi
leaq -0x180(%rbp), %rdx
callq 0x46d0
leaq -0x170(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %r15d, %r15d
movb %r15b, (%rax)
leaq -0xb0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq -0x150(%rbp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb %r15b, (%rax)
movb %r15b, (%rcx)
leaq -0xf0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq -0x130(%rbp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb %r15b, (%rax)
movb %r15b, (%rcx)
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
andq $0x0, -0x70(%rbp)
movaps %xmm0, -0xa0(%rbp)
andq $0x0, -0x90(%rbp)
movaps %xmm0, -0x60(%rbp)
andq $0x0, -0x50(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, %r12d
movl $0x0, %r13d
cmpl $0x2, %r14d
jl 0x37c8
movq 0x8(%rbx), %rax
cmpb $0x2d, (%rax)
jne 0x36f2
cmpb $0x6d, 0x1(%rax)
jne 0x36ca
cmpb $0x0, 0x2(%rax)
je 0x3712
cmpb $0x76, 0x1(%rax)
jne 0x36d6
cmpb $0x0, 0x2(%rax)
je 0x3731
cmpb $0x66, 0x1(%rax)
jne 0x36e2
cmpb $0x0, 0x2(%rax)
je 0x3755
cmpb $0x68, 0x1(%rax)
jne 0x36f2
cmpb $0x0, 0x2(%rax)
sete %r12b
jmp 0x36f5
xorl %r12d, %r12d
movl %r12d, %r13d
xorb $0x1, %r13b
xorl %r15d, %r15d
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
jmp 0x37c8
movq 0x58af(%rip), %rdi      # 0x8fc8
leaq 0x2902(%rip), %rsi      # 0x6022
callq 0x3200
movb $0x1, %r15b
movl $0x0, -0x38(%rbp)
jmp 0x374c
movq 0x5890(%rip), %rdi      # 0x8fc8
leaq 0x28f0(%rip), %rsi      # 0x602f
callq 0x3200
movb $0x1, %al
movl %eax, -0x38(%rbp)
xorl %r15d, %r15d
movl $0x0, -0x34(%rbp)
jmp 0x37c2
movq 0x586c(%rip), %rdi      # 0x8fc8
leaq 0x28da(%rip), %rsi      # 0x603d
callq 0x3200
cmpl $0x3, %r14d
jne 0x377e
movq 0x10(%rbx), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x33e0
movq -0xe0(%rbp), %rsi
leaq -0x430(%rbp), %rdi
pushq $0x10
popq %rdx
callq 0x3040
leaq 0x28ad(%rip), %rsi      # 0x6048
leaq -0x430(%rbp), %rdi
callq 0x3200
leaq -0x430(%rbp), %rdi
callq 0x32e0
movb $0x1, %al
movl %eax, -0x34(%rbp)
xorl %r15d, %r15d
movl $0x0, -0x38(%rbp)
xorl %r12d, %r12d
xorl %r13d, %r13d
leaq 0x288c(%rip), %rsi      # 0x605b
leaq -0x2c(%rbp), %rdi
movl $0x1c200, %edx          # imm = 0x1C200
callq 0x4c16
movq 0x57e4(%rip), %rbx      # 0x8fc8
leaq 0x287d(%rip), %rsi      # 0x6068
movq %rbx, %rdi
callq 0x3200
leaq -0x2c(%rbp), %rdi
callq 0x51f2
testb %r13b, %r13b
je 0x38ba
leaq 0x2880(%rip), %rsi      # 0x608c
movq %rbx, %rdi
callq 0x3200
xorl %ebx, %ebx
leaq -0x2c(%rbp), %rdi
callq 0x4c0a
leaq -0x60(%rbp), %rdi
callq 0x4718
leaq -0xa0(%rbp), %rdi
callq 0x4718
leaq -0x80(%rbp), %rdi
callq 0x4718
leaq -0x140(%rbp), %rdi
callq 0x30c0
leaq -0x100(%rbp), %rdi
callq 0x30c0
leaq -0x160(%rbp), %rdi
callq 0x30c0
leaq -0xc0(%rbp), %rdi
callq 0x30c0
leaq -0x180(%rbp), %rdi
callq 0x30c0
leaq -0xe0(%rbp), %rdi
callq 0x30c0
leaq -0x430(%rbp), %rdi
callq 0x3310
leaq -0x638(%rbp), %rdi
callq 0x3050
leaq -0x2c(%rbp), %rdi
callq 0x4bf6
movl %ebx, %eax
addq $0x1618, %rsp           # imm = 0x1618
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb %r15b, %r15b
je 0x39f0
movq 0x56fe(%rip), %rdi      # 0x8fc8
leaq 0x27ef(%rip), %rsi      # 0x60c0
callq 0x3200
movq 0x56eb(%rip), %rdi      # 0x8fc8
leaq 0x27f0(%rip), %rsi      # 0x60d4
callq 0x3200
movq 0x56e8(%rip), %rdi      # 0x8fd8
leaq -0x100(%rbp), %rsi
callq 0x32a0
leaq -0x100(%rbp), %r14
leaq -0x2c(%rbp), %r12
movq 0x56ba(%rip), %r13      # 0x8fc8
leaq -0x1640(%rbp), %rbx
leaq -0x120(%rbp), %r15
movq %r14, %rdi
leaq 0x27e8(%rip), %rsi      # 0x610e
callq 0x470b
testb %al, %al
je 0x3814
movq %r14, %rdi
pushq $0xa
popq %rsi
callq 0x31c0
movq -0x100(%rbp), %rsi
movq %r12, %rdi
callq 0x4dea
movq %r13, %rdi
leaq 0x27bc(%rip), %rsi      # 0x6113
callq 0x3200
movq %rax, %rdi
movq %r14, %rsi
callq 0x31e0
pushq $0x1
popq %rdi
callq 0x3190
movq %r12, %rdi
movq %rbx, %rsi
pushq $0xa
popq %rdx
movl $0x1000, %ecx           # imm = 0x1000
movl $0x1388, %r8d           # imm = 0x1388
callq 0x500e
movq %r15, %rdi
movq %rbx, %rsi
leaq -0x2d(%rbp), %rdx
callq 0x46d0
movq %r14, %rdi
movq %r15, %rsi
callq 0x3280
movq %r15, %rdi
callq 0x30c0
movq %r14, %rdi
callq 0x42d8
movq %r13, %rdi
callq 0x30e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x31e0
movq %rax, %rdi
callq 0x30e0
movq %r13, %rdi
leaq 0x274e(%rip), %rsi      # 0x6125
callq 0x3200
movq 0x55f5(%rip), %rdi      # 0x8fd8
movq %r14, %rsi
callq 0x32a0
jmp 0x391c
testb %r12b, %r12b
je 0x3a72
movq 0x55cc(%rip), %rdi      # 0x8fc8
leaq 0x2731(%rip), %rsi      # 0x6134
callq 0x3200
movq 0x55b9(%rip), %rdi      # 0x8fc8
leaq 0x27c3(%rip), %rsi      # 0x61d9
callq 0x3200
movq 0x55a6(%rip), %rdi      # 0x8fc8
leaq 0x27ce(%rip), %rsi      # 0x61f7
callq 0x3200
movq 0x5593(%rip), %rdi      # 0x8fc8
leaq 0x2831(%rip), %rsi      # 0x626d
callq 0x3200
movq 0x5580(%rip), %rbx      # 0x8fc8
leaq 0x288d(%rip), %rsi      # 0x62dc
movq %rbx, %rdi
callq 0x3200
leaq 0x2925(%rip), %rsi      # 0x6383
movq %rbx, %rdi
callq 0x3200
leaq 0x295c(%rip), %rsi      # 0x63c9
jmp 0x380c
leaq -0x120(%rbp), %rdi
leaq -0x638(%rbp), %rsi
callq 0x42f8
leaq -0x80(%rbp), %rdi
leaq -0x120(%rbp), %rbx
movq %rbx, %rsi
callq 0x48f4
movq %rbx, %rdi
callq 0x4718
movq 0x5521(%rip), %rdi      # 0x8fc8
leaq 0x29c0(%rip), %rsi      # 0x646e
callq 0x3200
xorl %ecx, %ecx
leaq -0x120(%rbp), %r15
leaq -0x140(%rbp), %r12
leaq -0x230(%rbp), %r13
leaq -0x160(%rbp), %rbx
movq -0x78(%rbp), %rax
subq -0x80(%rbp), %rax
sarq $0x5, %rax
movq %rcx, -0x68(%rbp)
cmpq %rax, %rcx
jae 0x4079
movq 0x54d7(%rip), %rdi      # 0x8fc8
leaq 0x298d(%rip), %rsi      # 0x6485
callq 0x3200
movq -0x68(%rbp), %rcx
shlq $0x5, %rcx
movq -0x80(%rbp), %rsi
movq %rcx, -0x40(%rbp)
addq %rcx, %rsi
movq %rax, %rdi
callq 0x31e0
movq %rax, %rdi
callq 0x30e0
movq -0x80(%rbp), %rsi
addq -0x40(%rbp), %rsi
leaq -0x1a0(%rbp), %rdi
callq 0x32c0
leaq -0x1a0(%rbp), %r14
movq %r14, %rdi
callq 0x4404
movb %al, -0x2e(%rbp)
movq %r14, %rdi
callq 0x30c0
cmpb $0x0, -0x2e(%rbp)
je 0x3eaa
leaq -0x1d0(%rbp), %r14
movq %r14, %rdi
leaq -0x80(%rbp), %rsi
callq 0x4744
movq %r15, %rdi
movq %r14, %rsi
movq -0x68(%rbp), %rdx
callq 0x44e1
leaq -0xa0(%rbp), %rdi
movq %r15, %rsi
callq 0x48f4
movq %r15, %rdi
callq 0x4718
movq %r14, %rdi
callq 0x4718
leaq -0x1b8(%rbp), %r14
movq %r14, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x4744
movq %r15, %rdi
movq %r14, %rsi
callq 0x5baf
leaq -0x60(%rbp), %rdi
movq %r15, %rsi
callq 0x48f4
movq %r15, %rdi
callq 0x4718
movq %r14, %rdi
callq 0x4718
movq 0x53eb(%rip), %rdi      # 0x8fc8
leaq 0x28b3(%rip), %rsi      # 0x6497
callq 0x3200
xorl %r14d, %r14d
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %rax, %r14
jae 0x403a
movq %r14, -0x40(%rbp)
shlq $0x5, %r14
addq %r14, %rdi
pushq $0xa
popq %rsi
callq 0x31c0
cmpb $0x0, -0x38(%rbp)
je 0x3c80
movq 0x53a4(%rip), %rdi      # 0x8fc8
leaq 0x2888(%rip), %rsi      # 0x64b3
callq 0x3200
movq %rax, %rdi
movq -0x40(%rbp), %rsi
callq 0x31f0
movq %rax, %rdi
leaq 0x2882(%rip), %rsi      # 0x64c8
callq 0x3200
movq -0x58(%rbp), %rsi
subq -0x60(%rbp), %rsi
sarq $0x5, %rsi
decq %rsi
movq %rax, %rdi
callq 0x3150
movq %rax, %rdi
leaq 0x285e(%rip), %rsi      # 0x64ca
callq 0x3200
movq -0x60(%rbp), %rsi
addq %r14, %rsi
movq %rax, %rdi
callq 0x31e0
movq -0x60(%rbp), %rax
movq (%rax,%r14), %rsi
leaq -0x2c(%rbp), %rdi
callq 0x4dea
movq -0x60(%rbp), %rdi
addq %r14, %rdi
leaq 0x23ba(%rip), %rsi      # 0x6059
callq 0x470b
testb %al, %al
je 0x3d41
leaq -0x2c(%rbp), %rdi
leaq -0x1640(%rbp), %rsi
pushq $0xa
popq %rdx
movl $0xbebc200, %ecx        # imm = 0xBEBC200
movl $0x1388, %r8d           # imm = 0x1388
callq 0x500e
movq %r15, %rdi
leaq -0x1640(%rbp), %rsi
leaq -0x2d(%rbp), %rdx
callq 0x46d0
movq %r12, %rdi
movq %r15, %rsi
callq 0x3280
movq %r15, %rdi
callq 0x30c0
movq %r12, %rdi
callq 0x42d8
movq %r13, %rdi
movq %r12, %rsi
callq 0x32c0
movq %r15, %rdi
movq %r13, %rsi
callq 0x461e
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3280
movq %r15, %rdi
callq 0x30c0
movq %r13, %rdi
callq 0x30c0
movq -0x60(%rbp), %rdi
addq %r14, %rdi
movq %rbx, %rsi
callq 0x3030
cmpl $0x1, %eax
jne 0x3cac
cmpb $0x0, -0x38(%rbp)
je 0x3db7
movq 0x527a(%rip), %rdi      # 0x8fc8
leaq 0x2788(%rip), %rsi      # 0x64dd
callq 0x3200
movq %rax, %rdi
movq -0x40(%rbp), %rsi
callq 0x31f0
movq %rax, %rdi
leaq 0x2758(%rip), %rsi      # 0x64c8
callq 0x3200
movq -0x58(%rbp), %rsi
subq -0x60(%rbp), %rsi
sarq $0x5, %rsi
decq %rsi
movq %rax, %rdi
callq 0x3150
movq %rax, %rdi
leaq 0x2764(%rip), %rsi      # 0x64fa
callq 0x3200
movq %rax, %rdi
movq %r12, %rsi
callq 0x31e0
movq %rax, %rdi
leaq 0x274f(%rip), %rsi      # 0x64ff
callq 0x3200
jmp 0x3e13
movq 0x520a(%rip), %rdi      # 0x8fc8
leaq 0x2709(%rip), %rsi      # 0x64ce
callq 0x3200
movq %rax, %rdi
movq -0x40(%rbp), %rsi
callq 0x31f0
movq %rax, %rdi
leaq 0x26e8(%rip), %rsi      # 0x64c8
callq 0x3200
movq -0x58(%rbp), %rsi
subq -0x60(%rbp), %rsi
sarq $0x5, %rsi
decq %rsi
movq %rax, %rdi
callq 0x3150
movq %rax, %rdi
leaq 0x26d5(%rip), %rsi      # 0x64db
callq 0x3200
movq %rax, %rdi
callq 0x3160
cmpb $0x0, -0x34(%rbp)
je 0x3e9e
movq -0xe0(%rbp), %rsi
leaq -0x430(%rbp), %rdi
pushq $0x1
popq %rdx
callq 0x3040
leaq -0x430(%rbp), %rdi
leaq 0x26c1(%rip), %rsi      # 0x6502
callq 0x3200
movq %rax, %rdi
movq -0x40(%rbp), %rsi
callq 0x31f0
movq %rax, %rdi
leaq 0x266c(%rip), %rsi      # 0x64c8
callq 0x3200
movq -0x58(%rbp), %rsi
subq -0x60(%rbp), %rsi
sarq $0x5, %rsi
decq %rsi
movq %rax, %rdi
callq 0x3150
movq %rax, %rdi
leaq 0x21d7(%rip), %rsi      # 0x6059
callq 0x3200
movq %rax, %rdi
movq %r12, %rsi
callq 0x31e0
leaq -0x430(%rbp), %rdi
callq 0x32e0
movq -0x40(%rbp), %r14
incq %r14
jmp 0x3bec
movq -0x40(%rbp), %rsi
addq -0x80(%rbp), %rsi
leaq -0x210(%rbp), %r14
movq %r14, %rdi
callq 0x32c0
movq %r15, %rdi
movq %r14, %rsi
callq 0x5344
leaq -0xc0(%rbp), %rdi
movq %r15, %rsi
callq 0x3280
movq %r15, %rdi
callq 0x30c0
movq %r14, %rdi
callq 0x30c0
leaq -0xc0(%rbp), %rdi
leaq 0x2161(%rip), %rsi      # 0x605a
callq 0x470b
testb %al, %al
je 0x3f2c
movq 0x50bf(%rip), %rdi      # 0x8fc8
leaq 0x2627(%rip), %rsi      # 0x6537
callq 0x3200
movq %rax, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x31e0
movq %rax, %rdi
callq 0x30e0
leaq -0xc0(%rbp), %rdi
pushq $0xa
popq %rsi
callq 0x31c0
movq -0xc0(%rbp), %rsi
leaq -0x2c(%rbp), %rdi
callq 0x4dea
pushq $0x1
popq %rdi
callq 0x3190
leaq -0xc0(%rbp), %rdi
leaq 0x20f8(%rip), %rsi      # 0x6059
callq 0x470b
testb %al, %al
je 0x406d
leaq -0x2c(%rbp), %rdi
leaq -0x1640(%rbp), %rsi
pushq $0xa
popq %rdx
movl $0xbebc200, %ecx        # imm = 0xBEBC200
movl $0x1388, %r8d           # imm = 0x1388
callq 0x500e
movq %r15, %rdi
leaq -0x1640(%rbp), %rsi
leaq -0x2d(%rbp), %rdx
callq 0x46d0
movq %r12, %rdi
movq %r15, %rsi
callq 0x3280
movq %r15, %rdi
callq 0x30c0
movq %r12, %rdi
callq 0x42d8
leaq -0x1f0(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x32c0
movq %r15, %rdi
movq %r14, %rsi
callq 0x461e
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3280
movq %r15, %rdi
callq 0x30c0
movq %r14, %rdi
callq 0x30c0
leaq -0xc0(%rbp), %rdi
movq %rbx, %rsi
callq 0x3030
cmpl $0x1, %eax
jne 0x3f6e
movq 0x4fb7(%rip), %rdi      # 0x8fc8
leaq 0x2539(%rip), %rsi      # 0x6551
callq 0x3200
movq %rax, %rdi
callq 0x30e0
movq %rax, %rdi
movq %r12, %rsi
callq 0x31e0
movq %rax, %rdi
callq 0x30e0
jmp 0x406d
movq 0x4f87(%rip), %rdi      # 0x8fc8
leaq 0x24d1(%rip), %rsi      # 0x6519
callq 0x3200
movq -0x98(%rbp), %rax
subq -0xa0(%rbp), %rax
sarq $0x5, %rax
movq -0x68(%rbp), %rcx
addq %rax, %rcx
decq %rcx
movq %rcx, -0x68(%rbp)
movq -0x68(%rbp), %rcx
incq %rcx
jmp 0x3ad1
movq 0x4f48(%rip), %rdi      # 0x8fc8
leaq 0x24db(%rip), %rsi      # 0x6562
callq 0x3200
movq %rax, %rdi
callq 0x30e0
cmpb $0x0, -0x34(%rbp)
je 0x3814
movq 0x4f23(%rip), %rdi      # 0x8fc8
leaq 0x24c8(%rip), %rsi      # 0x6574
callq 0x3200
leaq -0xe0(%rbp), %rsi
movq %rax, %rdi
callq 0x31e0
movq %rax, %rbx
leaq 0x1fbf(%rip), %rsi      # 0x6089
jmp 0x380c
jmp 0x41f6
movq %rax, %rbx
jmp 0x414f
movq %rax, %rbx
jmp 0x415b
movq %rax, %rbx
jmp 0x4167
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x4718
leaq -0xa0(%rbp), %rdi
callq 0x4718
leaq -0x80(%rbp), %rdi
callq 0x4718
leaq -0x140(%rbp), %rdi
callq 0x30c0
leaq -0x100(%rbp), %rdi
callq 0x30c0
leaq -0x160(%rbp), %rdi
callq 0x30c0
leaq -0xc0(%rbp), %rdi
callq 0x30c0
leaq -0x180(%rbp), %rdi
callq 0x30c0
leaq -0xe0(%rbp), %rdi
callq 0x30c0
leaq -0x430(%rbp), %rdi
callq 0x3310
leaq -0x638(%rbp), %rdi
callq 0x3050
leaq -0x2c(%rbp), %rdi
callq 0x4bf6
movq %rbx, %rdi
callq 0x3390
jmp 0x41f6
movq %rdx, %r14
movq %rax, %rbx
leaq -0x1d0(%rbp), %rdi
jmp 0x4198
jmp 0x41f6
movq %rdx, %r14
movq %rax, %rbx
leaq -0x1b8(%rbp), %rdi
callq 0x4718
jmp 0x41fc
movq %rdx, %r14
movq %rax, %rbx
leaq -0x210(%rbp), %rdi
jmp 0x41e9
jmp 0x41f6
movq %rdx, %r14
movq %rax, %rbx
leaq -0x1a0(%rbp), %rdi
jmp 0x41e9
jmp 0x41f6
jmp 0x41f6
movq %rdx, %r14
movq %rax, %rbx
leaq -0x1f0(%rbp), %rdi
jmp 0x41e9
jmp 0x41f6
jmp 0x41f6
jmp 0x41f6
jmp 0x41f6
jmp 0x41f6
movq %rdx, %r14
movq %rax, %rbx
leaq -0x230(%rbp), %rdi
callq 0x30c0
jmp 0x41fc
jmp 0x41f6
jmp 0x41f6
jmp 0x41f6
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x2, %r14d
jne 0x4258
movq %rbx, %rdi
callq 0x30a0
movq %rax, %rbx
movq 0x4db4(%rip), %rdi      # 0x8fc8
leaq 0x239c(%rip), %rsi      # 0x65b7
callq 0x3200
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x3200
movq %rax, %rdi
callq 0x30e0
leaq -0x2c(%rbp), %rdi
callq 0x51f2
leaq -0x2c(%rbp), %rdi
callq 0x4c0a
callq 0x3350
jmp 0x42a4
cmpl $0x1, %r14d
jne 0x40e9
movq %rbx, %rdi
callq 0x30a0
movq %rax, %rbx
movq 0x4d54(%rip), %rdi      # 0x8fc8
leaq 0x2327(%rip), %rsi      # 0x65a2
callq 0x3200
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x3200
movq %rax, %rdi
callq 0x30e0
callq 0x3350
pushq $0x1
popq %rbx
jmp 0x381f
jmp 0x40e6
jmp 0x40e6
movq %rax, %rbx
callq 0x3350
jmp 0x40e9
movq %rax, %rbx
callq 0x3350
jmp 0x40e9
movq %rax, %rdi
callq 0x4797