// File: /workspace/github_c_makefile_star2_O3/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 %rdi, %r14
movq %rdi, 0x8(%rsi)
movslq (%rsi), %rax
testq %rax, %rax
jle 0x2a4685
movq %r14, 0x18(%rsp)
shlq $0x4, %rax
leaq (%rax,%rax,4), %rax
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
movq %rsi, 0x10(%rsp)
movq 0x18(%rsi), %r15
movq 0x48(%r15,%rbx), %r14
testq %r14, %r14
je 0x2a45aa
movq (%r14), %r12
movq 0x8(%r14), %rsi
movq 0x10(%r12), %rax
movq 0x20(%rax), %r13
movq %r12, %rdi
callq 0x2a44d9
testl %eax, %eax
jne 0x2a468d
movslq 0x18(%r14), %rbp
movq 0x58(%r12), %rax
movq 0x60(%r12), %rsi
testq %rax, %rax
jne 0x2a4582
leaq 0x58(%r12), %rax
movq %r13, %rdi
movq %rax, %r13
movq %rax, %rdx
callq 0x2a42ad
movq $0x0, 0x60(%r12)
testl %eax, %eax
jne 0x2a468d
movq (%r13), %rax
xorl %esi, %esi
addq %rbx, %r15
movq %rax, 0x38(%r14)
movq %rsi, 0x10(%r14)
addq %rsi, %rbp
movq %rbp, 0x60(%r12)
movq %r15, %rdi
callq 0x2a4a33
testl %eax, %eax
movq 0x10(%rsp), %rsi
jne 0x2a468d
addq $0x50, %rbx
cmpq %rbx, 0x20(%rsp)
jne 0x2a4513
movslq (%rsi), %rax
cmpq $0x2, %rax
movq 0x18(%rsp), %r14
jl 0x2a4685
movq %rax, %r12
incq %r12
leal -0x2(,%rax,2), %ebp
movq %r12, %r13
decq %r12
movl (%rsi), %ecx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
movslq %eax, %rcx
cmpq %rcx, %r12
jle 0x2a45ff
addl %eax, %eax
movl %ebp, %r15d
subl %eax, %r15d
leal 0x1(%r15), %ebx
jmp 0x2a460d
movq 0x10(%rsi), %rax
movl -0x10(%rax,%r13,8), %r15d
movl -0xc(%rax,%r13,8), %ebx
movq 0x18(%rsi), %rax
movslq %r15d, %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x4, %rcx
cmpq $0x0, 0x18(%rax,%rcx)
je 0x2a466f
movslq %ebx, %rdx
leaq (%rdx,%rdx,4), %r9
shlq $0x4, %r9
addq %rax, %r9
cmpq $0x0, 0x18(%r9)
je 0x2a466c
addq %rcx, %rax
movq 0x8(%rsi), %rdi
movl $0x0, 0xc(%rsp)
movq 0x28(%rax), %rdx
movl 0x14(%rax), %ecx
movq 0x28(%r9), %r8
movl 0x14(%r9), %r9d
leaq 0xc(%rsp), %rsi
callq *0x40(%rdi)
movq 0x10(%rsp), %rsi
testl %eax, %eax
cmovlel %r15d, %ebx
jmp 0x2a466f
movl %r15d, %ebx
movq 0x10(%rsi), %rax
movl %ebx, -0x8(%rax,%r13,4)
addl $-0x2, %ebp
cmpq $0x2, %r12
ja 0x2a45d8
movq 0x18(%r14), %rax
movzbl 0x13(%rax), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq