// File: /workspace/github_c_makefile_star2_O0/ukontainer[P]sqlite-bench/sqlite3.c
// Function: isLikeOrGlob
static int isLikeOrGlob(
  Parse *pParse,    /* Parsing and code generating context */
  Expr *pExpr,      /* Test this expression */
  Expr **ppPrefix,  /* Pointer to TK_STRING expression with pattern prefix */
  int *pisComplete, /* True if the only wildcard is % in the last character */
  int *pnoCase      /* True if uppercase is equivalent to lowercase */
){
  const u8 *z = 0;           /* String on RHS of LIKE operator */
  Expr *pRight, *pLeft;      /* Right and left size of LIKE operator */
  ExprList *pList;           /* List of operands to the LIKE operator */
  u8 c;                      /* One character in z[] */
  int cnt;                   /* Number of non-wildcard prefix characters */
  u8 wc[4];                  /* Wildcard characters */
  sqlite3 *db = pParse->db;  /* Database connection */
  sqlite3_value *pVal = 0;
  int op;                    /* Opcode of pRight */
  int rc;                    /* Result code to return */

  if( !sqlite3IsLikeFunction(db, pExpr, pnoCase, (char*)wc) ){
    return 0;
  }
#ifdef SQLITE_EBCDIC
  if( *pnoCase ) return 0;
#endif
  pList = pExpr->x.pList;
  pLeft = pList->a[1].pExpr;

  pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr);
  op = pRight->op;
  if( op==TK_VARIABLE && (db->flags & SQLITE_EnableQPSG)==0 ){
    Vdbe *pReprepare = pParse->pReprepare;
    int iCol = pRight->iColumn;
    pVal = sqlite3VdbeGetBoundValue(pReprepare, iCol, SQLITE_AFF_BLOB);
    if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){
      z = sqlite3_value_text(pVal);
    }
    sqlite3VdbeSetVarmask(pParse->pVdbe, iCol);
    assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
  }else if( op==TK_STRING ){
    z = (u8*)pRight->u.zToken;
  }
  if( z ){

    /* Count the number of prefix characters prior to the first wildcard */
    cnt = 0;
    while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
      cnt++;
      if( c==wc[3] && z[cnt]!=0 ) cnt++;
    }

    /* The optimization is possible only if (1) the pattern does not begin
    ** with a wildcard and if (2) the non-wildcard prefix does not end with
    ** an (illegal 0xff) character, or (3) the pattern does not consist of
    ** a single escape character. The second condition is necessary so
    ** that we can increment the prefix key to find an upper bound for the
    ** range search. The third is because the caller assumes that the pattern
    ** consists of at least one character after all escapes have been
    ** removed.  */
    if( cnt!=0 && 255!=(u8)z[cnt-1] && (cnt>1 || z[0]!=wc[3]) ){
      Expr *pPrefix;

      /* A "complete" match if the pattern ends with "*" or "%" */
      *pisComplete = c==wc[0] && z[cnt+1]==0;

      /* Get the pattern prefix.  Remove all escapes from the prefix. */
      pPrefix = sqlite3Expr(db, TK_STRING, (char*)z);
      if( pPrefix ){
        int iFrom, iTo;
        char *zNew = pPrefix->u.zToken;
        zNew[cnt] = 0;
        for(iFrom=iTo=0; iFrom<cnt; iFrom++){
          if( zNew[iFrom]==wc[3] ) iFrom++;
          zNew[iTo++] = zNew[iFrom];
        }
        zNew[iTo] = 0;

        /* If the RHS begins with a digit or a minus sign, then the LHS must be
        ** an ordinary column (not a virtual table column) with TEXT affinity.
        ** Otherwise the LHS might be numeric and "lhs >= rhs" would be false
        ** even though "lhs LIKE rhs" is true.  But if the RHS does not start
        ** with a digit or '-', then "lhs LIKE rhs" will always be false if
        ** the LHS is numeric and so the optimization still works.
        **
        ** 2018-09-10 ticket c94369cae9b561b1f996d0054bfab11389f9d033
        ** The RHS pattern must not be '/%' because the termination condition
        ** will then become "x<'0'" and if the affinity is numeric, will then
        ** be converted into "x<0", which is incorrect.
        */
        if( sqlite3Isdigit(zNew[0])
         || zNew[0]=='-'
         || (zNew[0]+1=='0' && iTo==1)
        ){
          if( pLeft->op!=TK_COLUMN 
           || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT 
           || IsVirtual(pLeft->pTab)  /* Value might be numeric */
          ){
            sqlite3ExprDelete(db, pPrefix);
            sqlite3ValueFree(pVal);
            return 0;
          }
        }
      }
      *ppPrefix = pPrefix;

      /* If the RHS pattern is a bound parameter, make arrangements to
      ** reprepare the statement when that parameter is rebound */
      if( op==TK_VARIABLE ){
        Vdbe *v = pParse->pVdbe;
        sqlite3VdbeSetVarmask(v, pRight->iColumn);
        if( *pisComplete && pRight->u.zToken[1] ){
          /* If the rhs of the LIKE expression is a variable, and the current
          ** value of the variable means there is no need to invoke the LIKE
          ** function, then no OP_Variable will be added to the program.
          ** This causes problems for the sqlite3_bind_parameter_name()
          ** API. To work around them, add a dummy OP_Variable here.
          */ 
          int r1 = sqlite3GetTempReg(pParse);
          sqlite3ExprCodeTarget(pParse, pRight, r1);
          sqlite3VdbeChangeP3(v, sqlite3VdbeCurrentAddr(v)-1, 0);
          sqlite3ReleaseTempReg(pParse, r1);
        }
      }
    }else{
      z = 0;
    }
  }

  rc = (z!=0);
  sqlite3ValueFree(pVal);
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x5c(%rbp), %rcx
callq 0x48d240
cmpl $0x0, %eax
jne 0x48c600
movl $0x0, -0x4(%rbp)
jmp 0x48ca5f
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x470a60
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x74(%rbp)
cmpl $0x90, -0x74(%rbp)
jne 0x48c6b9
movq -0x68(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x800000, %eax         # imm = 0x800000
cmpl $0x0, %eax
jne 0x48c6b9
movq -0x10(%rbp), %rax
movq 0x128(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x40(%rbp), %rax
movswl 0x30(%rax), %eax
movl %eax, -0x84(%rbp)
movq -0x80(%rbp), %rdi
movl -0x84(%rbp), %esi
movl $0x41, %edx
callq 0x471bb0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x48c6a4
movq -0x70(%rbp), %rdi
callq 0x40d660
cmpl $0x3, %eax
jne 0x48c6a4
movq -0x70(%rbp), %rdi
callq 0x40d230
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x84(%rbp), %esi
callq 0x471b60
jmp 0x48c6cd
cmpl $0x6a, -0x74(%rbp)
jne 0x48c6cb
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x48c6cd
cmpq $0x0, -0x38(%rbp)
je 0x48ca40
movl $0x0, -0x58(%rbp)
movq -0x38(%rbp), %rax
movslq -0x58(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x51(%rbp)
movzbl %al, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xad(%rbp)
je 0x48c738
movzbl -0x51(%rbp), %ecx
movzbl -0x5c(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0xad(%rbp)
je 0x48c738
movzbl -0x51(%rbp), %ecx
movzbl -0x5b(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0xad(%rbp)
je 0x48c738
movzbl -0x51(%rbp), %eax
movzbl -0x5a(%rbp), %ecx
cmpl %ecx, %eax
setne %al
movb %al, -0xad(%rbp)
movb -0xad(%rbp), %al
testb $0x1, %al
jne 0x48c744
jmp 0x48c778
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movzbl -0x51(%rbp), %eax
movzbl -0x59(%rbp), %ecx
cmpl %ecx, %eax
jne 0x48c773
movq -0x38(%rbp), %rax
movslq -0x58(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x48c773
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x48c6df
cmpl $0x0, -0x58(%rbp)
je 0x48ca36
movq -0x38(%rbp), %rax
movl -0x58(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %ecx
movl $0xff, %eax
cmpl %ecx, %eax
je 0x48ca36
cmpl $0x1, -0x58(%rbp)
jg 0x48c7b9
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
movzbl -0x59(%rbp), %ecx
cmpl %ecx, %eax
je 0x48ca36
movzbl -0x51(%rbp), %ecx
movzbl -0x5c(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0xae(%rbp)
jne 0x48c7ea
movq -0x38(%rbp), %rax
movl -0x58(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
sete %al
movb %al, -0xae(%rbp)
movb -0xae(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x68(%rbp), %rdi
movq -0x38(%rbp), %rdx
movl $0x6a, %esi
callq 0x460a60
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x48c97c
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movslq -0x58(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl $0x0, -0x98(%rbp)
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x58(%rbp), %eax
jge 0x48c8cb
movq -0xa0(%rbp), %rax
movslq -0x94(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movzbl -0x59(%rbp), %ecx
cmpl %ecx, %eax
jne 0x48c88b
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
movq -0xa0(%rbp), %rax
movslq -0x94(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0xa0(%rbp), %rax
movl -0x98(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x98(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x48c857
movq -0xa0(%rbp), %rax
movslq -0x98(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0xa0(%rbp), %rax
movzbl (%rax), %eax
movl %eax, %ecx
leaq 0xed960(%rip), %rax     # 0x57a250
movzbl (%rax,%rcx), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x48c926
movq -0xa0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x48c926
movq -0xa0(%rbp), %rax
movsbl (%rax), %eax
addl $0x1, %eax
cmpl $0x30, %eax
jne 0x48c97a
cmpl $0x1, -0x98(%rbp)
jne 0x48c97a
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x9e, %eax
jne 0x48c953
movq -0x48(%rbp), %rdi
callq 0x470b70
movsbl %al, %eax
cmpl $0x42, %eax
jne 0x48c953
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0x54(%rax)
je 0x48c978
movq -0x68(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x44fdb0
movq -0x70(%rbp), %rdi
callq 0x40d870
movl $0x0, -0x4(%rbp)
jmp 0x48ca5f
jmp 0x48c97a
jmp 0x48c97c
movq -0x90(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
cmpl $0x90, -0x74(%rbp)
jne 0x48ca34
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdi
movq -0x40(%rbp), %rax
movswl 0x30(%rax), %esi
callq 0x471b60
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x48ca32
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x48ca32
movq -0x10(%rbp), %rdi
callq 0x470ad0
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0xac(%rbp), %edx
callq 0x46c620
movq -0xa8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x473080
movq -0xb8(%rbp), %rdi
movl %eax, %esi
subl $0x1, %esi
xorl %edx, %edx
callq 0x46fab0
movq -0x10(%rbp), %rdi
movl -0xac(%rbp), %esi
callq 0x470060
jmp 0x48ca34
jmp 0x48ca3e
movq $0x0, -0x38(%rbp)
jmp 0x48ca40
cmpq $0x0, -0x38(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
callq 0x40d870
movl -0x78(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)