// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %r9, %r14
movq %r8, %r13
movl %ecx, -0x2c(%rbp)
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %rbx
xorl %eax, %eax
movq %rax, -0x38(%rbp)
movq %rax, (%r8)
callq 0x12bc6
testl %eax, %eax
je 0x1304d
testl %r12d, %r12d
js 0x13079
je 0x13076
xorl %eax, %eax
cmpb $0x0, (%r15,%rax)
jne 0x1303f
cmpb $0x0, 0x1(%r15,%rax)
je 0x13048
addq $0x2, %rax
cmpl %r12d, %eax
jl 0x13030
movl %eax, %r12d
jmp 0x13079
leaq 0x6a390(%rip), %rsi     # 0x7d3e4
leaq 0x664de(%rip), %rcx     # 0x79539
movl $0x15, %ebx
movl $0x15, %edi
movl $0x17881, %edx          # imm = 0x17881
xorl %eax, %eax
callq 0xb9c7
jmp 0x13123
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x1538e
movq %rax, %r12
testq %rax, %rax
je 0x13108
leaq -0x38(%rbp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl -0x2c(%rbp), %ecx
xorl %r8d, %r8d
movq %r13, %r9
callq 0x12ed6
movl %eax, %r13d
leaq -0x38(%rbp), %rax
movq (%rax), %rsi
testq %rsi, %rsi
sete %al
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0x1310b
subl %r12d, %esi
movq %r12, %rdi
callq 0x375df
movq %r15, %rcx
testl %eax, %eax
jle 0x130fa
movq %r15, %rcx
movb 0x1(%rcx), %dl
andb $-0x8, %dl
xorl %esi, %esi
cmpb $-0x28, %dl
sete %sil
leaq (%rcx,%rsi,2), %rcx
addq $0x2, %rcx
decl %eax
jne 0x130df
subl %r15d, %ecx
movslq %ecx, %rax
addq %r15, %rax
movq %rax, (%r14)
jmp 0x1310b
xorl %r13d, %r13d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x9ca4
movq %rbx, %rdi
movl %r13d, %esi
callq 0xeaff
movl %eax, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq