// File: /workspace/github_cpp_makefile_star2_O2/IHorvalds[P]RomAna/gui.cpp
// Function: main
int main(int argc, char** argv) {
  if (argc < 3) {
    std::cout << "The following options are available: 0(BUILD_TRIE) or 1 (PROCESS_TEXT) or 2 (UPDATE_DICT) or 3 (PROCESS_POET) or 4 (GINIFY_POET) or 5 (ESSENCE_POET) or 6 (COMPUTE_SIMILARITY)" << std::endl;
    std::cout << "You should insert one of the following schemas: " << std::endl;
    std::cout << "BUILD_TRIE: " << argv[0] << " 0 [file to read the inflections from] [file in which to save the dictionary]" << std::endl;
    std::cout << "PROCESS_TEXT: " << argv[0] << " 1 [dictionary file name] [input file name] [output file name]" << std::endl;
    std::cout << "UPDATE_DICT: " << argv[0] << " 2 [dictionary file name] [input file name] [output file name] [new dictionary file name]" << std::endl;
    std::cout << "ANALYZE_POET: " << argv[0] << " 3 [poet name from poets.txt]" << std::endl;
    std::cout << "GINIFY_POET: " << argv[0] << " 4 [poet name from poets.txt]" << std::endl;
    std::cout << "ESSENCE_POET: " << argv[0] << " 5 [poet name from poets.txt] [distribution type - richness or relative] [sortValues - if the ratios should be sorted]" << std::endl;
    std::cout << "COMPUTE_SIMILARITY: " << argv[0] << " 6 [poet name from poets.txt]" << std::endl;
    return -1;
  }
  
  uint32_t option = atoi(argv[1]);
  switch (option) {
    case BUILD_TRIE : {
      errorArgs(BUILD_TRIE, argc, 4); 
      
      const char* filename = argv[2];
      const char* saveInto = argv[3];
      
      // Create the latin file with python
      std::string tmp = filename;
      std::string pythonCommand = "python3 processing/convert_into_latin.py " + tmp;
      int warning = system(pythonCommand.data());
      size_t pos = tmp.find_last_of("/");
      if (pos == std::string::npos)
        tmp = "latin_" + tmp;
      else
        tmp = tmp.substr(0, pos) + "/latin_" + tmp.substr(pos + 1, tmp.size());
      const char* latinFilename = tmp.data();
      
      // Alloc the dictionary
      InflexEngine A(InflexEngine::Build, filename, latinFilename);
      
      std::cerr << "Size of InflexEngine = " << A.getSize() << std::endl;
      
      // And save the InflexEngine
      A.saveExternal(saveInto);
      
      // Erase the temporary latin file
      std::string eraseCommand = "rm " + tmp;
      warning = system(eraseCommand.data());
      break;
    }
    case PROCESS_TEXT : {
      errorArgs(PROCESS_TEXT, argc, 5); 
      
      // Use the InflexEngine while parsing the text
      std::string dictName = argv[2];
      InflexEngine dict(InflexEngine::Load, dictName.data());
      dictionaryTask(dict, argv[3]);
     
      // Print the frequencies obtained
      dict.showFreqs(argv[4]);
      break;
    }
    case UPDATE_DICT : {
      errorArgs(UPDATE_DICT, argc, 6); 
      
      // Use the InflexEngine while parsing the text
      std::string dictName = argv[2];
      InflexEngine dict(InflexEngine::Load, dictName.data()); 
      
      dictionaryTask(dict, argv[3]);
      
      // Print the frequencies obtained
      dict.showFreqs(argv[4]);
    
      // Save the new obtained dictionary
      dict.saveExternal(argv[5]);
      break;
    }
    case ANALYZE_POET : {
      errorArgs(ANALYZE_POET, argc, 3);
      
      // Compute the local frequencies of each word
      std::string poetName = argv[2];  
      PoetAnalyzer analyzer(poetName);
      analyzer.saveFrequencies();
      break;
    }
    case GINIFY_POET : {
      errorArgs(GINIFY_POET, argc, 3);
      
      // Ginify the poet, i.e, compute the local ginis
      std::string poetName = argv[2];
      LocalGiniGenerator gini(poetName);
      gini.save();
      break;
    }
    case ESSENCE_POET : {
      errorArgs(ESSENCE_POET, argc, 5);
      
      // Ginify the poet, i.e, compute the gini coefficient for each word
      std::string poetName = argv[2];
      std::string distributionType = argv[3];
      bool sortValues = atoi(argv[4]);
      EssenceGenerator essence(poetName, distributionType, sortValues);
      essence.save();
      break;
    }
    case COMPUTE_SIMILARITY : {
      errorArgs(COMPUTE_SIMILARITY, argc, 3);
      
      // Ginify the poet, i.e, compute the gini coefficient for each word
      std::string poetName = argv[2];
      SimilarityGenerator cmp(poetName);
      cmp.save();
      break;
    }
    default : {
      std::cout << "The option " << argv[1] << " is not (yet) available!" << std::endl;
    }
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rsi, %rbx
cmpl $0x2, %edi
jg 0x59de
movq 0x9777(%rip), %r14      # 0xefc8
leaq 0x4983(%rip), %rsi      # 0xa1db
movq %r14, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x4a1b(%rip), %rsi      # 0xa28a
movq %r14, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x4a35(%rip), %rsi      # 0xa2bb
movq %r14, %rdi
callq 0x3250
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x3250
leaq 0x4a28(%rip), %rsi      # 0xa2c8
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x4a5f(%rip), %rsi      # 0xa316
movq %r14, %rdi
callq 0x3250
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x3250
leaq 0x4a54(%rip), %rsi      # 0xa325
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x4a7c(%rip), %rsi      # 0xa364
movq %r14, %rdi
callq 0x3250
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x3250
leaq 0x4a70(%rip), %rsi      # 0xa372
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x4ab3(%rip), %rsi      # 0xa3cc
movq %r14, %rdi
callq 0x3250
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x3250
leaq 0x4aa8(%rip), %rsi      # 0xa3db
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x4aaf(%rip), %rsi      # 0xa3f9
movq %r14, %rdi
callq 0x3250
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x3250
leaq 0x4aa3(%rip), %rsi      # 0xa407
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x4aaa(%rip), %rsi      # 0xa425
movq %r14, %rdi
callq 0x3250
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x3250
leaq 0x4a9f(%rip), %rsi      # 0xa434
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x4aff(%rip), %rsi      # 0xa4ab
movq %r14, %rdi
callq 0x3250
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x3250
leaq 0x4afa(%rip), %rsi      # 0xa4c0
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
pushq $-0x1
popq %rax
jmp 0x5eff
movl %edi, %ebp
movq 0x8(%rbx), %rdi
callq 0x33c0
cmpl $0x6, %eax
ja 0x5c58
movl %eax, %eax
leaq 0x4625(%rip), %rcx      # 0xa020
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x4
popq %rdx
xorl %edi, %edi
movl %ebp, %esi
callq 0x54e0
movq 0x10(%rbx), %r14
movq 0x18(%rbx), %rbx
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
movq %r14, %rsi
callq 0x64da
leaq 0x477a(%rip), %rsi      # 0xa1a9
leaq 0x98(%rsp), %rdi
movq %rsp, %rdx
callq 0x6670
movq 0x98(%rsp), %rdi
callq 0x31f0
leaq 0x4b8d(%rip), %rsi      # 0xa5e0
movq %rsp, %rdi
pushq $-0x1
popq %rdx
callq 0x3240
cmpq $-0x1, %rax
je 0x5e37
movq %rax, %r15
leaq 0x1d8(%rsp), %rdi
movq %rsp, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x3280
leaq 0x4a57(%rip), %rdx      # 0xa4de
leaq 0xb8(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
callq 0x67cf
incq %r15
movq %rsp, %rsi
movq 0x8(%rsi), %rcx
leaq 0x1b8(%rsp), %rdi
movq %r15, %rdx
callq 0x3280
leaq 0x20(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x1b8(%rsp), %rdx
callq 0x6515
movq %rsp, %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x32e0
movq %r15, %rdi
callq 0x3120
leaq 0x1b8(%rsp), %rdi
callq 0x3120
leaq 0xb8(%rsp), %rdi
callq 0x3120
leaq 0x1d8(%rsp), %rdi
jmp 0x5e5e
pushq $0x4
popq %rdi
pushq $0x3
popq %rdx
movl %ebp, %esi
callq 0x54e0
movq 0x10(%rbx), %rsi
leaq 0x20(%rsp), %rdi
movq %rsp, %rdx
callq 0x64da
leaq 0x138(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3350
movq %rsp, %rdi
leaq 0x138(%rsp), %rsi
callq 0x3350
leaq 0x138(%rsp), %rdi
callq 0x3120
movq %rsp, %rdi
callq 0x6ae4
jmp 0x5e25
pushq $0x2
popq %rdi
pushq $0x6
popq %rdx
movl %ebp, %esi
callq 0x54e0
movq 0x10(%rbx), %rsi
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x64da
movq (%rsp), %rdx
leaq 0x20(%rsp), %rdi
pushq $0x1
popq %rsi
xorl %ecx, %ecx
callq 0x42c2
movq 0x18(%rbx), %rsi
leaq 0x20(%rsp), %rdi
callq 0x5540
movq 0x20(%rbx), %rsi
leaq 0x178(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0x64da
leaq 0x20(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x530e
leaq 0x178(%rsp), %rdi
callq 0x3120
movq 0x28(%rbx), %rsi
leaq 0x20(%rsp), %rdi
callq 0x4f44
jmp 0x5d0a
pushq $0x3
popq %rdi
movl %ebp, %esi
movl %edi, %edx
callq 0x54e0
movq 0x10(%rbx), %rsi
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x64da
leaq 0x158(%rsp), %rdi
movq %rsp, %rsi
callq 0x3350
leaq 0x20(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x67ee
leaq 0x158(%rsp), %rdi
callq 0x3120
leaq 0x20(%rsp), %rdi
callq 0x6834
leaq 0x20(%rsp), %rdi
callq 0x6ac0
jmp 0x5ef5
movq 0x9369(%rip), %rdi      # 0xefc8
leaq 0x489c(%rip), %rsi      # 0xa502
callq 0x3250
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x3250
leaq 0x4890(%rip), %rsi      # 0xa50e
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
jmp 0x5efd
pushq $0x1
popq %rdi
pushq $0x5
popq %rdx
movl %ebp, %esi
callq 0x54e0
movq 0x10(%rbx), %rsi
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x64da
movq (%rsp), %rdx
leaq 0x20(%rsp), %rdi
pushq $0x1
popq %rsi
xorl %ecx, %ecx
callq 0x42c2
movq 0x18(%rbx), %rsi
leaq 0x20(%rsp), %rdi
callq 0x5540
movq 0x20(%rbx), %rsi
leaq 0x198(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0x64da
leaq 0x20(%rsp), %rdi
leaq 0x198(%rsp), %rsi
callq 0x530e
leaq 0x198(%rsp), %rdi
callq 0x3120
leaq 0x20(%rsp), %rdi
callq 0x4bc6
jmp 0x5ef5
pushq $0x5
popq %rdi
movl %ebp, %esi
movl %edi, %edx
callq 0x54e0
movq 0x10(%rbx), %rsi
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x64da
movq 0x18(%rbx), %rsi
leaq 0x98(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x64da
movq 0x20(%rbx), %rdi
callq 0x33c0
movl %eax, %ebx
leaq 0x118(%rsp), %rdi
movq %rsp, %rsi
callq 0x3350
leaq 0xf8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x3350
xorl %ecx, %ecx
testl %ebx, %ebx
setne %cl
leaq 0x20(%rsp), %rdi
leaq 0x118(%rsp), %rsi
leaq 0xf8(%rsp), %rdx
callq 0x6b6e
leaq 0xf8(%rsp), %rdi
callq 0x3120
leaq 0x118(%rsp), %rdi
callq 0x3120
leaq 0x20(%rsp), %rdi
callq 0x6ba8
leaq 0x20(%rsp), %rdi
callq 0x6d5a
jmp 0x5ee8
pushq $0x6
popq %rdi
pushq $0x3
popq %rdx
movl %ebp, %esi
callq 0x54e0
movq 0x10(%rbx), %rsi
leaq 0x20(%rsp), %rdi
movq %rsp, %rdx
callq 0x64da
leaq 0xd8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3350
movq %rsp, %rdi
leaq 0xd8(%rsp), %rsi
callq 0x3350
leaq 0xd8(%rsp), %rdi
callq 0x3120
movq %rsp, %rdi
callq 0x6d70
movq %rsp, %rdi
callq 0x3120
leaq 0x20(%rsp), %rdi
jmp 0x5ef8
leaq 0x46a1(%rip), %rsi      # 0xa4df
leaq 0x20(%rsp), %rdi
movq %rsp, %rdx
callq 0x6670
movq %rsp, %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x32e0
movq %r15, %rdi
callq 0x3120
movq (%rsp), %rcx
leaq 0x20(%rsp), %rdi
pushq $0x2
popq %rsi
movq %r14, %rdx
callq 0x42c2
movq 0x9172(%rip), %rdi      # 0xeff0
leaq 0x4661(%rip), %rsi      # 0xa4e6
callq 0x3250
movl 0x48(%rsp), %esi
incl %esi
movq %rax, %rdi
callq 0x3190
movq %rax, %rdi
callq 0x3130
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x4f44
leaq 0x464a(%rip), %rsi      # 0xa4fe
leaq 0xb8(%rsp), %rdi
movq %rsp, %rdx
callq 0x6670
movq 0xb8(%rsp), %rdi
callq 0x31f0
leaq 0xb8(%rsp), %rdi
callq 0x3120
leaq 0x20(%rsp), %rdi
callq 0x4bc6
leaq 0x98(%rsp), %rdi
callq 0x3120
movq %rsp, %rdi
callq 0x3120
xorl %eax, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5ff3
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
callq 0x3120
jmp 0x5f27
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x3120
jmp 0x5f39
movq %rax, %rbx
leaq 0x1d8(%rsp), %rdi
jmp 0x5fba
jmp 0x5ff3
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x3120
jmp 0x6053
jmp 0x6050
jmp 0x5ff3
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x6d5a
jmp 0x605d
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x3120
jmp 0x5fb2
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
jmp 0x5fa3
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x3120
jmp 0x6044
jmp 0x5fda
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0x3120
jmp 0x605d
jmp 0x6041
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x6ac0
jmp 0x606a
jmp 0x6041
movq %rax, %rbx
movq %rsp, %rdi
jmp 0x6010
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
jmp 0x6010
jmp 0x5ff3
jmp 0x6041
movq %rax, %rbx
jmp 0x605d
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
jmp 0x6065
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x3120
jmp 0x6029
jmp 0x6026
jmp 0x6021
jmp 0x6021
jmp 0x6021
jmp 0x6021
movq %rax, %rbx
jmp 0x606a
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
jmp 0x606d
jmp 0x603c
jmp 0x603c
jmp 0x603c
jmp 0x603c
jmp 0x603c
jmp 0x603c
movq %rax, %rbx
jmp 0x6072
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x4bc6
jmp 0x606a
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x4bc6
leaq 0x98(%rsp), %rdi
callq 0x3120
movq %rsp, %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x3480