// File: /workspace/github_c_makefile_star2_O2/skeeto[P]flappy/sqlite3.c
// Function: sqlite3ValueFromExpr
static int valueFromExpr(
  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 */
  struct ValueNewStat4Ctx *pCtx   /* Second argument for valueNew() */
){
  int op;
  char *zVal = 0;
  sqlite3_value *pVal = 0;
  int negInt = 1;
  const char *zNeg = "";
  int rc = SQLITE_OK;

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

  /* 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 = valueNew(db, pCtx);
    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 ){
      rc = 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) 
     && pVal!=0
    ){
      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 = valueNew(db, pCtx);
    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 = valueNew(db, pCtx);
    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 rc;

no_mem:
  db->mallocFailed = 1;
  sqlite3DbFree(db, zVal);
  assert( *ppVal==0 );
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
  if( pCtx==0 ) sqlite3ValueFree(pVal);
#else
  assert( pCtx==0 ); sqlite3ValueFree(pVal);
#endif
  return SQLITE_NOMEM;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
andq $0x0, 0x20(%rsp)
testq %rsi, %rsi
je 0x468b5
movl %ecx, %ebp
movq %rsi, %rbx
movq %rdi, %r12
movb (%rsi), %r15b
cmpb $-0x7b, %r15b
jne 0x46890
movb 0x36(%rbx), %r15b
cmpb $-0x64, %r15b
jne 0x468c1
movq 0x10(%rbx), %rbx
movb (%rbx), %r15b
movl %r15d, %eax
andb $-0x2, %al
cmpb $-0x7e, %al
jne 0x46973
leaq 0x1e398(%rip), %rsi     # 0x64c49
pushq $-0x1
jmp 0x468ca
andq $0x0, (%r8)
xorl %r13d, %r13d
jmp 0x46b2f
leaq 0x1f73c(%rip), %rsi     # 0x66004
pushq $0x1
popq %r13
movzbl %r15b, %eax
leal -0x82(%rax), %ecx
cmpl $0x2, %ecx
jb 0x468f8
cmpl $0x84, %eax
je 0x46a0e
cmpl $0x63, %eax
je 0x469dd
cmpl $0x5f, %eax
jne 0x46a84
movq %rsi, 0x18(%rsp)
movl %edx, 0x14(%rsp)
movq %r8, 0x8(%rsp)
movq %r12, %rdi
callq 0x1362e
testq %rax, %rax
je 0x46a6a
movq %rax, %r14
testb $0x4, 0x5(%rbx)
jne 0x46a8f
movq 0x8(%rbx), %rcx
leaq 0x1f19b(%rip), %rsi     # 0x65aca
movq %r12, %rdi
movq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x10c1b
testq %rax, %rax
je 0x46a6d
leaq -0x3d449(%rip), %r8     # 0x9505
pushq $-0x1
popq %rdx
pushq $0x1
popq %rcx
movq %r14, %rdi
movq %rax, %rsi
callq 0xe897
cmpb $-0x7d, %r15b
jne 0x46aa2
movb $0x2, 0x26(%r14)
jmp 0x46aa2
movq %r8, 0x8(%rsp)
movzbl %dl, %r15d
movzbl %bpl, %ecx
leaq 0x20(%rsp), %r14
movq %r12, %rdi
movq %rbx, %rsi
movl %r15d, %edx
movq %r14, %r8
callq 0x46862
testl %eax, %eax
sete %al
movq (%r14), %r14
testq %r14, %r14
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x469fa
movq %r14, %rdi
callq 0x2a9b4
movq 0x18(%r14), %rax
negq %rax
jno 0x46af7
movzwl 0x24(%r14), %eax
andl $0x4, %eax
orl $0x8, %eax
movw %ax, 0x24(%r14)
movsd 0x1c610(%rip), %xmm0    # 0x62fe8
jmp 0x46b01
movq %r8, 0x8(%rsp)
movq %r12, %rdi
callq 0x1362e
xorl %r13d, %r13d
testq %rax, %rax
je 0x46a6a
movq %rax, %r14
jmp 0x46b1f
xorl %r13d, %r13d
testq %r14, %r14
jne 0x46b1f
xorl %r14d, %r14d
jmp 0x46b27
movq %r8, 0x8(%rsp)
movq %r12, %rdi
callq 0x1362e
xorl %r13d, %r13d
testq %rax, %rax
je 0x46a6a
movq %rax, %r14
movq 0x8(%rbx), %rbx
addq $0x2, %rbx
movq %rbx, %rdi
callq 0x90a2
movl %eax, %ebp
decl %ebp
movq %r12, %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x45613
movq %rax, %rsi
pushq $0x2
popq %rcx
movl %ebp, %eax
cltd
idivl %ecx
leaq -0x3d554(%rip), %r8     # 0x9505
movq %r14, %rdi
movl %eax, %edx
xorl %ecx, %ecx
callq 0xe897
jmp 0x46b1f
xorl %r14d, %r14d
movb $0x1, 0x50(%r12)
movq %r14, %rdi
callq 0x13663
pushq $0x7
popq %r13
jmp 0x46b2f
xorl %r13d, %r13d
xorl %r14d, %r14d
jmp 0x46b2c
movslq 0x8(%rbx), %rax
imulq %rax, %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0xeaad
andb $-0x22, %r15b
xorb $-0x7e, %r15b
movzbl %bpl, %eax
xorb $0x62, %bpl
orb %r15b, %bpl
pushq $0x63
popq %rcx
cmovnel %eax, %ecx
movsbl %cl, %esi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x2a93e
movzwl 0x24(%r14), %eax
testb $0xc, %al
je 0x46adc
andl $0xfffd, %eax           # imm = 0xFFFD
movw %ax, 0x24(%r14)
xorl %r13d, %r13d
movl 0x14(%rsp), %eax
cmpb $0x1, %al
je 0x46b1f
movzbl %al, %esi
movq %r14, %rdi
callq 0x2276d
movl %eax, %r13d
jmp 0x46b1f
movq %rax, 0x18(%r14)
movsd 0x10(%r14), %xmm0
xorps 0x1c5c8(%rip), %xmm0    # 0x630d0
movlps %xmm0, 0x10(%r14)
movsbl %bpl, %esi
movq %r14, %rdi
movl %r15d, %edx
callq 0x2a93e
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x104cf
movq 0x8(%rsp), %r8
movq %r14, (%r8)
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq