// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: patternCompare
static int patternCompare(
  const u8 *zPattern,              /* The glob pattern */
  const u8 *zString,               /* The string to compare against the glob */
  const struct compareInfo *pInfo, /* Information about how to do the compare */
  u32 esc                          /* The escape character */
){
  u32 c, c2;
  int invert;
  int seen;
  u8 matchOne = pInfo->matchOne;
  u8 matchAll = pInfo->matchAll;
  u8 matchSet = pInfo->matchSet;
  u8 noCase = pInfo->noCase; 
  int prevEscape = 0;     /* True if the previous character was 'escape' */

  while( (c = sqlite3Utf8Read(&zPattern))!=0 ){
    if( c==matchAll && !prevEscape ){
      while( (c=sqlite3Utf8Read(&zPattern)) == matchAll
               || c == matchOne ){
        if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
          return 0;
        }
      }
      if( c==0 ){
        return 1;
      }else if( c==esc ){
        c = sqlite3Utf8Read(&zPattern);
        if( c==0 ){
          return 0;
        }
      }else if( c==matchSet ){
        assert( esc==0 );         /* This is GLOB, not LIKE */
        assert( matchSet<0x80 );  /* '[' is a single-byte character */
        while( *zString && patternCompare(&zPattern[-1],zString,pInfo,esc)==0 ){
          SQLITE_SKIP_UTF8(zString);
        }
        return *zString!=0;
      }
      while( (c2 = sqlite3Utf8Read(&zString))!=0 ){
        if( noCase ){
          GlogUpperToLower(c2);
          GlogUpperToLower(c);
          while( c2 != 0 && c2 != c ){
            c2 = sqlite3Utf8Read(&zString);
            GlogUpperToLower(c2);
          }
        }else{
          while( c2 != 0 && c2 != c ){
            c2 = sqlite3Utf8Read(&zString);
          }
        }
        if( c2==0 ) return 0;
        if( patternCompare(zPattern,zString,pInfo,esc) ) return 1;
      }
      return 0;
    }else if( c==matchOne && !prevEscape ){
      if( sqlite3Utf8Read(&zString)==0 ){
        return 0;
      }
    }else if( c==matchSet ){
      u32 prior_c = 0;
      assert( esc==0 );    /* This only occurs for GLOB, not LIKE */
      seen = 0;
      invert = 0;
      c = sqlite3Utf8Read(&zString);
      if( c==0 ) return 0;
      c2 = sqlite3Utf8Read(&zPattern);
      if( c2=='^' ){
        invert = 1;
        c2 = sqlite3Utf8Read(&zPattern);
      }
      if( c2==']' ){
        if( c==']' ) seen = 1;
        c2 = sqlite3Utf8Read(&zPattern);
      }
      while( c2 && c2!=']' ){
        if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){
          c2 = sqlite3Utf8Read(&zPattern);
          if( c>=prior_c && c<=c2 ) seen = 1;
          prior_c = 0;
        }else{
          if( c==c2 ){
            seen = 1;
          }
          prior_c = c2;
        }
        c2 = sqlite3Utf8Read(&zPattern);
      }
      if( c2==0 || (seen ^ invert)==0 ){
        return 0;
      }
    }else if( esc==c && !prevEscape ){
      prevEscape = 1;
    }else{
      c2 = sqlite3Utf8Read(&zString);
      if( noCase ){
        GlogUpperToLower(c);
        GlogUpperToLower(c2);
      }
      if( c!=c2 ){
        return 0;
      }
      prevEscape = 0;
    }
  }
  return *zString==0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, -0x3c(%rbp)
leaq -0x38(%rbp), %rax
movq %rdi, (%rax)
leaq -0x48(%rbp), %rax
movq %rsi, (%rax)
movzbl 0x1(%rdx), %r12d
movzbl (%rdx), %eax
movl %eax, -0x50(%rbp)
movzbl 0x2(%rdx), %eax
movl %eax, -0x4c(%rbp)
movq %rdx, -0x60(%rbp)
movb 0x3(%rdx), %al
movb %al, -0x29(%rbp)
xorl %r14d, %r14d
movl %r14d, -0x54(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x318c9
testl %eax, %eax
je 0x11275
movl %eax, %r13d
xorl -0x50(%rbp), %eax
orl %r14d, %eax
je 0x11282
movl %r13d, %eax
xorl %r12d, %eax
orl %r14d, %eax
je 0x11205
cmpl -0x4c(%rbp), %r13d
jne 0x1121e
movl %r12d, %r15d
leaq -0x48(%rbp), %rdi
callq 0x318c9
xorl %r12d, %r12d
testl %eax, %eax
je 0x112b9
movl %eax, %r13d
leaq -0x38(%rbp), %rdi
callq 0x318c9
cmpl $0x5e, %eax
jne 0x1117a
leaq -0x38(%rbp), %rdi
callq 0x318c9
pushq $0x1
popq %r12
xorl %ebx, %ebx
movl $0x0, %r14d
cmpl $0x5d, %eax
jne 0x1119e
xorl %ebx, %ebx
cmpl $0x5d, %r13d
sete %bl
xorl %eax, %eax
movl %eax, %r14d
leaq -0x38(%rbp), %rdi
callq 0x318c9
cmpl $0x2d, %eax
je 0x111c6
cmpl $0x5d, %eax
je 0x111b1
testl %eax, %eax
jne 0x111fa
jmp 0x112b9
cmpl %r12d, %ebx
movl -0x54(%rbp), %r14d
movl %r15d, %r12d
jne 0x1110c
jmp 0x112b9
movq -0x38(%rbp), %rcx
movb (%rcx), %cl
cmpb $0x5d, %cl
je 0x111fa
testb %cl, %cl
sete %cl
testl %r14d, %r14d
sete %dl
orb %cl, %dl
jne 0x111fa
leaq -0x38(%rbp), %rdi
callq 0x318c9
cmpl %eax, %r13d
pushq $0x1
popq %rax
cmoval %ebx, %eax
cmpl %r14d, %r13d
cmovael %eax, %ebx
jmp 0x11190
cmpl %eax, %r13d
pushq $0x1
popq %rcx
cmovel %ecx, %ebx
jmp 0x11192
leaq -0x48(%rbp), %rdi
callq 0x318c9
xorl %r14d, %r14d
testl %eax, %eax
jne 0x11108
jmp 0x112bc
movl %r13d, %eax
xorl -0x3c(%rbp), %eax
orl %r14d, %eax
pushq $0x1
popq %r14
je 0x11108
leaq -0x48(%rbp), %rdi
callq 0x318c9
cmpb $0x0, -0x29(%rbp)
je 0x11267
cmpl $0x7f, %r13d
ja 0x11255
movl %r13d, %ecx
leaq 0x56e20(%rip), %rdx     # 0x68070
movzbl (%rcx,%rdx), %r13d
cmpl $0x7f, %eax
ja 0x11267
movl %eax, %eax
leaq 0x56e0d(%rip), %rcx     # 0x68070
movzbl (%rax,%rcx), %eax
xorl %r14d, %r14d
cmpl %eax, %r13d
je 0x11108
jmp 0x112bc
movq -0x48(%rbp), %rax
cmpb $0x0, (%rax)
sete %r14b
jmp 0x112bc
leaq -0x38(%rbp), %rbx
leaq -0x48(%rbp), %r13
movq %rbx, %rdi
callq 0x318c9
movl %eax, %r15d
cmpl -0x50(%rbp), %eax
sete %al
cmpl %r12d, %r15d
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x112cf
cmpl %r12d, %r15d
jne 0x1128a
movq %r13, %rdi
callq 0x318c9
testl %eax, %eax
jne 0x1128a
xorl %r14d, %r14d
movzbl %r14b, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %r14b
testl %r15d, %r15d
je 0x112bc
cmpl -0x3c(%rbp), %r15d
jne 0x112ef
leaq -0x38(%rbp), %rdi
callq 0x318c9
testl %eax, %eax
je 0x112b9
movl %eax, %r15d
jmp 0x1133f
cmpl -0x4c(%rbp), %r15d
jne 0x1133f
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %r15
decq %r15
movb (%rax), %bl
testb %bl, %bl
setne %r14b
je 0x112bc
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
movq -0x60(%rbp), %rdx
movl -0x3c(%rbp), %ecx
callq 0x110c7
testl %eax, %eax
jne 0x112bc
leaq 0x1(%r12), %rax
cmpb $-0x40, %bl
jb 0x11300
movq %r12, %rax
movb 0x1(%rax), %cl
incq %rax
andb $-0x40, %cl
negb %cl
jo 0x11330
jmp 0x11300
movq -0x38(%rbp), %r12
leaq -0x48(%rbp), %r13
movq %r13, %rdi
callq 0x318c9
testl %eax, %eax
je 0x112b9
cmpb $0x0, -0x29(%rbp)
je 0x113b1
cmpl $0x7f, %eax
ja 0x1136f
movl %eax, %eax
leaq 0x56d05(%rip), %rcx     # 0x68070
movzbl (%rax,%rcx), %eax
cmpl $0x7f, %r15d
ja 0x11384
movl %r15d, %ecx
leaq 0x56cf1(%rip), %rdx     # 0x68070
movzbl (%rcx,%rdx), %r15d
testl %eax, %eax
je 0x113ba
cmpl %r15d, %eax
je 0x113ba
movq %r13, %rdi
callq 0x318c9
cmpl $0x7f, %eax
ja 0x11384
movl %eax, %eax
leaq 0x56ccd(%rip), %rcx     # 0x68070
movzbl (%rax,%rcx), %eax
jmp 0x11384
movq %r13, %rdi
callq 0x318c9
testl %eax, %eax
je 0x113ba
cmpl %r15d, %eax
jne 0x113a9
testl %eax, %eax
je 0x112b9
movq -0x48(%rbp), %rsi
movq %r12, %rdi
movq -0x60(%rbp), %rdx
movl -0x3c(%rbp), %ecx
callq 0x110c7
testl %eax, %eax
je 0x11347
jmp 0x112bc