// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: unixFullPathname
static int unixFullPathname(
  sqlite3_vfs *pVfs,            /* Pointer to vfs object */
  const char *zPath,            /* Possibly relative input path */
  int nOut,                     /* Size of output buffer in bytes */
  char *zOut                    /* Output buffer */
){
#if !defined(HAVE_READLINK) || !defined(HAVE_LSTAT)
  return mkFullPathname(zPath, zOut, nOut);
#else
  int rc = SQLITE_OK;
  int nByte;
  int nLink = 0;                /* Number of symbolic links followed so far */
  const char *zIn = zPath;      /* Input path for each iteration of loop */
  char *zDel = 0;

  assert( pVfs->mxPathname==MAX_PATHNAME );
  UNUSED_PARAMETER(pVfs);

  /* It's odd to simulate an io-error here, but really this is just
  ** using the io-error infrastructure to test that SQLite handles this
  ** function failing. This function could fail if, for example, the
  ** current working directory has been unlinked.
  */
  SimulateIOError( return SQLITE_ERROR );

  do {

    /* Call stat() on path zIn. Set bLink to true if the path is a symbolic
    ** link, or false otherwise.  */
    int bLink = 0;
    struct stat buf;
    if( osLstat(zIn, &buf)!=0 ){
      if( errno!=ENOENT ){
        rc = unixLogError(SQLITE_CANTOPEN_BKPT, "lstat", zIn);
      }
    }else{
      bLink = S_ISLNK(buf.st_mode);
    }

    if( bLink ){
      nLink++;
      if( zDel==0 ){
        zDel = sqlite3_malloc(nOut);
        if( zDel==0 ) rc = SQLITE_NOMEM_BKPT;
      }else if( nLink>=SQLITE_MAX_SYMLINKS ){
        rc = SQLITE_CANTOPEN_BKPT;
      }

      if( rc==SQLITE_OK ){
        nByte = osReadlink(zIn, zDel, nOut-1);
        if( nByte<0 ){
          rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zIn);
        }else{
          if( zDel[0]!='/' ){
            int n;
            for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--);
            if( nByte+n+1>nOut ){
              rc = SQLITE_CANTOPEN_BKPT;
            }else{
              memmove(&zDel[n], zDel, nByte+1);
              memcpy(zDel, zIn, n);
              nByte += n;
            }
          }
          zDel[nByte] = '\0';
        }
      }

      zIn = zDel;
    }

    assert( rc!=SQLITE_OK || zIn!=zOut || zIn[0]=='/' );
    if( rc==SQLITE_OK && zIn!=zOut ){
      rc = mkFullPathname(zIn, zOut, nOut);
    }
    if( bLink==0 ) break;
    zIn = zOut;
  }while( rc==SQLITE_OK );

  sqlite3_free(zDel);
  if( rc==SQLITE_OK && nLink ) rc = SQLITE_OK_SYMLINK;
  return rc;
