// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: vdbeMergeEngineInit
static int vdbeMergeEngineInit(
  SortSubtask *pTask,             /* Thread that will run pMerger */
  MergeEngine *pMerger,           /* MergeEngine to initialize */
  int eMode                       /* One of the INCRINIT_XXX constants */
){
  int rc = SQLITE_OK;             /* Return code */
  int i;                          /* For looping over PmaReader objects */
  int nTree;                      /* Number of subtrees to merge */

  /* Failure to allocate the merge would have been detected prior to
  ** invoking this routine */
  assert( pMerger!=0 );

  /* eMode is always INCRINIT_NORMAL in single-threaded mode */
  assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );

  /* Verify that the MergeEngine is assigned to a single thread */
  assert( pMerger->pTask==0 );
  pMerger->pTask = pTask;

  nTree = pMerger->nTree;
  for(i=0; i<nTree; i++){
    if( SQLITE_MAX_WORKER_THREADS>0 && eMode==INCRINIT_ROOT ){
      /* PmaReaders should be normally initialized in order, as if they are
      ** reading from the same temp file this makes for more linear file IO.
      ** However, in the INCRINIT_ROOT case, if PmaReader aReadr[nTask-1] is
      ** in use it will block the vdbePmaReaderNext() call while it uses
      ** the main thread to fill its buffer. So calling PmaReaderNext()
      ** on this PmaReader before any of the multi-threaded PmaReaders takes
      ** better advantage of multi-processor hardware. */
      rc = vdbePmaReaderNext(&pMerger->aReadr[nTree-i-1]);
    }else{
      rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i], INCRINIT_NORMAL);
    }
    if( rc!=SQLITE_OK ) return rc;
  }

  for(i=pMerger->nTree-1; i>0; i--){
    vdbeMergeEngineCompare(pMerger, i);
  }
  return pTask->pUnpacked->errCode;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, 0x10(%rsp)
movq %rdi, 0x8(%rsi)
movslq (%rsi), %rax
testq %rax, %rax
jle 0x2ae123
shlq $0x4, %rax
leaq (%rax,%rax,4), %rax
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
movq 0x18(%r14), %r15
movq 0x48(%r15,%rbx), %rbp
movl $0x0, %eax
testq %rbp, %rbp
je 0x2ae10c
movq (%rbp), %r12
movq 0x8(%rbp), %rsi
movq 0x10(%r12), %rax
movq 0x20(%rax), %r13
movq %r12, %rdi
callq 0x2ae047
testl %eax, %eax
jne 0x2ae0fd
movslq 0x18(%rbp), %rdx
xorl %eax, %eax
cmpq $0x0, 0x58(%r12)
jne 0x2ae0df
movq %rdx, 0x18(%rsp)
leaq 0x58(%r12), %rdx
movq 0x60(%r12), %rsi
movq %r13, %rdi
callq 0x2ade1e
movq 0x18(%rsp), %rdx
movq $0x0, 0x60(%r12)
testl %eax, %eax
jne 0x2ae0fd
movq 0x58(%r12), %rcx
movq %rcx, 0x38(%rbp)
movq 0x60(%r12), %rcx
movq %rcx, 0x10(%rbp)
addq %rcx, %rdx
movq %rdx, 0x60(%r12)
testl %eax, %eax
jne 0x2ae10c
addq %rbx, %r15
movq %r15, %rdi
callq 0x2ae5a6
testl %eax, %eax
jne 0x2ae1f3
addq $0x50, %rbx
cmpq %rbx, 0x20(%rsp)
jne 0x2ae07c
movslq (%r14), %rax
cmpq $0x2, %rax
jl 0x2ae1e6
movq %rax, %r12
incq %r12
leal -0x2(,%rax,2), %ebx
movq %r12, %r13
decq %r12
movl (%r14), %ecx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
movslq %eax, %rcx
cmpq %rcx, %r12
jle 0x2ae165
addl %eax, %eax
movl %ebx, %r15d
subl %eax, %r15d
leal 0x1(%r15), %ebp
jmp 0x2ae173
movq 0x10(%r14), %rax
movl -0x10(%rax,%r13,8), %r15d
movl -0xc(%rax,%r13,8), %ebp
movq 0x18(%r14), %rax
movslq %r15d, %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x4, %rcx
cmpq $0x0, 0x18(%rax,%rcx)
je 0x2ae1d0
movslq %ebp, %rdx
leaq (%rdx,%rdx,4), %rsi
shlq $0x4, %rsi
addq %rax, %rsi
cmpq $0x0, 0x18(%rsi)
je 0x2ae1cd
addq %rcx, %rax
movq 0x8(%r14), %rdi
movl $0x0, 0xc(%rsp)
movq 0x28(%rax), %rdx
movl 0x14(%rax), %ecx
movq 0x28(%rsi), %r8
movl 0x14(%rsi), %r9d
leaq 0xc(%rsp), %rsi
callq *0x40(%rdi)
testl %eax, %eax
cmovlel %r15d, %ebp
jmp 0x2ae1d0
movl %r15d, %ebp
movq 0x10(%r14), %rax
movl %ebp, -0x8(%rax,%r13,4)
addl $-0x2, %ebx
cmpq $0x2, %r12
jg 0x2ae13d
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movzbl 0x13(%rax), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq