// File: /workspace/github_c_makefile_star2_O2/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 0x5b7b6
xorl %r14d, %r14d
cmpw $0x0, 0x2c(%rbx)
je 0x5b961
movq (%rbx), %rsi
movswl 0x14(%rbx), %edx
movswl 0x16(%rbx), %ecx
callq 0x5b973
jmp 0x5b961
movq (%rax), %r14
movq (%r14), %rax
movq (%rax), %r15
movq 0x20(%r14), %r12
addq $0x20, %r14
testq %r12, %r12
je 0x5b82d
movl $0x200, %eax            # imm = 0x200
andl 0x28(%rbx), %eax
je 0x5b82d
movb 0x10(%rbx), %r13b
cmpb %r13b, 0x10(%r12)
jne 0x5b823
testb $0x2, 0x29(%r12)
je 0x5b823
movq %r12, %rdi
movq %rbx, %rsi
callq 0x5baef
movw $0xffff, %cx            # imm = 0xFFFF
testl %eax, %eax
jne 0x5b80f
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5baef
movw $0x1, %cx
testl %eax, %eax
je 0x5b823
movzwl 0x14(%r12), %eax
movw %ax, 0x14(%rbx)
addw 0x16(%r12), %cx
movw %cx, 0x16(%rbx)
movq 0x40(%r12), %r12
testq %r12, %r12
jne 0x5b7da
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5ba29
xorl %r14d, %r14d
testq %rax, %rax
je 0x5b961
movq %rax, %r13
movq (%rax), %r12
testq %r12, %r12
je 0x5b888
leaq 0x40(%r12), %r13
cmpq $0x0, (%r13)
je 0x5b8c7
movq %r13, %rdi
movq %rbx, %rsi
callq 0x5ba29
testq %rax, %rax
je 0x5b8c7
movq %rax, %r13
movq (%rax), %rsi
testq %rsi, %rsi
je 0x5b8c7
movq 0x40(%rsi), %rax
movq %rax, (%r13)
movq %r15, %rdi
callq 0x5bace
jmp 0x5b854
pushq $0x60
popq %rsi
movq %r15, %rdi
callq 0x132c5
movq %rax, (%r13)
testq %rax, %rax
je 0x5b95d
movq %rax, %r12
addq $0x48, %rax
movq %rax, 0x38(%r12)
andw $0x0, 0x2c(%r12)
movw $0x3, 0x30(%r12)
andl $0x0, 0x28(%r12)
andq $0x0, 0x40(%r12)
movq %r15, %rdi
movq %r12, %rsi
callq 0x5bb77
movzwl 0x2c(%rbx), %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x5b6f0
testl %eax, %eax
je 0x5b8f0
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r12)
jmp 0x5b93d
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 0xa3b0
movl 0x28(%rbx), %eax
btl $0xa, %eax
jb 0x5b939
btl $0xe, %eax
jae 0x5b93d
andq $0x0, 0x20(%rbx)
jmp 0x5b93d
movb $0x0, 0x1c(%rbx)
testb $0x4, 0x29(%r12)
jne 0x5b961
movq 0x20(%r12), %rax
testq %rax, %rax
je 0x5b961
cmpl $0x0, 0x58(%rax)
jne 0x5b961
andq $0x0, 0x20(%r12)
jmp 0x5b961
pushq $0x7
popq %r14
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq