// File: /workspace/github_cpp_makefile_star2_O3/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 $0x288, %rsp            # imm = 0x288
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq (%rdi), %rsi
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
movl $0x4, %edx
callq 0x3480
movq (%rbx), %rax
movq -0x18(%rax), %rax
xorl %ebx, %ebx
testb $0x5, 0xa0(%rsp,%rax)
jne 0x12c2a
movq %r15, 0x78(%rsp)
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rsi
movaps %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq 0x80(%rsp), %rdi
movl $0x1, %edx
callq 0x1bfef
leaq 0x80(%rsp), %rdi
callq 0x3080
movl %ebp, 0xc(%rsp)
movq %r14, 0x70(%rsp)
movq 0x50(%rsp), %r13
cmpq 0x58(%rsp), %r13
je 0x12aae
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %r14d, %r14d
movl $0x0, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq %rbx, 0x40(%rsp)
movq %rbx, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
movl $0x3a, %edx
leaq 0x10(%rsp), %rcx
callq 0x1278d
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rdx
subq %rcx, %rdx
movb $0x1, %al
cmpq $0x4, %rdx
jne 0x12a62
movl %r14d, %ebx
movl (%rcx), %r14d
movq (%r12), %rcx
movl 0x820(%rcx), %ecx
cmpl %r14d, %ecx
jae 0x12a60
movq 0x8(%r12), %rdx
movq 0x10(%r12), %rsi
movl 0x4(%rdx), %edx
addl %ecx, %edx
addl 0x4(%rsi), %edx
cmpl %r14d, %edx
jb 0x12a60
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %rax
cmpq %rax, %r15
je 0x12aa7
notl %ecx
addl %ecx, %r14d
xorl %ecx, %ecx
movl (%r15), %edx
testl %edx, %edx
je 0x12a24
movq (%r12), %rsi
cmpl %edx, 0x820(%rsi)
jae 0x12a32
movb $0x1, %bpl
addq $0x4, %r15
cmpq %rax, %r15
jne 0x12a11
jmp 0x12a5e
cmpl %ecx, %edx
je 0x12a27
decl %edx
movl %r14d, 0x48(%rsp)
movl %edx, 0x4c(%rsp)
movq 0x78(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0xdb56
incl 0x8(%rsp)
movl (%r15), %ecx
movq 0x18(%rsp), %rax
jmp 0x12a27
movl %ebx, %eax
xorl %ebx, %ebx
movq 0x10(%rsp), %r15
movl %eax, %r14d
testq %r15, %r15
je 0x12a7f
movq 0x20(%rsp), %rsi
subq %r15, %rsi
movq %r15, %rdi
callq 0x3270
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x12a96
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
addq $0x20, %r13
cmpq 0x58(%rsp), %r13
jne 0x12980
jmp 0x12abb
movl %ebx, %r14d
xorl %ebx, %ebx
jmp 0x12a6a
movl $0x0, 0x8(%rsp)
xorl %r14d, %r14d
xorl %ebp, %ebp
cmpb $0x0, 0xc(%rsp)
movl 0x8(%rsp), %ebx
je 0x12c20
movq 0x154ff(%rip), %rdi     # 0x27fd0
leaq 0xbf01(%rip), %rsi      # 0x1e9d9
movl $0xe, %edx
callq 0x32b0
movq 0x70(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x154db(%rip), %r12     # 0x27fd0
movq %r12, %rdi
callq 0x32b0
movq %rax, %r15
leaq 0xb70f(%rip), %rsi      # 0x1e216
movl $0x2, %edx
movq %rax, %rdi
callq 0x32b0
movl %ebx, %esi
movq %r15, %rdi
callq 0x3180
movq %rax, %r15
leaq 0xbec0(%rip), %rsi      # 0x1e9e8
movl $0xb, %edx
movq %rax, %rdi
callq 0x32b0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3240
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3190
testb $0x1, %r14b
je 0x12ba8
movq 0x15467(%rip), %r15     # 0x27fd0
leaq 0xbe84(%rip), %rsi      # 0x1e9f4
movl $0x1d, %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 0x15435(%rip), %rdi     # 0x27fd0
callq 0x3040
movq %rax, %rdi
callq 0x3190
testb $0x1, %bpl
je 0x12bf4
movq 0x1541b(%rip), %r15     # 0x27fd0
leaq 0xbe56(%rip), %rsi      # 0x1ea12
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 0x153e9(%rip), %rdi     # 0x27fd0
callq 0x3040
movq %rax, %rdi
callq 0x3190
movq (%r12), %rax
addq -0x18(%rax), %r12
movq %r12, %rdi
movl $0xa, %esi
callq 0x3240
movsbl %al, %esi
movq 0x153bd(%rip), %rdi     # 0x27fd0
callq 0x3040
movq %rax, %rdi
callq 0x3190
leaq 0x50(%rsp), %rdi
callq 0x14752
leaq 0x80(%rsp), %rdi
callq 0x3090
movl %ebx, %eax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x12c4d
movq %rax, %rbx
jmp 0x12c85
jmp 0x12c54
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x12c6e
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x12c85
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
leaq 0x50(%rsp), %rdi
callq 0x14752
leaq 0x80(%rsp), %rdi
callq 0x3090
movq %rbx, %rdi
callq 0x3460