// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3Prepare16
static int sqlite3Prepare16(
  sqlite3 *db,              /* Database handle. */ 
  const void *zSql,         /* UTF-16 encoded SQL statement. */
  int nBytes,               /* Length of zSql in bytes. */
  int saveSqlFlag,          /* True to save SQL text into the sqlite3_stmt */
  sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
  const void **pzTail       /* OUT: End of parsed string */
){
  /* This function currently works by first transforming the UTF-16
  ** encoded string to UTF-8, then invoking sqlite3_prepare(). The
  ** tricky bit is figuring out the pointer to return in *pzTail.
  */
  char *zSql8;
  const char *zTail8 = 0;
  int rc = SQLITE_OK;

  assert( ppStmt );
  *ppStmt = 0;
  if( !sqlite3SafetyCheckOk(db) ){
    return SQLITE_MISUSE_BKPT;
  }
  if( nBytes>=0 ){
    int sz;
    const char *z = (const char*)zSql;
    for(sz=0; sz<nBytes && (z[sz]!=0 || z[sz+1]!=0); sz += 2){}
    nBytes = sz;
  }
  sqlite3_mutex_enter(db->mutex);
  zSql8 = sqlite3Utf16to8(db, zSql, nBytes, SQLITE_UTF16NATIVE);
  if( zSql8 ){
    rc = sqlite3LockAndPrepare(db, zSql8, -1, saveSqlFlag, 0, ppStmt, &zTail8);
  }

  if( zTail8 && pzTail ){
    /* If sqlite3_prepare returns a tail pointer, we calculate the
    ** equivalent pointer into the UTF-16 string by counting the unicode
    ** characters between zSql8 and zTail8, and then returning a pointer
    ** the same number of characters into the UTF-16 string.
    */
    int chars_parsed = sqlite3Utf8CharLen(zSql8, (int)(zTail8-zSql8));
    *pzTail = (u8 *)zSql + sqlite3Utf16ByteLen(zSql, chars_parsed);
  }
  sqlite3DbFree(db, zSql8); 
  rc = sqlite3ApiExit(db, rc);
  sqlite3_mutex_leave(db->mutex);
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r14
movq %r8, %r13
movl %ecx, -0x2c(%rbp)
movl %edx, %r12d
movq %rsi, %r15
andq $0x0, -0x38(%rbp)
movq %rdi, %rbx
andq $0x0, (%r8)
callq 0x116ef
testl %eax, %eax
je 0x11aa6
testl %r12d, %r12d
js 0x11a14
movl %r12d, %eax
xorl %r12d, %r12d
cmpq %rax, %r12
jae 0x11a14
cmpb $0x0, (%r15,%r12)
jne 0x11a0e
cmpb $0x0, 0x1(%r15,%r12)
je 0x11a14
addq $0x2, %r12
jmp 0x119fa
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x1396d
testq %rax, %rax
je 0x11ab5
leaq -0x38(%rbp), %rcx
movq %rcx, (%rsp)
movq %r14, %r12
xorl %r14d, %r14d
pushq $-0x1
popq %rdx
movq %rbx, %rdi
movq %r13, %r9
movq %rax, %r13
movq %rax, %rsi
movl -0x2c(%rbp), %ecx
xorl %r8d, %r8d
callq 0x118f7
movl %eax, -0x2c(%rbp)
leaq -0x38(%rbp), %rax
movq (%rax), %rsi
testq %rsi, %rsi
sete %al
movq %r12, -0x40(%rbp)
testq %r12, %r12
sete %cl
orb %al, %cl
jne 0x11aba
subl %r13d, %esi
movq %r13, %r12
movq %r13, %rdi
callq 0x31e38
testl %eax, %eax
cmovgl %eax, %r14d
movq %r15, %rax
subl $0x1, %r14d
jb 0x11abf
movb 0x1(%rax), %cl
andb $-0x8, %cl
xorl %edx, %edx
cmpb $-0x28, %cl
sete %dl
leaq (%rax,%rdx,2), %rax
addq $0x2, %rax
jmp 0x11a88
movl $0x17881, %edi          # imm = 0x17881
callq 0x9008
pushq $0x15
popq %rax
jmp 0x11aeb
xorl %r14d, %r14d
jmp 0x11ad5
movq %r13, %rax
jmp 0x11ad1
subl %r15d, %eax
cltq
addq %r15, %rax
movq -0x40(%rbp), %rcx
movq %rax, (%rcx)
movq %r12, %rax
movl -0x2c(%rbp), %r14d
movq %rbx, %rdi
movq %rax, %rsi
callq 0x968b
movq %rbx, %rdi
movl %r14d, %esi
callq 0xdc59
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq