// File: /workspace/github_c_makefile_star2_O2/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 0x27a879
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 0x27a84d
movl $0x200, %eax            # imm = 0x200
andl 0x28(%rbx), %eax
je 0x27a84d
movb 0x10(%rbx), %bpl
cmpb %bpl, 0x10(%r13)
jne 0x27a844
testb $0x2, 0x29(%r13)
je 0x27a844
movq %r13, %rdi
movq %rbx, %rsi
callq 0x27ab45
movw $0xffff, %cx            # imm = 0xFFFF
testl %eax, %eax
jne 0x27a832
movq %rbx, %rdi
movq %r13, %rsi
callq 0x27ab45
movw $0x1, %cx
testl %eax, %eax
je 0x27a844
movzwl 0x14(%r13), %eax
movw %ax, 0x14(%rbx)
addw 0x16(%r13), %cx
movw %cx, 0x16(%rbx)
movq 0x40(%r13), %r13
testq %r13, %r13
jne 0x27a7ff
movq 0x20(%r12), %rdi
testq %rdi, %rdi
je 0x27a893
xorl %ebp, %ebp
cmpw $0x0, 0x2c(%rbx)
je 0x27a9c6
movq (%rbx), %rsi
movswl 0x14(%rbx), %edx
movswl 0x16(%rbx), %ecx
callq 0x27a9d7
jmp 0x27a9c6
movq 0x20(%r12), %rax
pushq $0x65
popq %rbp
testq %rax, %rax
je 0x27a9c6
andw $0x0, (%rax)
jmp 0x27a9c6
addq $0x50, %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x27aa84
testq %rax, %rax
je 0x27a8ea
movq %rax, %r12
movq (%rax), %r15
testq %r15, %r15
je 0x27a8f1
leaq 0x40(%r15), %r12
cmpq $0x0, (%r12)
je 0x27a92b
movq %r12, %rdi
movq %rbx, %rsi
callq 0x27aa84
testq %rax, %rax
je 0x27a92b
movq %rax, %r12
movq (%rax), %rsi
testq %rsi, %rsi
je 0x27a92b
movq 0x40(%rsi), %rax
movq %rax, (%r12)
movq %r14, %rdi
callq 0x27ab24
jmp 0x27a8b6
xorl %ebp, %ebp
jmp 0x27a9c6
pushq $0x60
popq %rsi
movq %r14, %rdi
callq 0x22d205
movq %rax, (%r12)
testq %rax, %rax
je 0x27a9c3
movq %rax, %r15
addq $0x48, %rax
movq %rax, 0x38(%r15)
andw $0x0, 0x2c(%r15)
movw $0x3, 0x30(%r15)
andl $0x0, 0x28(%r15)
andq $0x0, 0x40(%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x27abcc
movzwl 0x2c(%rbx), %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x27a36d
testl %eax, %eax
je 0x27a956
pushq $0x7
popq %rbp
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r15)
jmp 0x27a9a2
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 0x17630
movl 0x28(%rbx), %eax
btl $0xa, %eax
jb 0x27a99c
xorl %ebp, %ebp
btl $0xe, %eax
jae 0x27a9a2
andq $0x0, 0x20(%rbx)
jmp 0x27a9a2
movb $0x0, 0x1c(%rbx)
xorl %ebp, %ebp
testb $0x4, 0x29(%r15)
jne 0x27a9c6
movq 0x20(%r15), %rax
testq %rax, %rax
je 0x27a9c6
movzwl 0x63(%rax), %eax
notl %eax
testb $0x3, %al
jne 0x27a9c6
andq $0x0, 0x20(%r15)
jmp 0x27a9c6
pushq $0x7
popq %rbp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq