// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movq %r8, 0x20(%rsp)
movq %rsi, %r13
movq %rdi, %r14
movq $0x0, 0x8(%rsp)
movzbl (%r13), %r12d
cmpl $0xab, %r12d
je 0x2c9afa
cmpl $0xb2, %r12d
jne 0x2c9b00
movq 0x10(%r13), %r13
jmp 0x2c9ae3
cmpl $0xad, %r12d
jne 0x2c9b0d
movb 0x2(%r13), %r12b
leaq 0x109d7c(%rip), %r15    # 0x3d3890
movl $0x1, %ebp
cmpb $-0x56, %r12b
je 0x2c9b89
movzbl %r12b, %eax
cmpl $0x24, %eax
jne 0x2c9bb7
movl %ecx, %r15d
movq 0x8(%r13), %rdi
xorl %esi, %esi
movl %edx, %ebp
callq 0x2c7b4e
movq 0x10(%r13), %rsi
movzbl %al, %ebx
movzbl %bpl, %edx
movq %r14, %rdi
movl %ebx, %ecx
movq 0x20(%rsp), %r14
movq %r14, %r8
callq 0x2c9ac1
movl %eax, %ebp
movq (%r14), %rdi
testq %rdi, %rdi
je 0x2c9f0c
movl %ebx, %esi
movl $0x1, %edx
callq 0x2a44c0
movq (%r14), %rdi
movsbl %r15b, %esi
movl $0x1, %edx
callq 0x2a445f
jmp 0x2c9f0c
movq 0x10(%r13), %rax
movzbl (%rax), %esi
cmpl $0x98, %esi
je 0x2c9ba3
movb $-0x56, %r12b
cmpl $0x96, %esi
jne 0x2c9bb7
leaq 0x107928(%rip), %r15    # 0x3d14d2
movq $-0x1, %rbp
movl %esi, %r12d
movq %rax, %r13
movzbl %r12b, %eax
movl $0x0, 0x14(%rsp)
cmpl $0x96, %eax
jle 0x2c9bec
cmpl $0xa6, %eax
jg 0x2c9c85
cmpl $0x97, %eax
je 0x2c9d1c
cmpl $0x98, %eax
je 0x2c9c05
jmp 0x2c9efb
cmpl $0x73, %eax
je 0x2c9c05
cmpl $0x77, %eax
je 0x2c9dd5
cmpl $0x96, %eax
jne 0x2c9efb
movl %edx, 0x18(%rsp)
movl %ecx, 0x1c(%rsp)
movl $0x38, %esi
movq %r14, %rdi
callq 0x283569
movq %rax, %rbx
testq %rax, %rax
je 0x2c9d12
movw $0x1, 0x8(%rbx)
movq %r14, 0x28(%rbx)
movq %rbx, 0x8(%rsp)
testb $0x4, 0x5(%r13)
jne 0x2c9e01
movq 0x8(%r13), %rcx
leaq 0xef53e(%rip), %rsi     # 0x3b9189
xorl %r13d, %r13d
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x284f95
testq %rax, %rax
je 0x2c9e41
leaq -0x477b0(%rip), %r8     # 0x2824bb
movq %rbx, %rdi
movq %rax, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
callq 0x281f27
jmp 0x2c9e76
cmpl $0xa7, %eax
je 0x2c9d95
cmpl $0xaa, %eax
jne 0x2c9efb
movq 0x10(%r13), %rsi
movzbl %dl, %ebx
movl %ecx, %ebp
movzbl %cl, %ecx
leaq 0x8(%rsp), %r15
movq %r14, %rdi
movl %ebx, %edx
movq %r15, %r8
callq 0x2c9ac1
testl %eax, %eax
sete %al
movq (%r15), %r14
testq %r14, %r14
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2c9efb
movq %r14, %rdi
callq 0x2a84fc
movzwl 0x8(%r14), %eax
testb $0x8, %al
jne 0x2c9ed8
movq (%r14), %rcx
negq %rcx
jno 0x2c9eea
movabsq $0x43e0000000000000, %rcx # imm = 0x43E0000000000000
movq %rcx, (%r14)
andl $0x3e40, %eax           # imm = 0x3E40
orl $0x8, %eax
movw %ax, 0x8(%r14)
jmp 0x2c9eed
movq %rbx, 0x8(%rsp)
jmp 0x2c9e3e
movl $0x38, %esi
movq %r14, %rdi
callq 0x283569
movq %rax, %rbx
testq %rax, %rax
je 0x2c9e1c
movw $0x1, 0x8(%rbx)
movq %r14, 0x28(%rbx)
movq %rbx, 0x8(%rsp)
movq 0x8(%r13), %r13
addq $0x2, %r13
movq %r13, %rdi
callq 0x172f0
movq %rax, %r15
andl $0x3fffffff, %r15d      # imm = 0x3FFFFFFF
leal -0x1(%r15), %r12d
movq %r14, %rdi
movq %r13, %rsi
movl %r12d, %edx
callq 0x2c7ad2
shrl $0x1f, %r12d
leal (%r15,%r12), %edx
decl %edx
sarl %edx
leaq -0x478c8(%rip), %r8     # 0x2824bb
movq %rbx, %rdi
movq %rax, %rsi
xorl %ecx, %ecx
callq 0x281f27
jmp 0x2c9e24
movl $0x38, %esi
movq %r14, %rdi
callq 0x283569
testq %rax, %rax
je 0x2c9e2f
movw $0x1, 0x8(%rax)
movq %r14, 0x28(%rax)
movq %rax, 0x8(%rsp)
movw $0x4, 0x8(%rax)
movq 0x8(%r13), %rcx
xorl %edx, %edx
cmpb $0x0, 0x4(%rcx)
sete %dl
movq %rdx, (%rax)
jmp 0x2c9efb
movl $0x38, %esi
movq %r14, %rdi
callq 0x283569
testq %rax, %rax
je 0x2c9e39
movw $0x1, %cx
movw %cx, 0x8(%rax)
movq %r14, 0x28(%rax)
movq %rax, 0x8(%rsp)
movw %cx, 0x8(%rax)
jmp 0x2c9efb
movslq 0x8(%r13), %rax
imulq %rax, %rbp
testb $0x24, 0x9(%rbx)
je 0x2c9e6d
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x29c706
jmp 0x2c9e76
movq %rbx, 0x8(%rsp)
xorl %r13d, %r13d
testq %rbx, %rbx
jne 0x2c9efb
jmp 0x2c9e41
movq %rax, 0x8(%rsp)
jmp 0x2c9efb
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x2824bb
testq %r13, %r13
je 0x2c9e59
movq %r14, %rdi
movq %r13, %rsi
callq 0x28c3e7
movq 0x8(%rsp), %rdi
callq 0x281de6
movl $0x7, %ebp
jmp 0x2c9f0c
movq %rbp, (%rbx)
movw $0x4, 0x8(%rbx)
movl 0x1c(%rsp), %ecx
movzbl %cl, %eax
xorb $0x41, %cl
addb $0x6a, %r12b
andb $-0x3, %r12b
orb %cl, %r12b
movl $0x43, %ecx
cmovnel %eax, %ecx
movsbl %cl, %esi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x2a445f
movzwl 0x8(%rbx), %eax
testb $0x2c, %al
je 0x2c9eb4
andl $0xfffd, %eax           # imm = 0xFFFD
movw %ax, 0x8(%rbx)
movl 0x18(%rsp), %eax
cmpb $0x1, %al
je 0x2c9efb
testb $0x2, 0x8(%rbx)
je 0x2c9efb
cmpb %al, 0xa(%rbx)
je 0x2c9efb
movzbl %al, %esi
movq %rbx, %rdi
callq 0x29b888
movl %eax, 0x14(%rsp)
jmp 0x2c9efb
movsd (%r14), %xmm0
xorps 0x8eb9c(%rip), %xmm0    # 0x358a80
movlps %xmm0, (%r14)
jmp 0x2c9eed
movq %rcx, (%r14)
movsbl %bpl, %esi
movq %r14, %rdi
movl %ebx, %edx
callq 0x2a445f
movq 0x8(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rax, (%rcx)
movl 0x14(%rsp), %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq