// File: /workspace/github_cpp_makefile_star2_O2/roberto-bayardo[P]google-extremal-sets/all-maximal-sets-cardinality.cc
// Function: google_extremal_sets::AllMaximalSetsCardinality::FindAllMaximalSets(google_extremal_sets::DataSourceIterator*, unsigned int, unsigned int, google_extremal_sets::OutputModeEnum)
bool AllMaximalSetsCardinality::FindAllMaximalSets(
    DataSourceIterator* data,
    uint32_t max_item_id,
    uint32_t max_items_in_ram,
    OutputModeEnum output_mode) {
  Init();

  // The index_us vector contains the previous itemsets whose
  // cardinality is the same as the current itemset. We delay their
  // indexing until they can potentially be subsumed; that is, when
  // the data iterator reaches itemsets with a higher cardinality.
  std::vector<SetProperties*> index_us;

  // Vars set by the data source iterator.
  int result;
  uint32_t set_id;
  std::vector<uint32_t> current_set;

  // This outer loop supports multiple passes over the data in the
  // case where the dataset exceeds the bound on max_items_in_ram. As
  // long as resume_offset == 0, we will continue retaining itemsets
  // in RAM. Otherwise itemsets from the data iterator will be used
  // only to perform subsumption checks against existing candidates,
  // and will be indexed during a subsequent pass.
  off_t resume_offset = 0;
  do {  // while (resume_offset != 0)
    if (!PrepareForDataScan(data, max_item_id, resume_offset))
      return false;  // IO error
    resume_offset = 0;
    uint32_t items_in_ram = 0;
    int current_set_size = -1;

    // This loop scans the input data from beginning to end.
    while ((result = data->Next(&set_id, &current_set)) > 0) {
      DeleteSubsumedCandidates(current_set);

      // If current_set has higher cardinality than the itemsets within
      // index_us, we move them from index_us into the candidate index.
      if (current_set.size() != static_cast<uint32_t>(current_set_size)) {
        IndexSets(index_us);
        index_us.clear();
        current_set_size = current_set.size();
      }

      if (resume_offset == 0) {
        // Copy the current_set into RAM and place a pointer to it in index_us.
        index_us.push_back(SetProperties::Create(set_id, current_set));
        items_in_ram += current_set.size();
        ++input_sets_count_;

        // Check if we've exceeded the RAM limit and if so stop
        // retaining any further itemsets in memory until the next
        // scan.
        if (items_in_ram >= max_items_in_ram) {
          resume_offset = data->Tell();
          std::cerr << "; Halting indexing at input set number "
                    << input_sets_count_ << " with id " << set_id << std::endl;
          // Force the sets in index_us to get added to the index.
          current_set_size = -1;
        }
      }  // if (resume_offset = 0)
    }  // while ((result = data->Next())

    if (result != 0)  // IO error
      return false;

    // At this point, any remaining candidate set and any remaining set
    // in index_us is maximal!
    DumpMaximalSets(&index_us, output_mode);
  } while (resume_offset != 0);

  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r8d, 0x8(%rsp)
movl %ecx, 0x4(%rsp)
movl %edx, 0xc(%rsp)
movq %rsi, %r15
movq %rdi, %r12
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x30(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x10(%rsp), %rbx
andq $0x0, 0x10(%rbx)
movaps %xmm0, (%rbx)
xorl %r14d, %r14d
movq %rsp, %rbp
movq %r12, %rdi
movq %r15, %rsi
movl 0xc(%rsp), %edx
movq %r14, %rcx
callq 0x26c2
xorl %r14d, %r14d
testb %al, %al
je 0x2669
movq $0x0, 0x48(%rsp)
xorl %r14d, %r14d
pushq $-0x1
popq %rax
movl %eax, %r13d
movq %r15, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x3436
testl %eax, %eax
jle 0x2645
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2738
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x2, %rax
movl %r13d, %ecx
cmpq %rcx, %rax
je 0x259a
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
callq 0x2864
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x258c
movq %rax, 0x38(%rsp)
movq 0x18(%rsp), %r13
subq 0x10(%rsp), %r13
shrq $0x2, %r13
testq %r14, %r14
jne 0x2537
movl (%rsp), %edi
movq %rbx, %rsi
callq 0x3cc4
movq %rax, 0x50(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2b96
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
incq 0x8(%r12)
shrq $0x2, %rax
movq 0x48(%rsp), %rcx
addl %eax, %ecx
movl $0x0, %r14d
movq %rcx, 0x48(%rsp)
cmpl 0x4(%rsp), %ecx
jb 0x2537
movq %r15, %rdi
callq 0x342e
movq %rax, %r14
movq 0x49f1(%rip), %rdi      # 0x6ff0
leaq 0x19fe(%rip), %rsi      # 0x4004
callq 0x21b0
movq 0x8(%r12), %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
leaq 0x1a0a(%rip), %rsi      # 0x402c
callq 0x21b0
movl (%rsp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20d0
pushq $-0x1
popq %rax
movl %eax, %r13d
jmp 0x2537
jne 0x2666
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
movl 0x8(%rsp), %edx
callq 0x28da
testq %r14, %r14
jne 0x2508
movb $0x1, %r14b
jmp 0x2669
xorl %r14d, %r14d
leaq 0x10(%rsp), %rdi
callq 0x2b62
leaq 0x30(%rsp), %rdi
callq 0x2b2e
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2697
jmp 0x2697
jmp 0x2697
jmp 0x2697
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2b62
leaq 0x30(%rsp), %rdi
callq 0x2b2e
movq %rbx, %rdi
callq 0x22b0