// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/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;
        assert( iTo>0 );

        /* If the LHS is not an ordinary column with TEXT affinity, then the
        ** pattern prefix boundaries (both the start and end boundaries) must
        ** not look like a number.  Otherwise the pattern might be treated as
        ** a number, which will invalidate the LIKE optimization.
        **
        ** Getting this right has been a persistent source of bugs in the
        ** LIKE optimization.  See, for example:
        **    2018-09-10 https://sqlite.org/src/info/c94369cae9b561b1
        **    2019-05-02 https://sqlite.org/src/info/b043a54c3de54b28
        **    2019-06-10 https://sqlite.org/src/info/fd76310a5e843e07
        **    2019-06-14 https://sqlite.org/src/info/ce8717f0885af975
        **    2019-09-03 https://sqlite.org/src/info/0f0428096f17252a
        */
        if( pLeft->op!=TK_COLUMN
         || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
         || IsVirtual(pLeft->y.pTab)  /* Value might be numeric */
        ){
          int isNum;
          double rDummy;
          isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
          if( isNum<=0 ){
            if( iTo==1 && zNew[0]=='-' ){
              isNum = +1;
            }else{
              zNew[iTo-1]++;
              isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
              zNew[iTo-1]--;
            }
          }
          if( isNum>0 ){
            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 $0xd0, %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 0x450380
cmpl $0x0, %eax
jne 0x44f680
movl $0x0, -0x4(%rbp)
jmp 0x44fb5d
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x42ef20
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x74(%rbp)
cmpl $0x99, -0x74(%rbp)
jne 0x44f740
movq -0x68(%rbp), %rax
movq 0x30(%rax), %rax
andq $0x800000, %rax         # imm = 0x800000
cmpq $0x0, %rax
jne 0x44f740
movq -0x10(%rbp), %rax
movq 0x138(%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 0x4304d0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x44f72b
movq -0x70(%rbp), %rdi
callq 0x3c7cc0
cmpl $0x3, %eax
jne 0x44f72b
movq -0x70(%rbp), %rdi
callq 0x3c7880
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x84(%rbp), %esi
callq 0x430480
jmp 0x44f754
cmpl $0x73, -0x74(%rbp)
jne 0x44f752
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x44f754
cmpq $0x0, -0x38(%rbp)
je 0x44fb3e
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, -0xbd(%rbp)
je 0x44f7bf
movzbl -0x51(%rbp), %ecx
movzbl -0x5c(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0xbd(%rbp)
je 0x44f7bf
movzbl -0x51(%rbp), %ecx
movzbl -0x5b(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0xbd(%rbp)
je 0x44f7bf
movzbl -0x51(%rbp), %eax
movzbl -0x5a(%rbp), %ecx
cmpl %ecx, %eax
setne %al
movb %al, -0xbd(%rbp)
movb -0xbd(%rbp), %al
testb $0x1, %al
jne 0x44f7cb
jmp 0x44f7ff
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movzbl -0x51(%rbp), %eax
movzbl -0x59(%rbp), %ecx
cmpl %ecx, %eax
jne 0x44f7fa
movq -0x38(%rbp), %rax
movslq -0x58(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x44f7fa
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x44f766
cmpl $0x0, -0x58(%rbp)
je 0x44fb34
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 0x44fb34
cmpl $0x1, -0x58(%rbp)
jg 0x44f840
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
movzbl -0x59(%rbp), %ecx
cmpl %ecx, %eax
je 0x44fb34
movzbl -0x51(%rbp), %ecx
movzbl -0x5c(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0xbe(%rbp)
jne 0x44f871
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, -0xbe(%rbp)
movb -0xbe(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x68(%rbp), %rdi
movq -0x38(%rbp), %rdx
movl $0x73, %esi
callq 0x41d620
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x44fa7a
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 0x44f952
movq -0xa0(%rbp), %rax
movslq -0x94(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movzbl -0x59(%rbp), %ecx
cmpl %ecx, %eax
jne 0x44f912
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 0x44f8de
movq -0xa0(%rbp), %rax
movslq -0x98(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xa4, %eax
jne 0x44f995
movq -0x48(%rbp), %rdi
callq 0x42f230
movsbl %al, %eax
cmpl $0x42, %eax
jne 0x44f995
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0x54(%rax)
je 0x44fa78
movq -0xa0(%rbp), %rdi
movl -0x98(%rbp), %edx
leaq -0xb0(%rbp), %rsi
movl $0x1, %ecx
callq 0x3ef260
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
jg 0x44fa48
cmpl $0x1, -0x98(%rbp)
jne 0x44f9ea
movq -0xa0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x44f9ea
movl $0x1, -0xa4(%rbp)
jmp 0x44fa46
movq -0xa0(%rbp), %rax
movl -0x98(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
addb $0x1, %dl
movb %dl, (%rax,%rcx)
movq -0xa0(%rbp), %rdi
movl -0x98(%rbp), %edx
leaq -0xb0(%rbp), %rsi
movl $0x1, %ecx
callq 0x3ef260
movl %eax, -0xa4(%rbp)
movq -0xa0(%rbp), %rax
movl -0x98(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
addb $-0x1, %dl
movb %dl, (%rax,%rcx)
jmp 0x44fa48
cmpl $0x0, -0xa4(%rbp)
jle 0x44fa76
movq -0x68(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x40c670
movq -0x70(%rbp), %rdi
callq 0x3c7ef0
movl $0x0, -0x4(%rbp)
jmp 0x44fb5d
jmp 0x44fa78
jmp 0x44fa7a
movq -0x90(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
cmpl $0x99, -0x74(%rbp)
jne 0x44fb32
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
movq -0x40(%rbp), %rax
movswl 0x30(%rax), %esi
callq 0x430480
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x44fb30
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x44fb30
movq -0x10(%rbp), %rdi
callq 0x42f190
movl %eax, -0xbc(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0xbc(%rbp), %edx
callq 0x42a500
movq -0xb8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x430ae0
movq -0xc8(%rbp), %rdi
movl %eax, %esi
subl $0x1, %esi
xorl %edx, %edx
callq 0x42deb0
movq -0x10(%rbp), %rdi
movl -0xbc(%rbp), %esi
callq 0x42e560
jmp 0x44fb32
jmp 0x44fb3c
movq $0x0, -0x38(%rbp)
jmp 0x44fb3e
cmpq $0x0, -0x38(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
callq 0x3c7ef0
movl -0x78(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax)