// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x4(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movslq -0x18(%rbp), %rax
imulq $0x50, %rax, %rax
addq %rax, %rdi
callq 0x409bc0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x40a3a5
movl $0x0, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x18(%rbp), %ecx
andl $0xfffe, %ecx           # imm = 0xFFFE
movslq %ecx, %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x18(%rbp), %ecx
orl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
addl -0x18(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jle 0x40a377
movq -0x30(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x40a243
movl $0x1, -0x40(%rbp)
jmp 0x40a28d
movq -0x38(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x40a257
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
jmp 0x40a28b
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rcx
movq 0x28(%rcx), %rdx
movq -0x30(%rbp), %rcx
movl 0x14(%rcx), %ecx
movq -0x38(%rbp), %rsi
movq 0x28(%rsi), %r8
movq -0x38(%rbp), %rsi
movl 0x14(%rsi), %r9d
leaq -0x3c(%rbp), %rsi
callq *%rax
movl %eax, -0x40(%rbp)
jmp 0x40a28d
cmpl $0x0, -0x40(%rbp)
jl 0x40a2a3
cmpl $0x0, -0x40(%rbp)
jne 0x40a2fe
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x40a2fe
movq -0x30(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
subq %rcx, %rax
movl $0x50, %ecx
cqto
idivq %rcx
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x24(%rbp), %edx
xorl $0x1, %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
jmp 0x40a362
movq -0x30(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x40a310
movl $0x0, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
subq %rcx, %rax
movl $0x50, %ecx
cqto
idivq %rcx
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x24(%rbp), %edx
xorl $0x1, %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0x40a364
movl -0x24(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x24(%rbp)
jmp 0x40a225
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq 0x4(%rcx), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x18(%rax)
sete %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x14(%rbp)
jne 0x40a3bc
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movzbl 0x13(%rax), %eax
movl %eax, -0x44(%rbp)
jmp 0x40a3c2
movl -0x14(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)