// File: /workspace/github_c_makefile_star2_O1/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, -0x38(%rbp)
movq %r8, %r13
movl %ecx, %r14d
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %rbx
xorl %eax, %eax
movq %rax, -0x30(%rbp)
movq %rax, (%r8)
callq 0x12b2e
testl %eax, %eax
je 0x12f56
testl %r12d, %r12d
js 0x12f82
je 0x12f7f
xorl %eax, %eax
cmpb $0x0, (%r15,%rax)
jne 0x12f48
cmpb $0x0, 0x1(%r15,%rax)
je 0x12f51
addq $0x2, %rax
cmpl %r12d, %eax
jl 0x12f39
movl %eax, %r12d
jmp 0x12f82
leaq 0x6a487(%rip), %rsi     # 0x7d3e4
leaq 0x665d5(%rip), %rcx     # 0x79539
movl $0x15, %ebx
movl $0x15, %edi
movl $0x17881, %edx          # imm = 0x17881
xorl %eax, %eax
callq 0xb8cc
jmp 0x1302e
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x1538d
movq %rax, %r12
testq %rax, %rax
je 0x12fbe
leaq -0x30(%rbp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %r14d, %ecx
xorl %r8d, %r8d
movq %r13, %r9
callq 0x12dde
movl %eax, %r14d
jmp 0x12fc1
xorl %r14d, %r14d
movq -0x30(%rbp), %rsi
testq %rsi, %rsi
sete %al
movq -0x38(%rbp), %r13
testq %r13, %r13
sete %cl
orb %al, %cl
jne 0x13016
subl %r12d, %esi
movq %r12, %rdi
callq 0x36ef7
movq %r15, %rcx
testl %eax, %eax
jle 0x13009
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 0x12fee
subl %r15d, %ecx
movslq %ecx, %rax
addq %r15, %rax
movq %rax, (%r13)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x9c3a
movq %rbx, %rdi
movl %r14d, %esi
callq 0xea22
movl %eax, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq