// File: /workspace/github_c_makefile_star2_O3/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 %rdx, %rbx
testq %rsi, %rsi
je 0x671f6
xorl %r14d, %r14d
cmpw $0x0, 0x2c(%rbx)
je 0x673c7
movq (%rbx), %rax
movswl 0x14(%rbx), %edx
movswl 0x16(%rbx), %ecx
movq %rsi, %rdi
movq %rax, %rsi
callq 0x673e1
jmp 0x673c7
movq %rdi, %r14
movq (%rdi), %rax
movq (%rax), %r15
movq 0x20(%rdi), %r12
addq $0x20, %r14
testq %r12, %r12
je 0x6726d
movl $0x200, %eax            # imm = 0x200
andl 0x28(%rbx), %eax
je 0x6726d
movb 0x10(%rbx), %r13b
cmpb %r13b, 0x10(%r12)
jne 0x67263
testb $0x2, 0x29(%r12)
je 0x67263
movq %r12, %rdi
movq %rbx, %rsi
callq 0x67540
movw $0xffff, %cx            # imm = 0xFFFF
testl %eax, %eax
jne 0x6724f
movq %rbx, %rdi
movq %r12, %rsi
callq 0x67540
movw $0x1, %cx
testl %eax, %eax
je 0x67263
movzwl 0x14(%r12), %eax
movw %ax, 0x14(%rbx)
addw 0x16(%r12), %cx
movw %cx, 0x16(%rbx)
movq 0x40(%r12), %r12
testq %r12, %r12
jne 0x6721a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6748b
xorl %r14d, %r14d
testq %rax, %rax
je 0x673c7
movq %rax, %r13
movq (%rax), %r12
testq %r12, %r12
je 0x672e2
cmpq $0x0, 0x40(%r12)
je 0x6732a
leaq 0x40(%r12), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x6748b
testq %rax, %rax
je 0x6732a
movq %rax, %r13
movq (%rax), %r14
testq %r14, %r14
je 0x6732a
movq 0x40(%r14), %rax
movq %rax, (%r13)
movq %r15, %rdi
movq %r14, %rsi
callq 0x670dd
movq %r15, %rdi
movq %r14, %rsi
callq 0xb752
cmpq $0x0, (%r13)
jne 0x672a0
jmp 0x6732a
movl $0x60, %esi
movq %r15, %rdi
callq 0x145aa
movq %rax, (%r13)
testq %rax, %rax
je 0x673d9
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 0x675d0
movzwl 0x2c(%rbx), %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x6712f
testl %eax, %eax
je 0x67353
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r12)
jmp 0x673a3
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 0xa320
movl 0x28(%rbx), %eax
btl $0xa, %eax
jb 0x6739f
btl $0xe, %eax
jae 0x673a3
movq $0x0, 0x20(%rbx)
jmp 0x673a3
movb $0x0, 0x1c(%rbx)
testb $0x4, 0x29(%r12)
jne 0x673c4
movq 0x20(%r12), %rax
testq %rax, %rax
je 0x673c4
cmpl $0x0, 0x58(%rax)
jne 0x673c4
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 0x673c7