// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movq %r9, %r12
movq %r8, 0x60(%rsp)
movq %rcx, 0x50(%rsp)
movq %rsi, %rbx
movq %rdi, %r13
movq %rdx, 0x58(%rsp)
movl (%rdx), %ebp
testq %rsi, %rsi
je 0x2f1824
movq %rbx, %rdi
callq 0x172f0
movq %rax, %r14
andl $0x3fffffff, %r14d      # imm = 0x3FFFFFFF
jmp 0x2f1827
xorl %r14d, %r14d
movl %ebp, %eax
shrb $0x6, %al
cmpb $0x0, 0x1d4e33(%rip)    # 0x4c6666
setne %cl
orb %al, %cl
cmpl $0x5, %r14d
setae %al
andb %cl, %al
cmpb $0x1, %al
jne 0x2f185b
movl $0x656c6966, %eax       # imm = 0x656C6966
xorl (%rbx), %eax
movzbl 0x4(%rbx), %ecx
xorl $0x3a, %ecx
orl %eax, %ecx
je 0x2f18eb
callq 0x27bed9
testl %eax, %eax
je 0x2f1868
xorl %edi, %edi
jmp 0x2f1874
leal 0x8(%r14), %edi
callq 0x27c381
movq %rax, %rdi
testq %rdi, %rdi
je 0x2f18e1
movl $0x0, (%rdi)
addq $0x4, %rdi
movl %r14d, %r15d
testl %r14d, %r14d
movq %rdi, %r14
je 0x2f189c
movq %rbx, %rsi
movq %r15, %rdx
callq 0x17660
movq %r14, %rdi
movl $0x0, (%rdi,%r15)
andl $-0x41, %ebp
xorl %ebx, %ebx
movq %r13, %rdi
callq 0x27be83
movq 0x50(%rsp), %rcx
movq %rax, (%rcx)
testq %rax, %rax
jne 0x2f1deb
leaq 0xf138c(%rip), %rdi     # 0x3e2c55
movq %r13, %rsi
xorl %eax, %eax
callq 0x27e482
movq %rax, (%r12)
movl $0x1, %ebx
jmp 0x2f1deb
movl $0x7, %eax
jmp 0x2f1e0b
leal 0x8(%r14), %r15d
movl %r14d, %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpb $0x26, (%rbx,%rcx)
sete %dl
addq %rdx, %r15
incq %rcx
cmpq %rcx, %rax
jne 0x2f18f4
callq 0x27bed9
testl %eax, %eax
je 0x2f1915
xorl %eax, %eax
jmp 0x2f191d
movq %r15, %rdi
callq 0x27c381
orl $0x40, %ebp
testq %rax, %rax
je 0x2f195f
movl $0x0, (%rax)
addq $0x4, %rax
movq %rax, 0x10(%rsp)
movl $0x5, %r9d
cmpb $0x2f, 0x5(%rbx)
jne 0x2f19c9
cmpb $0x2f, 0x6(%rbx)
jne 0x2f19c9
xorl %esi, %esi
movzbl 0x7(%rbx,%rsi), %eax
testl %eax, %eax
je 0x2f196e
cmpl $0x2f, %eax
je 0x2f196e
incq %rsi
jmp 0x2f194c
movl $0x1, %eax
xorl %r14d, %r14d
xorl %ebx, %ebx
jmp 0x2f1dd7
leaq 0x7(%rsi), %r9
cmpl $0x10, %r9d
je 0x2f1980
cmpl $0x7, %r9d
je 0x2f19c9
jmp 0x2f199b
movabsq $0x736f686c61636f6c, %rax # imm = 0x736F686C61636F6C
xorq 0x7(%rbx), %rax
movzbl 0xf(%rbx), %ecx
xorq $0x74, %rcx
orq %rax, %rcx
je 0x2f19c3
addq $0x7, %rbx
leaq 0xf1257(%rip), %rdi     # 0x3e2bfd
movq %rbx, %rdx
xorl %eax, %eax
callq 0x27e482
movq %rax, (%r12)
movl $0x1, %ebx
movl $0x7, %eax
jmp 0x2f1dc9
movl $0x10, %r9d
xorl %edx, %edx
leaq 0xe91ee(%rip), %rcx     # 0x3dabc0
xorl %eax, %eax
movslq %eax, %rsi
movl %r9d, %edi
movslq %edi, %r11
movzbl (%rbx,%r11), %r8d
testl %r8d, %r8d
je 0x2f1b56
cmpl $0x23, %r8d
je 0x2f1b56
leal 0x1(%rdi), %r9d
movslq %r9d, %r10
cmpb $0x25, %r8b
jne 0x2f1ab0
movzbl (%rbx,%r10), %r14d
testb $0x8, (%r14,%rcx)
je 0x2f1ab0
movzbl 0x2(%rbx,%r11), %r11d
testb $0x8, (%r11,%rcx)
je 0x2f1ab0
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
je 0x2f1a66
movl %r9d, %r8d
testb %r9b, %r9b
je 0x2f19da
jmp 0x2f1b06
movslq %edi, %r10
addq %rbx, %r10
movl %edi, %r11d
movl %r11d, %edi
movzbl (%r10), %r8d
testl %r8d, %r8d
je 0x2f1a58
cmpl $0x23, %r8d
je 0x2f1a58
testl %edx, %edx
jne 0x2f1a8b
cmpb $0x3f, %r8b
je 0x2f1a58
cmpl $0x1, %edx
jne 0x2f1a9c
cmpl $0x26, %r8d
je 0x2f1a58
cmpl $0x3d, %r8d
je 0x2f1a58
leal 0x1(%rdi), %r11d
incq %r10
cmpl $0x2, %edx
jne 0x2f1a6f
cmpb $0x26, %r8b
jne 0x2f1a6f
jmp 0x2f1a58
cmpl $0x1, %edx
jne 0x2f1b1c
cmpl $0x3d, %r8d
je 0x2f1ac1
cmpl $0x26, %r8d
jne 0x2f1b1c
movq 0x10(%rsp), %rdx
cmpb $0x0, -0x1(%rdx,%rsi)
jne 0x2f1b33
incl %edi
addq %rbx, %r10
movl %edi, %r8d
movzbl (%r10), %edi
movl $0x1, %edx
testl %edi, %edi
je 0x2f1afe
cmpl $0x23, %edi
je 0x2f1afe
cmpb $0x26, -0x1(%r10)
movl %r8d, %edi
leal 0x1(%r8), %r8d
leaq 0x1(%r10), %r10
jne 0x2f1ad5
jmp 0x2f19da
movl %r8d, %edi
jmp 0x2f19da
movl %edi, %r9d
movslq %eax, %rsi
incl %eax
movq 0x10(%rsp), %rdi
movb %r8b, (%rdi,%rsi)
jmp 0x2f19d4
testl %edx, %edx
jne 0x2f1b26
cmpb $0x3f, %r8b
je 0x2f1b45
cmpl $0x2, %edx
jne 0x2f1b09
cmpb $0x26, %r8b
je 0x2f1b45
jmp 0x2f1b09
cmpb $0x26, %r8b
jne 0x2f1b4c
leal 0x1(%rsi), %eax
movq 0x10(%rsp), %rdx
movb $0x0, (%rdx,%rsi)
movl $0x1, %edx
jmp 0x2f1b51
movl $0x2, %edx
xorl %r8d, %r8d
jmp 0x2f1b09
cmpl $0x1, %edx
jne 0x2f1b67
leal 0x1(%rsi), %eax
movq 0x10(%rsp), %rcx
movb $0x0, (%rcx,%rsi)
cltq
movq 0x10(%rsp), %rbx
movl $0x0, (%rbx,%rax)
movq %rbx, %rdi
callq 0x172f0
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
leaq (%rbx,%rax), %r15
incq %r15
xorl %ebx, %ebx
movq %r12, 0x40(%rsp)
cmpb $0x0, (%r15)
je 0x2f1dd0
movq %r15, %rdi
callq 0x172f0
movq %rax, %r14
andl $0x3fffffff, %r14d      # imm = 0x3FFFFFFF
movq %r15, 0x28(%rsp)
leaq (%r14,%r15), %rdi
incq %rdi
movq %rdi, 0x30(%rsp)
callq 0x172f0
movq %rax, %r15
cmpl $0x5, %r14d
je 0x2f1bf4
cmpl $0x3, %r14d
jne 0x2f1c2f
movq 0x28(%rsp), %rcx
movzwl (%rcx), %eax
xorl $0x6676, %eax           # imm = 0x6676
movzbl 0x2(%rcx), %ecx
xorl $0x73, %ecx
orw %ax, %cx
je 0x2f1d9e
cmpl $0x5, %r14d
jne 0x2f1c2f
movq %r13, 0x20(%rsp)
movq 0x28(%rsp), %rdx
movl (%rdx), %eax
movl $0x68636163, %ecx       # imm = 0x68636163
xorl %ecx, %eax
movzbl 0x4(%rdx), %ecx
xorl $0x65, %ecx
orl %eax, %ecx
jne 0x2f1c34
movl $0x60000, 0xc(%rsp)     # imm = 0x60000
leaq 0x1d127f(%rip), %r13    # 0x4c2ea0
leaq 0x6a512(%rip), %rax     # 0x35c13a
movq %rax, 0x18(%rsp)
jmp 0x2f1c48
movq %r13, 0x20(%rsp)
xorl %r13d, %r13d
movq $0x0, 0x18(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x4, %r14d
jne 0x2f1c84
movq 0x28(%rsp), %rax
cmpl $0x65646f6d, (%rax)     # imm = 0x65646F6D
movl 0xc(%rsp), %ecx
jne 0x2f1c88
movl %ebp, %ecx
andl $0x87, %ecx
movl $0x87, 0xc(%rsp)
leaq 0x1d125a(%rip), %r13    # 0x4c2ed0
leaq 0x7f524(%rip), %rax     # 0x3711a1
movq %rax, 0x18(%rsp)
jmp 0x2f1c88
movl 0xc(%rsp), %ecx
movl %ecx, 0x3c(%rsp)
movb $0x1, %r14b
testq %r13, %r13
je 0x2f1cfa
movq %rbx, 0x48(%rsp)
movl %ebp, 0x38(%rsp)
movq (%r13), %rbp
testq %rbp, %rbp
je 0x2f1cfe
movl %r15d, %r14d
andl $0x3fffffff, %r14d      # imm = 0x3FFFFFFF
addq $0x10, %r13
xorl %ebx, %ebx
movq %rbp, %rdi
callq 0x172f0
xorl %r15d, %eax
movb $0x1, %r12b
testl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
jne 0x2f1ce6
movq 0x30(%rsp), %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x17830
testl %eax, %eax
jne 0x2f1ce6
movl -0x8(%r13), %ebx
xorl %r12d, %r12d
testb %r12b, %r12b
je 0x2f1d00
movq (%r13), %rbp
addq $0x10, %r13
testq %rbp, %rbp
jne 0x2f1cb6
jmp 0x2f1d00
xorl %eax, %eax
jmp 0x2f1d7c
xorl %ebx, %ebx
testl %ebx, %ebx
je 0x2f1d4a
movl %ebx, %eax
andl $0xffffff7f, %eax       # imm = 0xFFFFFF7F
cmpl 0x3c(%rsp), %eax
movl 0x38(%rsp), %ebp
movq 0x40(%rsp), %r12
movq 0x20(%rsp), %r13
jle 0x2f1d83
xorl %r14d, %r14d
leaq 0xf0f14(%rip), %rdi     # 0x3e2c3d
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x27e482
movq %rax, (%r12)
movl $0x3, %ebx
movl $0x7, %eax
jmp 0x2f1d97
xorl %r14d, %r14d
leaq 0xf0ed5(%rip), %rdi     # 0x3e2c29
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x27e482
movq 0x40(%rsp), %r12
movq %rax, (%r12)
movl $0x1, %ebx
movl $0x7, %eax
movl 0x38(%rsp), %ebp
movq 0x20(%rsp), %r13
jmp 0x2f1d97
movl 0xc(%rsp), %eax
notl %eax
andl %eax, %ebp
orl %ebx, %ebp
xorl %eax, %eax
movq 0x48(%rsp), %rbx
movb $0x1, %r14b
testb %r14b, %r14b
jne 0x2f1da3
jmp 0x2f1dbc
movq 0x30(%rsp), %r13
andl $0x3fffffff, %r15d      # imm = 0x3FFFFFFF
movq 0x30(%rsp), %rax
addq %r15, %rax
incq %rax
movq %rax, 0x28(%rsp)
xorl %eax, %eax
testl %eax, %eax
movq 0x28(%rsp), %r15
je 0x2f1b90
movq 0x10(%rsp), %r14
jmp 0x2f1dd7
movq 0x10(%rsp), %r14
xorl %eax, %eax
testl %eax, %eax
je 0x2f18a9
movl %eax, %ecx
movl $0x7, %eax
cmpl $0x7, %ecx
jne 0x2f1e0b
testl %ebx, %ebx
je 0x2f1dfa
movq %r14, %rdi
callq 0x28bda3
xorl %r14d, %r14d
movq 0x58(%rsp), %rax
movl %ebp, (%rax)
movq 0x60(%rsp), %rax
movq %r14, (%rax)
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq