// File: /workspace/github_c_makefile_star2_O2/jflatow[P]jfdb/src/trie.c
// Function: JFT_iter_all_next
JFT_Boolean JFT_iter_all_next(JFT_Iter *iter) {
  // if any iterators are exhausted, we are done
  if (!iter->sub.many.active || iter->sub.many.active != iter->sub.many.exists)
    return False;

  JFT_Word *words = iter->batch.data = iter->words;
  for (iter->batch.size = 0; iter->batch.size < JFT_ITER_WORDS; ) {
    // scour the active iters for the next min element, until we fill a batch
    JFT_Mask hasMin = 0;
    JFT_Word min = -1, elem;
    JFT_Mask active = iter->sub.many.active;
    for (int b = ffsll(active); b; b = ffsll(active &= active - 1)) {
      JFT_Amount k = b - 1;
      JFT_Iter *i = iter->sub.many.iters + k;
      // as long as the position is out of bounds on the iter, reload it
      // if the iter is exhausted, remove it from active and skip to next
      while (i->batch.position >= i->batch.size)
        if (!JFT_iter_next(i)) {
          iter->sub.many.active &= ~(1LLU << k);
          goto nextActive;
        }
      if ((elem = i->batch.data[i->batch.position]) == min) {
        hasMin |= (1LLU << k);
      } else if (elem < min) {
        min = elem;
        hasMin = (1LLU << k);
      }
    nextActive:
      /* done with the active iter, move on to next */;
    }
    // if we can't find another min, all iters are exhausted and we are done
    // add the min to the batch iff everyone has it (main difference b/w any & all)
    if (!hasMin)
      break;
    else if (hasMin == iter->sub.many.exists)
      words[iter->batch.size++] = min;
    // advance any iters we found the min on
    for (int b = ffsll(hasMin); b; b = ffsll(hasMin &= hasMin - 1))
      iter->sub.many.iters[b - 1].batch.position++;
  }
  return True;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0xb0(%rdi), %rax
movl $0x0, 0x4(%rsp)
testq %rax, %rax
je 0x460f
movq %rdi, %r14
cmpq 0xa8(%rdi), %rax
jne 0x460f
leaq 0x18(%r14), %rax
movq %rax, 0x10(%r14)
andl $0x0, 0xc(%r14)
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
xorl %eax, %eax
cmpl $0xf, %eax
ja 0x460f
movq 0xb0(%r14), %r13
bsfq %r13, %r15
pushq $-0x1
popq %rbp
xorl %ebx, %ebx
testq %r13, %r13
je 0x45b0
imulq $0xc8, %r15, %r12
addq 0xa0(%r14), %r12
movl 0x8(%r12), %eax
cmpl 0xc(%r12), %eax
jb 0x457b
andl $0x0, 0x8(%r12)
movq %r12, %rdi
callq *(%r12)
testl %eax, %eax
jne 0x454c
pushq $-0x2
popq %rax
movl %r15d, %ecx
rolq %cl, %rax
andq %rax, 0xb0(%r14)
jmp 0x45a3
movq 0x10(%r12), %rcx
movq (%rcx,%rax,8), %rax
cmpq %rbp, %rax
jne 0x458f
btsq %r15, %rbx
jmp 0x45a3
pushq $0x1
popq %rdx
movl %r15d, %ecx
shlq %cl, %rdx
cmpq %rbp, %rax
cmovbq %rax, %rbp
cmovbq %rdx, %rbx
leaq -0x1(%r13), %rax
andq %rax, %r13
bsfq %r13, %r15
jmp 0x4539
testq %rbx, %rbx
je 0x460f
cmpq 0xa8(%r14), %rbx
jne 0x45ce
movl 0xc(%r14), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0xc(%r14)
movq %rbp, 0x18(%r14,%rax,8)
bsfq %rbx, %rax
incl %eax
xorl %edx, %edx
testl %eax, %eax
je 0x4606
movq 0xa0(%r14), %rcx
movl %eax, %eax
imulq $0xc8, %rax, %rax
incl -0xc0(%rcx,%rax)
leaq -0x1(%rbx), %rax
andq %rax, %rbx
bsfq %rbx, %rax
incl %eax
testq %rbx, %rbx
cmovel %edx, %eax
jmp 0x45d6
movl 0xc(%r14), %eax
jmp 0x4520
movl 0x4(%rsp), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq