// File: /workspace/github_c_makefile_star2_O0/jflatow[P]jfdb/src/trie.c
// Function: JFT_iter_any_next
JFT_Boolean JFT_iter_any_next(JFT_Iter *iter) {
  // if all iterators are exhausted we are done
  if (!iter->sub.many.active)
    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 always (main difference b/w any & all)
    if (!hasMin)
      break;
    else
      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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0xb0(%rax)
jne 0x6ac6
movl $0x0, -0x4(%rbp)
jmp 0x6ccd
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq -0x10(%rbp), %rcx
movq %rax, 0x10(%rcx)
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x10(%rbp), %rax
cmpl $0x10, 0xc(%rax)
jae 0x6cc6
movq $0x0, -0x20(%rbp)
movq $-0x1, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdx
tzcntq %rdx, %rax
addq $0x1, %rax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmoveq %rcx, %rax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x6c29
movl -0x3c(%rbp), %eax
subl $0x1, %eax
cltq
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rax
imulq $0xc8, -0x48(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x50(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jb 0x6ba3
movq -0x50(%rbp), %rdi
callq 0x6ce0
cmpl $0x0, %eax
jne 0x6ba1
movq -0x48(%rbp), %rcx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
xorq $-0x1, %rcx
movq -0x10(%rbp), %rax
andq 0xb0(%rax), %rcx
movq %rcx, 0xb0(%rax)
jmp 0x6bfc
jmp 0x6b5c
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rcx
movl 0x8(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
cmpq -0x28(%rbp), %rax
jne 0x6bd6
movq -0x48(%rbp), %rcx
movl $0x1, %eax
shlq %cl, %rax
orq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x6bfa
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x6bf8
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x48(%rbp), %rcx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x20(%rbp)
jmp 0x6bfa
jmp 0x6bfc
jmp 0x6bfe
movq -0x38(%rbp), %rdx
subq $0x1, %rdx
andq -0x38(%rbp), %rdx
movq %rdx, -0x38(%rbp)
tzcntq %rdx, %rax
addq $0x1, %rax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmoveq %rcx, %rax
movl %eax, -0x3c(%rbp)
jmp 0x6b2c
cmpq $0x0, -0x20(%rbp)
jne 0x6c35
jmp 0x6cc6
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rsi
movl 0xc(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0xc(%rsi)
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rdx
tzcntq %rdx, %rax
addq $0x1, %rax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmoveq %rcx, %rax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
je 0x6cc1
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rax
movl -0x54(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xc8, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rdx
subq $0x1, %rdx
andq -0x20(%rbp), %rdx
movq %rdx, -0x20(%rbp)
tzcntq %rdx, %rax
addq $0x1, %rax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmoveq %rcx, %rax
movl %eax, -0x54(%rbp)
jmp 0x6c6c
jmp 0x6ae5
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)