// File: /workspace/github_c_makefile_star2_O2/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 0x224710
movq %r8, %r13
movl %edx, %r14d
movq %rsi, %r12
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0x224720
movl 0x7c(%rdi), %edx
jmp 0x224725
movq %rbx, %rdi
callq 0x224946
xorl %r15d, %r15d
jmp 0x2248f8
movl $0x3b9aca00, %edx       # imm = 0x3B9ACA00
testb %cl, %cl
pushq $0x10
popq %rax
pushq $0x2
popq %rbp
cmovel %eax, %ebp
testl %r14d, %r14d
movl %edx, 0x4(%rsp)
jns 0x22476d
cmpb $0x1, %cl
jne 0x2247f2
movq %rdi, %r14
movq %r12, %rdi
movl %ecx, %r15d
callq 0x172d0
movq %r14, %rdi
movl %r15d, %ecx
movl 0x4(%rsp), %edx
movq %rax, %r14
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movzwl %bp, %ebp
orl $0x200, %ebp            # imm = 0x200
pushq $0x7
popq %r15
cmpq $-0x1, %r13
je 0x2247b2
movl %ecx, (%rsp)
movq %rbx, %rdi
callq 0x224336
movq %r12, 0x10(%rbx)
leaq 0x424(%rip), %rax       # 0x224bb1
cmpq %rax, %r13
je 0x2247dd
movq %r13, 0x30(%rbx)
xorl %eax, %eax
testq %r13, %r13
sete %al
shll $0xa, %eax
movzwl %bp, %ecx
leal (%rax,%rcx), %ebp
addl $0x400, %ebp            # imm = 0x400
jmp 0x224846
xorl %eax, %eax
cmpb $0x1, %cl
setne %al
incl %eax
xorl %r13d, %r13d
btl $0x9, %ebp
cmovbl %eax, %r13d
cmpl %edx, %r14d
jle 0x224816
pushq $0x12
popq %r15
movl %r15d, %esi
callq 0x22d19b
jmp 0x2248f8
movq %r12, 0x18(%rbx)
movq 0x28(%rbx), %rdi
movq %r12, %rsi
callq 0x22103d
movl %eax, 0x20(%rbx)
jmp 0x224846
movslq %edx, %rax
xorl %r14d, %r14d
cmpq %rax, %r14
jg 0x224764
movb 0x1(%r12,%r14), %sil
orb (%r12,%r14), %sil
je 0x224764
addq $0x2, %r14
jmp 0x2247f8
movl %ecx, (%rsp)
addl %r14d, %r13d
cmpl $0x21, %r13d
pushq $0x20
popq %rsi
cmovael %r13d, %esi
movq %rbx, %rdi
callq 0x23a881
testl %eax, %eax
jne 0x2248f8
movq 0x10(%rbx), %rdi
movl %r13d, %edx
movq %r12, %rsi
callq 0x17630
movl %r14d, 0xc(%rbx)
movw %bp, 0x8(%rbx)
movl (%rsp), %eax
testb %al, %al
movl 0x4(%rsp), %edi
je 0x2248e1
movb %al, 0xa(%rbx)
cmpb $0x1, %al
je 0x2248eb
cmpl $0x2, %r14d
jl 0x2248eb
movq 0x10(%rbx), %rcx
movb (%rcx), %al
movb 0x1(%rcx), %cl
movl %eax, %edx
notb %dl
movl %ecx, %esi
xorb $-0x2, %sil
movb $0x2, %bpl
orb %dl, %sil
je 0x224894
xorb $-0x2, %al
notb %cl
movb $0x3, %bpl
orb %al, %cl
jne 0x2248eb
movl %edi, %r12d
movq %rbx, %rdi
callq 0x2245b6
testl %eax, %eax
jne 0x2248f8
movslq 0xc(%rbx), %rdx
addq $-0x2, %rdx
movl %edx, 0xc(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x2(%rdi), %rsi
callq 0x17c50
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)
movl %r12d, %edi
jmp 0x2248eb
movq 0x28(%rbx), %rax
movb 0x5e(%rax), %al
movb %al, 0xa(%rbx)
xorl %eax, %eax
cmpl %edi, %r14d
pushq $0x12
popq %r15
cmovlel %eax, %r15d
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq