// File: /workspace/github_c_makefile_star2_O0/jflatow[P]jfdb/src/trie.c
// Function: JFT_iter_but_next
JFT_Boolean JFT_iter_but_next(JFT_Iter *iter) {
  // a - b - c - d - ...
  // if the first iter is exhausted, we are done
  if (ffsll(iter->sub.many.exists) != ffsll(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 iff only the first has it (main difference b/w but & all)
    if (!hasMin)
      break;
    else if (hasMin == (1LLU << (ffsll(iter->sub.many.exists) - 1)))
      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
movq 0xa8(%rax), %rdx
tzcntq %rdx, %rax
addq $0x1, %rax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmoveq %rcx, %rax
movq -0x10(%rbp), %rcx
movq 0xb0(%rcx), %rsi
tzcntq %rsi, %rcx
addq $0x1, %rcx
xorl %edx, %edx
cmpq $0x0, %rsi
cmoveq %rdx, %rcx
cmpl %ecx, %eax
je 0x6fd8
movl $0x0, -0x4(%rbp)
jmp 0x7218
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 0x7211
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 0x713b
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 0x70b5
movq -0x50(%rbp), %rdi
callq 0x6ce0
cmpl $0x0, %eax
jne 0x70b3
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 0x710e
jmp 0x706e
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 0x70e8
movq -0x48(%rbp), %rcx
movl $0x1, %eax
shlq %cl, %rax
orq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x710c
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x710a
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x48(%rbp), %rcx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x20(%rbp)
jmp 0x710c
jmp 0x710e
jmp 0x7110
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 0x703e
cmpq $0x0, -0x20(%rbp)
jne 0x7147
jmp 0x7211
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0xa8(%rcx), %rsi
tzcntq %rsi, %rcx
addq $0x1, %rcx
xorl %edx, %edx
cmpq $0x0, %rsi
cmoveq %rdx, %rcx
subl $0x1, %ecx
movl %ecx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
cmpq %rcx, %rax
jne 0x719b
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)
jmp 0x719d
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 0x720c
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 0x71b7
jmp 0x6ff7
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)