#endif   /* HAVE_READLINK && HAVE_LSTAT */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rcx, %r12
movq %rsi, %rbx
leal -0x1(%rdx), %eax
cltq
movq %rax, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
leal -0x2(%rdx), %eax
cltq
movq %rax, 0x20(%rsp)
movq $0x0, 0x8(%rsp)
xorl %r15d, %r15d
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
callq *0x218c8e(%rip)         # 0x43ad10
testl %eax, %eax
je 0x222095
callq 0x17060
cmpl $0x2, (%rax)
je 0x2220cb
jmp 0x222230
movl 0x40(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0xa000, %eax           # imm = 0xA000
jne 0x2220cb
leal 0x1(%r15), %r14d
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x222157
cmpl $0x63, %r15d
jge 0x2222a5
movq %rax, %r15
jmp 0x22216d
movb $0x1, %bpl
cmpq %r12, %rbx
je 0x22222b
movl %r15d, %r14d
movq %rbx, %r15
movq %r15, %rdi
callq 0x2211ac
movl %eax, %ebx
xorl %eax, %eax
cmpb $0x2f, (%r15)
je 0x222117
movq %r12, %rdi
movq 0x20(%rsp), %rsi
callq *0x2189d3(%rip)         # 0x43aad0
testq %rax, %rax
je 0x22225b
movq %r12, %rdi
callq 0x2211ac
movl %eax, %ecx
incl %eax
movb $0x2f, (%r12,%rcx)
addl %eax, %ebx
movl %eax, %esi
movq 0x10(%rsp), %rcx
cmpl %ecx, %ebx
jge 0x222214
movl %ecx, %edi
subl %eax, %edi
addq %r12, %rsi
xorl %r13d, %r13d
leaq 0x146d70(%rip), %rdx    # 0x368ea9
movq %r15, %rcx
xorl %eax, %eax
callq 0x221418
testb %bpl, %bpl
jne 0x2222e4
movl %r14d, %r15d
movq %r12, %rbx
jmp 0x222074
movq 0x10(%rsp), %rdi
callq 0x21f6c0
movq %rax, %r15
testq %rax, %rax
je 0x2222d7
movq %rbx, %rdi
movq %r15, %rsi
movq 0x18(%rsp), %rdx
callq *0x218b7a(%rip)         # 0x43acf8
movq %rax, %rbp
testl %ebp, %ebp
js 0x222280
cmpb $0x2f, (%r15)
jne 0x222194
movl %ebp, %r13d
jmp 0x2221f1
movq %rbx, %rdi
callq 0x2211ac
movl %eax, %ecx
movq %rcx, %rax
movq 0x10(%rsp), %rdx
subq $0x1, %rax
jb 0x2221ba
cmpb $0x2f, -0x1(%rbx,%rcx)
movq %rax, %rcx
jne 0x2221a6
incl %eax
jmp 0x2221bc
xorl %eax, %eax
leal (%rax,%rbp), %r13d
cmpl %edx, %r13d
jge 0x2222b8
movl %eax, %eax
movq %rax, 0x8(%rsp)
leaq (%r15,%rax), %rdi
incl %ebp
movq %r15, %rsi
movq %rbp, %rdx
callq 0x17c50
movq %r15, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %rdx
callq 0x17630
movl %r13d, %eax
movb $0x0, (%r15,%rax)
cmpq %r12, %r15
je 0x22220a
xorl %ebp, %ebp
movq %r15, 0x8(%rsp)
jmp 0x2220dd
movq %r15, 0x8(%rsp)
jmp 0x22214c
movb $0x0, (%r12,%rsi)
movl $0x9bbf, %edi           # imm = 0x9BBF
callq 0x22e760
movl %eax, %r13d
jmp 0x2222e4
xorl %r13d, %r13d
jmp 0x222253
movl $0x9bef, %edi           # imm = 0x9BEF
callq 0x22e760
movl %eax, %r13d
leaq 0x153d40(%rip), %rsi    # 0x375f84
movl %eax, %edi
movq %rbx, %rdx
movl $0x9bef, %ecx           # imm = 0x9BEF
callq 0x22e701
movl %r15d, %r14d
jmp 0x2222e4
movl $0x9bb6, %edi           # imm = 0x9BB6
callq 0x22e760
movl %eax, %r13d
leaq 0x153c8f(%rip), %rsi    # 0x375efe
movl %eax, %edi
movq %r15, %rdx
movl $0x9bb6, %ecx           # imm = 0x9BB6
callq 0x22e701
jmp 0x2222e4
movl $0x9c01, %edi           # imm = 0x9C01
callq 0x22e760
movl %eax, %r13d
leaq 0x153ce7(%rip), %rsi    # 0x375f7b
movl %eax, %edi
movq %rbx, %rdx
movl $0x9c01, %ecx           # imm = 0x9C01
callq 0x22e701
jmp 0x2222d0
movl $0x9bfb, %edi           # imm = 0x9BFB
callq 0x22e760
movl %eax, %r13d
pushq $0x1
popq %r14
jmp 0x2222e4
movl $0x9c07, %edi           # imm = 0x9C07
callq 0x22e760
movl %eax, %r13d
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movb $0x0, (%r15,%rbp)
movq %r15, 0x8(%rsp)
jmp 0x2222e4
pushq $0x7
popq %r13
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rdi
callq 0x21f7f9
testl %r14d, %r14d
movl $0x200, %eax            # imm = 0x200
cmovel %r13d, %eax
testl %r13d, %r13d
cmovnel %r13d, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq