// File: /workspace/github_c_makefile_star2_O3/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 0x2785be
movq %r8, %r12
movl %edx, %r14d
movq %rsi, %r15
movq 0x28(%rbx), %rbp
testq %rbp, %rbp
je 0x2785ce
movl 0x7c(%rbp), %edx
jmp 0x2785d3
testb $0x24, 0x9(%rbx)
je 0x27860e
movq %rbx, %rdi
callq 0x2917ab
jmp 0x278614
movl $0x3b9aca00, %edx       # imm = 0x3B9ACA00
testb %cl, %cl
movl $0x10, %eax
movl $0x2, %r13d
cmovel %eax, %r13d
testl %r14d, %r14d
movl %edx, (%rsp)
jns 0x278641
cmpb $0x1, %cl
jne 0x27861b
movq %r15, %rdi
movl %ecx, %r14d
callq 0x172f0
movl %r14d, %ecx
movl (%rsp), %edx
movq %rax, %r14
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
jmp 0x278636
movw $0x1, 0x8(%rbx)
xorl %eax, %eax
jmp 0x278820
xorl %r14d, %r14d
testl %edx, %edx
js 0x278636
movb 0x1(%r15,%r14), %al
orb (%r15,%r14), %al
je 0x278636
addq $0x2, %r14
cmpl %r14d, %edx
jge 0x278622
movzwl %r13w, %r13d
orl $0x200, %r13d           # imm = 0x200
cmpq $-0x1, %r12
je 0x278692
testb $0x24, 0x9(%rbx)
jne 0x278653
cmpl $0x0, 0x20(%rbx)
je 0x27865f
movq %rbx, %rdi
movl %ecx, %ebp
callq 0x291775
movl %ebp, %ecx
movq %r15, 0x10(%rbx)
leaq 0x4b2(%rip), %rax       # 0x278b1c
cmpq %rax, %r12
je 0x2786da
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 0x278771
xorl %eax, %eax
cmpb $0x1, %cl
setne %al
incl %eax
xorl %r12d, %r12d
btl $0x9, %r13d
cmovbl %eax, %r12d
cmpl %edx, %r14d
jle 0x27871d
movl $0x12, %eax
testq %rbp, %rbp
je 0x278820
movq 0x130(%rbp), %rcx
testq %rcx, %rcx
je 0x278820
movl $0x12, 0x18(%rcx)
incl 0x30(%rcx)
jmp 0x278820
movq %r15, 0x18(%rbx)
movq 0x28(%rbx), %rdx
testq %rdx, %rdx
je 0x27870b
cmpq %r15, 0x1c0(%rdx)
jbe 0x27870b
movl $0x80, %eax
cmpq %r15, 0x1b0(%rdx)
jbe 0x278718
cmpq %r15, 0x1b8(%rdx)
jbe 0x27882f
movq %r15, %rdi
movl %ecx, %ebp
callq *0x242f82(%rip)         # 0x4bb698
movl %ebp, %ecx
movl %eax, 0x20(%rbx)
jmp 0x278771
movl %ecx, 0x4(%rsp)
addl %r14d, %r12d
cmpl $0x21, %r12d
movl $0x20, %esi
cmovael %r12d, %esi
cmpl %esi, 0x20(%rbx)
jge 0x278755
movq %rbx, %rdi
xorl %edx, %edx
callq 0x291865
movl %eax, %ecx
movl $0x7, %eax
testl %ecx, %ecx
jne 0x278820
movq 0x10(%rbx), %rdi
jmp 0x278762
movq 0x18(%rbx), %rdi
movq %rdi, 0x10(%rbx)
andw $0x2d, 0x8(%rbx)
movl %r12d, %edx
movq %r15, %rsi
callq 0x17660
movl 0x4(%rsp), %ecx
movl %r14d, 0xc(%rbx)
movw %r13w, 0x8(%rbx)
testb %cl, %cl
je 0x278808
movb %cl, 0xa(%rbx)
cmpb $0x1, %cl
je 0x278812
cmpl $0x2, %r14d
jl 0x278812
movq 0x10(%rbx), %rcx
movb (%rcx), %al
movb 0x1(%rcx), %cl
movl %eax, %edx
notb %dl
movl %ecx, %esi
xorb $-0x2, %sil
movb $0x2, %r15b
orb %dl, %sil
je 0x2787ba
xorb $-0x2, %al
notb %cl
movb $0x3, %r15b
orb %al, %cl
jne 0x278812
movq %rbx, %rdi
callq 0x27840a
movl %eax, %ecx
movl $0x7, %eax
testl %ecx, %ecx
jne 0x278820
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 %r15b, 0xa(%rbx)
jmp 0x278812
movq 0x28(%rbx), %rax
movb 0x5e(%rax), %al
movb %al, 0xa(%rbx)
xorl %ecx, %ecx
cmpl (%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 0x278718