// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, -0x48(%rbp)
xorl %eax, %eax
testq %rsi, %rsi
je 0x4a0bc
movl %ecx, %r9d
movq %rsi, %r14
movq %rdi, %rbx
movb (%rsi), %r13b
cmpb $-0x7c, %r13b
jne 0x4a098
movb 0x37(%r14), %r13b
cmpb $-0x64, %r13b
jne 0x4a0c4
movq 0x10(%r14), %r14
movb (%r14), %r13b
leal 0x7f(%r13), %eax
cmpb $0x1, %al
ja 0x4a177
leaq 0x25f1d(%rip), %rsi     # 0x6ffd5
pushq $-0x1
jmp 0x4a0cd
xorl %r15d, %r15d
jmp 0x4a31e
leaq 0x2627a(%rip), %rsi     # 0x70345
pushq $0x1
popq %r12
movzbl %r13b, %eax
leal -0x81(%rax), %ecx
cmpl $0x2, %ecx
jb 0x4a0fb
cmpl $0x83, %eax
je 0x4a1d3
cmpl $0x62, %eax
je 0x4a1b9
cmpl $0x5e, %eax
jne 0x4a257
movq %rsi, -0x40(%rbp)
movl %edx, -0x34(%rbp)
movl %r9d, -0x38(%rbp)
movq %r8, -0x30(%rbp)
movq %rbx, %rdi
callq 0x129fe
testq %rax, %rax
je 0x4a22f
movq %rax, %r15
testb $0x4, 0x3(%r14)
jne 0x4a25f
movq 0x8(%r14), %rcx
leaq 0x23a7d(%rip), %rsi     # 0x6dbb1
movq %rbx, %rdi
movq -0x40(%rbp), %rdx
xorl %eax, %eax
callq 0x10594
testq %rax, %rax
je 0x4a232
leaq -0x40ddb(%rip), %r8     # 0x9377
pushq $-0x1
popq %rsi
pushq $0x1
popq %rcx
movq %r15, %rdi
movq %rax, %rdx
callq 0x12a28
cmpb $-0x7e, %r13b
jne 0x4a272
movb $0x2, 0x26(%r15)
jmp 0x4a272
movq %r8, -0x30(%rbp)
movzbl %dl, %r12d
movzbl %r9b, %ecx
leaq -0x48(%rbp), %r15
movq %rbx, %rdi
movq %r14, %rsi
movl %r12d, %edx
movq %r15, %r8
movl %r9d, %ebx
callq 0x4a065
movq (%r15), %r15
testl %eax, %eax
je 0x4a2c1
testq %r15, %r15
jne 0x4a310
xorl %r15d, %r15d
xorl %eax, %eax
jmp 0x4a24e
movq %r8, -0x30(%rbp)
movq %rbx, %rdi
callq 0x129fe
movq %rax, %r15
testq %rax, %rax
jne 0x4a310
jmp 0x4a22f
movq %r8, -0x30(%rbp)
movq %rbx, %rdi
callq 0x129fe
testq %rax, %rax
je 0x4a22f
movq %rax, %r15
movq 0x8(%r14), %r14
addq $0x2, %r14
movq %r14, %rdi
callq 0x8f8e
movl %eax, %r12d
decl %r12d
movq %rbx, %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x49473
movq %rax, %rsi
pushq $0x2
popq %rcx
movl %r12d, %eax
cltd
idivl %ecx
leaq -0x40ea7(%rip), %r8     # 0x9377
movq %r15, %rdi
movl %eax, %edx
xorl %ecx, %ecx
callq 0xe1d3
jmp 0x4a310
xorl %r15d, %r15d
movb $0x1, 0x50(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x968b
movq %r15, %rdi
callq 0x12a43
pushq $0x7
popq %rax
xorl %r15d, %r15d
movq -0x30(%rbp), %r8
jmp 0x4a31e
xorl %r15d, %r15d
jmp 0x4a31c
movslq 0x8(%r14), %rax
imulq %rax, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0xe3ff
addb $0x7f, %r13b
cmpb $0x2, %r13b
movl -0x38(%rbp), %edx
movzbl %dl, %eax
pushq $0x63
popq %rcx
cmovael %eax, %ecx
cmpb $0x62, %dl
cmovnel %eax, %ecx
movsbl %cl, %esi
pushq $0x1
popq %rdx
movq %r15, %rdi
callq 0x29a62
movzwl 0x24(%r15), %eax
testb $0xc, %al
je 0x4a2ad
andl $0xfffd, %eax           # imm = 0xFFFD
movw %ax, 0x24(%r15)
movl -0x34(%rbp), %eax
cmpb $0x1, %al
je 0x4a310
movzbl %al, %esi
movq %r15, %rdi
callq 0x2144b
jmp 0x4a310
movq %r15, %rdi
callq 0x29af1
movq 0x18(%r15), %rax
negq %rax
jno 0x4a2ec
movzwl 0x24(%r15), %eax
andl $0x4, %eax
orl $0x8, %eax
movw %ax, 0x24(%r15)
movsd 0x20fce(%rip), %xmm0    # 0x6b2b8
jmp 0x4a2f6
movq %rax, 0x18(%r15)
movsd 0x10(%r15), %xmm0
xorps 0x210c3(%rip), %xmm0    # 0x6b3c0
movlps %xmm0, 0x10(%r15)
movsbl %bl, %esi
movq %r15, %rdi
movl %r12d, %edx
callq 0x29a62
movq %r15, %rdi
callq 0xfe30
movq -0x30(%rbp), %r8
xorl %eax, %eax
movq %r15, (%r8)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq