// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movb %cl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movb %al, -0x1d(%rbp)
movq %r8, -0x28(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movw $0x0, -0x32(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x3c81b4
movq -0x10(%rbp), %rdi
callq 0x3c8550
movl $0x0, -0x4(%rbp)
jmp 0x3c8418
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x3c81cf
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x7c(%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x3c81d6
movl $0x3b9aca00, -0x30(%rbp) # imm = 0x3B9ACA00
movzbl -0x1d(%rbp), %edx
movl $0x2, %eax
movl $0x10, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
movw %ax, -0x32(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x3c8271
movzbl -0x1d(%rbp), %eax
cmpl $0x1, %eax
jne 0x3c8210
movq -0x18(%rbp), %rdi
callq 0x192b0
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x2c(%rbp)
jmp 0x3c8264
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x30(%rbp), %ecx
movb %al, -0x39(%rbp)
jg 0x3c824c
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movl -0x2c(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movsbl (%rcx,%rdx), %ecx
orl %ecx, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x3c8255
jmp 0x3c8262
jmp 0x3c8257
movl -0x2c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3c8217
jmp 0x3c8264
movzwl -0x32(%rbp), %eax
orl $0x200, %eax            # imm = 0x200
movw %ax, -0x32(%rbp)
movq $-0x1, %rax
cmpq %rax, -0x28(%rbp)
jne 0x3c8327
movl -0x2c(%rbp), %eax
movl %eax, -0x38(%rbp)
movzwl -0x32(%rbp), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x3c82b0
movzbl -0x1d(%rbp), %edx
movl $0x2, %eax
movl $0x1, %ecx
cmpl $0x1, %edx
cmovel %ecx, %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jle 0x3c82d2
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movl $0x12, %esi
callq 0x3d6170
movl %eax, -0x4(%rbp)
jmp 0x3c8418
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpl $0x20, -0x38(%rbp)
jbe 0x3c82e8
movl -0x38(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x3c82f2
movl $0x20, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3c82f2
movq -0x48(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x3ef030
cmpl $0x0, %eax
je 0x3c830f
movl $0x7, -0x4(%rbp)
jmp 0x3c8418
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x38(%rbp), %eax
movl %eax, %edx
callq 0x19610
jmp 0x3c83a6
movq -0x10(%rbp), %rdi
callq 0x3c76d0
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
leaq 0x85d(%rip), %rax       # 0x3c8ba0
cmpq %rax, -0x28(%rbp)
jne 0x3c8379
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x3c30e0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
jmp 0x3c83a4
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x28(%rbp), %rdx
movl $0x400, %ecx            # imm = 0x400
movl $0x800, %eax            # imm = 0x800
cmpq $0x0, %rdx
cmovel %eax, %ecx
movzwl -0x32(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x32(%rbp)
jmp 0x3c83a6
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movw -0x32(%rbp), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x8(%rax)
cmpb $0x0, -0x1d(%rbp)
je 0x3c83ce
movb -0x1d(%rbp), %cl
movq -0x10(%rbp), %rax
movb %cl, 0xa(%rax)
jmp 0x3c83e0
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movb 0x5e(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0xa(%rax)
movzbl -0x1d(%rbp), %eax
cmpl $0x1, %eax
jle 0x3c8400
movq -0x10(%rbp), %rdi
callq 0x3effb0
cmpl $0x0, %eax
je 0x3c8400
movl $0x7, -0x4(%rbp)
jmp 0x3c8418
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jle 0x3c8411
movl $0x12, -0x4(%rbp)
jmp 0x3c8418
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)