// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/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)             /* IMP: R-48725-32206 */
            || sqlite3GlobalConfig.bOpenUri) /* IMP: R-51689-46548 */
   && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
  ){
    char *zOpt;
    int eState;                   /* Parser state when parsing URI */
    int iIn;                      /* Input character index */
    int iOut = 0;                 /* Output character index */
    u64 nByte = nUri+8;           /* 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_malloc64(nByte);
    if( !zFile ) return SQLITE_NOMEM_BKPT;

    memset(zFile, 0, 4);  /* 4-byte of 0x00 is the start of DB name marker */
    zFile += 4;

    iIn = 5;
#ifdef SQLITE_ALLOW_URI_AUTHORITY
    if( strncmp(zUri+5, "///", 3)==0 ){
      iIn = 7;
      /* The following condition causes URIs with five leading / characters
      ** like file://///host/path to be converted into UNCs like //host/path.
      ** The correct URI for that UNC has only two or four leading / characters
      ** file://host/path or file:////host/path.  But 5 leading slashes is a
      ** common error, we are told, so we handle it as a special case. */
      if( strncmp(zUri+7, "///", 3)==0 ){ iIn++; }
    }else if( strncmp(zUri+5, "//localhost/", 12)==0 ){
      iIn = 16;
    }
#else
    /* 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 ){
#ifndef SQLITE_ENABLE_URI_00_ERROR
          /* 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;
#else
          /* If ENABLE_URI_00_ERROR is defined, "%00" in a URI is an error. */
          *pzErrMsg = sqlite3_mprintf("unexpected %%00 in uri");
          rc = SQLITE_ERROR;
          goto parse_uri_out;
#endif
        }
        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';
    memset(zFile+iOut, 0, 4); /* end-of-options + empty journal filenames */

    /* 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_malloc64(nUri+8);
    if( !zFile ) return SQLITE_NOMEM_BKPT;
    memset(zFile, 0, 4);
    zFile += 4;
    if( nUri ){
      memcpy(zFile, zUri, nUri);
    }
    memset(zFile+nUri, 0, 4);
    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_filename(zFile);
    zFile = 0;
  }
  *pFlags = flags;
  *pzFile = zFile;
  return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x38(%rsp)
movq %r8, %r14
movq %rcx, 0x40(%rsp)
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, 0x18(%rsp)
movl (%rdx), %ebp
testq %rsi, %rsi
je 0x2e858e
movq %r15, %rdi
callq 0x172f0
movq %rax, %r13
andl $0x3fffffff, %r13d      # imm = 0x3FFFFFFF
jmp 0x2e8591
xorl %r13d, %r13d
movl %ebp, %eax
shrb $0x6, %al
cmpb $0x0, 0x1d30c9(%rip)    # 0x4bb666
setne %cl
orb %al, %cl
cmpl $0x5, %r13d
setae %al
andb %cl, %al
cmpb $0x1, %al
jne 0x2e85c3
movl $0x656c6966, %eax       # imm = 0x656C6966
xorl (%r15), %eax
movzbl 0x4(%r15), %ecx
xorl $0x3a, %ecx
orl %eax, %ecx
je 0x2e8617
callq 0x2725a7
movl $0x7, %ebx
testl %eax, %eax
jne 0x2e8708
movl %ebp, 0xc(%rsp)
leal 0x8(%r13), %edi
callq 0x272ae6
testq %rax, %rax
je 0x2e8708
movq %rax, %rbp
movl $0x0, (%rax)
addq $0x4, %rbp
testl %r13d, %r13d
je 0x2e86aa
movl %r13d, %ebx
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x17660
jmp 0x2e86ac
movq %r12, 0x10(%rsp)
leal 0x8(%r13), %r12d
movl %r13d, %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpb $0x26, (%r15,%rcx)
sete %dl
addq %rdx, %r12
incq %rcx
cmpq %rcx, %rax
jne 0x2e8625
callq 0x2725a7
movl $0x7, %ebx
testl %eax, %eax
jne 0x2e8708
movl %ebp, 0xc(%rsp)
movq %r12, %rdi
callq 0x272ae6
testq %rax, %rax
movq 0x10(%rsp), %r12
je 0x2e8708
movq %rax, %rbp
orl $0x40, 0xc(%rsp)
movl $0x0, (%rax)
addq $0x4, %rbp
movl $0x5, %r8d
cmpb $0x2f, 0x5(%r15)
jne 0x2e8764
cmpb $0x2f, 0x6(%r15)
jne 0x2e8764
xorl %esi, %esi
movzbl 0x7(%r15,%rsi), %eax
testl %eax, %eax
je 0x2e8719
cmpl $0x2f, %eax
je 0x2e8719
incq %rsi
jmp 0x2e8696
xorl %ebx, %ebx
movq 0x18(%rsp), %r15
movl $0x0, (%rbp,%rbx)
andl $-0x41, 0xc(%rsp)
movq %r15, %rdi
callq 0x272556
movq 0x40(%rsp), %rcx
movq %rax, (%rcx)
xorl %ebx, %ebx
testq %rax, %rax
jne 0x2e86fd
leaq 0xf0e24(%rip), %rdi     # 0x3d9500
movq %r15, %rsi
xorl %eax, %eax
callq 0x274b53
movl $0x1, %ebx
movq 0x38(%rsp), %rcx
movq %rax, (%rcx)
movq %rbp, %rdi
callq 0x28224c
xorl %ebp, %ebp
movl 0xc(%rsp), %eax
movl %eax, (%r12)
movq %rbp, (%r14)
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7(%rsi), %r8
cmpl $0x10, %r8d
je 0x2e872b
cmpl $0x7, %r8d
je 0x2e8764
jmp 0x2e8747
movabsq $0x736f686c61636f6c, %rax # imm = 0x736F686C61636F6C
xorq 0x7(%r15), %rax
movzbl 0xf(%r15), %ecx
xorq $0x74, %rcx
orq %rax, %rcx
je 0x2e875e
addq $0x7, %r15
leaq 0xf0d56(%rip), %rdi     # 0x3d94a8
movq %r15, %rdx
xorl %eax, %eax
callq 0x274b53
jmp 0x2e86e6
movl $0x10, %r8d
xorl %esi, %esi
leaq 0xe8cd3(%rip), %rcx     # 0x3d1440
xorl %edx, %edx
movslq %edx, %rax
movl %r8d, %edi
movslq %edi, %r11
movzbl (%r15,%r11), %r9d
testl %r9d, %r9d
je 0x2e88e8
cmpl $0x23, %r9d
je 0x2e88e8
leal 0x1(%rdi), %r8d
movslq %r8d, %r10
cmpb $0x25, %r9b
jne 0x2e884e
movzbl (%r15,%r10), %ebx
testb $0x8, (%rbx,%rcx)
je 0x2e884e
movzbl 0x2(%r15,%r11), %r11d
testb $0x8, (%r11,%rcx)
je 0x2e884e
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
jne 0x2e8899
movslq %edi, %r8
addq %r15, %r8
movzbl (%r8), %r9d
testl %r9d, %r9d
je 0x2e8775
cmpl $0x23, %r9d
je 0x2e8775
testl %esi, %esi
jne 0x2e881e
cmpb $0x3f, %r9b
je 0x2e8775
cmpl $0x1, %esi
jne 0x2e8838
cmpl $0x26, %r9d
je 0x2e8775
cmpl $0x3d, %r9d
jne 0x2e8847
jmp 0x2e8775
cmpl $0x2, %esi
jne 0x2e8847
cmpb $0x26, %r9b
je 0x2e8775
incl %edi
incq %r8
jmp 0x2e87f9
cmpl $0x1, %esi
jne 0x2e88a8
cmpl $0x3d, %r9d
je 0x2e885f
cmpl $0x26, %r9d
jne 0x2e88d7
cmpb $0x0, -0x1(%rbp,%rax)
jne 0x2e88bf
incl %edi
addq %r15, %r10
movzbl (%r10), %r8d
movl $0x1, %esi
testl %r8d, %r8d
je 0x2e8775
cmpl $0x23, %r8d
je 0x2e8775
cmpb $0x26, -0x1(%r10)
je 0x2e8775
incl %edi
incq %r10
jmp 0x2e886b
movl %edi, %r8d
incl %edx
movb %r9b, (%rbp,%rax)
jmp 0x2e876f
testl %esi, %esi
jne 0x2e88b2
cmpb $0x3f, %r9b
je 0x2e88d0
cmpl $0x2, %esi
jne 0x2e889c
cmpb $0x26, %r9b
je 0x2e88d0
jmp 0x2e889c
cmpb $0x26, %r9b
jne 0x2e88de
leal 0x1(%rax), %edx
movb $0x0, (%rbp,%rax)
movslq %edx, %rax
movl $0x1, %esi
jmp 0x2e88e3
movl $0x1, %esi
jmp 0x2e889c
movl $0x2, %esi
xorl %r9d, %r9d
jmp 0x2e889c
cmpl $0x1, %esi
jne 0x2e88f8
leal 0x1(%rax), %ecx
movb $0x0, (%rbp,%rax)
movslq %ecx, %rax
movq 0x18(%rsp), %r15
movl $0x0, (%rbp,%rax)
movq %rbp, %rdi
callq 0x172f0
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cmpb $0x0, 0x1(%rbp,%rax)
je 0x2e86be
leaq (%rax,%rbp), %r13
incq %r13
movq %r14, 0x30(%rsp)
movq %r13, %rdi
callq 0x172f0
movq %rax, %r12
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
leaq (%r12,%r13), %r15
incq %r15
movq %r15, %rdi
callq 0x172f0
movq %rax, %rbx
cmpl $0x5, %r12d
je 0x2e89c5
cmpl $0x4, %r12d
je 0x2e898d
cmpl $0x3, %r12d
jne 0x2e8a77
movzwl (%r13), %eax
xorl $0x6676, %eax           # imm = 0x6676
movzbl 0x2(%r13), %ecx
xorl $0x73, %ecx
orw %ax, %cx
movq 0x10(%rsp), %r12
jne 0x2e8a7c
movq %r15, 0x18(%rsp)
jmp 0x2e8a7c
cmpl $0x65646f6d, (%r13)     # imm = 0x65646F6D
movq 0x10(%rsp), %r12
jne 0x2e8a7c
movl 0xc(%rsp), %eax
andl $0x87, %eax
movl %eax, 0x24(%rsp)
movl $0xffffff78, 0x20(%rsp) # imm = 0xFFFFFF78
leaq 0x1cf504(%rip), %r14    # 0x4b7ec0
leaq 0x7f5a7(%rip), %rax     # 0x367f6a
jmp 0x2e89fe
movl (%r13), %eax
movl $0x68636163, %ecx       # imm = 0x68636163
xorl %ecx, %eax
movzbl 0x4(%r13), %ecx
xorl $0x65, %ecx
orl %eax, %ecx
jne 0x2e8a77
movl $0x60000, 0x24(%rsp)    # imm = 0x60000
movl $0xfff9ffff, 0x20(%rsp) # imm = 0xFFF9FFFF
leaq 0x1cf499(%rip), %r14    # 0x4b7e90
leaq 0x6a704(%rip), %rax     # 0x353102
movq %rax, 0x28(%rsp)
movq (%r14), %r12
testq %r12, %r12
je 0x2e8a9e
movl %ebx, %r13d
andl $0x3fffffff, %r13d      # imm = 0x3FFFFFFF
addq $0x10, %r14
movq %r12, %rdi
callq 0x172f0
xorl %ebx, %eax
testl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
jne 0x2e8a40
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x17830
testl %eax, %eax
je 0x2e8a4e
movq (%r14), %r12
addq $0x10, %r14
testq %r12, %r12
jne 0x2e8a1d
jmp 0x2e8a9e
movl -0x8(%r14), %eax
testl %eax, %eax
je 0x2e8a9e
movl %eax, %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
cmpl 0x24(%rsp), %ecx
jg 0x2e8ac8
movl 0x20(%rsp), %ecx
andl 0xc(%rsp), %ecx
orl %ecx, %eax
movl %eax, 0xc(%rsp)
movq 0x30(%rsp), %r14
movq 0x10(%rsp), %r12
andl $0x3fffffff, %ebx       # imm = 0x3FFFFFFF
leaq (%r15,%rbx), %r13
incq %r13
cmpb $0x0, (%r13)
jne 0x2e8929
movq 0x18(%rsp), %r15
jmp 0x2e86be
leaq 0xf0a2f(%rip), %rdi     # 0x3d94d4
movq 0x28(%rsp), %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x274b53
movl $0x1, %ebx
movq 0x30(%rsp), %r14
movq 0x10(%rsp), %r12
jmp 0x2e86eb
leaq 0xf0a19(%rip), %rdi     # 0x3d94e8
movq 0x28(%rsp), %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x274b53
movl $0x3, %ebx
jmp 0x2e8ab9