// File: /workspace/github_c_makefile_star2_O0/jflatow[P]jfdb/src/trie.c
// Function: JFT_iter_trans_next
JFT_Boolean JFT_iter_trans_next(JFT_Iter *iter) {
  // translate the next batch of offsets in the leaf
  // we are done once the position reaches the leaf size
  JFT_Leaf *leaf = &iter->sub.trans.leaf;
  JFT_Count left = leaf->size - iter->sub.trans.position;
  if (!left)
    return False;

  JFT_Word *words = iter->batch.data = iter->words;
  JFT_Word last = leaf->data[leaf->size - 1];
  JFT_Count lower = iter->sub.trans.lower;
  JFT_Count upper = MIN(iter->sub.trans.upper, iter->sub.trans.TLBSize / 2);
  for (iter->batch.size = 0; iter->batch.size < JFT_ITER_WORDS; ) {
    // try to make an informed initial guess
    // if that fails, fall back to bisection
    // NB: we could keep making 'informed' guesses, but it requires more work
    //    (because once we guess too high we no longer know how many are in range)
    JFT_Word word = leaf->data[iter->sub.trans.position++], at;
    JFT_Count lo = lower, hi = upper, mid = lo + (hi - lo) / (left + 1);
    while (lo < hi) {
      at = iter->sub.trans.TLB[2 * mid];
      if (at < word) {
        lo = mid + 1;
      } else if (at > word) {
        hi = mid;
        if (at > last)
          upper = mid;
      } else {
        lower = mid;
        break;
      }
      mid = lo + (hi - lo) / 2;
    }

    // we either found the word, or the bounds collapsed
    // if we found it, add the translated value
    // if the bounds collapsed, we won't be finding any more
    if (lo < hi)
      words[iter->batch.size++] = iter->sub.trans.TLB[2 * mid + 1];
    else
      iter->sub.trans.position = leaf->size;

    // once we are out of leaf words, we are done
    if (!(left = leaf->size - iter->sub.trans.position))
      break;
  }

  // remember the bounds for next time
  iter->sub.trans.lower = lower;
  iter->sub.trans.upper = upper;

  return True;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0xa0, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
subl 0xbc(%rcx), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x68ab
movl $0x0, -0x4(%rbp)
jmp 0x6a92
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq -0x10(%rbp), %rcx
movq %rax, 0x10(%rcx)
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0xc0(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movl 0xc4(%rax), %eax
movq -0x10(%rbp), %rcx
movl 0xb8(%rcx), %ecx
shrl %ecx
cmpl %ecx, %eax
jae 0x6910
movq -0x10(%rbp), %rax
movl 0xc4(%rax), %eax
movl %eax, -0x58(%rbp)
jmp 0x691f
movq -0x10(%rbp), %rax
movl 0xb8(%rax), %eax
shrl %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x10(%rbp), %rax
cmpl $0x10, 0xc(%rax)
jae 0x6a71
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rdx
movl 0xbc(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0xbc(%rdx)
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x50(%rbp), %eax
subl -0x4c(%rbp), %eax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movl -0x5c(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x54(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jae 0x6a06
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movl -0x54(%rbp), %ecx
shll %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x69c8
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x69f4
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jbe 0x69ea
movl -0x54(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x30(%rbp), %rax
jbe 0x69e8
movl -0x54(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x69f2
movl -0x54(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x6a06
jmp 0x69f4
movl -0x4c(%rbp), %eax
movl -0x50(%rbp), %ecx
subl -0x4c(%rbp), %ecx
shrl %ecx
addl %ecx, %eax
movl %eax, -0x54(%rbp)
jmp 0x6991
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jae 0x6a42
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movl -0x54(%rbp), %ecx
shll %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
movq -0x28(%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 0x6a52
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xbc(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
subl 0xbc(%rcx), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
jne 0x6a6c
jmp 0x6a71
jmp 0x6930
movl -0x34(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc0(%rax)
movl -0x38(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc4(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw (%rax,%rax)