// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/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( !sqlite3VdbeMemIsRowSet(pMem) );

  /* 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 ){
      nByte = 0x7fffffff & (int)strlen(z);
    }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 ){
    u32 nAlloc = nByte;
    if( flags&MEM_Term ){
      nAlloc += (enc==SQLITE_UTF8?1:2);
    }
    if( nByte>iLimit ){
      return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
    }
    testcase( nAlloc==0 );
    testcase( nAlloc==31 );
    testcase( nAlloc==32 );
    if( sqlite3VdbeMemClearAndResize(pMem, (int)MAX(nAlloc,32)) ){
      return SQLITE_NOMEM_BKPT;
    }
    memcpy(pMem->z, z, nAlloc);
  }else{
    sqlite3VdbeMemRelease(pMem);
    pMem->z = (char *)z;
    if( xDel==SQLITE_DYNAMIC ){
      pMem->zMalloc = pMem->z;
      pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
    }else{
      pMem->xDel = xDel;
      flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
    }
  }

  pMem->n = nByte;
  pMem->flags = flags;
  if( enc ){
    pMem->enc = enc;
#ifdef SQLITE_ENABLE_SESSION
  }else if( pMem->db==0 ){
    pMem->enc = SQLITE_UTF8;
#endif
  }else{
    assert( pMem->db!=0 );
    pMem->enc = ENC(pMem->db);
  }

#ifndef SQLITE_OMIT_UTF16
  if( enc>SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
    return SQLITE_NOMEM_BKPT;
  }
#endif

  if( nByte>iLimit ){
    return SQLITE_TOOBIG;
  }

  return SQLITE_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
testq %rsi, %rsi
je 0x281f51
movq %r8, %r12
movl %edx, %r14d
movq %rsi, %r15
movq 0x28(%rbx), %rbp
testq %rbp, %rbp
je 0x281f61
movl 0x7c(%rbp), %edx
jmp 0x281f66
testb $0x24, 0x9(%rbx)
je 0x281fa3
movq %rbx, %rdi
callq 0x29b491
jmp 0x281fa9
movl $0x3b9aca00, %edx       # imm = 0x3B9ACA00
testb %cl, %cl
movl $0x10, %eax
movl $0x2, %r13d
cmovel %eax, %r13d
testl %r14d, %r14d
movl %edx, 0x4(%rsp)
jns 0x281fd6
cmpb $0x1, %cl
jne 0x281fb0
movq %r15, %rdi
movl %ecx, %r14d
callq 0x172f0
movl %r14d, %ecx
movl 0x4(%rsp), %edx
movq %rax, %r14
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
jmp 0x281fcb
movw $0x1, 0x8(%rbx)
xorl %eax, %eax
jmp 0x2821bf
xorl %r14d, %r14d
testl %edx, %edx
js 0x281fcb
movb 0x1(%r15,%r14), %al
orb (%r15,%r14), %al
je 0x281fcb
addq $0x2, %r14
cmpl %r14d, %edx
jge 0x281fb7
movzwl %r13w, %r13d
orl $0x200, %r13d           # imm = 0x200
cmpq $-0x1, %r12
je 0x282027
testb $0x24, 0x9(%rbx)
jne 0x281fe8
cmpl $0x0, 0x20(%rbx)
je 0x281ff4
movq %rbx, %rdi
movl %ecx, %ebp
callq 0x29b45b
movl %ebp, %ecx
movq %r15, 0x10(%rbx)
leaq 0x4bc(%rip), %rax       # 0x2824bb
cmpq %rax, %r12
je 0x282069
movq %r12, 0x30(%rbx)
xorl %eax, %eax
testq %r12, %r12
sete %al
shll $0xa, %eax
movzwl %r13w, %edx
leal (%rax,%rdx), %r13d
addl $0x400, %r13d           # imm = 0x400
jmp 0x282106
xorl %eax, %eax
cmpb $0x1, %cl
setne %al
incl %eax
xorl %r12d, %r12d
btl $0x9, %r13d
cmovbl %eax, %r12d
cmpl %edx, %r14d
jle 0x2820ac
movl $0x12, %eax
testq %rbp, %rbp
je 0x282062
movq 0x130(%rbp), %rdx
testq %rdx, %rdx
je 0x282062
movl $0x12, 0x18(%rdx)
incl 0x30(%rdx)
xorl %ebp, %ebp
jmp 0x2820fd
movq %r15, 0x18(%rbx)
movq 0x28(%rbx), %rdx
testq %rdx, %rdx
je 0x28209a
cmpq %r15, 0x1c0(%rdx)
jbe 0x28209a
movl $0x80, %eax
cmpq %r15, 0x1b0(%rdx)
jbe 0x2820a7
cmpq %r15, 0x1b8(%rdx)
jbe 0x2821ce
movq %r15, %rdi
movl %ecx, %ebp
callq *0x2445f3(%rip)         # 0x4c6698
movl %ebp, %ecx
movl %eax, 0x20(%rbx)
jmp 0x282106
movl %ecx, (%rsp)
addl %r14d, %r12d
cmpl $0x21, %r12d
movl $0x20, %esi
cmovael %r12d, %esi
cmpl %esi, 0x20(%rbx)
jge 0x2820db
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %edx, %edx
callq 0x29b54f
testl %eax, %eax
je 0x2820e8
movl $0x7, %eax
jmp 0x2820fa
movq 0x18(%rbx), %rax
movq %rax, 0x10(%rbx)
andw $0x2d, 0x8(%rbx)
movq 0x10(%rbx), %rdi
movl %r12d, %edx
movq %r15, %rsi
callq 0x17660
movb $0x1, %bpl
movl (%rsp), %ecx
testb %bpl, %bpl
je 0x2821bf
movl %r14d, 0xc(%rbx)
movw %r13w, 0x8(%rbx)
movl %ecx, %eax
testb %cl, %cl
jne 0x28211c
movq 0x28(%rbx), %rax
movb 0x5e(%rax), %al
movb %al, 0xa(%rbx)
cmpb $0x2, %cl
jb 0x2821b0
cmpl $0x2, %r14d
jl 0x28215d
movq 0x10(%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, %ebp
cmovnel %edx, %ebp
jmp 0x28215f
xorl %ebp, %ebp
testb %bpl, %bpl
je 0x2821b0
movq %rbx, %rdi
callq 0x281d9d
movl %eax, %ecx
movl $0x7, %eax
testl %ecx, %ecx
jne 0x2821bf
movslq 0xc(%rbx), %rdx
addq $-0x2, %rdx
movl %edx, 0xc(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x2(%rdi), %rsi
callq 0x17cd0
movq 0x10(%rbx), %rax
movslq 0xc(%rbx), %rcx
xorl %edx, %edx
movb %dl, (%rax,%rcx)
movq 0x10(%rbx), %rax
movslq 0xc(%rbx), %rcx
movb %dl, 0x1(%rax,%rcx)
orb $0x2, 0x9(%rbx)
movb %bpl, 0xa(%rbx)
xorl %ecx, %ecx
cmpl 0x4(%rsp), %r14d
movl $0x12, %eax
cmovlel %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzwl 0x176(%rdx), %eax
jmp 0x2820a7