// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: vdbeMergeEngineStep
static int vdbeMergeEngineStep(
  MergeEngine *pMerger,      /* The merge engine to advance to the next row */
  int *pbEof                 /* Set TRUE at EOF.  Set false for more content */
){
  int rc;
  int iPrev = pMerger->aTree[1];/* Index of PmaReader to advance */
  SortSubtask *pTask = pMerger->pTask;

  /* Advance the current PmaReader */
  rc = vdbePmaReaderNext(&pMerger->aReadr[iPrev]);

  /* Update contents of aTree[] */
  if( rc==SQLITE_OK ){
    int i;                      /* Index of aTree[] to recalculate */
    PmaReader *pReadr1;         /* First PmaReader to compare */
    PmaReader *pReadr2;         /* Second PmaReader to compare */
    int bCached = 0;

    /* Find the first two PmaReaders to compare. The one that was just
    ** advanced (iPrev) and the one next to it in the array.  */
    pReadr1 = &pMerger->aReadr[(iPrev & 0xFFFE)];
    pReadr2 = &pMerger->aReadr[(iPrev | 0x0001)];

    for(i=(pMerger->nTree+iPrev)/2; i>0; i=i/2){
      /* Compare pReadr1 and pReadr2. Store the result in variable iRes. */
      int iRes;
      if( pReadr1->pFd==0 ){
        iRes = +1;
      }else if( pReadr2->pFd==0 ){
        iRes = -1;
      }else{
        iRes = pTask->xCompare(pTask, &bCached,
            pReadr1->aKey, pReadr1->nKey, pReadr2->aKey, pReadr2->nKey
        );
      }

      /* If pReadr1 contained the smaller value, set aTree[i] to its index.
      ** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this
      ** case there is no cache of pReadr2 in pTask->pUnpacked, so set
      ** pKey2 to point to the record belonging to pReadr2.
      **
      ** Alternatively, if pReadr2 contains the smaller of the two values,
      ** set aTree[i] to its index and update pReadr1. If vdbeSorterCompare()
      ** was actually called above, then pTask->pUnpacked now contains
      ** a value equivalent to pReadr2. So set pKey2 to NULL to prevent
      ** vdbeSorterCompare() from decoding pReadr2 again.
      **
      ** If the two values were equal, then the value from the oldest
      ** PMA should be considered smaller. The VdbeSorter.aReadr[] array
      ** is sorted from oldest to newest, so pReadr1 contains older values
      ** than pReadr2 iff (pReadr1<pReadr2).  */
      if( iRes<0 || (iRes==0 && pReadr1<pReadr2) ){
        pMerger->aTree[i] = (int)(pReadr1 - pMerger->aReadr);
        pReadr2 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
        bCached = 0;
      }else{
        if( pReadr1->pFd ) bCached = 0;
        pMerger->aTree[i] = (int)(pReadr2 - pMerger->aReadr);
        pReadr1 = &pMerger->aReadr[ pMerger->aTree[i ^ 0x0001] ];
      }
    }
    *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd==0);
  }

  return (rc==SQLITE_OK ? pTask->pUnpacked->errCode : rc);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r12
movq %rdi, %r15
movq 0x8(%rdi), %r14
movq 0x10(%rdi), %rax
movslq 0x4(%rax), %rbx
leaq (%rbx,%rbx,4), %rdi
shlq $0x4, %rdi
addq 0x18(%r15), %rdi
callq 0x2ae5a6
testl %eax, %eax
jne 0x2aeaff
movq %r12, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
movl (%r15), %ebp
addl %ebx, %ebp
cmpl $0x2, %ebp
jl 0x2aead1
movq 0x18(%r15), %rax
movq %rbx, %rcx
orq $0x1, %rcx
leaq (%rcx,%rcx,4), %r13
shlq $0x4, %r13
addq %rax, %r13
andl $0xfffe, %ebx           # imm = 0xFFFE
leaq (%rbx,%rbx,4), %rbx
shll $0x4, %ebx
addq %rax, %rbx
leaq 0xc(%rsp), %r12
cmpq $0x0, 0x18(%rbx)
je 0x2aea32
cmpq $0x0, 0x18(%r13)
je 0x2aea39
movq 0x28(%rbx), %rdx
movl 0x14(%rbx), %ecx
movq 0x28(%r13), %r8
movl 0x14(%r13), %r9d
movq %r14, %rdi
movq %r12, %rsi
callq *0x40(%r14)
jmp 0x2aea3e
movl $0x1, %eax
jmp 0x2aea3e
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %ebp, %ecx
shrl %ecx
movl %ecx, %edx
testl %eax, %eax
js 0x2aea4f
jne 0x2aea88
cmpq %r13, %rbx
jae 0x2aea88
movq 0x10(%r15), %rax
movq 0x18(%r15), %rsi
movq %rbx, %rdi
subq %rsi, %rdi
shrq $0x4, %rdi
imull $0xcccccccd, %edi, %edi # imm = 0xCCCCCCCD
movl %edi, (%rax,%rdx,4)
movl %ecx, %edx
xorl $0x1, %edx
movslq (%rax,%rdx,4), %rax
leaq (%rax,%rax,4), %r13
shlq $0x4, %r13
addq %rsi, %r13
movl $0x0, 0xc(%rsp)
jmp 0x2aeac6
cmpq $0x0, 0x18(%rbx)
je 0x2aea97
movl $0x0, 0xc(%rsp)
movq 0x10(%r15), %rax
movq 0x18(%r15), %rsi
movq %r13, %rdi
subq %rsi, %rdi
shrq $0x4, %rdi
imull $0xcccccccd, %edi, %edi # imm = 0xCCCCCCCD
movl %edi, (%rax,%rdx,4)
movl %ecx, %edx
xorl $0x1, %edx
movslq (%rax,%rdx,4), %rax
leaq (%rax,%rax,4), %rbx
shlq $0x4, %rbx
addq %rsi, %rbx
cmpl $0x3, %ebp
movl %ecx, %ebp
ja 0x2aea09
movq 0x10(%r15), %rax
movq 0x18(%r15), %rcx
movslq 0x4(%rax), %rax
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
xorl %edx, %edx
cmpq $0x0, 0x18(%rcx,%rax)
sete %dl
movq 0x10(%rsp), %rax
movl %edx, (%rax)
movq 0x18(%r14), %rax
movzbl 0x13(%rax), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq