// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: valueFromExpr
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;

  assert( pExpr!=0 );
  while( (op = pExpr->op)==TK_UPLUS || op==TK_SPAN ) pExpr = pExpr->pLeft;
#if defined(SQLITE_ENABLE_STAT4)
  if( op==TK_REGISTER ) op = pExpr->op2;
#else
  if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
#endif

  /* Compressed expressions only appear when parsing the DEFAULT clause
  ** on a table column definition, and hence only when pCtx==0.  This
  ** check ensures that an EP_TokenOnly expression is never passed down
  ** into valueFromFunction(). */
  assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 );

  if( op==TK_CAST ){
    u8 aff = sqlite3AffinityType(pExpr->u.zToken,0);
    rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
    testcase( rc!=SQLITE_OK );
    if( *ppVal ){
      sqlite3VdbeMemCast(*ppVal, aff, SQLITE_UTF8);
      sqlite3ValueApplyAffinity(*ppVal, affinity, SQLITE_UTF8);
    }
    return rc;
  }

  /* 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_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_BLOB ){
      sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
    }else{
      sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
    }
    assert( (pVal->flags & MEM_IntReal)==0 );
    if( pVal->flags & (MEM_Int|MEM_IntReal|MEM_Real) ){
      testcase( pVal->flags & MEM_Int );
      testcase( pVal->flags & 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==valueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal,pCtx)
     && pVal!=0
    ){
      sqlite3VdbeMemNumerify(pVal);
      if( pVal->flags & MEM_Real ){
        pVal->u.r = -pVal->u.r;
      }else if( pVal->u.i==SMALLEST_INT64 ){
#ifndef SQLITE_OMIT_FLOATING_POINT
        pVal->u.r = -(double)SMALLEST_INT64;
#else
        pVal->u.r = LARGEST_INT64;
#endif
        MemSetTypeFlag(pVal, MEM_Real);
      }else{
        pVal->u.i = -pVal->u.i;
      }
      sqlite3ValueApplyAffinity(pVal, affinity, enc);
    }
  }else if( op==TK_NULL ){
    pVal = valueNew(db, pCtx);
    if( pVal==0 ) goto no_mem;
    sqlite3VdbeMemSetNull(pVal);
  }
#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
#ifdef SQLITE_ENABLE_STAT4
  else if( op==TK_FUNCTION && pCtx!=0 ){
    rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
  }
#endif
  else if( op==TK_TRUEFALSE ){
    pVal = valueNew(db, pCtx);
    if( pVal ){
      pVal->flags = MEM_Int;
      pVal->u.i = pExpr->u.zToken[4]==0;
    }
  }

  *ppVal = pVal;
  return rc;

no_mem:
#ifdef SQLITE_ENABLE_STAT4
  if( pCtx==0 || pCtx->pParse->nErr==0 )
#endif
    sqlite3OomFault(db);
  sqlite3DbFree(db, zVal);
  assert( *ppVal==0 );
#ifdef SQLITE_ENABLE_STAT4
  if( pCtx==0 ) sqlite3ValueFree(pVal);
#else
  assert( pCtx==0 ); sqlite3ValueFree(pVal);
#endif
  return SQLITE_NOMEM_BKPT;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r14
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r15
andq $0x0, 0x10(%rsp)
movzbl (%rbx), %r12d
cmpl $0xab, %r12d
je 0x2678bd
cmpl $0xb2, %r12d
jne 0x2678c3
movq 0x10(%rbx), %rbx
jmp 0x2678a7
cmpl $0xad, %r12d
jne 0x2678d0
movb 0x2(%rbx), %r12b
cmpb $-0x56, %r12b
je 0x267937
movzbl %r12b, %eax
cmpl $0x24, %eax
jne 0x2679e6
movl %ecx, %r12d
movq 0x8(%rbx), %rdi
xorl %esi, %esi
callq 0x266062
movq 0x10(%rbx), %rsi
movzbl %al, %ebx
movzbl %bpl, %edx
movq %r15, %rdi
movl %ebx, %ecx
movq %r14, %r8
callq 0x267888
movl %eax, %r13d
movq (%r14), %rdi
testq %rdi, %rdi
je 0x267c00
pushq $0x1
popq %rbp
movl %ebx, %esi
movl %ebp, %edx
callq 0x2423ea
movq (%r14), %rdi
movsbl %r12b, %esi
movl %ebp, %edx
callq 0x242363
jmp 0x267c00
movl %ebp, (%rsp)
movq 0x10(%rbx), %rbx
movzbl (%rbx), %r12d
leaq 0x100861(%rip), %r13    # 0x3681aa
pushq $-0x1
popq %rbp
cmpl $0x98, %r12d
je 0x2679f3
cmpl $0x96, %r12d
je 0x2679f3
movq %r14, 0x8(%rsp)
movzbl (%rsp), %ebp
movl %ecx, %r12d
movzbl %cl, %ecx
leaq 0x10(%rsp), %r14
movq %r15, %rdi
movq %rbx, %rsi
movl %ebp, %edx
movq %r14, %r8
callq 0x267888
testl %eax, %eax
sete %al
movq (%r14), %r14
testq %r14, %r14
setne %cl
andb %al, %cl
xorl %r13d, %r13d
cmpb $0x1, %cl
jne 0x267bf8
movq %r14, %rdi
callq 0x244ff7
movzwl 0x8(%r14), %eax
testb $0x8, %al
jne 0x267bd5
movq (%r14), %rcx
negq %rcx
jno 0x267be7
movabsq $0x43e0000000000000, %rcx # imm = 0x43E0000000000000
movq %rcx, (%r14)
andl $0x3e40, %eax           # imm = 0x3E40
orl $0x8, %eax
movw %ax, 0x8(%r14)
jmp 0x267bea
movl %ebp, (%rsp)
leaq 0x102b80(%rip), %r13    # 0x36a570
pushq $0x1
popq %rbp
cmpb $0x73, %r12b
movq %r14, 0x8(%rsp)
je 0x267a2f
movzbl %r12b, %eax
cmpl $0x77, %eax
je 0x267b20
cmpl $0x96, %eax
je 0x267a2f
cmpl $0x97, %eax
je 0x267abe
cmpl $0xa7, %eax
je 0x267a8c
cmpl $0x98, %eax
jne 0x267b15
movl %ecx, 0x4(%rsp)
movq %r15, %rdi
callq 0x22998f
testq %rax, %rax
je 0x267b40
movq %rax, %r14
testb $0x4, 0x5(%rbx)
jne 0x267b66
movq 0x8(%rbx), %rcx
leaq 0xe8575(%rip), %rsi     # 0x34ffd1
movq %r15, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x226ec3
testq %rax, %rax
je 0x267b43
leaq -0x42ec8(%rip), %rcx    # 0x224bb1
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x2299ac
jmp 0x267b79
movq %r15, %rdi
callq 0x22998f
xorl %r13d, %r13d
testq %rax, %rax
je 0x267bd0
movq %rax, %r14
movw $0x4, 0x8(%rax)
movq 0x8(%rbx), %rax
xorl %ecx, %ecx
cmpb $0x0, 0x4(%rax)
sete %cl
movq %rcx, (%r14)
jmp 0x267bf8
movq %r15, %rdi
callq 0x22998f
xorl %r13d, %r13d
testq %rax, %rax
je 0x267b40
movq %rax, %r14
movq 0x8(%rbx), %rbx
addq $0x2, %rbx
movq %rbx, %rdi
callq 0x2211ac
movl %eax, %ebp
decl %ebp
movq %r15, %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x265fee
movq %rax, %rsi
pushq $0x2
popq %rcx
movl %ebp, %eax
cltd
idivl %ecx
leaq -0x42f53(%rip), %r8     # 0x224bb1
movq %r14, %rdi
movl %eax, %edx
xorl %ecx, %ecx
callq 0x2246e6
jmp 0x267bf8
xorl %r14d, %r14d
xorl %r13d, %r13d
jmp 0x267bf8
movq %r15, %rdi
callq 0x22998f
xorl %r13d, %r13d
testq %rax, %rax
je 0x267b40
movq %rax, %r14
movq %rax, %rdi
callq 0x224946
jmp 0x267bf8
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x224bb1
movq %r15, %rdi
xorl %esi, %esi
callq 0x21f26b
movq %r14, %rdi
callq 0x2245fd
pushq $0x7
popq %r13
jmp 0x267c00
movslq 0x8(%rbx), %rax
imulq %rax, %rbp
movq %r14, %rdi
movq %rbp, %rsi
callq 0x224928
movl 0x4(%rsp), %ecx
movzbl %cl, %eax
xorb $0x41, %cl
addb $0x6a, %r12b
andb $-0x3, %r12b
orb %cl, %r12b
pushq $0x43
popq %rcx
cmovnel %eax, %ecx
movsbl %cl, %esi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x242363
movzwl 0x8(%r14), %eax
testb $0x2c, %al
movl (%rsp), %ecx
je 0x267bb8
andl $0xfffd, %eax           # imm = 0xFFFD
movw %ax, 0x8(%r14)
xorl %r13d, %r13d
cmpb $0x1, %cl
je 0x267bf8
movzbl %cl, %esi
movq %r14, %rdi
callq 0x23a21d
movl %eax, %r13d
jmp 0x267bf8
xorl %r14d, %r14d
jmp 0x267bf8
movsd (%r14), %xmm0
xorps 0x87e6f(%rip), %xmm0    # 0x2efa50
movlps %xmm0, (%r14)
jmp 0x267bea
movq %rcx, (%r14)
movsbl %r12b, %esi
movq %r14, %rdi
movl %ebp, %edx
callq 0x242363
movq 0x8(%rsp), %rax
movq %r14, (%rax)
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq