// File: roberto-bayardo[P]google-extremal-sets/all-maximal-sets-lexicographic.cc
// Function: google_extremal_sets::AllMaximalSetsLexicographic::BuildIndex()
void AllMaximalSetsLexicographic::BuildIndex() {
  // Finally, we compress out the blanks, identify blocks of candidates that
  // start with the same item id, and build the index.
  std::cerr << "; Building index..." << std::endl;
  int blanks = 0;
  index_.resize(candidates_.back()->item[0] + 1);
  int begin_candidate_index = -1;
  SetProperties* begin_candidate = 0;  // candidate at the beginning of a block.
  uint32_t previous_item = 0;
  for (size_t i = 0; i < candidates_.size(); ++i) {
    SetProperties* candidate = candidates_[i];
    if (!candidate) {
      blanks++;
    } else {
      candidates_[i - blanks] = candidate;
      if (!begin_candidate) {
        begin_candidate = candidate;
        begin_candidate_index = i - blanks;
      } else if (candidate->item[0] != begin_candidate->item[0]) {
        // We've started a new block. Update the index with
        // the stats from the previous block.
        for (uint32_t item = previous_item + 1; item <= begin_candidate->item[0]; ++item) {
          index_[item] = begin_candidate_index;
        }
        previous_item = begin_candidate->item[0];
        begin_candidate = candidate;
        begin_candidate_index = i - blanks;
      }
    }
  }  // for()
  // Finish processing the final block.
  for (uint32_t item = previous_item + 1; item <= begin_candidate->item[0]; ++item) {
    index_[item] = begin_candidate_index;
  }
  candidates_.resize(candidates_.size() - blanks);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0xb2a5(%rip), %rdi      # 0xdff0
leaq 0x6469(%rip), %rsi      # 0x91bb
callq 0x2200
movq %rax, %rdi
movq 0xb257(%rip), %rsi      # 0xdfb8
callq 0x2240
movq -0x48(%rbp), %rdi
movl $0x0, -0xc(%rbp)
movq %rdi, %rax
addq $0x30, %rax
movq %rax, -0x40(%rbp)
addq $0x18, %rdi
callq 0x3a90
movq -0x40(%rbp), %rdi
movq (%rax), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x3ad0
movl $0xffffffff, -0x10(%rbp) # imm = 0xFFFFFFFF
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
addq $0x18, %rdi
callq 0x39a0
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
jae 0x2ed9
movq -0x48(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rsi
callq 0x39c0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x2e0b
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x2ec6
movq -0x48(%rbp), %rdi
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
addq $0x18, %rdi
movq -0x28(%rbp), %rsi
movslq -0xc(%rbp), %rax
subq %rax, %rsi
callq 0x39c0
movq -0x58(%rbp), %rcx
movq %rcx, (%rax)
cmpq $0x0, -0x18(%rbp)
jne 0x2e51
movq -0x30(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rax
movslq -0xc(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x10(%rbp)
jmp 0x2ec4
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
je 0x2ec2
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
ja 0x2ea2
movq -0x48(%rbp), %rdi
movslq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
addq $0x30, %rdi
movl -0x34(%rbp), %eax
movl %eax, %esi
callq 0x3b60
movq -0x60(%rbp), %rcx
movq %rcx, (%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2e6a
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rax
movslq -0xc(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x10(%rbp)
jmp 0x2ec4
jmp 0x2ec6
jmp 0x2ec8
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x2db9
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
ja 0x2f1a
movq -0x48(%rbp), %rdi
movslq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
addq $0x30, %rdi
movl -0x38(%rbp), %eax
movl %eax, %esi
callq 0x3b60
movq -0x68(%rbp), %rcx
movq %rcx, (%rax)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2ee2
movq -0x48(%rbp), %rdi
movq %rdi, %rax
addq $0x18, %rax
movq %rax, -0x70(%rbp)
addq $0x18, %rdi
callq 0x39a0
movq -0x70(%rbp), %rdi
movq %rax, %rsi
movslq -0xc(%rbp), %rax
subq %rax, %rsi
callq 0x3b80
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)