// File: /workspace/github_c_makefile_star2_O0/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: vdbeSorterSetupMerge
static int vdbeSorterSetupMerge(VdbeSorter *pSorter){
  int rc;                         /* Return code */
  SortSubtask *pTask0 = &pSorter->aTask[0];
  MergeEngine *pMain = 0;
#if SQLITE_MAX_WORKER_THREADS
  sqlite3 *db = pTask0->pSorter->db;
  int i;
  SorterCompare xCompare = vdbeSorterGetCompare(pSorter);
  for(i=0; i<pSorter->nTask; i++){
    pSorter->aTask[i].xCompare = xCompare;
  }
#endif

  rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
  if( rc==SQLITE_OK ){
#if SQLITE_MAX_WORKER_THREADS
    assert( pSorter->bUseThreads==0 || pSorter->nTask>1 );
    if( pSorter->bUseThreads ){
      int iTask;
      PmaReader *pReadr = 0;
      SortSubtask *pLast = &pSorter->aTask[pSorter->nTask-1];
      rc = vdbeSortAllocUnpacked(pLast);
      if( rc==SQLITE_OK ){
        pReadr = (PmaReader*)sqlite3DbMallocZero(db, sizeof(PmaReader));
        pSorter->pReader = pReadr;
        if( pReadr==0 ) rc = SQLITE_NOMEM;
      }
      if( rc==SQLITE_OK ){
        rc = vdbeIncrMergerNew(pLast, pMain, &pReadr->pIncr);
        if( rc==SQLITE_OK ){
          vdbeIncrMergerSetThreads(pReadr->pIncr);
          for(iTask=0; iTask<(pSorter->nTask-1); iTask++){
            IncrMerger *pIncr;
            if( (pIncr = pMain->aReadr[iTask].pIncr) ){
              vdbeIncrMergerSetThreads(pIncr);
              assert( pIncr->pTask!=pLast );
            }
          }
          for(iTask=0; rc==SQLITE_OK && iTask<pSorter->nTask; iTask++){
            /* Check that:
            **   
            **   a) The incremental merge object is configured to use the
            **      right task, and
            **   b) If it is using task (nTask-1), it is configured to run
            **      in single-threaded mode. This is important, as the
            **      root merge (INCRINIT_ROOT) will be using the same task
            **      object.
            */
            PmaReader *p = &pMain->aReadr[iTask];
            assert( p->pIncr==0 || (
                (p->pIncr->pTask==&pSorter->aTask[iTask])             /* a */
             && (iTask!=pSorter->nTask-1 || p->pIncr->bUseThread==0)  /* b */
            ));
            rc = vdbePmaReaderIncrInit(p, INCRINIT_TASK);
          }
        }
        pMain = 0;
      }
      if( rc==SQLITE_OK ){
        rc = vdbePmaReaderIncrMergeInit(pReadr, INCRINIT_ROOT);
      }
    }else
#endif
    {
      rc = vdbeMergeEngineInit(pTask0, pMain, INCRINIT_NORMAL);
      pSorter->pMerger = pMain;
      pMain = 0;
    }
  }

  if( rc!=SQLITE_OK ){
    vdbeMergeEngineFree(pMain);
  }
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x4fc00
movq %rax, -0x38(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl 0x5b(%rcx), %ecx
cmpl %ecx, %eax
jge 0x4f989
movq -0x38(%rbp), %rcx
movq -0x8(%rbp), %rax
addq $0x60, %rax
movslq -0x2c(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x40(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x4f954
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x50920
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4fb4f
movq -0x8(%rbp), %rax
cmpb $0x0, 0x59(%rax)
je 0x4fb27
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rax
movq -0x8(%rbp), %rcx
movzbl 0x5b(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x4fb70
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4fa1a
movq -0x28(%rbp), %rdi
movl $0x50, %esi
callq 0x15b80
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
cmpq $0x0, -0x48(%rbp)
jne 0x4fa18
movl $0x7, -0xc(%rbp)
jmp 0x4fa1a
cmpl $0x0, -0xc(%rbp)
jne 0x4fb0e
movq -0x50(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq $0x48, %rdx
callq 0x50b70
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4fb06
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x50c70
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl 0x5b(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4faa3
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq 0x48(%rax), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x4fa96
movq -0x58(%rbp), %rdi
callq 0x50c70
jmp 0x4fa98
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4fa5a
movl $0x0, -0x3c(%rbp)
xorl %eax, %eax
cmpl $0x0, -0xc(%rbp)
movb %al, -0x61(%rbp)
jne 0x4fac8
movl -0x3c(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl 0x5b(%rcx), %ecx
cmpl %ecx, %eax
setl %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x4fad1
jmp 0x4fb04
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
movl $0x1, %esi
callq 0x50ca0
movl %eax, -0xc(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4faaa
jmp 0x4fb06
movq $0x0, -0x20(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x4fb25
movq -0x48(%rbp), %rdi
movl $0x2, %esi
callq 0x50d20
movl %eax, -0xc(%rbp)
jmp 0x4fb4d
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x50e80
movl %eax, -0xc(%rbp)
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
movq $0x0, -0x20(%rbp)
jmp 0x4fb4f
cmpl $0x0, -0xc(%rbp)
je 0x4fb5e
movq -0x20(%rbp), %rdi
callq 0x373f0
movl -0xc(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)