// File: /workspace/github_c_makefile_star2_O1/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 0xf024
movq %r8, %r13
movl %edx, %r14d
movq %rsi, %r12
movq (%rbx), %rax
testq %rax, %rax
je 0xf033
movl 0x68(%rax), %r8d
jmp 0xf039
movq %rbx, %rdi
callq 0xf2d0
xorl %eax, %eax
jmp 0xf23d
movl $0x3b9aca00, %r8d       # imm = 0x3B9ACA00
testb %cl, %cl
movl $0x10, %eax
movl $0x2, %r15d
cmovel %eax, %r15d
testl %r14d, %r14d
jns 0xf0a1
cmpb $0x1, %cl
jne 0xf070
testl %r8d, %r8d
js 0xf08e
leal 0x1(%r8), %r14d
xorl %eax, %eax
cmpb $0x0, (%r12,%rax)
je 0xf093
incq %rax
cmpq %rax, %r14
jne 0xf05f
jmp 0xf096
testl %r8d, %r8d
js 0xf08e
xorl %r14d, %r14d
movb 0x1(%r12,%r14), %al
orb (%r12,%r14), %al
je 0xf096
addq $0x2, %r14
cmpl %r14d, %r8d
jge 0xf078
jmp 0xf096
xorl %r14d, %r14d
jmp 0xf096
movl %eax, %r14d
movzwl %r15w, %r15d
orl $0x200, %r15d           # imm = 0x200
cmpq $-0x1, %r13
je 0xf0e6
movl %ecx, -0x2c(%rbp)
movq %r8, -0x38(%rbp)
movq %rbx, %rdi
callq 0xec23
movq %r12, 0x8(%rbx)
leaq -0x57ed(%rip), %rax     # 0x98d4
cmpq %rax, %r13
je 0xf10a
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 0xf116
xorl %r13d, %r13d
cmpb $0x1, %cl
setne %r13b
incl %r13d
xorl %edx, %edx
btl $0x9, %r15d
cmovael %edx, %r13d
cmpl %r8d, %r14d
jle 0xf11f
movl $0x12, %eax
jmp 0xf162
movq %r12, 0x30(%rbx)
movq $0x0, 0x28(%rbx)
movq -0x38(%rbp), %r8
movl -0x2c(%rbp), %ecx
jmp 0xf16a
movl %ecx, -0x2c(%rbp)
movq %r8, -0x38(%rbp)
addl %r14d, %r13d
movq %rbx, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x1025e
testl %eax, %eax
je 0xf14a
movl $0x7, %eax
movq -0x38(%rbp), %r8
movl -0x2c(%rbp), %ecx
xorl %edx, %edx
jmp 0xf162
movq 0x8(%rbx), %rdi
movslq %r13d, %rdx
movq %r12, %rsi
callq 0x82f0
movb $0x1, %dl
movq -0x38(%rbp), %r8
movl -0x2c(%rbp), %ecx
testb %dl, %dl
je 0xf23d
movl %r14d, 0x20(%rbx)
movw %r15w, 0x24(%rbx)
movzbl %cl, %eax
xorl %r15d, %r15d
cmpb $0x1, %cl
movl $0x0, %esi
adcb $0x3, %sil
movl $0x1, %edx
cmpb $0x2, %cl
cmovael %eax, %edx
movb %dl, 0x27(%rbx)
movb %sil, 0x26(%rbx)
jb 0xf22e
cmpl $0x2, %r14d
jl 0xf1d4
movq 0x8(%rbx), %rax
movb (%rax), %cl
movb 0x1(%rax), %al
movl %ecx, %edx
xorb $-0x2, %dl
movl %eax, %esi
notb %sil
xorl %edi, %edi
orb %dl, %sil
sete %dil
leal (%rdi,%rdi,2), %edx
notb %cl
xorb $-0x2, %al
orb %cl, %al
movl $0x2, %r12d
cmovnel %edx, %r12d
jmp 0xf1d7
xorl %r12d, %r12d
testb %r12b, %r12b
je 0xf22e
movq %rbx, %rdi
movq %r8, %r13
callq 0x253d5
movl %eax, %ecx
movl $0x7, %eax
testl %ecx, %ecx
jne 0xf23d
movslq 0x20(%rbx), %rdx
addq $-0x2, %rdx
movl %edx, 0x20(%rbx)
movq 0x8(%rbx), %rdi
leaq 0x2(%rdi), %rsi
callq 0x8650
movq %r13, %r8
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 %r8d, %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