// File: 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
movq %rsp, %rbp
subq $0x370, %rsp            # imm = 0x370
movb %cl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3130
movq %rax, %rsi
leaq -0x230(%rbp), %rdi
movl $0x4, %edx
callq 0x35a0
movq -0x230(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x230(%rbp,%rax), %rdi
callq 0x3160
movb %al, -0x2cd(%rbp)
jmp 0x20eab
movb -0x2cd(%rbp), %al
testb $0x1, %al
jne 0x20eb7
jmp 0x20ee4
movl $0x0, -0x4(%rbp)
movl $0x1, -0x240(%rbp)
jmp 0x213ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x213c6
movl $0x0, -0x244(%rbp)
leaq -0x260(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x23820
movq -0x2d8(%rbp), %rsi
leaq -0x230(%rbp), %rdi
movl $0x1, %edx
callq 0x2f270
jmp 0x20f1b
leaq -0x230(%rbp), %rdi
callq 0x30b0
jmp 0x20f29
movb $0x0, -0x261(%rbp)
movb $0x0, -0x262(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x23840
movq %rax, -0x270(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x238b0
movq %rax, -0x278(%rbp)
leaq -0x270(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x23870
testb $0x1, %al
jne 0x20f79
jmp 0x21249
leaq -0x290(%rbp), %rdi
movq %rdi, -0x2e8(%rbp)
callq 0x10bc0
leaq -0x2a8(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
callq 0x10bc0
leaq -0x270(%rbp), %rdi
callq 0x238e0
movq -0x2e8(%rbp), %rsi
movq -0x2e0(%rbp), %rcx
movq %rax, %rdi
movl $0x3a, %edx
callq 0x20d20
jmp 0x20fc8
leaq -0x290(%rbp), %rdi
callq 0x7810
cmpq $0x1, %rax
jne 0x21017
movq -0x18(%rbp), %rax
movq %rax, -0x2f8(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x290(%rbp), %rdi
callq 0x9420
movq -0x2f8(%rbp), %rdi
movl (%rax), %esi
callq 0x23900
movb %al, -0x2e9(%rbp)
jmp 0x2100b
movb -0x2e9(%rbp), %al
testb $0x1, %al
jne 0x21073
jmp 0x21017
movb $0x1, -0x261(%rbp)
movl $0x4, -0x240(%rbp)
jmp 0x21210
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x213a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x1c250
leaq -0x290(%rbp), %rdi
callq 0x1c250
jmp 0x213a0
movq -0x18(%rbp), %rax
movq %rax, -0x308(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x290(%rbp), %rdi
callq 0x9420
movq -0x308(%rbp), %rdi
movl (%rax), %esi
callq 0x23970
movl %eax, -0x2fc(%rbp)
jmp 0x210a4
movl -0x2fc(%rbp), %eax
movl %eax, -0x2ac(%rbp)
movl $0x0, -0x2b0(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x7870
movq %rax, -0x2b8(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x78e0
movq %rax, -0x2c0(%rbp)
leaq -0x2b8(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x78a0
testb $0x1, %al
jne 0x210fc
jmp 0x21206
movq -0x18(%rbp), %rax
movq %rax, -0x318(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0x7910
movq -0x318(%rbp), %rdi
movl (%rax), %esi
callq 0x239a0
movb %al, -0x309(%rbp)
jmp 0x21129
movb -0x309(%rbp), %al
testb $0x1, %al
jne 0x21138
jmp 0x211ec
leaq -0x2b8(%rbp), %rdi
callq 0x7910
movl (%rax), %eax
cmpl -0x2b0(%rbp), %eax
je 0x211ea
movq -0x20(%rbp), %rax
movq %rax, -0x330(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x328(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0x7910
movq -0x328(%rbp), %rdi
movl (%rax), %esi
callq 0x239f0
movl %eax, -0x31c(%rbp)
jmp 0x2118a
movl -0x31c(%rbp), %eax
movl %eax, -0x2cc(%rbp)
leaq -0x2c8(%rbp), %rdi
leaq -0x2ac(%rbp), %rsi
leaq -0x2cc(%rbp), %rdx
callq 0x11230
jmp 0x211b2
movq -0x330(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0x17930
jmp 0x211c7
movl -0x244(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x244(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0x7910
movl (%rax), %eax
movl %eax, -0x2b0(%rbp)
jmp 0x211f3
movb $0x1, -0x262(%rbp)
jmp 0x211f5
leaq -0x2b8(%rbp), %rdi
callq 0x7930
jmp 0x210cd
movl $0x0, -0x240(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x1c250
leaq -0x290(%rbp), %rdi
callq 0x1c250
movl -0x240(%rbp), %eax
testl %eax, %eax
je 0x21236
jmp 0x21234
jmp 0x21238
jmp 0x21238
leaq -0x270(%rbp), %rdi
callq 0x23a10
jmp 0x20f4a
testb $0x1, -0x21(%rbp)
je 0x2137f
movq 0x24d76(%rip), %rdi     # 0x45fd0
leaq 0x1373c(%rip), %rsi     # 0x3499d
callq 0x32c0
movq %rax, -0x338(%rbp)
jmp 0x2126f
movq -0x338(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3290
movq %rax, -0x340(%rbp)
jmp 0x21288
movq -0x340(%rbp), %rdi
leaq 0x12f85(%rip), %rsi     # 0x3421b
callq 0x32c0
movq %rax, -0x348(%rbp)
jmp 0x212a4
movq -0x348(%rbp), %rdi
movl -0x244(%rbp), %esi
callq 0x3420
movq %rax, -0x350(%rbp)
jmp 0x212bf
movq -0x350(%rbp), %rdi
leaq 0x136df(%rip), %rsi     # 0x349ac
callq 0x32c0
movq %rax, -0x358(%rbp)
jmp 0x212db
movq -0x358(%rbp), %rdi
movq 0x24cc7(%rip), %rsi     # 0x45fb0
callq 0x3330
jmp 0x212f0
testb $0x1, -0x261(%rbp)
je 0x2132c
movq 0x24cd0(%rip), %rdi     # 0x45fd0
leaq 0x136b1(%rip), %rsi     # 0x349b8
callq 0x32c0
movq %rax, -0x360(%rbp)
jmp 0x21315
movq -0x360(%rbp), %rdi
movq 0x24c8d(%rip), %rsi     # 0x45fb0
callq 0x3330
jmp 0x2132a
jmp 0x2132c
testb $0x1, -0x262(%rbp)
je 0x21368
movq 0x24c94(%rip), %rdi     # 0x45fd0
leaq 0x13693(%rip), %rsi     # 0x349d6
callq 0x32c0
movq %rax, -0x368(%rbp)
jmp 0x21351
movq -0x368(%rbp), %rdi
movq 0x24c51(%rip), %rsi     # 0x45fb0
callq 0x3330
jmp 0x21366
jmp 0x21368
movq 0x24c61(%rip), %rdi     # 0x45fd0
movq 0x24c3a(%rip), %rsi     # 0x45fb0
callq 0x3330
jmp 0x2137d
jmp 0x2137f
movl -0x244(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x240(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x23a30
jmp 0x213ae
leaq -0x260(%rbp), %rdi
callq 0x23a30
jmp 0x213c6
leaq -0x230(%rbp), %rdi
callq 0x30e0
movl -0x4(%rbp), %eax
addq $0x370, %rsp            # imm = 0x370
popq %rbp
retq
leaq -0x230(%rbp), %rdi
callq 0x30e0
movq -0x238(%rbp), %rdi
callq 0x3570
nop