// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movq %r9, -0x50(%rbp)
movq %r8, %rbx
movq %rdx, %r14
movq %rsi, %r13
movl (%rdx), %eax
movl %eax, -0x2c(%rbp)
testq %rsi, %rsi
movq %rdi, -0x78(%rbp)
movq %rcx, -0x80(%rbp)
je 0x619ed
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %r13, %rax
incl %r12d
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x619d8
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
jmp 0x619f0
xorl %r12d, %r12d
movl -0x2c(%rbp), %eax
andl $0x40, %eax
orl 0x32a10(%rip), %eax     # 0x9440c
setne %al
cmpl $0x5, %r12d
jb 0x61a22
testb %al, %al
je 0x61a22
movl $0x656c6966, %eax       # imm = 0x656C6966
xorl (%r13), %eax
movzbl 0x4(%r13), %ecx
xorl $0x3a, %ecx
orl %eax, %ecx
je 0x61aad
callq 0x9d1f
testl %eax, %eax
je 0x61a2f
xorl %edi, %edi
jmp 0x61a3c
leal 0x2(%r12), %edi
callq 0xa2a2
movq %rax, %rdi
testq %rdi, %rdi
je 0x61aa3
movl %r12d, %r15d
movq %r13, %rsi
movq %r15, %rdx
movq %rdi, %r12
callq 0x82f0
movq %r12, -0x38(%rbp)
movw $0x0, (%r12,%r15)
andl $-0x41, -0x2c(%rbp)
xorl %r13d, %r13d
movq -0x78(%rbp), %r15
movq %r15, %rdi
callq 0x9cc9
movq -0x80(%rbp), %rcx
movq %rax, (%rcx)
testq %rax, %rax
jne 0x61f9c
leaq 0x1acfb(%rip), %rdi     # 0x7c782
movq %r15, %rsi
xorl %eax, %eax
callq 0xb76d
movq -0x50(%rbp), %rcx
movq %rax, (%rcx)
movl $0x1, %r13d
jmp 0x61f9c
movl $0x7, %eax
jmp 0x61fbe
movl %r12d, %eax
addl $0x2, %r12d
xorl %ecx, %ecx
xorl %edx, %edx
cmpb $0x26, (%r13,%rcx)
sete %dl
addl %edx, %r12d
incq %rcx
cmpq %rcx, %rax
jne 0x61ab6
callq 0x9d1f
testl %eax, %eax
je 0x61ad9
xorl %eax, %eax
jmp 0x61ae1
movl %r12d, %edi
callq 0xa2a2
movq %rax, -0x38(%rbp)
movq %r14, -0x60(%rbp)
movq %rbx, -0x68(%rbp)
orl $0x40, -0x2c(%rbp)
testq %rax, %rax
je 0x61b28
movl $0x5, %r9d
cmpb $0x2f, 0x5(%r13)
jne 0x61b95
cmpb $0x2f, 0x6(%r13)
jne 0x61b95
xorl %esi, %esi
movzbl 0x7(%r13,%rsi), %eax
testl %eax, %eax
je 0x61b35
cmpl $0x2f, %eax
je 0x61b35
incq %rsi
jmp 0x61b14
movl $0x1, %ecx
xorl %r13d, %r13d
jmp 0x61f86
leaq 0x7(%rsi), %r9
cmpl $0x10, %r9d
je 0x61b47
cmpl $0x7, %r9d
je 0x61b95
jmp 0x61b63
movabsq $0x736f686c61636f6c, %rax # imm = 0x736F686C61636F6C
xorq 0x7(%r13), %rax
movzbl 0xf(%r13), %ecx
xorq $0x74, %rcx
orq %rax, %rcx
je 0x61b8f
addq $0x7, %r13
leaq 0x1abac(%rip), %rdi     # 0x7c71a
movq %r13, %rdx
xorl %eax, %eax
callq 0xb76d
movq -0x50(%rbp), %rcx
movq %rax, (%rcx)
movl $0x1, %r13d
movl $0x7, %ecx
jmp 0x61f86
movl $0x10, %r9d
xorl %edx, %edx
leaq 0x143c2(%rip), %rcx     # 0x75f60
xorl %eax, %eax
movslq %eax, %rsi
movl %r9d, %edi
movslq %edi, %r11
movzbl (%r13,%r11), %r8d
testl %r8d, %r8d
je 0x61d20
cmpl $0x23, %r8d
je 0x61d20
leal 0x1(%rdi), %r9d
movslq %r9d, %r10
cmpb $0x25, %r8b
jne 0x61c7d
movzbl (%r13,%r10), %ebx
testb $0x8, (%rbx,%rcx)
je 0x61c7d
movzbl 0x2(%r13,%r11), %r11d
testb $0x8, (%r11,%rcx)
je 0x61c7d
leal (%rbx,%rbx), %r8d
sarb $0x7, %r8b
andb $0x9, %r8b
addb %bl, %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
je 0x61c33
movl %r9d, %r8d
testb %r9b, %r9b
je 0x61ba6
jmp 0x61cd2
movslq %edi, %r10
addq %r13, %r10
movl %edi, %r11d
movl %r11d, %edi
movzbl (%r10), %r8d
testl %r8d, %r8d
je 0x61c25
cmpl $0x23, %r8d
je 0x61c25
testl %edx, %edx
jne 0x61c58
cmpb $0x3f, %r8b
je 0x61c25
cmpl $0x1, %edx
jne 0x61c69
cmpl $0x26, %r8d
je 0x61c25
cmpl $0x3d, %r8d
je 0x61c25
leal 0x1(%rdi), %r11d
incq %r10
cmpl $0x2, %edx
jne 0x61c3c
cmpb $0x26, %r8b
jne 0x61c3c
jmp 0x61c25
cmpl $0x1, %edx
jne 0x61ce7
cmpl $0x3d, %r8d
je 0x61c8e
cmpl $0x26, %r8d
jne 0x61ce7
movq -0x38(%rbp), %rdx
cmpb $0x0, -0x1(%rdx,%rsi)
jne 0x61cfe
incl %edi
addq %r13, %r10
movl %edi, %r8d
movzbl (%r10), %edi
movl $0x1, %edx
testl %edi, %edi
je 0x61cca
cmpl $0x23, %edi
je 0x61cca
cmpb $0x26, -0x1(%r10)
movl %r8d, %edi
leal 0x1(%r8), %r8d
leaq 0x1(%r10), %r10
jne 0x61ca1
jmp 0x61ba6
movl %r8d, %edi
jmp 0x61ba6
movl %edi, %r9d
movslq %eax, %rsi
incl %eax
movq -0x38(%rbp), %rdi
movb %r8b, (%rdi,%rsi)
jmp 0x61ba0
testl %edx, %edx
jne 0x61cf1
cmpb $0x3f, %r8b
je 0x61d0f
cmpl $0x2, %edx
jne 0x61cd5
cmpb $0x26, %r8b
je 0x61d0f
jmp 0x61cd5
cmpb $0x26, %r8b
jne 0x61d16
leal 0x1(%rsi), %eax
movq -0x38(%rbp), %rdx
movb $0x0, (%rdx,%rsi)
movl $0x1, %edx
jmp 0x61d1b
movl $0x2, %edx
xorl %r8d, %r8d
jmp 0x61cd5
cmpl $0x1, %edx
movq -0x38(%rbp), %rcx
jne 0x61d30
leal 0x1(%rsi), %eax
movb $0x0, (%rcx,%rsi)
cltq
movw $0x0, (%rcx,%rax)
movq $-0x1, %rax
cmpb $0x0, 0x1(%rcx,%rax)
leaq 0x1(%rax), %rax
jne 0x61d3f
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
leaq (%rcx,%rax), %r14
incq %r14
xorl %r13d, %r13d
cmpb $0x0, (%r14)
je 0x61f84
movl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
xorl %edx, %edx
movq %rdx, %rax
incq %rdx
incl %ecx
cmpb $0x0, (%r14,%rax)
jne 0x61d6a
movl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl %edx, %eax
leaq (%rax,%r14), %rsi
incq %rsi
movq %rsi, -0x48(%rbp)
andl %edx, %ecx
addq %r14, %rcx
incq %rcx
movq $-0x1, %r15
cmpb $0x0, 0x1(%rcx,%r15)
leaq 0x1(%r15), %r15
jne 0x61d9a
cmpl $0x5, %eax
je 0x61dd0
cmpl $0x3, %eax
jne 0x61dea
movzwl (%r14), %ecx
xorl $0x6676, %ecx           # imm = 0x6676
movzbl 0x2(%r14), %edx
xorl $0x73, %edx
orw %cx, %dx
je 0x61f5e
cmpl $0x5, %eax
jne 0x61dea
movl (%r14), %ecx
movl $0x68636163, %edx       # imm = 0x68636163
xorl %edx, %ecx
movzbl 0x4(%r14), %edx
xorl $0x65, %edx
orl %ecx, %edx
je 0x61f46
xorl %r12d, %r12d
xorl %ecx, %ecx
xorl %edx, %edx
cmpl $0x4, %eax
jne 0x61e1f
cmpl $0x65646f6d, (%r14)     # imm = 0x65646F6D
movl %edx, %esi
jne 0x61e21
movl -0x2c(%rbp), %esi
andl $0x87, %esi
movl $0x87, %edx
leaq 0x3189a(%rip), %r12     # 0x936b0
leaq 0x17812(%rip), %rcx     # 0x7962f
jmp 0x61e21
movl %edx, %esi
testq %r12, %r12
je 0x61f3c
movl %esi, -0x58(%rbp)
movl %edx, -0x54(%rbp)
movq %rcx, -0x70(%rbp)
movq %r13, -0x88(%rbp)
movq (%r12), %rsi
testq %rsi, %rsi
je 0x61eb9
movl %r15d, %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq %rax, -0x90(%rbp)
xorl %r13d, %r13d
movl $0x0, -0x3c(%rbp)
movq $-0x1, %rax
cmpb $0x0, 0x1(%rsi,%rax)
leaq 0x1(%rax), %rax
jne 0x61e64
xorl %r15d, %eax
movb $0x1, %bl
testl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
jne 0x61ea0
movq -0x48(%rbp), %rdi
movq -0x90(%rbp), %rdx
callq 0x8410
testl %eax, %eax
jne 0x61ea0
movq %r13, %rax
shlq $0x4, %rax
movl 0x8(%r12,%rax), %eax
movl %eax, -0x3c(%rbp)
xorl %ebx, %ebx
testb %bl, %bl
je 0x61ec0
incq %r13
movq %r13, %rax
shlq $0x4, %rax
movq (%r12,%rax), %rsi
testq %rsi, %rsi
jne 0x61e5d
jmp 0x61ec0
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %edx
testl %edx, %edx
movq -0x88(%rbp), %r13
je 0x61f01
movl %edx, %eax
andl $0xffffff7f, %eax       # imm = 0xFFFFFF7F
cmpl -0x58(%rbp), %eax
movq -0x70(%rbp), %rsi
jle 0x61f2d
xorl %ebx, %ebx
leaq 0x1a883(%rip), %rdi     # 0x7c76a
movq -0x48(%rbp), %rdx
xorl %eax, %eax
callq 0xb76d
movq -0x50(%rbp), %rcx
movq %rax, (%rcx)
movl $0x3, %r13d
jmp 0x61f26
xorl %ebx, %ebx
leaq 0x1a84c(%rip), %rdi     # 0x7c756
movq -0x70(%rbp), %rsi
movq -0x48(%rbp), %rdx
xorl %eax, %eax
callq 0xb76d
movq -0x50(%rbp), %rcx
movq %rax, (%rcx)
movl $0x1, %r13d
movl $0x7, %ecx
jmp 0x61f40
movl -0x54(%rbp), %ecx
notl %ecx
movl -0x2c(%rbp), %eax
andl %ecx, %eax
orl %edx, %eax
movl %eax, -0x2c(%rbp)
xorl %ecx, %ecx
movb $0x1, %bl
testb %bl, %bl
jne 0x61f66
jmp 0x61f7a
movl $0x60000, %edx          # imm = 0x60000
leaq 0x3172e(%rip), %r12     # 0x93680
leaq 0x1a7e1(%rip), %rcx     # 0x7c73a
jmp 0x61df1
movq -0x48(%rbp), %rax
movq %rax, -0x78(%rbp)
andl $0x3fffffff, %r15d      # imm = 0x3FFFFFFF
movq -0x48(%rbp), %rax
leaq (%rax,%r15), %r14
incq %r14
xorl %ecx, %ecx
testl %ecx, %ecx
je 0x61d59
jmp 0x61f86
xorl %ecx, %ecx
testl %ecx, %ecx
je 0x61fcd
movl $0x7, %eax
cmpl $0x7, %ecx
movq -0x68(%rbp), %rbx
movq -0x60(%rbp), %r14
jne 0x61fbe
testl %r13d, %r13d
je 0x61fae
movq -0x38(%rbp), %rdi
callq 0xa2e8
xorl %ecx, %ecx
jmp 0x61fb2
movq -0x38(%rbp), %rcx
movl -0x2c(%rbp), %eax
movl %eax, (%r14)
movq %rcx, (%rbx)
movl %r13d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x68(%rbp), %rbx
movq -0x60(%rbp), %r14
jmp 0x61a64