// File: /workspace/github_cpp_makefile_star2_O1/adamnovak[P]rlcsa/docarray.cpp
// Function: CSA::parseSingletonFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, CSA::DocArray const&, std::vector<std::pair<unsigned int, unsigned int>, std::allocator<std::pair<unsigned int, unsigned int>>>&, bool)
usint
parseSingletonFile(const std::string& file_name, const DocArray& docarray, std::vector<pair_type>& occurrences, bool print)
{
  std::ifstream input(file_name.c_str(), std::ios_base::binary);
  if(!input) { return 0; }

  usint total_singletons = 0;
  std::vector<std::string> rows;
  readRows(input, rows, true);
  input.close();

  bool invalid_blocks = false, invalid_docs = false;
  for(std::vector<std::string>::iterator iter = rows.begin(); iter != rows.end(); ++iter)
  {
    std::vector<usint> before, after;
    parseLine(*iter, before, ':', after);

    if(before.size() != 1 || !(docarray.nodeIsBlock(before[0])))
    {
      invalid_blocks = true;
      continue;
    }
    usint block_id = docarray.nodeToBlock(before[0]);

    usint prev_singleton = 0;
    for(std::vector<usint>::iterator iter = after.begin(); iter != after.end(); ++iter)
    {
      if(docarray.nodeIsDoc(*iter))
      {
        // There may be duplicates due to the implementation used to find bicliques.
        if(*iter != prev_singleton)
        {
          occurrences.push_back(pair_type(block_id, docarray.nodeToDoc(*iter)));
          total_singletons++; prev_singleton = *iter;
        }
      }
      else { invalid_docs = true; }
    }
  }

  if(print)
  {
    std::cout << "Singleton file" << file_name << ": " << total_singletons << " singletons" << std::endl;
    if(invalid_blocks)     { std::cout << "There were invalid block ids." << std::endl; }
    if(invalid_docs)       { std::cout << "There were invalid document ids." << std::endl; }
    std::cout << std::endl;
  }

  return total_singletons;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq (%rdi), %rsi
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movl $0x4, %edx
callq 0x3480
movq (%rbx), %rax
movq -0x18(%rax), %rax
xorl %ebx, %ebx
testb $0x5, 0xb0(%rsp,%rax)
jne 0x129b3
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rsi
movaps %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq 0x90(%rsp), %rdi
movl $0x1, %edx
callq 0x1badf
leaq 0x90(%rsp), %rdi
callq 0x3080
movq 0x60(%rsp), %r13
cmpq 0x68(%rsp), %r13
je 0x12846
movq %r15, 0x88(%rsp)
movl %ebp, 0xc(%rsp)
movq %r14, 0x80(%rsp)
xorl %ebp, %ebp
leaq 0x30(%rsp), %r14
xorl %r15d, %r15d
xorl %ebx, %ebx
movl $0x0, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq %rbp, 0x40(%rsp)
movq %rbp, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq %r13, %rdi
movq %r14, %rsi
movl $0x3a, %edx
leaq 0x10(%rsp), %rcx
callq 0x124f7
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rax, %rcx
cmpq $0x4, %rcx
jne 0x12781
movq %r14, %rbp
movl (%rax), %r14d
movq (%r12), %rax
movl 0x820(%rax), %eax
cmpl %r14d, %eax
jae 0x1277d
movq 0x8(%r12), %rcx
movq 0x10(%r12), %rdx
movl 0x4(%rcx), %ecx
addl %eax, %ecx
addl 0x4(%rdx), %ecx
cmpl %r14d, %ecx
jae 0x12785
movb $0x1, %bl
jmp 0x127ef
movb $0x1, %bl
jmp 0x127f4
movq %rbx, 0x50(%rsp)
movq 0x10(%rsp), %rbx
cmpq 0x18(%rsp), %rbx
je 0x127ea
notl %eax
addl %eax, %r14d
xorl %eax, %eax
movl (%rbx), %ecx
testl %ecx, %ecx
je 0x127af
movq (%r12), %rdx
cmpl %ecx, 0x820(%rdx)
jae 0x127bf
movb $0x1, %r15b
addq $0x4, %rbx
cmpq 0x18(%rsp), %rbx
jne 0x1279d
jmp 0x127ea
cmpl %eax, %ecx
je 0x127b2
movl (%rbx), %eax
decl %eax
movl %r14d, 0x58(%rsp)
movl %eax, 0x5c(%rsp)
movq 0x88(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xda22
incl 0x8(%rsp)
movl (%rbx), %eax
jmp 0x127b2
movq 0x50(%rsp), %rbx
movq %rbp, %r14
xorl %ebp, %ebp
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1280b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x12822
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
addq $0x20, %r13
cmpq 0x68(%rsp), %r13
jne 0x12712
movq %rbx, %r13
movl 0x8(%rsp), %ebx
movq 0x80(%rsp), %r14
movl 0xc(%rsp), %ebp
jmp 0x1284e
xorl %ebx, %ebx
xorl %r13d, %r13d
xorl %r15d, %r15d
testb %bpl, %bpl
je 0x129a9
movq 0x15772(%rip), %rdi     # 0x27fd0
leaq 0xc124(%rip), %rsi      # 0x1e989
movl $0xe, %edx
callq 0x32b0
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x15753(%rip), %r14     # 0x27fd0
movq %r14, %rdi
callq 0x32b0
movq %rax, %r12
leaq 0xb987(%rip), %rsi      # 0x1e216
movl $0x2, %edx
movq %rax, %rdi
callq 0x32b0
movl %ebx, %esi
movq %r12, %rdi
callq 0x3180
movq %rax, %r12
leaq 0xc0e8(%rip), %rsi      # 0x1e998
movl $0xb, %edx
movq %rax, %rdi
callq 0x32b0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3240
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3190
testb $0x1, %r13b
je 0x12932
movq 0x156de(%rip), %r12     # 0x27fd0
leaq 0xc0ab(%rip), %rsi      # 0x1e9a4
movl $0x1d, %edx
movq %r12, %rdi
callq 0x32b0
movq (%r12), %rax
addq -0x18(%rax), %r12
movq %r12, %rdi
movl $0xa, %esi
callq 0x3240
movsbl %al, %esi
movq 0x156ab(%rip), %rdi     # 0x27fd0
callq 0x3040
movq %rax, %rdi
callq 0x3190
testb $0x1, %r15b
je 0x1297e
movq 0x15691(%rip), %r15     # 0x27fd0
leaq 0xc07c(%rip), %rsi      # 0x1e9c2
movl $0x20, %edx
movq %r15, %rdi
callq 0x32b0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x3240
movsbl %al, %esi
movq 0x1565f(%rip), %rdi     # 0x27fd0
callq 0x3040
movq %rax, %rdi
callq 0x3190
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3240
movsbl %al, %esi
movq 0x15634(%rip), %rdi     # 0x27fd0
callq 0x3040
movq %rax, %rdi
callq 0x3190
leaq 0x60(%rsp), %rdi
callq 0x14482
leaq 0x90(%rsp), %rdi
callq 0x3090
movl %ebx, %eax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x129d6
movq %rax, %rbx
jmp 0x12a0e
jmp 0x129dd
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x129f7
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x12a0e
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
leaq 0x60(%rsp), %rdi
callq 0x14482
leaq 0x90(%rsp), %rdi
callq 0x3090
movq %rbx, %rdi
callq 0x3460
nop