// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movb %cl, %al
movb %dl, %cl
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb %cl, -0x19(%rbp)
movb %al, -0x1a(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x1, -0x4c(%rbp)
leaq 0x16ec48(%rip), %rax    # 0x59d628
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x18(%rbp), %rax
movzbl (%rax), %ecx
movl %ecx, -0x34(%rbp)
movb $0x1, %al
cmpl $0xab, %ecx
movb %al, -0x65(%rbp)
je 0x42ea0f
cmpl $0xb2, -0x34(%rbp)
sete %al
movb %al, -0x65(%rbp)
movb -0x65(%rbp), %al
testb $0x1, %al
jne 0x42ea18
jmp 0x42ea26
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x42e9eb
cmpl $0xad, -0x34(%rbp)
jne 0x42ea3a
movq -0x18(%rbp), %rax
movzbl 0x2(%rax), %eax
movl %eax, -0x34(%rbp)
cmpl $0x24, -0x34(%rbp)
jne 0x42eabb
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x42c020
movb %al, -0x5d(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movb -0x19(%rbp), %cl
movb -0x5d(%rbp), %al
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
movzbl %cl, %edx
movzbl %al, %ecx
callq 0x42e9a0
movl %eax, -0x5c(%rbp)
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
je 0x42eab0
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movl $0x1, %edx
movzbl -0x5d(%rbp), %esi
callq 0x3fa000
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movl $0x1, %edx
movzbl -0x1a(%rbp), %esi
callq 0x400250
movl -0x5c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x42ee76
cmpl $0xaa, -0x34(%rbp)
jne 0x42eb10
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x98, %eax
je 0x42eae8
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x96, %eax
jne 0x42eb10
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x34(%rbp)
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
leaq 0x16c81b(%rip), %rax    # 0x59b327
movq %rax, -0x58(%rbp)
cmpl $0x73, -0x34(%rbp)
je 0x42eb2c
cmpl $0x96, -0x34(%rbp)
je 0x42eb2c
cmpl $0x98, -0x34(%rbp)
jne 0x42ec40
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x42ee80
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x42eb49
jmp 0x42ee50
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x42eb75
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq 0x8(%rax), %rsi
movslq -0x4c(%rbp), %rax
imulq %rax, %rsi
callq 0x3c84b0
jmp 0x42ebc1
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
leaq 0x153d67(%rip), %rsi    # 0x5828f3
movb $0x0, %al
callq 0x3cb7d0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x42eba3
jmp 0x42ee50
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %ecx
leaq -0x6601c(%rip), %r8     # 0x3c8ba0
callq 0x3cf8d0
cmpl $0x98, -0x34(%rbp)
je 0x42ebd3
cmpl $0x96, -0x34(%rbp)
jne 0x42ebf1
movzbl -0x1a(%rbp), %eax
cmpl $0x41, %eax
jne 0x42ebf1
movq -0x48(%rbp), %rdi
movl $0x43, %esi
movl $0x1, %edx
callq 0x400250
jmp 0x42ec03
movq -0x48(%rbp), %rdi
movl $0x1, %edx
movzbl -0x1a(%rbp), %esi
callq 0x400250
movq -0x48(%rbp), %rax
movzwl 0x8(%rax), %eax
andl $0x2c, %eax
cmpl $0x0, %eax
je 0x42ec22
movq -0x48(%rbp), %rax
movzwl 0x8(%rax), %ecx
andl $-0x3, %ecx
movw %cx, 0x8(%rax)
movzbl -0x19(%rbp), %eax
cmpl $0x1, %eax
je 0x42ec3b
movq -0x48(%rbp), %rdi
movzbl -0x19(%rbp), %esi
callq 0x3ee400
movl %eax, -0x5c(%rbp)
jmp 0x42ee3d
cmpl $0xaa, -0x34(%rbp)
jne 0x42ed35
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movb -0x19(%rbp), %cl
movb -0x1a(%rbp), %al
movq -0x30(%rbp), %r9
leaq -0x48(%rbp), %r8
movzbl %cl, %edx
movzbl %al, %ecx
callq 0x42e9a0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x42ed30
cmpq $0x0, -0x48(%rbp)
je 0x42ed30
movq -0x48(%rbp), %rdi
callq 0x400280
movq -0x48(%rbp), %rax
movzwl 0x8(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x42eccb
movq -0x48(%rbp), %rax
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x48(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x42ed1d
movq -0x48(%rbp), %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
cmpq %rcx, (%rax)
jne 0x42ed0b
movq -0x48(%rbp), %rax
movsd 0xea086(%rip), %xmm0    # 0x518d70
movsd %xmm0, (%rax)
movq -0x48(%rbp), %rax
movzwl 0x8(%rax), %eax
andl $0xffff3e40, %eax       # imm = 0xFFFF3E40
orl $0x8, %eax
movw %ax, %cx
movq -0x48(%rbp), %rax
movw %cx, 0x8(%rax)
jmp 0x42ed1b
movq -0x48(%rbp), %rax
xorl %ecx, %ecx
subq (%rax), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
jmp 0x42ed1d
movq -0x48(%rbp), %rdi
movb -0x1a(%rbp), %al
movzbl %al, %esi
movzbl -0x19(%rbp), %edx
callq 0x400250
jmp 0x42ee3b
cmpl $0x77, -0x34(%rbp)
jne 0x42ed66
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x42ee80
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x42ed58
jmp 0x42ee50
movq -0x48(%rbp), %rdi
callq 0x3c8550
jmp 0x42ee39
cmpl $0x97, -0x34(%rbp)
jne 0x42ede7
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x42ee80
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x42ed8c
jmp 0x42ee50
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x3c3400
subl $0x1, %eax
movl %eax, -0x64(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x64(%rbp), %edx
callq 0x42bf30
movq -0x70(%rbp), %rdi
movq %rax, %rsi
movl -0x64(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %edx
xorl %ecx, %ecx
leaq -0x66240(%rip), %r8     # 0x3c8ba0
callq 0x3c8170
jmp 0x42ee37
cmpl $0xa7, -0x34(%rbp)
jne 0x42ee35
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x42ee80
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x42ee33
movq -0x48(%rbp), %rax
movw $0x4, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movsbl 0x4(%rax), %eax
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
jmp 0x42ee35
jmp 0x42ee37
jmp 0x42ee39
jmp 0x42ee3b
jmp 0x42ee3d
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl -0x5c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x42ee76
movq -0x10(%rbp), %rdi
callq 0x3c8ba0
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x3c00a0
movq -0x48(%rbp), %rdi
callq 0x3c7ef0
movl $0x7, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop