// File: /workspace/github_c_makefile_star2_O3/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 $0x0, -0x48(%rbp)
xorl %eax, %eax
testq %rsi, %rsi
je 0x4f4a9
movl %ecx, %r9d
movq %rsi, %rbx
movq %rdi, %r15
movb (%rsi), %r12b
cmpb $-0x7c, %r12b
jne 0x4f47f
movb 0x37(%rbx), %r12b
cmpb $-0x64, %r12b
jne 0x4f4b1
movq 0x10(%rbx), %rbx
movb (%rbx), %r12b
leal 0x7f(%r12), %eax
cmpb $0x1, %al
ja 0x4f66b
leaq 0x2eb8f(%rip), %rsi     # 0x7e02f
movq $-0x1, %r13
jmp 0x4f4be
xorl %r14d, %r14d
jmp 0x4f7a3
leaq 0x2eef8(%rip), %rsi     # 0x7e3b0
movl $0x1, %r13d
movzbl %r12b, %ecx
xorl %r14d, %r14d
cmpl $0x80, %ecx
jle 0x4f581
leal -0x81(%rcx), %eax
cmpl $0x2, %eax
jb 0x4f5d2
movl $0x0, %eax
cmpl $0x83, %ecx
jne 0x4f7a3
movq %r8, -0x30(%rbp)
movq %r15, %rdi
movl $0x38, %esi
callq 0x11721
testq %rax, %rax
je 0x4f6ab
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x28(%rax)
movups %xmm0, 0x8(%rax)
movw $0x1, 0x24(%rax)
movb $0x5, 0x26(%rax)
movq %r15, (%rax)
movq 0x8(%rbx), %rsi
addq $0x2, %rsi
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %rsi, %rax
incl %r12d
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x4f53b
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
leal -0x1(%r12), %ebx
movq %r15, %rdi
movl %ebx, %edx
callq 0x4e483
shrl $0x1f, %ebx
leal (%r12,%rbx), %edx
decl %edx
sarl %edx
leaq -0x45c5f(%rip), %r8     # 0x9910
movq %r14, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0xf0d7
jmp 0x4f69a
cmpl $0x5e, %ecx
je 0x4f5d2
movl $0x0, %eax
cmpl $0x62, %ecx
jne 0x4f7a3
movq %r8, -0x30(%rbp)
movq %r15, %rdi
movl $0x38, %esi
callq 0x11721
testq %rax, %rax
je 0x4f6ab
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x28(%rax)
movups %xmm0, 0x8(%rax)
movw $0x1, 0x24(%rax)
movb $0x5, 0x26(%rax)
movq %r15, (%rax)
jmp 0x4f795
movq %rsi, -0x40(%rbp)
movl %edx, -0x34(%rbp)
movl %r9d, -0x38(%rbp)
movq %r8, -0x30(%rbp)
movq %r15, %rdi
movl $0x38, %esi
callq 0x11721
testq %rax, %rax
je 0x4f6ab
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x28(%rax)
movups %xmm0, 0x8(%rax)
movw $0x1, 0x24(%rax)
movb $0x5, 0x26(%rax)
movq %r15, (%rax)
testb $0x4, 0x3(%rbx)
jne 0x4f6d2
movq 0x8(%rbx), %rcx
leaq 0x2c566(%rip), %rsi     # 0x7bb91
movq %r15, %rdi
movq -0x40(%rbp), %rdx
xorl %eax, %eax
callq 0x11900
testq %rax, %rax
je 0x4f6ae
leaq -0x45d35(%rip), %r8     # 0x9910
movq %r14, %rdi
movq %rax, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
callq 0xf0d7
movb $0x2, %al
cmpb $-0x7e, %r12b
je 0x4f6ef
jmp 0x4f6f3
movq %r8, -0x30(%rbp)
movzbl %dl, %r13d
movzbl %r9b, %ecx
leaq -0x48(%rbp), %r14
movq %r15, %rdi
movq %rbx, %rsi
movl %r13d, %edx
movq %r14, %r8
movl %r9d, %ebx
callq 0x4f449
movq (%r14), %r14
testl %eax, %eax
je 0x4f746
testq %r14, %r14
jne 0x4f795
xorl %r14d, %r14d
jmp 0x4f79d
xorl %r14d, %r14d
movb $0x1, 0x50(%r15)
movq %r15, %rdi
xorl %esi, %esi
callq 0x9ca4
movq %r14, %rdi
callq 0x142f2
movl $0x7, %eax
xorl %r14d, %r14d
jmp 0x4f79f
movslq 0x8(%rbx), %rax
imulq %rax, %r13
movq %r14, %rdi
callq 0xecfd
movq %r13, 0x18(%r14)
movw $0x4, 0x24(%r14)
movb $0x1, %al
movb %al, 0x26(%r14)
addb $0x7f, %r12b
cmpb $0x2, %r12b
movl -0x38(%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 0x2c8d6
movzwl 0x24(%r14), %eax
testb $0xc, %al
je 0x4f732
andl $0xfffd, %eax           # imm = 0xFFFD
movw %ax, 0x24(%r14)
movl -0x34(%rbp), %eax
cmpb $0x1, %al
je 0x4f795
movzbl %al, %esi
movq %r14, %rdi
callq 0x24930
jmp 0x4f795
movq %r14, %rdi
callq 0x2c981
movq 0x18(%r14), %rax
negq %rax
jno 0x4f771
movzwl 0x24(%r14), %eax
andl $0x4, %eax
orl $0x8, %eax
movw %ax, 0x24(%r14)
movsd 0x29b39(%rip), %xmm0    # 0x792a8
jmp 0x4f77b
movq %rax, 0x18(%r14)
movsd 0x10(%r14), %xmm0
xorps 0x29c2e(%rip), %xmm0    # 0x793b0
movlps %xmm0, 0x10(%r14)
movsbl %bl, %esi
movq %r14, %rdi
movl %r13d, %edx
callq 0x2c8d6
movq %r14, %rdi
callq 0x110b5
xorl %eax, %eax
movq -0x30(%rbp), %r8
movq %r14, (%r8)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq