// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %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 0x10944
movq -0x10(%rbp), %rdi
callq 0x10ce0
movl $0x0, -0x4(%rbp)
jmp 0x10bc5
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x1095d
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x68(%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x10964
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 0x10a31
movzbl -0x1d(%rbp), %eax
cmpl $0x1, %eax
jne 0x109d0
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x30(%rbp), %ecx
movb %al, -0x39(%rbp)
jg 0x109b8
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x109c1
jmp 0x109ce
jmp 0x109c3
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x10996
jmp 0x10a24
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x30(%rbp), %ecx
movb %al, -0x3a(%rbp)
jg 0x10a0c
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, -0x3a(%rbp)
movb -0x3a(%rbp), %al
testb $0x1, %al
jne 0x10a15
jmp 0x10a22
jmp 0x10a17
movl -0x2c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x2c(%rbp)
jmp 0x109d7
jmp 0x10a24
movzwl -0x32(%rbp), %eax
orl $0x200, %eax            # imm = 0x200
movw %ax, -0x32(%rbp)
movq $-0x1, %rax
cmpq %rax, -0x28(%rbp)
jne 0x10ab6
movl -0x2c(%rbp), %eax
movl %eax, -0x38(%rbp)
movzwl -0x32(%rbp), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x10a6c
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 0x10a80
movl $0x12, -0x4(%rbp)
jmp 0x10bc5
movq -0x10(%rbp), %rdi
movl -0x38(%rbp), %esi
xorl %edx, %edx
callq 0x11940
cmpl $0x0, %eax
je 0x10a9f
movl $0x7, -0x4(%rbp)
jmp 0x10bc5
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
movslq -0x38(%rbp), %rdx
callq 0x82f0
jmp 0x10b30
leaq -0x712d(%rip), %rax     # 0x9990
cmpq %rax, -0x28(%rbp)
jne 0x10aee
movq -0x10(%rbp), %rdi
callq 0x10190
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x28(%rax)
jmp 0x10b2e
movq -0x10(%rbp), %rdi
callq 0x10190
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%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 0x10b30
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movw -0x32(%rbp), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x24(%rax)
movzbl -0x1d(%rbp), %eax
cmpl $0x0, %eax
jne 0x10b59
movl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x10b60
movzbl -0x1d(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x27(%rax)
movzbl -0x1d(%rbp), %edx
movl $0x3, %eax
movl $0x4, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x26(%rax)
movq -0x10(%rbp), %rax
movzbl 0x27(%rax), %eax
cmpl $0x1, %eax
je 0x10bad
movq -0x10(%rbp), %rdi
callq 0x31f70
cmpl $0x0, %eax
je 0x10bad
movl $0x7, -0x4(%rbp)
jmp 0x10bc5
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jle 0x10bbe
movl $0x12, -0x4(%rbp)
jmp 0x10bc5
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop