// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x4
popq %rdx
movq %rbx, %rdi
callq 0x3450
movq (%rbx), %rax
movq -0x18(%rax), %rax
xorl %ebx, %ebx
testb $0x5, 0xa0(%rsp,%rax)
jne 0xfbeb
movq %r15, 0x58(%rsp)
movl %ebp, (%rsp)
movq %r14, 0x50(%rsp)
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rsi
movaps %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
leaq 0x80(%rsp), %rdi
pushq $0x1
popq %rdx
callq 0x15a4e
leaq 0x80(%rsp), %rdi
callq 0x3080
xorl %ebx, %ebx
movq 0x60(%rsp), %r13
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpq 0x68(%rsp), %r13
je 0xfb39
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
pushq $0x3a
popq %rdx
leaq 0x30(%rsp), %rcx
callq 0xf8ff
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
movb $0x1, %r14b
cmpq $0x4, %rcx
jne 0xfb19
movl (%rax), %esi
movq %r12, %rdi
callq 0x10e24
testb %al, %al
je 0xfb19
movl %r15d, 0x4(%rsp)
movq 0x10(%rsp), %rax
movq (%r12), %rcx
movl 0x820(%rcx), %r15d
notl %r15d
addl (%rax), %r15d
xorl %eax, %eax
movq 0x30(%rsp), %r14
cmpq 0x38(%rsp), %r14
je 0xfb12
movl (%r14), %ecx
testl %ecx, %ecx
je 0xfae4
movq (%r12), %rdx
cmpl %ecx, 0x820(%rdx)
jae 0xfaed
movb $0x1, %bpl
addq $0x4, %r14
jmp 0xfaca
cmpl %eax, %ecx
je 0xfae7
decl %ecx
movl %r15d, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xbbce
incl %ebx
movl (%r14), %eax
jmp 0xfae7
movl 0x4(%rsp), %eax
movl %eax, %r14d
leaq 0x30(%rsp), %rdi
callq 0xd8ea
leaq 0x10(%rsp), %rdi
callq 0xd8ea
addq $0x20, %r13
movl %r14d, %r15d
jmp 0xfa4b
cmpb $0x0, (%rsp)
je 0xfbe1
movq 0x14486(%rip), %rdi     # 0x23fd0
leaq 0x8e48(%rip), %rsi      # 0x18999
callq 0x3210
movq %rax, %rdi
movq 0x50(%rsp), %rsi
callq 0x3200
leaq 0x86b1(%rip), %rsi      # 0x1821b
movq %rax, %rdi
callq 0x3210
movl %ebx, %esi
movq %rax, %rdi
callq 0x3160
leaq 0x8e25(%rip), %rsi      # 0x189a8
movq %rax, %rdi
callq 0x3210
movq %rax, %rdi
callq 0x3100
testb $0x1, %r15b
je 0xfbb4
movq 0x14430(%rip), %rdi     # 0x23fd0
leaq 0x8e0d(%rip), %rsi      # 0x189b4
callq 0x3210
movq %rax, %rdi
callq 0x3100
testb $0x1, %bpl
je 0xfbd5
movq 0x1440f(%rip), %rdi     # 0x23fd0
leaq 0x8e0a(%rip), %rsi      # 0x189d2
callq 0x3210
movq %rax, %rdi
callq 0x3100
movq 0x143f4(%rip), %rdi     # 0x23fd0
callq 0x3100
leaq 0x60(%rsp), %rdi
callq 0x10e48
leaq 0x80(%rsp), %rdi
callq 0x30a0
movl %ebx, %eax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xfc0e
movq %rax, %rbx
jmp 0xfc2c
jmp 0xfc15
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xd8ea
leaq 0x10(%rsp), %rdi
callq 0xd8ea
leaq 0x60(%rsp), %rdi
callq 0x10e48
leaq 0x80(%rsp), %rdi
callq 0x30a0
movq %rbx, %rdi
callq 0x3430
nop