// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3ParseUri
SQLITE_PRIVATE int sqlite3ParseUri(
  const char *zDefaultVfs,        /* VFS to use if no "vfs=xxx" query option */
  const char *zUri,               /* Nul-terminated URI to parse */
  unsigned int *pFlags,           /* IN/OUT: SQLITE_OPEN_XXX flags */
  sqlite3_vfs **ppVfs,            /* OUT: VFS to use */ 
  char **pzFile,                  /* OUT: Filename component of URI */
  char **pzErrMsg                 /* OUT: Error message (if rc!=SQLITE_OK) */
){
  int rc = SQLITE_OK;
  unsigned int flags = *pFlags;
  const char *zVfs = zDefaultVfs;
  char *zFile;
  char c;
  int nUri = sqlite3Strlen30(zUri);

  assert( *pzErrMsg==0 );

  if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri) 
   && nUri>=5 && memcmp(zUri, "file:", 5)==0 
  ){
    char *zOpt;
    int eState;                   /* Parser state when parsing URI */
    int iIn;                      /* Input character index */
    int iOut = 0;                 /* Output character index */
    int nByte = nUri+2;           /* Bytes of space to allocate */

    /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen 
    ** method that there may be extra parameters following the file-name.  */
    flags |= SQLITE_OPEN_URI;

    for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
    zFile = sqlite3_malloc(nByte);
    if( !zFile ) return SQLITE_NOMEM;

    iIn = 5;
#ifndef SQLITE_ALLOW_URI_AUTHORITY
    /* Discard the scheme and authority segments of the URI. */
    if( zUri[5]=='/' && zUri[6]=='/' ){
      iIn = 7;
      while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
      if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
        *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s", 
            iIn-7, &zUri[7]);
        rc = SQLITE_ERROR;
        goto parse_uri_out;
      }
    }
#endif

    /* Copy the filename and any query parameters into the zFile buffer. 
    ** Decode %HH escape codes along the way. 
    **
    ** Within this loop, variable eState may be set to 0, 1 or 2, depending
    ** on the parsing context. As follows:
    **
    **   0: Parsing file-name.
    **   1: Parsing name section of a name=value query parameter.
    **   2: Parsing value section of a name=value query parameter.
    */
    eState = 0;
    while( (c = zUri[iIn])!=0 && c!='#' ){
      iIn++;
      if( c=='%' 
       && sqlite3Isxdigit(zUri[iIn]) 
       && sqlite3Isxdigit(zUri[iIn+1]) 
      ){
        int octet = (sqlite3HexToInt(zUri[iIn++]) << 4);
        octet += sqlite3HexToInt(zUri[iIn++]);

        assert( octet>=0 && octet<256 );
        if( octet==0 ){
          /* This branch is taken when "%00" appears within the URI. In this
          ** case we ignore all text in the remainder of the path, name or
          ** value currently being parsed. So ignore the current character
          ** and skip to the next "?", "=" or "&", as appropriate. */
          while( (c = zUri[iIn])!=0 && c!='#' 
              && (eState!=0 || c!='?')
              && (eState!=1 || (c!='=' && c!='&'))
              && (eState!=2 || c!='&')
          ){
            iIn++;
          }
          continue;
        }
        c = octet;
      }else if( eState==1 && (c=='&' || c=='=') ){
        if( zFile[iOut-1]==0 ){
          /* An empty option name. Ignore this option altogether. */
          while( zUri[iIn] && zUri[iIn]!='#' && zUri[iIn-1]!='&' ) iIn++;
          continue;
        }
        if( c=='&' ){
          zFile[iOut++] = '\0';
        }else{
          eState = 2;
        }
        c = 0;
      }else if( (eState==0 && c=='?') || (eState==2 && c=='&') ){
        c = 0;
        eState = 1;
      }
      zFile[iOut++] = c;
    }
    if( eState==1 ) zFile[iOut++] = '\0';
    zFile[iOut++] = '\0';
    zFile[iOut++] = '\0';

    /* Check if there were any options specified that should be interpreted 
    ** here. Options that are interpreted here include "vfs" and those that
    ** correspond to flags that may be passed to the sqlite3_open_v2()
    ** method. */
    zOpt = &zFile[sqlite3Strlen30(zFile)+1];
    while( zOpt[0] ){
      int nOpt = sqlite3Strlen30(zOpt);
      char *zVal = &zOpt[nOpt+1];
      int nVal = sqlite3Strlen30(zVal);

      if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){
        zVfs = zVal;
      }else{
        struct OpenMode {
          const char *z;
          int mode;
        } *aMode = 0;
        char *zModeType = 0;
        int mask = 0;
        int limit = 0;

        if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){
          static struct OpenMode aCacheMode[] = {
            { "shared",  SQLITE_OPEN_SHAREDCACHE },
            { "private", SQLITE_OPEN_PRIVATECACHE },
            { 0, 0 }
          };

          mask = SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_PRIVATECACHE;
          aMode = aCacheMode;
          limit = mask;
          zModeType = "cache";
        }
        if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
          static struct OpenMode aOpenMode[] = {
            { "ro",  SQLITE_OPEN_READONLY },
            { "rw",  SQLITE_OPEN_READWRITE }, 
            { "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE },
            { "memory", SQLITE_OPEN_MEMORY },
            { 0, 0 }
          };

          mask = SQLITE_OPEN_READONLY | SQLITE_OPEN_READWRITE
                   | SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY;
          aMode = aOpenMode;
          limit = mask & flags;
          zModeType = "access";
        }

        if( aMode ){
          int i;
          int mode = 0;
          for(i=0; aMode[i].z; i++){
            const char *z = aMode[i].z;
            if( nVal==sqlite3Strlen30(z) && 0==memcmp(zVal, z, nVal) ){
              mode = aMode[i].mode;
              break;
            }
          }
          if( mode==0 ){
            *pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal);
            rc = SQLITE_ERROR;
            goto parse_uri_out;
          }
          if( (mode & ~SQLITE_OPEN_MEMORY)>limit ){
            *pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s",
                                        zModeType, zVal);
            rc = SQLITE_PERM;
            goto parse_uri_out;
          }
          flags = (flags & ~mask) | mode;
        }
      }

      zOpt = &zVal[nVal+1];
    }

  }else{
    zFile = sqlite3_malloc(nUri+2);
    if( !zFile ) return SQLITE_NOMEM;
    memcpy(zFile, zUri, nUri);
    zFile[nUri] = '\0';
    zFile[nUri+1] = '\0';
    flags &= ~SQLITE_OPEN_URI;
  }

  *ppVfs = sqlite3_vfs_find(zVfs);
  if( *ppVfs==0 ){
    *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs);
    rc = SQLITE_ERROR;
  }
 parse_uri_out:
  if( rc!=SQLITE_OK ){
    sqlite3_free(zFile);
    zFile = 0;
  }
  *pFlags = flags;
  *pzFile = zFile;
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %r15
movq %r8, %rbx
movq %rcx, -0x68(%rbp)
movq %rsi, %r12
movq %rdi, -0x40(%rbp)
movl (%rdx), %esi
testq %r12, %r12
je 0x618ed
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq %r12, %rax
incl %r13d
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x618d8
andl $0x3fffffff, %r13d      # imm = 0x3FFFFFFF
jmp 0x618f0
xorl %r13d, %r13d
movl %esi, %eax
andl $0x40, %eax
orl 0x32b11(%rip), %eax     # 0x9440c
setne %al
cmpl $0x5, %r13d
movq %rdx, -0x70(%rbp)
jb 0x61926
testb %al, %al
je 0x61926
movl $0x656c6966, %eax       # imm = 0x656C6966
xorl (%r12), %eax
movzbl 0x4(%r12), %ecx
xorl $0x3a, %ecx
orl %eax, %ecx
je 0x619ac
movl %esi, -0x2c(%rbp)
callq 0x9d86
movl $0x7, %r14d
testl %eax, %eax
jne 0x61e3f
movq %rbx, -0x60(%rbp)
leal 0x2(%r13), %edi
callq 0xa38c
testq %rax, %rax
je 0x61e3f
movq %rax, %rbx
movl %r13d, %r14d
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x82f0
movw $0x0, (%rbx,%r14)
andl $-0x41, -0x2c(%rbp)
movq -0x40(%rbp), %r13
movq %r13, %rdi
callq 0x9d35
movq -0x68(%rbp), %rcx
movq %rax, (%rcx)
xorl %r14d, %r14d
testq %rax, %rax
jne 0x61e2f
leaq 0x1adeb(%rip), %rdi     # 0x7c782
movq %r13, %rsi
xorl %eax, %eax
callq 0xb868
movl $0x1, %r14d
jmp 0x61e22
movq %r15, -0x48(%rbp)
movl %esi, %r15d
movl %r13d, %eax
addl $0x2, %r13d
xorl %ecx, %ecx
xorl %edx, %edx
cmpb $0x26, (%r12,%rcx)
sete %dl
addl %edx, %r13d
incq %rcx
cmpq %rcx, %rax
jne 0x619bc
callq 0x9d86
movl $0x7, %r14d
testl %eax, %eax
jne 0x61e3f
movq %rbx, -0x60(%rbp)
movl %r13d, %edi
callq 0xa38c
testq %rax, %rax
je 0x61e3f
movq %rax, -0x38(%rbp)
movl %r15d, %edx
orl $0x40, %edx
movl $0x5, %r8d
cmpb $0x2f, 0x5(%r12)
movl %edx, -0x2c(%rbp)
jne 0x61a42
cmpb $0x2f, 0x6(%r12)
movq -0x48(%rbp), %r15
movq -0x40(%rbp), %r13
jne 0x61a4a
xorl %esi, %esi
movzbl 0x7(%r12,%rsi), %eax
testl %eax, %eax
je 0x61dcf
cmpl $0x2f, %eax
je 0x61dcf
incq %rsi
jmp 0x61a26
movq -0x48(%rbp), %r15
movq -0x40(%rbp), %r13
xorl %esi, %esi
leaq 0x1455d(%rip), %rcx     # 0x75fb0
xorl %edx, %edx
movslq %edx, %rax
movl %r8d, %edi
movslq %edi, %r11
movzbl (%r12,%r11), %r9d
testl %r9d, %r9d
je 0x61bdd
cmpl $0x23, %r9d
je 0x61bdd
leal 0x1(%rdi), %r8d
movslq %r8d, %r10
cmpb $0x25, %r9b
jne 0x61b35
movzbl (%r12,%r10), %r14d
testb $0x8, (%r14,%rcx)
je 0x61b35
movzbl 0x2(%r12,%r11), %r11d
testb $0x8, (%r11,%rcx)
je 0x61b35
leal (%r14,%r14), %r8d
sarb $0x7, %r8b
andb $0x9, %r8b
addb %r14b, %r8b
shlb $0x4, %r8b
addl $0x3, %edi
leal (%r11,%r11), %r9d
sarb $0x7, %r9b
andb $0x9, %r9b
addb %r11b, %r9b
andb $0xf, %r9b
orb %r8b, %r9b
jne 0x61b88
movslq %edi, %r8
addq %r12, %r8
movzbl (%r8), %r9d
testl %r9d, %r9d
je 0x61a5b
cmpl $0x23, %r9d
je 0x61a5b
testl %esi, %esi
jne 0x61b05
cmpb $0x3f, %r9b
je 0x61a5b
cmpl $0x1, %esi
jne 0x61b1f
cmpl $0x26, %r9d
je 0x61a5b
cmpl $0x3d, %r9d
jne 0x61b2e
jmp 0x61a5b
cmpl $0x2, %esi
jne 0x61b2e
cmpb $0x26, %r9b
je 0x61a5b
incl %edi
incq %r8
jmp 0x61ae0
cmpl $0x1, %esi
jne 0x61b9a
cmpl $0x3d, %r9d
je 0x61b4a
cmpl $0x26, %r9d
jne 0x61bcc
movq -0x38(%rbp), %rsi
cmpb $0x0, -0x1(%rsi,%rax)
jne 0x61bb1
incl %edi
addq %r12, %r10
movzbl (%r10), %r8d
movl $0x1, %esi
testl %r8d, %r8d
je 0x61a5b
cmpl $0x23, %r8d
je 0x61a5b
cmpb $0x26, -0x1(%r10)
je 0x61a5b
incl %edi
incq %r10
jmp 0x61b5a
movl %edi, %r8d
incl %edx
movq -0x38(%rbp), %rdi
movb %r9b, (%rdi,%rax)
jmp 0x61a55
testl %esi, %esi
jne 0x61ba4
cmpb $0x3f, %r9b
je 0x61bc5
cmpl $0x2, %esi
jne 0x61b8b
cmpb $0x26, %r9b
je 0x61bc5
jmp 0x61b8b
cmpb $0x26, %r9b
jne 0x61bd3
leal 0x1(%rax), %edx
movq -0x38(%rbp), %rsi
movb $0x0, (%rsi,%rax)
movslq %edx, %rax
movl $0x1, %esi
jmp 0x61bd8
movl $0x1, %esi
jmp 0x61b8b
movl $0x2, %esi
xorl %r9d, %r9d
jmp 0x61b8b
cmpl $0x1, %esi
jne 0x61bf2
leal 0x1(%rax), %ecx
movq -0x38(%rbp), %rbx
movb $0x0, (%rbx,%rax)
movslq %ecx, %rax
jmp 0x61bf6
movq -0x38(%rbp), %rbx
movw $0x0, (%rbx,%rax)
movq $-0x1, %rax
cmpb $0x0, 0x1(%rbx,%rax)
leaq 0x1(%rax), %rax
jne 0x61c03
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cmpb $0x0, 0x1(%rbx,%rax)
je 0x61975
addq %rbx, %rax
incq %rax
movl $0x68636163, %esi       # imm = 0x68636163
xorl %ecx, %ecx
cmpb $0x0, 0x1(%rax,%rcx)
leaq 0x1(%rcx), %rcx
jne 0x61c2b
movl %ecx, %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
leaq (%rax,%rdx), %rbx
incq %rbx
movq $-0x1, %r12
cmpb $0x0, 0x1(%rbx,%r12)
leaq 0x1(%r12), %r12
jne 0x61c4c
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
cmpl $0x5, %ecx
je 0x61cc5
cmpl $0x4, %ecx
je 0x61c93
cmpl $0x3, %ecx
jne 0x61d8b
movzwl (%rax), %ecx
xorl $0x6676, %ecx           # imm = 0x6676
movzbl 0x2(%rax), %eax
xorl $0x73, %eax
orw %cx, %ax
jne 0x61d8b
movq %rbx, %r13
jmp 0x61d8b
cmpl $0x65646f6d, (%rax)     # imm = 0x65646F6D
jne 0x61d8b
movq %r13, -0x40(%rbp)
movl -0x2c(%rbp), %eax
andl $0x87, %eax
movl %eax, -0x50(%rbp)
movl $0xffffff78, -0x4c(%rbp) # imm = 0xFFFFFF78
leaq 0x319f4(%rip), %r14     # 0x936b0
leaq 0x1796c(%rip), %rax     # 0x7962f
jmp 0x61cf8
movl (%rax), %ecx
xorl %esi, %ecx
movzbl 0x4(%rax), %eax
xorl $0x65, %eax
orl %ecx, %eax
jne 0x61d8b
movq %r13, -0x40(%rbp)
movl $0x60000, -0x50(%rbp)   # imm = 0x60000
movl $0xfff9ffff, -0x4c(%rbp) # imm = 0xFFF9FFFF
leaq 0x3198f(%rip), %r14     # 0x93680
leaq 0x1aa42(%rip), %rax     # 0x7c73a
movq %rax, -0x58(%rbp)
movq (%r14), %rsi
testq %rsi, %rsi
je 0x61dae
movl %r12d, %r13d
andl $0x3fffffff, %r13d      # imm = 0x3FFFFFFF
xorl %r15d, %r15d
movq $-0x1, %rax
cmpb $0x0, 0x1(%rsi,%rax)
leaq 0x1(%rax), %rax
jne 0x61d1c
xorl %r12d, %eax
testl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
jne 0x61d40
movq %rbx, %rdi
movq %r13, %rdx
callq 0x8410
testl %eax, %eax
je 0x61d55
incq %r15
movq %r15, %rax
shlq $0x4, %rax
movq (%r14,%rax), %rsi
testq %rsi, %rsi
jne 0x61d15
jmp 0x61dae
shlq $0x4, %r15
movl 0x8(%r14,%r15), %eax
testl %eax, %eax
je 0x61dae
movl %eax, %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
cmpl -0x50(%rbp), %ecx
jg 0x61e5c
movl -0x4c(%rbp), %ecx
andl -0x2c(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movq -0x48(%rbp), %r15
movq -0x40(%rbp), %r13
movl $0x68636163, %esi       # imm = 0x68636163
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
leaq (%rbx,%r12), %rax
incq %rax
cmpb $0x0, 0x1(%rbx,%r12)
jne 0x61c29
movq -0x38(%rbp), %rbx
jmp 0x61975
leaq 0x1a9a1(%rip), %rdi     # 0x7c756
movq -0x58(%rbp), %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xb868
movl $0x1, %r14d
movq -0x48(%rbp), %r15
jmp 0x61e1e
leaq 0x7(%rsi), %r8
cmpl $0x10, %r8d
je 0x61de5
cmpl $0x7, %r8d
je 0x61a4a
jmp 0x61e03
movabsq $0x736f686c61636f6c, %rax # imm = 0x736F686C61636F6C
xorq 0x7(%r12), %rax
movzbl 0xf(%r12), %ecx
xorq $0x74, %rcx
orq %rax, %rcx
je 0x61e51
addq $0x7, %r12
leaq 0x1a90c(%rip), %rdi     # 0x7c71a
movq %r12, %rdx
xorl %eax, %eax
callq 0xb868
movl $0x1, %r14d
movq -0x38(%rbp), %rbx
movq %rax, (%r15)
movq %rbx, %rdi
callq 0xa3c7
xorl %ebx, %ebx
movl -0x2c(%rbp), %eax
movq -0x70(%rbp), %rcx
movl %eax, (%rcx)
movq -0x60(%rbp), %rax
movq %rbx, (%rax)
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %r8d
jmp 0x61a4a
leaq 0x1a907(%rip), %rdi     # 0x7c76a
movq -0x58(%rbp), %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xb868
movl $0x3, %r14d
jmp 0x61dc9