// File: /workspace/github_c_makefile_star2_O2/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, -0x60(%rbp)
movq %r8, -0x48(%rbp)
movq %rcx, -0x68(%rbp)
movq %rsi, %rbx
movq %rdi, -0x58(%rbp)
movq %rdx, -0x70(%rbp)
movl (%rdx), %r14d
movq %rsi, %rdi
callq 0x8f8e
movl %eax, %r15d
movl %r14d, -0x2c(%rbp)
movl %r14d, %eax
andl $0x40, %eax
orl 0x30a36(%rip), %eax     # 0x8740c
setne %al
cmpl $0x5, %r15d
setae %cl
andb %al, %cl
movl %r15d, %r13d
pushq $0x7
popq %r12
cmpb $0x1, %cl
jne 0x56a08
leaq 0x17d35(%rip), %rsi     # 0x6e72a
pushq $0x5
popq %rdx
movq %rbx, %rdi
callq 0x83e0
testl %eax, %eax
je 0x56a9a
addl $0x2, %r15d
movl %r15d, %edi
callq 0x9c1c
testq %rax, %rax
je 0x56a88
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x82c0
andw $0x0, (%r15,%r13)
movl -0x2c(%rbp), %r13d
andl $-0x41, %r13d
movq -0x58(%rbp), %r14
movq %r14, %rdi
callq 0x96f9
movq -0x68(%rbp), %rcx
movq %rax, (%rcx)
xorl %r12d, %r12d
testq %rax, %rax
movq -0x48(%rbp), %rbx
jne 0x56a7e
leaq 0x17d44(%rip), %rdi     # 0x6e7a2
movq %r14, %rsi
xorl %eax, %eax
callq 0xae3e
pushq $0x1
popq %r12
movq -0x60(%rbp), %rcx
movq %rax, (%rcx)
movq %r15, %rdi
callq 0x9c7b
xorl %r15d, %r15d
movq -0x70(%rbp), %rax
movl %r13d, (%rax)
movq %r15, (%rbx)
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addl $0x2, %r15d
xorl %eax, %eax
cmpq %rax, %r13
je 0x56ab6
xorl %ecx, %ecx
cmpb $0x26, (%rbx,%rax)
sete %cl
addl %ecx, %r15d
incq %rax
jmp 0x56aa0
movl %r15d, %edi
callq 0x9c1c
testq %rax, %rax
je 0x56a88
movq %rax, %r15
movl -0x2c(%rbp), %r13d
orl $0x40, %r13d
pushq $0x5
popq %r10
cmpb $0x2f, 0x5(%rbx)
jne 0x56b44
cmpb $0x2f, 0x6(%rbx)
jne 0x56b44
xorl %r12d, %r12d
movzbl 0x7(%rbx,%r12), %eax
testl %eax, %eax
je 0x56af5
cmpl $0x2f, %eax
je 0x56af5
incq %r12
jmp 0x56ae1
leaq 0x7(%r12), %r10
cmpl $0x10, %r10d
je 0x56b08
cmpl $0x7, %r10d
je 0x56b44
jmp 0x56b1f
leaq 0x7(%rbx), %rsi
leaq 0x17c1d(%rip), %rdi     # 0x6e730
pushq $0x9
popq %rdx
callq 0x83e0
testl %eax, %eax
je 0x56b40
addq $0x7, %rbx
leaq 0x17c10(%rip), %rdi     # 0x6e73a
movl %r12d, %esi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xae3e
movq -0x48(%rbp), %rbx
jmp 0x56a68
pushq $0x10
popq %r10
movq %r15, -0x38(%rbp)
xorl %r8d, %r8d
leaq 0x1141e(%rip), %rax     # 0x67f70
pushq $0x1
popq %rcx
pushq $0x2
popq %rsi
xorl %edi, %edi
movslq %edi, %rdx
movl %r10d, %r9d
movslq %r9d, %r15
movzbl (%rbx,%r15), %r11d
testl %r11d, %r11d
je 0x56cd9
cmpl $0x23, %r11d
je 0x56cd9
leal 0x1(%r9), %r10d
movslq %r10d, %r14
cmpb $0x25, %r11b
jne 0x56c3f
movzbl (%rbx,%r14), %r12d
testb $0x8, (%r12,%rax)
je 0x56c3f
movzbl 0x2(%rbx,%r15), %r15d
testb $0x8, (%r15,%rax)
je 0x56c3f
leal (%r12,%r12), %r10d
sarb $0x7, %r10b
andb $0x9, %r10b
addb %r12b, %r10b
shlb $0x4, %r10b
addl $0x3, %r9d
leal (%r15,%r15), %r11d
sarb $0x7, %r11b
andb $0x9, %r11b
addb %r15b, %r11b
andb $0xf, %r11b
orb %r10b, %r11b
jne 0x56c89
movslq %r9d, %r10
addq %rbx, %r10
movzbl (%r10), %r11d
testl %r11d, %r11d
je 0x56b60
cmpl $0x23, %r11d
je 0x56b60
testl %r8d, %r8d
jne 0x56c0c
cmpb $0x3f, %r11b
je 0x56b60
cmpl $0x1, %r8d
jne 0x56c27
cmpl $0x26, %r11d
je 0x56b60
cmpl $0x3d, %r11d
jne 0x56c37
jmp 0x56b60
cmpl $0x2, %r8d
jne 0x56c37
cmpb $0x26, %r11b
je 0x56b60
incl %r9d
incq %r10
jmp 0x56be6
cmpl $0x1, %r8d
jne 0x56c9b
cmpl $0x3d, %r11d
movq -0x38(%rbp), %r15
je 0x56c55
cmpl $0x26, %r11d
jne 0x56ccc
cmpb $0x0, -0x1(%r15,%rdx)
jne 0x56cb8
incl %r9d
addq %rbx, %r14
movzbl (%r14), %r8d
testl %r8d, %r8d
je 0x56c81
cmpl $0x23, %r8d
je 0x56c81
cmpb $0x26, -0x1(%r14)
je 0x56c81
incl %r9d
incq %r14
jmp 0x56c63
movl %ecx, %r8d
jmp 0x56b60
movl %r9d, %r10d
movq -0x38(%rbp), %r15
incl %edi
movb %r11b, (%r15,%rdx)
jmp 0x56b5a
testl %r8d, %r8d
movq -0x38(%rbp), %r15
jne 0x56caa
cmpb $0x3f, %r11b
je 0x56cc9
cmpl $0x2, %r8d
jne 0x56c90
cmpb $0x26, %r11b
je 0x56cc9
jmp 0x56c90
cmpb $0x26, %r11b
jne 0x56cd1
leal 0x1(%rdx), %edi
movb $0x0, (%r15,%rdx)
movslq %edi, %rdx
xorl %r11d, %r11d
movl %ecx, %r8d
jmp 0x56c90
xorl %r11d, %r11d
movl %esi, %r8d
jmp 0x56c90
cmpl $0x1, %r8d
movl %r13d, -0x2c(%rbp)
jne 0x56cf4
leal 0x1(%rdx), %eax
movq -0x38(%rbp), %r15
movb $0x0, (%r15,%rdx)
movslq %eax, %rdx
jmp 0x56cf8
movq -0x38(%rbp), %r15
andw $0x0, (%r15,%rdx)
movq %r15, %rdi
callq 0x8f8e
movl %eax, %ebx
movq %r15, %r12
movq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movl %ebx, %eax
cmpb $0x0, 0x1(%r12,%rax)
je 0x56e3d
leaq (%r12,%rax), %r13
incq %r13
movq %r13, %rdi
callq 0x8f8e
movl %eax, %r14d
movl %eax, %eax
leaq (%rax,%r13), %r12
incq %r12
movq %r12, %rdi
callq 0x8f8e
movl %eax, %ebx
cmpl $0x5, %r14d
je 0x56d9f
cmpl $0x4, %r14d
je 0x56d73
cmpl $0x3, %r14d
jne 0x56d13
leaq 0x179f7(%rip), %rdi     # 0x6e756
movq %r13, %rsi
pushq $0x3
popq %rdx
callq 0x83e0
testl %eax, %eax
jne 0x56d13
jmp 0x56e35
cmpl $0x65646f6d, (%r13)     # imm = 0x65646F6D
jne 0x56d13
movl -0x2c(%rbp), %eax
andl $0x87, %eax
movl %eax, -0x40(%rbp)
movl $0xffffff78, -0x3c(%rbp) # imm = 0xFFFFFF78
leaq 0x2f96a(%rip), %r15     # 0x86700
leaq 0x148b2(%rip), %rax     # 0x6b64f
jmp 0x56dd5
leaq 0x179b4(%rip), %rdi     # 0x6e75a
movq %r13, %rsi
pushq $0x5
popq %rdx
callq 0x83e0
testl %eax, %eax
jne 0x56d13
movl $0x60000, -0x40(%rbp)   # imm = 0x60000
movl $0xfff9ffff, -0x3c(%rbp) # imm = 0xFFF9FFFF
leaq 0x2f902(%rip), %r15     # 0x866d0
leaq 0x17985(%rip), %rax     # 0x6e75a
movq %rax, -0x50(%rbp)
movl %ebx, %r13d
addq $0x8, %r15
movq -0x8(%r15), %r14
testq %r14, %r14
je 0x56e46
movq %r14, %rdi
callq 0x8f8e
cmpl %eax, %ebx
jne 0x56e07
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x83e0
testl %eax, %eax
je 0x56e0d
addq $0x10, %r15
jmp 0x56de0
movl (%r15), %eax
testl %eax, %eax
je 0x56e46
movl %eax, %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
cmpl -0x40(%rbp), %ecx
jg 0x56e70
movl -0x3c(%rbp), %ecx
andl -0x2c(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %r15
jmp 0x56d13
movq %r12, %rax
jmp 0x56d0f
movl -0x2c(%rbp), %r13d
jmp 0x56a38
leaq 0x17929(%rip), %rdi     # 0x6e776
movq -0x50(%rbp), %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0xae3e
pushq $0x1
popq %r12
movq -0x48(%rbp), %rbx
movl -0x2c(%rbp), %r13d
movq -0x38(%rbp), %r15
jmp 0x56a6c
leaq 0x17913(%rip), %rdi     # 0x6e78a
movq -0x50(%rbp), %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0xae3e
pushq $0x3
jmp 0x56e5d