// File: /workspace/github_c_makefile_star2_O1/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: whereLoopInsert
static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
  WhereLoop **ppPrev, *p;
  WhereInfo *pWInfo = pBuilder->pWInfo;
  sqlite3 *db = pWInfo->pParse->db;

  /* 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);
        whereLoopPrint(pTemplate, pBuilder->pWC);
      }
#endif
    }
    return SQLITE_OK;
  }

  /* Look for an existing WhereLoop to replace with pTemplate
  */
  whereLoopAdjustCost(pWInfo->pLoops, 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: ");
      whereLoopPrint(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: ");
      whereLoopPrint(p, pBuilder->pWC);
    }
    sqlite3DebugPrintf("    add: ");
    whereLoopPrint(pTemplate, pBuilder->pWC);
  }
#endif
  if( p==0 ){
    /* Allocate a new WhereLoop to add to the end of the list */
    *ppPrev = p = sqlite3DbMallocRaw(db, sizeof(WhereLoop));
    if( p==0 ) return SQLITE_NOMEM;
    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: ");
        whereLoopPrint(pToDel, pBuilder->pWC);
      }
#endif
      whereLoopDelete(db, pToDel);
    }
  }
  whereLoopXfer(db, p, pTemplate);
  if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
    Index *pIndex = p->u.btree.pIndex;
    if( pIndex && pIndex->tnum==0 ){
      p->u.btree.pIndex = 0;
    }
  }
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %rax
movq 0x20(%rdi), %rdi
testq %rdi, %rdi
je 0x686f4
xorl %r14d, %r14d
cmpw $0x0, 0x2c(%rbx)
je 0x688c5
movq (%rbx), %rsi
movswl 0x14(%rbx), %edx
movswl 0x16(%rbx), %ecx
callq 0x688df
jmp 0x688c5
movq (%rax), %r14
movq (%r14), %rax
movq (%rax), %r15
movq 0x20(%r14), %r12
addq $0x20, %r14
testq %r12, %r12
je 0x6876b
movl $0x200, %eax            # imm = 0x200
andl 0x28(%rbx), %eax
je 0x6876b
movb 0x10(%rbx), %r13b
cmpb %r13b, 0x10(%r12)
jne 0x68761
testb $0x2, 0x29(%r12)
je 0x68761
movq %r12, %rdi
movq %rbx, %rsi
callq 0x68a3e
movw $0xffff, %cx            # imm = 0xFFFF
testl %eax, %eax
jne 0x6874d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x68a3e
movw $0x1, %cx
testl %eax, %eax
je 0x68761
movzwl 0x14(%r12), %eax
movw %ax, 0x14(%rbx)
addw 0x16(%r12), %cx
movw %cx, 0x16(%rbx)
movq 0x40(%r12), %r12
testq %r12, %r12
jne 0x68718
movq %r14, %rdi
movq %rbx, %rsi
callq 0x68989
xorl %r14d, %r14d
testq %rax, %rax
je 0x688c5
movq %rax, %r13
movq (%rax), %r12
testq %r12, %r12
je 0x687e0
cmpq $0x0, 0x40(%r12)
je 0x68828
leaq 0x40(%r12), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x68989
testq %rax, %rax
je 0x68828
movq %rax, %r13
movq (%rax), %r14
testq %r14, %r14
je 0x68828
movq 0x40(%r14), %rax
movq %rax, (%r13)
movq %r15, %rdi
movq %r14, %rsi
callq 0x685da
movq %r15, %rdi
movq %r14, %rsi
callq 0xb6df
cmpq $0x0, (%r13)
jne 0x6879e
jmp 0x68828
movl $0x60, %esi
movq %r15, %rdi
callq 0x144ee
movq %rax, (%r13)
testq %rax, %rax
je 0x688d7
movq %rax, %r12
addq $0x48, %rax
movq %rax, 0x38(%r12)
movw $0x0, 0x2c(%r12)
movw $0x3, 0x30(%r12)
movl $0x0, 0x28(%r12)
movq $0x0, 0x40(%r12)
movq %r15, %rdi
movq %r12, %rsi
callq 0x68ae1
movzwl 0x2c(%rbx), %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x6862c
testl %eax, %eax
je 0x68851
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r12)
jmp 0x688a1
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm2, 0x20(%r12)
movups %xmm1, 0x10(%r12)
movups %xmm0, (%r12)
movq 0x38(%r12), %rdi
movq 0x38(%rbx), %rsi
movzwl 0x2c(%r12), %edx
shll $0x3, %edx
callq 0xa310
movl 0x28(%rbx), %eax
btl $0xa, %eax
jb 0x6889d
btl $0xe, %eax
jae 0x688a1
movq $0x0, 0x20(%rbx)
jmp 0x688a1
movb $0x0, 0x1c(%rbx)
testb $0x4, 0x29(%r12)
jne 0x688c2
movq 0x20(%r12), %rax
testq %rax, %rax
je 0x688c2
cmpl $0x0, 0x58(%rax)
jne 0x688c2
movq $0x0, 0x20(%r12)
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x7, %r14d
jmp 0x688c5