// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: whereLoopInsert
static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
  WhereLoop **ppPrev, *p;
  WhereInfo *pWInfo = pBuilder->pWInfo;
  sqlite3 *db = pWInfo->pParse->db;
  int rc;

  /* Stop the search once we hit the query planner search limit */
  if( pBuilder->iPlanLimit==0 ){
    WHERETRACE(0xffffffff,("=== query planner search limit reached ===\n"));
    if( pBuilder->pOrSet ) pBuilder->pOrSet->n = 0;
    return SQLITE_DONE;
  }
  pBuilder->iPlanLimit--;

  whereLoopAdjustCost(pWInfo->pLoops, pTemplate);

  /* If pBuilder->pOrSet is defined, then only keep track of the costs
  ** and prereqs.
  */
  if( pBuilder->pOrSet!=0 ){
    if( pTemplate->nLTerm ){
#if WHERETRACE_ENABLED
      u16 n = pBuilder->pOrSet->n;
      int x =
#endif
      whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
                                    pTemplate->nOut);
#if WHERETRACE_ENABLED /* 0x8 */
      if( sqlite3WhereTrace & 0x8 ){
        sqlite3DebugPrintf(x?"   or-%d:  ":"   or-X:  ", n);
        sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
      }
#endif
    }
    return SQLITE_OK;
  }

  /* Look for an existing WhereLoop to replace with pTemplate
  */
  ppPrev = whereLoopFindLesser(&pWInfo->pLoops, pTemplate);

  if( ppPrev==0 ){
    /* There already exists a WhereLoop on the list that is better
    ** than pTemplate, so just ignore pTemplate */
#if WHERETRACE_ENABLED /* 0x8 */
    if( sqlite3WhereTrace & 0x8 ){
      sqlite3DebugPrintf("   skip: ");
      sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
    }
#endif
    return SQLITE_OK;
  }else{
    p = *ppPrev;
  }

  /* If we reach this point it means that either p[] should be overwritten
  ** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
  ** WhereLoop and insert it.
  */
#if WHERETRACE_ENABLED /* 0x8 */
  if( sqlite3WhereTrace & 0x8 ){
    if( p!=0 ){
      sqlite3DebugPrintf("replace: ");
      sqlite3WhereLoopPrint(p, pBuilder->pWC);
      sqlite3DebugPrintf("   with: ");
    }else{
      sqlite3DebugPrintf("    add: ");
    }
    sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC);
  }
#endif
  if( p==0 ){
    /* Allocate a new WhereLoop to add to the end of the list */
    *ppPrev = p = sqlite3DbMallocRawNN(db, sizeof(WhereLoop));
    if( p==0 ) return SQLITE_NOMEM_BKPT;
    whereLoopInit(p);
    p->pNextLoop = 0;
  }else{
    /* We will be overwriting WhereLoop p[].  But before we do, first
    ** go through the rest of the list and delete any other entries besides
    ** p[] that are also supplated by pTemplate */
    WhereLoop **ppTail = &p->pNextLoop;
    WhereLoop *pToDel;
    while( *ppTail ){
      ppTail = whereLoopFindLesser(ppTail, pTemplate);
      if( ppTail==0 ) break;
      pToDel = *ppTail;
      if( pToDel==0 ) break;
      *ppTail = pToDel->pNextLoop;
#if WHERETRACE_ENABLED /* 0x8 */
      if( sqlite3WhereTrace & 0x8 ){
        sqlite3DebugPrintf(" delete: ");
        sqlite3WhereLoopPrint(pToDel, pBuilder->pWC);
      }
#endif
      whereLoopDelete(db, pToDel);
    }
  }
  rc = whereLoopXfer(db, p, pTemplate);
  if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
    Index *pIndex = p->u.btree.pIndex;
    if( pIndex && pIndex->idxType==SQLITE_IDXTYPE_IPK ){
      p->u.btree.pIndex = 0;
    }
  }
  return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r12
movl 0x2c(%rdi), %eax
testl %eax, %eax
je 0x2db609
movq %rsi, %rbx
movq (%r12), %r15
movq (%r15), %rcx
movq (%rcx), %r14
decl %eax
movl %eax, 0x2c(%r12)
movq 0x50(%r15), %r13
testq %r13, %r13
je 0x2db5dd
movl $0x200, %eax            # imm = 0x200
andl 0x28(%rbx), %eax
je 0x2db5dd
movb 0x10(%rbx), %bpl
cmpb %bpl, 0x10(%r13)
jne 0x2db5d4
testb $0x2, 0x29(%r13)
je 0x2db5d4
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2db8ea
movw $0xffff, %cx            # imm = 0xFFFF
testl %eax, %eax
jne 0x2db5c2
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2db8ea
movw $0x1, %cx
testl %eax, %eax
je 0x2db5d4
movzwl 0x14(%r13), %eax
movw %ax, 0x14(%rbx)
addw 0x16(%r13), %cx
movw %cx, 0x16(%rbx)
movq 0x40(%r13), %r13
testq %r13, %r13
jne 0x2db58f
movq 0x20(%r12), %rdi
testq %rdi, %rdi
je 0x2db626
xorl %ebp, %ebp
cmpw $0x0, 0x2c(%rbx)
je 0x2db785
movq (%rbx), %rsi
movswl 0x14(%rbx), %edx
movswl 0x16(%rbx), %ecx
callq 0x2db796
jmp 0x2db785
movq 0x20(%r12), %rax
movl $0x65, %ebp
testq %rax, %rax
je 0x2db785
movw $0x0, (%rax)
jmp 0x2db785
addq $0x50, %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2db83b
testq %rax, %rax
je 0x2db696
movq %rax, %r12
movq (%rax), %r15
testq %r15, %r15
je 0x2db69d
cmpq $0x0, 0x40(%r15)
je 0x2db6e0
leaq 0x40(%r15), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2db83b
testq %rax, %rax
je 0x2db6e0
movq %rax, %r12
movq (%rax), %r13
testq %r13, %r13
je 0x2db6e0
movq 0x40(%r13), %rax
movq %rax, (%r12)
movq %r14, %rdi
movq %r13, %rsi
callq 0x2db02e
movq %r14, %rdi
movq %r13, %rsi
callq 0x282904
cmpq $0x0, (%r12)
jne 0x2db654
jmp 0x2db6e0
xorl %ebp, %ebp
jmp 0x2db785
movl $0x60, %esi
movq %r14, %rdi
callq 0x282a35
movq %rax, (%r12)
testq %rax, %rax
je 0x2db780
movq %rax, %r15
addq $0x48, %rax
movq %rax, 0x38(%r15)
movw $0x0, 0x2c(%r15)
movw $0x3, 0x30(%r15)
movl $0x0, 0x28(%r15)
movq $0x0, 0x40(%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x2db981
movzwl 0x2c(%rbx), %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2db076
testl %eax, %eax
je 0x2db70d
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r15)
movl $0x7, %ebp
jmp 0x2db75c
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm2, 0x20(%r15)
movups %xmm1, 0x10(%r15)
movups %xmm0, (%r15)
movq 0x38(%r15), %rdi
movq 0x38(%rbx), %rsi
movzwl 0x2c(%r15), %edx
shll $0x3, %edx
callq 0x17660
movl 0x28(%rbx), %eax
btl $0xa, %eax
jb 0x2db756
xorl %ebp, %ebp
btl $0xe, %eax
jae 0x2db75c
movq $0x0, 0x20(%rbx)
jmp 0x2db75c
movb $0x0, 0x1c(%rbx)
xorl %ebp, %ebp
testb $0x4, 0x29(%r15)
jne 0x2db785
movq 0x20(%r15), %rax
testq %rax, %rax
je 0x2db785
movzwl 0x63(%rax), %eax
notl %eax
testb $0x3, %al
jne 0x2db785
movq $0x0, 0x20(%r15)
jmp 0x2db785
movl $0x7, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq