// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3ValueFromExpr
SQLITE_PRIVATE int sqlite3ValueFromExpr(
  sqlite3 *db,              /* The database connection */
  Expr *pExpr,              /* The expression to evaluate */
  u8 enc,                   /* Encoding to use */
  u8 affinity,              /* Affinity to use */
  sqlite3_value **ppVal     /* Write the new value here */
){
  int op;
  char *zVal = 0;
  sqlite3_value *pVal = 0;
  int negInt = 1;
  const char *zNeg = "";

  if( !pExpr ){
    *ppVal = 0;
    return SQLITE_OK;
  }
  op = pExpr->op;

  /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT3.
  ** The ifdef here is to enable us to achieve 100% branch test coverage even
  ** when SQLITE_ENABLE_STAT3 is omitted.
  */
#ifdef SQLITE_ENABLE_STAT3
  if( op==TK_REGISTER ) op = pExpr->op2;
#else
  if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
#endif

  /* Handle negative integers in a single step.  This is needed in the
  ** case when the value is -9223372036854775808.
  */
  if( op==TK_UMINUS
   && (pExpr->pLeft->op==TK_INTEGER || pExpr->pLeft->op==TK_FLOAT) ){
    pExpr = pExpr->pLeft;
    op = pExpr->op;
    negInt = -1;
    zNeg = "-";
  }

  if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
    pVal = sqlite3ValueNew(db);
    if( pVal==0 ) goto no_mem;
    if( ExprHasProperty(pExpr, EP_IntValue) ){
      sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt);
    }else{
      zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
      if( zVal==0 ) goto no_mem;
      sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
      if( op==TK_FLOAT ) pVal->type = SQLITE_FLOAT;
    }
    if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
      sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
    }else{
      sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
    }
    if( pVal->flags & (MEM_Int|MEM_Real) ) pVal->flags &= ~MEM_Str;
    if( enc!=SQLITE_UTF8 ){
      sqlite3VdbeChangeEncoding(pVal, enc);
    }
  }else if( op==TK_UMINUS ) {
    /* This branch happens for multiple negative signs.  Ex: -(-5) */
    if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) ){
      sqlite3VdbeMemNumerify(pVal);
      if( pVal->u.i==SMALLEST_INT64 ){
        pVal->flags &= MEM_Int;
        pVal->flags |= MEM_Real;
        pVal->r = (double)LARGEST_INT64;
      }else{
        pVal->u.i = -pVal->u.i;
      }
      pVal->r = -pVal->r;
      sqlite3ValueApplyAffinity(pVal, affinity, enc);
    }
  }else if( op==TK_NULL ){
    pVal = sqlite3ValueNew(db);
    if( pVal==0 ) goto no_mem;
  }
#ifndef SQLITE_OMIT_BLOB_LITERAL
  else if( op==TK_BLOB ){
    int nVal;
    assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
    assert( pExpr->u.zToken[1]=='\'' );
    pVal = sqlite3ValueNew(db);
    if( !pVal ) goto no_mem;
    zVal = &pExpr->u.zToken[2];
    nVal = sqlite3Strlen30(zVal)-1;
    assert( zVal[nVal]=='\'' );
    sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
                         0, SQLITE_DYNAMIC);
  }
#endif

  if( pVal ){
    sqlite3VdbeMemStoreType(pVal);
  }
  *ppVal = pVal;
  return SQLITE_OK;

no_mem:
  db->mallocFailed = 1;
  sqlite3DbFree(db, zVal);
  sqlite3ValueFree(pVal);
  *ppVal = 0;
  return SQLITE_NOMEM;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r12
movq $0x0, -0x30(%rbp)
xorl %eax, %eax
testq %rsi, %rsi
je 0x4f7a0
movl %ecx, %r14d
movq %rsi, %rbx
movq %rdi, %r15
movq %r12, -0x38(%rbp)
movb (%rsi), %r13b
cmpb $-0x7c, %r13b
jne 0x4f478
movb 0x37(%rbx), %r13b
leaq 0x2eee1(%rip), %rdi     # 0x7e360
movl $0x1, %r12d
cmpb $-0x64, %r13b
jne 0x4f4b1
movq 0x10(%rbx), %rax
movb (%rax), %cl
leal 0x7f(%rcx), %esi
movb $-0x64, %r13b
cmpb $0x1, %sil
ja 0x4f4b1
leaq 0x2eb3b(%rip), %rdi     # 0x7dfdf
movq $-0x1, %r12
movq %rax, %rbx
movl %ecx, %r13d
movzbl %r13b, %eax
cmpl $0x80, %eax
jle 0x4f549
leal -0x81(%rax), %ecx
cmpl $0x2, %ecx
jb 0x4f59d
cmpl $0x83, %eax
je 0x4f653
cmpl $0x9c, %eax
movq -0x38(%rbp), %r12
jne 0x4f7c8
movq 0x10(%rbx), %rsi
movzbl %dl, %ebx
movzbl %r14b, %ecx
leaq -0x30(%rbp), %r8
movq %r15, %rdi
movl %ebx, %edx
callq 0x4f437
testl %eax, %eax
jne 0x4f7c8
movl %r14d, %r15d
movq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0x2c074
movq 0x18(%r14), %rax
negq %rax
jno 0x4f7a4
movzwl 0x24(%r14), %eax
andl $0x4, %eax
orl $0x8, %eax
movw %ax, 0x24(%r14)
movabsq $0x43e0000000000000, %rax # imm = 0x43E0000000000000
movq %rax, 0x10(%r14)
jmp 0x4f7a8
cmpl $0x5e, %eax
je 0x4f59d
cmpl $0x62, %eax
movq -0x38(%rbp), %r12
jne 0x4f7c8
movq %r15, %rdi
movl $0x38, %esi
callq 0x115e9
testq %rax, %rax
je 0x4f76b
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movq $0x0, 0x30(%rax)
movw $0x1, 0x24(%rax)
movb $0x5, 0x26(%rax)
movq %r15, (%rax)
movq %rax, -0x30(%rbp)
jmp 0x4f7c8
movq %rdi, -0x48(%rbp)
movl %edx, -0x3c(%rbp)
movl %r14d, -0x40(%rbp)
movq %r15, %rdi
movl $0x38, %esi
callq 0x115e9
movq %rax, %r14
testq %rax, %rax
je 0x4f644
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%r14)
movups %xmm0, (%r14)
movups %xmm0, 0x10(%r14)
movq $0x0, 0x30(%r14)
movw $0x1, 0x24(%r14)
movb $0x5, 0x26(%r14)
movq %r15, (%r14)
movq %r14, -0x30(%rbp)
testb $0x4, 0x3(%rbx)
jne 0x4f6f3
movq 0x8(%rbx), %rcx
leaq 0x2c58f(%rip), %rsi     # 0x7bb91
xorl %ebx, %ebx
movq %r15, %rdi
movq -0x48(%rbp), %rdx
xorl %eax, %eax
callq 0x117e2
testq %rax, %rax
je 0x4f64a
leaq -0x45d4a(%rip), %r8     # 0x98d4
movq %r14, %rdi
movq %rax, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
callq 0xeff4
movb $0x2, %al
cmpb $-0x7e, %r13b
je 0x4f710
jmp 0x4f714
movq %r14, -0x30(%rbp)
xorl %ebx, %ebx
movq -0x38(%rbp), %r12
jmp 0x4f782
movq %r15, %rdi
movl $0x38, %esi
callq 0x115e9
movq %rax, %r14
testq %rax, %rax
je 0x4f773
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%r14)
movups %xmm0, (%r14)
movups %xmm0, 0x10(%r14)
movq $0x0, 0x30(%r14)
movw $0x1, 0x24(%r14)
movb $0x5, 0x26(%r14)
movq %r15, (%r14)
movq %r14, -0x30(%rbp)
movq 0x8(%rbx), %rbx
addq $0x2, %rbx
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq %rbx, %rax
incl %r13d
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x4f6a9
andl $0x3fffffff, %r13d      # imm = 0x3FFFFFFF
leal -0x1(%r13), %r12d
movq %r15, %rdi
movq %rbx, %rsi
movl %r12d, %edx
callq 0x4e439
shrl $0x1f, %r12d
leal (%r12,%r13), %edx
decl %edx
sarl %edx
leaq -0x45e0d(%rip), %r8     # 0x98d4
movq %r14, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0xeff4
jmp 0x4f779
movslq 0x8(%rbx), %rax
imulq %rax, %r12
movq %r14, %rdi
callq 0xec23
movq %r12, 0x18(%r14)
movw $0x4, 0x24(%r14)
movb $0x1, %al
movb %al, 0x26(%r14)
addb $0x7f, %r13b
cmpb $0x2, %r13b
movl -0x40(%rbp), %edx
movzbl %dl, %eax
movl $0x63, %ecx
cmovael %eax, %ecx
cmpb $0x62, %dl
cmovnel %eax, %ecx
movsbl %cl, %esi
movq %r14, %rdi
movl $0x1, %edx
callq 0x2bfce
movzwl 0x24(%r14), %eax
testb $0xc, %al
je 0x4f753
andl $0xfffd, %eax           # imm = 0xFFFD
movw %ax, 0x24(%r14)
movl -0x3c(%rbp), %eax
cmpb $0x1, %al
movq -0x38(%rbp), %r12
je 0x4f7c8
movzbl %al, %esi
movq %r14, %rdi
callq 0x24e59
jmp 0x4f7c8
movq %rax, -0x30(%rbp)
xorl %ebx, %ebx
jmp 0x4f782
movq %r14, -0x30(%rbp)
xorl %ebx, %ebx
testq %r14, %r14
movq -0x38(%rbp), %r12
jne 0x4f7c8
movb $0x1, 0x50(%r15)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x9c3a
movq -0x30(%rbp), %rdi
callq 0x14350
movl $0x7, %eax
xorl %ebx, %ebx
jmp 0x4f7db
movq %rax, 0x18(%r14)
movsd 0x10(%r14), %xmm0
xorps 0x29bfb(%rip), %xmm0    # 0x793b0
movlps %xmm0, 0x10(%r14)
movsbl %r15b, %esi
movq %r14, %rdi
movl %ebx, %edx
callq 0x2bfce
movq -0x30(%rbp), %rbx
testq %rbx, %rbx
je 0x4f7d9
movq %rbx, %rdi
callq 0x10fc1
xorl %eax, %eax
movq %rbx, (%r12)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq