// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: vdbeSorterAddToTree
static int vdbeSorterAddToTree(
  SortSubtask *pTask,             /* Task context */
  int nDepth,                     /* Depth of tree according to TreeDepth() */
  int iSeq,                       /* Sequence number of leaf within tree */
  MergeEngine *pRoot,             /* Root of tree */
  MergeEngine *pLeaf              /* Leaf to add to tree */
){
  int rc = SQLITE_OK;
  int nDiv = 1;
  int i;
  MergeEngine *p = pRoot;
  IncrMerger *pIncr;

  rc = vdbeIncrMergerNew(pTask, pLeaf, &pIncr);

  for(i=1; i<nDepth; i++){
    nDiv = nDiv * SORTER_MAX_MERGE_COUNT;
  }

  for(i=1; i<nDepth && rc==SQLITE_OK; i++){
    int iIter = (iSeq / nDiv) % SORTER_MAX_MERGE_COUNT;
    PmaReader *pReadr = &p->aReadr[iIter];

    if( pReadr->pIncr==0 ){
      MergeEngine *pNew = vdbeMergeEngineNew(SORTER_MAX_MERGE_COUNT);
      if( pNew==0 ){
        rc = SQLITE_NOMEM_BKPT;
      }else{
        rc = vdbeIncrMergerNew(pTask, pNew, &pReadr->pIncr);
      }
    }
    if( rc==SQLITE_OK ){
      p = pReadr->pIncr->pMerger;
      nDiv = nDiv / SORTER_MAX_MERGE_COUNT;
    }
  }

  if( rc==SQLITE_OK ){
    p->aReadr[iSeq % SORTER_MAX_MERGE_COUNT].pIncr = pIncr;
  }else{
    vdbeIncrFree(pIncr);
  }
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x1, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x40a3d0
movl %eax, -0x24(%rbp)
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x409757
movl -0x28(%rbp), %eax
shll $0x4, %eax
movl %eax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x40973b
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
cmpl -0xc(%rbp), %ecx
movb %al, -0x59(%rbp)
jge 0x409775
cmpl $0x0, -0x24(%rbp)
sete %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x409781
jmp 0x409821
movl -0x10(%rbp), %eax
cltd
idivl -0x28(%rbp)
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x44(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x44(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x4097ed
movl $0x10, %edi
callq 0x409630
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x4097d3
movl $0x7, -0x24(%rbp)
jmp 0x4097eb
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq $0x48, %rdx
callq 0x40a3d0
movl %eax, -0x24(%rbp)
jmp 0x4097ed
cmpl $0x0, -0x24(%rbp)
jne 0x409811
movq -0x50(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movl -0x28(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %eax, -0x28(%rbp)
jmp 0x409813
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x40975e
cmpl $0x0, -0x24(%rbp)
jne 0x409856
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x68(%rbp)
movl -0x10(%rbp), %eax
movl $0x10, %esi
cltd
idivl %esi
movq -0x68(%rbp), %rax
movslq %edx, %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x48(%rax)
jmp 0x40985f
movq -0x40(%rbp), %rdi
callq 0x3ed600
movl -0x24(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)