// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movq %rdi, %rbx
testq %rsi, %rsi
je 0xe1ff
movq %r8, %r13
movl %edx, %r14d
movq %rsi, %r12
movq (%rbx), %rax
testq %rax, %rax
je 0xe20e
movl 0x68(%rax), %edx
jmp 0xe213
movq %rbx, %rdi
callq 0xe43c
xorl %eax, %eax
jmp 0xe3ba
movl $0x3b9aca00, %edx       # imm = 0x3B9ACA00
testb %cl, %cl
pushq $0x10
popq %rax
pushq $0x2
popq %r15
cmovel %eax, %r15d
testl %r14d, %r14d
jns 0xe262
movslq %edx, %rax
xorl %r14d, %r14d
cmpb $0x1, %cl
jne 0xe241
cmpq %rax, %r14
jg 0xe257
cmpb $0x0, (%r12,%r14)
je 0xe257
incq %r14
jmp 0xe230
cmpq %rax, %r14
jg 0xe257
movb 0x1(%r12,%r14), %sil
orb (%r12,%r14), %sil
je 0xe257
addq $0x2, %r14
jmp 0xe241
movzwl %r15w, %r15d
orl $0x200, %r15d           # imm = 0x200
pushq $0x12
popq %rsi
cmpq $-0x1, %r13
je 0xe2a9
movl %ecx, -0x2c(%rbp)
movl %edx, -0x30(%rbp)
movq %rbx, %rdi
callq 0xde44
movq %r12, 0x8(%rbx)
leaq -0x4f0d(%rip), %rax     # 0x9377
cmpq %rax, %r13
je 0xe2cb
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 0xe307
xorl %eax, %eax
cmpb $0x1, %cl
setne %al
incl %eax
xorl %r13d, %r13d
btl $0x9, %r15d
cmovbl %eax, %r13d
cmpl %edx, %r14d
jle 0xe2d6
movl %esi, %eax
jmp 0xe3ba
movq %r12, 0x30(%rbx)
andq $0x0, 0x28(%rbx)
jmp 0xe307
movl %ecx, -0x2c(%rbp)
movl %edx, -0x30(%rbp)
addl %r14d, %r13d
movq %rbx, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0xf2c6
testl %eax, %eax
je 0xe2f8
pushq $0x7
popq %rax
jmp 0xe3ba
movq 0x8(%rbx), %rdi
movslq %r13d, %rdx
movq %r12, %rsi
callq 0x82c0
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
pushq $0x1
popq %rdx
cmpb $0x2, %sil
cmovael %eax, %edx
movb %dl, 0x27(%rbx)
movb %cl, 0x26(%rbx)
jb 0xe3ac
cmpl $0x2, %r14d
jl 0xe3ac
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 0xe364
xorb $-0x2, %al
notb %cl
movb $0x3, %r12b
orb %al, %cl
jne 0xe3ac
movq %rbx, %rdi
callq 0x2199f
testl %eax, %eax
pushq $0x7
popq %rax
jne 0xe3ba
movslq 0x20(%rbx), %rdx
addq $-0x2, %rdx
movl %edx, 0x20(%rbx)
movq 0x8(%rbx), %rdi
leaq 0x2(%rdi), %rsi
callq 0x8630
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 -0x30(%rbp), %r14d
pushq $0x12
popq %rax
cmovgl %eax, %r15d
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq