// File: /workspace/github_cpp_makefile_star2_O1/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)
xorl %ebp, %ebp
movq %rbp, 0x10(%rdi)
leaq 0x30(%rsp), %rax
movq %rbp, 0x10(%rax)
movaps %xmm0, (%rax)
leaq 0x10(%rsp), %rbx
movq %rbp, 0x10(%rbx)
movaps %xmm0, (%rbx)
movq %rsp, %r14
movq %r12, %rdi
movq %r15, %rsi
movl 0xc(%rsp), %edx
movq %rbp, %rcx
callq 0x2708
xorl %r13d, %r13d
testb %al, %al
je 0x2676
movq $0x0, 0x48(%rsp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x3680
testl %eax, %eax
jle 0x2652
movq %r12, %rdi
movq %rbx, %rsi
callq 0x27a8
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x2, %rax
movl %r13d, %ecx
cmpq %rcx, %rax
je 0x2575
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
callq 0x2976
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x2567
movq %rax, 0x38(%rsp)
movq 0x18(%rsp), %r13
subq 0x10(%rsp), %r13
shrq $0x2, %r13
testq %rbp, %rbp
jne 0x2512
movl (%rsp), %edi
movq %rbx, %rsi
callq 0x4138
movq %rax, 0x50(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2bee
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
incq 0x8(%r12)
shrq $0x2, %rax
movq 0x48(%rsp), %rcx
addl %eax, %ecx
movl $0x0, %ebp
movq %rcx, 0x48(%rsp)
cmpl 0x4(%rsp), %ecx
jb 0x2512
movq %r15, %rdi
callq 0x3678
movq %rax, %rbp
movl $0x27, %edx
movq 0x5a12(%rip), %rdi      # 0x7ff0
leaq 0x2a1f(%rip), %rsi      # 0x5004
callq 0x21e0
movq 0x8(%r12), %rsi
movq 0x59fa(%rip), %rdi      # 0x7ff0
callq 0x2170
movq %rax, %r13
movl $0x9, %edx
movq %rax, %rdi
leaq 0x2a1f(%rip), %rsi      # 0x502c
callq 0x21e0
movl (%rsp), %esi
movq %r13, %rdi
callq 0x20f0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x2512
jne 0x2673
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
movl 0x8(%rsp), %edx
callq 0x2a10
testq %rbp, %rbp
jne 0x24e4
movb $0x1, %r13b
jmp 0x2676
xorl %r13d, %r13d
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x268d
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x26a4
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movl %r13d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x26be
jmp 0x26be
jmp 0x26be
jmp 0x26be
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x26d8
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x26ef
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x2270
nop