// File: /workspace/github_c_makefile_star2_O3/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 %ecx, %r12d
movl %edx, %r13d
movq %rsi, %rbx
movq %rdi, %r15
movq $0x0, 0x10(%rsp)
movzbl (%rbx), %ebp
cmpl $0xab, %ebp
je 0x2c039e
cmpl $0xb2, %ebp
jne 0x2c03a4
movq 0x10(%rbx), %rbx
jmp 0x2c038b
cmpl $0xad, %ebp
jne 0x2c03b0
movb 0x2(%rbx), %bpl
cmpb $-0x56, %bpl
je 0x2c0417
movzbl %bpl, %eax
cmpl $0x24, %eax
jne 0x2c04cc
movq 0x8(%rbx), %rdi
xorl %esi, %esi
callq 0x2be46c
movq 0x10(%rbx), %rsi
movzbl %al, %ebx
movzbl %r13b, %edx
movq %r15, %rdi
movl %ebx, %ecx
movq %r14, %r8
callq 0x2c0365
movl %eax, %r13d
movq (%r14), %rdi
testq %rdi, %rdi
je 0x2c0751
movl %ebx, %esi
movl $0x1, %edx
callq 0x29b3bd
movq (%r14), %rdi
movsbl %r12b, %esi
movl $0x1, %edx
callq 0x29b351
jmp 0x2c0751
movl %r12d, 0x4(%rsp)
movq 0x10(%rbx), %rbx
movzbl (%rbx), %ebp
leaq 0x107980(%rip), %rcx    # 0x3c7daa
movq $-0x1, %r12
cmpl $0x98, %ebp
movq %r14, 0x8(%rsp)
je 0x2c04e3
cmpl $0x96, %ebp
je 0x2c04e3
movzbl %r13b, %ebp
movl 0x4(%rsp), %r12d
movzbl %r12b, %ecx
leaq 0x10(%rsp), %r14
movq %r15, %rdi
movq %rbx, %rsi
movl %ebp, %edx
movq %r14, %r8
callq 0x2c0365
testl %eax, %eax
sete %al
movq (%r14), %r14
testq %r14, %r14
setne %cl
andb %al, %cl
xorl %r13d, %r13d
cmpb $0x1, %cl
jne 0x2c0749
movq %r14, %rdi
callq 0x29ecc9
movzwl 0x8(%r14), %eax
testb $0x8, %al
jne 0x2c0726
movq (%r14), %rcx
negq %rcx
jno 0x2c0738
movabsq $0x43e0000000000000, %rcx # imm = 0x43E0000000000000
movq %rcx, (%r14)
andl $0x3e40, %eax           # imm = 0x3E40
orl $0x8, %eax
movw %ax, 0x8(%r14)
jmp 0x2c073b
movl %r12d, 0x4(%rsp)
movq %r14, 0x8(%rsp)
leaq 0x109c93(%rip), %rcx    # 0x3ca170
movl $0x1, %r12d
movzbl %bpl, %eax
xorl %r14d, %r14d
cmpl $0x96, %eax
jg 0x2c0515
movl %r13d, (%rsp)
cmpl $0x73, %eax
je 0x2c0540
cmpl $0x77, %eax
je 0x2c0628
movl $0x0, %r13d
cmpl $0x96, %eax
je 0x2c0540
jmp 0x2c0749
cmpl $0x97, %eax
je 0x2c05b2
cmpl $0xa7, %eax
je 0x2c066d
movl %r13d, (%rsp)
movl $0x0, %r13d
cmpl $0x98, %eax
jne 0x2c0749
movq %rcx, %r13
movl $0x38, %esi
movq %r15, %rdi
callq 0x279b27
testq %rax, %rax
je 0x2c064f
movq %rax, %r14
movw $0x1, 0x8(%rax)
movq %r15, 0x28(%rax)
testb $0x4, 0x5(%rbx)
jne 0x2c06a8
movq 0x8(%rbx), %rcx
leaq 0xef60e(%rip), %rsi     # 0x3afb89
movq %r15, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x27b56a
testq %rax, %rax
je 0x2c0652
leaq -0x47a7c(%rip), %r8     # 0x278b1c
movq %r14, %rdi
movq %rax, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
callq 0x278594
jmp 0x2c06ba
movl $0x38, %esi
movq %r15, %rdi
callq 0x279b27
xorl %r13d, %r13d
testq %rax, %rax
je 0x2c064f
movq %rax, %r14
movw $0x1, 0x8(%rax)
movq %r15, 0x28(%rax)
movq 0x8(%rbx), %rbx
addq $0x2, %rbx
movq %rbx, %rdi
callq 0x172f0
movq %rax, %r12
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
leal -0x1(%r12), %ebp
movq %r15, %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x2be3eb
shrl $0x1f, %ebp
leal (%r12,%rbp), %edx
decl %edx
sarl %edx
leaq -0x47afa(%rip), %r8     # 0x278b1c
movq %r14, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0x278594
jmp 0x2c0749
movl $0x38, %esi
movq %r15, %rdi
callq 0x279b27
xorl %r13d, %r13d
testq %rax, %rax
je 0x2c064f
movq %rax, %r14
movq %r15, 0x28(%rax)
movw $0x1, 0x8(%rax)
jmp 0x2c0749
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x278b1c
movq %r14, %rdi
callq 0x278453
movl $0x7, %r13d
jmp 0x2c0751
movl $0x38, %esi
movq %r15, %rdi
callq 0x279b27
xorl %r13d, %r13d
testq %rax, %rax
je 0x2c0721
movq %rax, %r14
movq %r15, 0x28(%rax)
movw $0x4, 0x8(%rax)
movq 0x8(%rbx), %rax
xorl %ecx, %ecx
cmpb $0x0, 0x4(%rax)
sete %cl
movq %rcx, (%r14)
jmp 0x2c0749
movslq 0x8(%rbx), %rax
imulq %rax, %r12
movq %r12, (%r14)
movw $0x4, 0x8(%r14)
movl 0x4(%rsp), %ecx
movzbl %cl, %eax
xorb $0x41, %cl
addb $0x6a, %bpl
andb $-0x3, %bpl
orb %cl, %bpl
movl $0x43, %ecx
cmovnel %eax, %ecx
movsbl %cl, %esi
movq %r14, %rdi
movl $0x1, %edx
callq 0x29b351
movzwl 0x8(%r14), %eax
testb $0x2c, %al
je 0x2c06fa
andl $0xfffd, %eax           # imm = 0xFFFD
movw %ax, 0x8(%r14)
xorl %r13d, %r13d
cmpb $0x1, (%rsp)
je 0x2c0749
andl $0x2, %eax
je 0x2c0749
movl (%rsp), %eax
cmpb %al, 0xa(%r14)
je 0x2c0749
movzbl %al, %esi
movq %r14, %rdi
callq 0x291bc7
movl %eax, %r13d
jmp 0x2c0749
xorl %r14d, %r14d
jmp 0x2c0749
movsd (%r14), %xmm0
xorps 0x8f31e(%rip), %xmm0    # 0x34fa50
movlps %xmm0, (%r14)
jmp 0x2c073b
movq %rcx, (%r14)
movsbl %r12b, %esi
movq %r14, %rdi
movl %ebp, %edx
callq 0x29b351
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