// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3VdbeMemSetStr
SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
  Mem *pMem,          /* Memory cell to set to string value */
  const char *z,      /* String pointer */
  int n,              /* Bytes in string, or negative */
  u8 enc,             /* Encoding of z.  0 for BLOBs */
  void (*xDel)(void*) /* Destructor function */
){
  int nByte = n;      /* New value for pMem->n */
  int iLimit;         /* Maximum allowed string or blob size */
  u16 flags = 0;      /* New value for pMem->flags */

  assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
  assert( (pMem->flags & MEM_RowSet)==0 );

  /* If z is a NULL pointer, set pMem to contain an SQL NULL. */
  if( !z ){
    sqlite3VdbeMemSetNull(pMem);
    return SQLITE_OK;
  }

  if( pMem->db ){
    iLimit = pMem->db->aLimit[SQLITE_LIMIT_LENGTH];
  }else{
    iLimit = SQLITE_MAX_LENGTH;
  }
  flags = (enc==0?MEM_Blob:MEM_Str);
  if( nByte<0 ){
    assert( enc!=0 );
    if( enc==SQLITE_UTF8 ){
      for(nByte=0; nByte<=iLimit && z[nByte]; nByte++){}
    }else{
      for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
    }
    flags |= MEM_Term;
  }

  /* The following block sets the new values of Mem.z and Mem.xDel. It
  ** also sets a flag in local variable "flags" to indicate the memory
  ** management (one of MEM_Dyn or MEM_Static).
  */
  if( xDel==SQLITE_TRANSIENT ){
    int nAlloc = nByte;
    if( flags&MEM_Term ){
      nAlloc += (enc==SQLITE_UTF8?1:2);
    }
    if( nByte>iLimit ){
      return SQLITE_TOOBIG;
    }
    if( sqlite3VdbeMemGrow(pMem, nAlloc, 0) ){
      return SQLITE_NOMEM;
    }
    memcpy(pMem->z, z, nAlloc);
  }else if( xDel==SQLITE_DYNAMIC ){
    sqlite3VdbeMemRelease(pMem);
    pMem->zMalloc = pMem->z = (char *)z;
    pMem->xDel = 0;
  }else{
    sqlite3VdbeMemRelease(pMem);
    pMem->z = (char *)z;
    pMem->xDel = xDel;
    flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
  }

  pMem->n = nByte;
  pMem->flags = flags;
  pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
  pMem->type = (enc==0 ? SQLITE_BLOB : SQLITE_TEXT);

#ifndef SQLITE_OMIT_UTF16
  if( pMem->enc!=SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
    return SQLITE_NOMEM;
  }
#endif

  if( nByte>iLimit ){
    return SQLITE_TOOBIG;
  }

  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
testq %rsi, %rsi
je 0xf106
movq %r8, %r13
movl %edx, %r14d
movq %rsi, %r12
movq (%rbx), %rax
testq %rax, %rax
je 0xf115
movl 0x68(%rax), %edx
jmp 0xf11a
movq %rbx, %rdi
callq 0xf373
xorl %eax, %eax
jmp 0xf2e0
movl $0x3b9aca00, %edx       # imm = 0x3B9ACA00
testb %cl, %cl
movl $0x10, %eax
movl $0x2, %r15d
cmovel %eax, %r15d
testl %r14d, %r14d
jns 0xf180
cmpb $0x1, %cl
jne 0xf150
testl %edx, %edx
js 0xf16d
leal 0x1(%rdx), %r14d
xorl %eax, %eax
cmpb $0x0, (%r12,%rax)
je 0xf172
incq %rax
cmpq %rax, %r14
jne 0xf13f
jmp 0xf175
testl %edx, %edx
js 0xf16d
xorl %r14d, %r14d
movb 0x1(%r12,%r14), %al
orb (%r12,%r14), %al
je 0xf175
addq $0x2, %r14
cmpl %r14d, %edx
jge 0xf157
jmp 0xf175
xorl %r14d, %r14d
jmp 0xf175
movl %eax, %r14d
movzwl %r15w, %r15d
orl $0x200, %r15d           # imm = 0x200
cmpq $-0x1, %r13
movq %rdx, -0x38(%rbp)
movl %ecx, -0x2c(%rbp)
je 0xf1c5
movq %rbx, %rdi
callq 0xecfd
movq %r12, 0x8(%rbx)
leaq -0x5890(%rip), %rax     # 0x9910
cmpq %rax, %r13
je 0xf219
movq %r13, 0x28(%rbx)
xorl %eax, %eax
testq %r13, %r13
sete %al
shll $0xa, %eax
movzwl %r15w, %ecx
leal (%rax,%rcx), %r15d
addl $0x400, %r15d           # imm = 0x400
jmp 0xf225
xorl %eax, %eax
cmpb $0x1, %cl
setne %al
incl %eax
xorl %r13d, %r13d
btl $0x9, %r15d
cmovbl %eax, %r13d
movl $0x12, %eax
cmpl %edx, %r14d
jg 0xf2e0
addl %r14d, %r13d
movq %rbx, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x1034d
movl %eax, %ecx
movl $0x7, %eax
testl %ecx, %ecx
jne 0xf2e0
movq 0x8(%rbx), %rdi
movslq %r13d, %rdx
movq %r12, %rsi
callq 0x82f0
jmp 0xf225
movq %r12, 0x30(%rbx)
movq $0x0, 0x28(%rbx)
movl -0x2c(%rbp), %esi
movl %r14d, 0x20(%rbx)
movw %r15w, 0x24(%rbx)
movzbl %sil, %eax
xorl %r15d, %r15d
cmpb $0x1, %sil
movl $0x0, %ecx
adcb $0x3, %cl
movl $0x1, %edx
cmpb $0x2, %sil
cmovael %eax, %edx
movb %dl, 0x27(%rbx)
movb %cl, 0x26(%rbx)
jb 0xf2d0
cmpl $0x2, %r14d
jl 0xf2d0
movq 0x8(%rbx), %rcx
movb (%rcx), %al
movb 0x1(%rcx), %cl
movl %eax, %edx
notb %dl
movl %ecx, %esi
xorb $-0x2, %sil
movb $0x2, %r12b
orb %dl, %sil
je 0xf284
xorb $-0x2, %al
notb %cl
movb $0x3, %r12b
orb %al, %cl
jne 0xf2d0
movq %rbx, %rdi
callq 0x24eb1
movl %eax, %ecx
movl $0x7, %eax
testl %ecx, %ecx
jne 0xf2e0
movslq 0x20(%rbx), %rdx
addq $-0x2, %rdx
movl %edx, 0x20(%rbx)
movq 0x8(%rbx), %rdi
leaq 0x2(%rdi), %rsi
callq 0x8650
movq 0x8(%rbx), %rax
movslq 0x20(%rbx), %rcx
xorl %edx, %edx
movb %dl, (%rax,%rcx)
movq 0x8(%rbx), %rax
movslq 0x20(%rbx), %rcx
movb %dl, 0x1(%rax,%rcx)
orb $0x2, 0x25(%rbx)
movb %r12b, 0x27(%rbx)
cmpl -0x38(%rbp), %r14d
movl $0x12, %eax
cmovgl %eax, %r15d
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq