// File: /workspace/github_c_makefile_star2_O2/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, 0x40(%rsp)
movq %r8, %r14
movq %rcx, 0x38(%rsp)
movq %rsi, %r15
movq %rdi, 0x28(%rsp)
movq %rdx, 0x10(%rsp)
movl (%rdx), %ebx
movq %rsi, %rdi
callq 0x2211ac
movl %eax, %r13d
movl %ebx, 0xc(%rsp)
movl %ebx, %eax
shrb $0x6, %al
cmpb $0x0, 0x1b6606(%rip)    # 0x43a616
setne %cl
orb %al, %cl
cmpl $0x5, %r13d
setae %al
andb %cl, %al
movl %r13d, %ebp
pushq $0x7
popq %r12
cmpb $0x1, %al
jne 0x284043
leaq 0xf5888(%rip), %rsi     # 0x3798b8
pushq $0x5
popq %rdx
movq %r15, %rdi
callq 0x177e0
testl %eax, %eax
je 0x2840e1
leal 0x8(%r13), %edi
callq 0x21f7df
testq %rax, %rax
je 0x2840cf
movq %rax, %rbx
andl $0x0, (%rax)
addq $0x4, %rbx
testl %r13d, %r13d
je 0x284070
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x17630
jmp 0x284072
xorl %ebp, %ebp
movq 0x10(%rsp), %r15
movq 0x28(%rsp), %r12
movq 0x38(%rsp), %r13
andl $0x0, (%rbx,%rbp)
andl $-0x41, 0xc(%rsp)
movq %r12, %rdi
callq 0x21f275
movq %rax, (%r13)
movq %r12, %rsi
xorl %r12d, %r12d
testq %rax, %rax
jne 0x2840c5
leaq 0xf5878(%rip), %rdi     # 0x379920
xorl %eax, %eax
callq 0x22132b
pushq $0x1
popq %r12
movq 0x40(%rsp), %rcx
movq %rax, (%rcx)
movq %rbx, %rdi
callq 0x22cc7d
xorl %ebx, %ebx
movl 0xc(%rsp), %eax
movl %eax, (%r15)
movq %rbx, (%r14)
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addl $0x8, %r13d
xorl %eax, %eax
cmpq %rax, %rbp
je 0x2840fe
xorl %ecx, %ecx
cmpb $0x26, (%r15,%rax)
sete %cl
addq %rcx, %r13
incq %rax
jmp 0x2840e7
movq %r13, %rdi
callq 0x21f7df
testq %rax, %rax
je 0x2840cf
movq %rax, %rbx
orl $0x40, 0xc(%rsp)
andl $0x0, (%rax)
addq $0x4, %rbx
pushq $0x5
popq %r10
cmpb $0x2f, 0x5(%r15)
jne 0x284193
cmpb $0x2f, 0x6(%r15)
jne 0x284193
xorl %r12d, %r12d
movzbl 0x7(%r15,%r12), %eax
testl %eax, %eax
je 0x284143
cmpl $0x2f, %eax
je 0x284143
incq %r12
jmp 0x28412f
leaq 0x7(%r12), %r10
cmpl $0x10, %r10d
je 0x284156
cmpl $0x7, %r10d
je 0x284193
jmp 0x28416d
leaq 0x7(%r15), %rsi
leaq 0xf575d(%rip), %rdi     # 0x3798be
pushq $0x9
popq %rdx
callq 0x177e0
testl %eax, %eax
je 0x28418f
addq $0x7, %r15
leaq 0xf5750(%rip), %rdi     # 0x3798c8
movl %r12d, %esi
movq %r15, %rdx
xorl %eax, %eax
callq 0x22132b
movq 0x10(%rsp), %r15
jmp 0x2840af
pushq $0x10
popq %r10
xorl %r8d, %r8d
leaq 0xed6b3(%rip), %rax     # 0x371850
pushq $0x1
popq %rcx
pushq $0x2
popq %rsi
xorl %edi, %edi
movq %r14, 0x20(%rsp)
movslq %edi, %rdx
movl %r10d, %r9d
movslq %r9d, %r14
movzbl (%r15,%r14), %r11d
testl %r11d, %r11d
je 0x284322
cmpl $0x23, %r11d
je 0x284322
leal 0x1(%r9), %r10d
movslq %r10d, %r12
cmpb $0x25, %r11b
jne 0x284294
movzbl (%r15,%r12), %r13d
testb $0x8, (%r13,%rax)
je 0x284294
movzbl 0x2(%r15,%r14), %r14d
testb $0x8, (%r14,%rax)
je 0x284294
leal (,%r13,2), %r10d
sarb $0x7, %r10b
andb $0x9, %r10b
addb %r13b, %r10b
shlb $0x4, %r10b
addl $0x3, %r9d
leal (%r14,%r14), %r11d
sarb $0x7, %r11b
andb $0x9, %r11b
addb %r14b, %r11b
andb $0xf, %r11b
orb %r10b, %r11b
jne 0x2842db
movslq %r9d, %r10
addq %r15, %r10
movzbl (%r10), %r11d
testl %r11d, %r11d
je 0x2841b0
cmpl $0x23, %r11d
je 0x2841b0
testl %r8d, %r8d
jne 0x284261
cmpb $0x3f, %r11b
je 0x2841b0
cmpl $0x1, %r8d
jne 0x28427c
cmpl $0x26, %r11d
je 0x2841b0
cmpl $0x3d, %r11d
jne 0x28428c
jmp 0x2841b0
cmpl $0x2, %r8d
jne 0x28428c
cmpb $0x26, %r11b
je 0x2841b0
incl %r9d
incq %r10
jmp 0x28423b
cmpl $0x1, %r8d
jne 0x2842e9
cmpl $0x3d, %r11d
je 0x2842a6
cmpl $0x26, %r11d
jne 0x284315
cmpb $0x0, -0x1(%rbx,%rdx)
jne 0x284302
incl %r9d
addq %r15, %r12
movzbl (%r12), %r8d
testl %r8d, %r8d
je 0x2842d3
cmpl $0x23, %r8d
je 0x2842d3
cmpb $0x26, -0x1(%r12)
je 0x2842d3
incl %r9d
incq %r12
jmp 0x2842b3
movl %ecx, %r8d
jmp 0x2841b0
movl %r9d, %r10d
incl %edi
movb %r11b, (%rbx,%rdx)
jmp 0x2841aa
testl %r8d, %r8d
jne 0x2842f4
cmpb $0x3f, %r11b
je 0x284312
cmpl $0x2, %r8d
jne 0x2842de
cmpb $0x26, %r11b
je 0x284312
jmp 0x2842de
cmpb $0x26, %r11b
jne 0x28431a
leal 0x1(%rdx), %edi
movb $0x0, (%rbx,%rdx)
movslq %edi, %rdx
xorl %r11d, %r11d
movl %ecx, %r8d
jmp 0x2842de
xorl %r11d, %r11d
movl %esi, %r8d
jmp 0x2842de
cmpl $0x1, %r8d
movq 0x20(%rsp), %r14
jne 0x284337
leal 0x1(%rdx), %eax
movb $0x0, (%rbx,%rdx)
movslq %eax, %rdx
andl $0x0, (%rbx,%rdx)
movq %rbx, %rdi
callq 0x2211ac
movl %eax, %r15d
movq %rbx, %r12
movl %r15d, %eax
cmpb $0x0, 0x1(%r12,%rax)
je 0x284477
leaq (%r12,%rax), %r13
incq %r13
movq %r13, %rdi
callq 0x2211ac
movl %eax, %ebp
movl %eax, %eax
leaq (%rax,%r13), %r12
incq %r12
movq %r12, %rdi
callq 0x2211ac
movl %eax, %r15d
cmpl $0x5, %ebp
je 0x2843d8
cmpl $0x4, %ebp
je 0x2843a9
cmpl $0x3, %ebp
jne 0x284349
leaq 0xf5551(%rip), %rdi     # 0x3798e4
movq %r13, %rsi
pushq $0x3
popq %rdx
callq 0x177e0
testl %eax, %eax
jne 0x284349
movq %r12, 0x28(%rsp)
jmp 0x284349
cmpl $0x65646f6d, (%r13)     # imm = 0x65646F6D
jne 0x284349
movl 0xc(%rsp), %eax
andl $0x87, %eax
movl %eax, 0x1c(%rsp)
movl $0xffffff78, 0x18(%rsp) # imm = 0xFFFFFF78
leaq 0x1b2ae1(%rip), %r14    # 0x436eb0
leaq 0x83af3(%rip), %rax     # 0x307ec9
jmp 0x284410
leaq 0x6ed33(%rip), %rdi     # 0x2f3112
movq %r13, %rsi
pushq $0x5
popq %rdx
callq 0x177e0
testl %eax, %eax
jne 0x284349
movl $0x60000, 0x1c(%rsp)    # imm = 0x60000
movl $0xfff9ffff, 0x18(%rsp) # imm = 0xFFF9FFFF
leaq 0x1b2a77(%rip), %r14    # 0x436e80
leaq 0x6ed02(%rip), %rax     # 0x2f3112
movq %rax, 0x30(%rsp)
movl %r15d, %ebp
addq $0x8, %r14
movq -0x8(%r14), %r13
testq %r13, %r13
je 0x28448b
movq %r13, %rdi
callq 0x2211ac
cmpl %eax, %r15d
jne 0x284444
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x177e0
testl %eax, %eax
je 0x28444a
addq $0x10, %r14
jmp 0x28441c
movl (%r14), %eax
testl %eax, %eax
je 0x28448b
movl %eax, %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
cmpl 0x1c(%rsp), %ecx
jg 0x2844b4
movl 0x18(%rsp), %ecx
andl 0xc(%rsp), %ecx
orl %ecx, %eax
movl %eax, 0xc(%rsp)
movq 0x20(%rsp), %r14
jmp 0x284349
movq 0x10(%rsp), %r15
movq 0x28(%rsp), %r12
movq 0x38(%rsp), %r13
jmp 0x28408a
leaq 0xf5462(%rip), %rdi     # 0x3798f4
movq 0x30(%rsp), %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x22132b
pushq $0x1
popq %r12
movq 0x20(%rsp), %r14
movq 0x10(%rsp), %r15
jmp 0x2840b3
leaq 0xf544d(%rip), %rdi     # 0x379908
movq 0x30(%rsp), %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x22132b
pushq $0x3
jmp 0x2844a3