// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3ValueFromExpr
SQLITE_PRIVATE int sqlite3ValueFromExpr(
  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 */
){
  int op;
  char *zVal = 0;
  sqlite3_value *pVal = 0;
  int negInt = 1;
  const char *zNeg = "";

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

  /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT3.
  ** The ifdef here is to enable us to achieve 100% branch test coverage even
  ** when SQLITE_ENABLE_STAT3 is omitted.
  */
#ifdef SQLITE_ENABLE_STAT3
  if( op==TK_REGISTER ) op = pExpr->op2;
#else
  if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
#endif

  /* 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 = sqlite3ValueNew(db);
    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 ){
      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) ){
      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 = sqlite3ValueNew(db);
    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 = sqlite3ValueNew(db);
    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 SQLITE_OK;

no_mem:
  db->mallocFailed = 1;
  sqlite3DbFree(db, zVal);
  sqlite3ValueFree(pVal);
  *ppVal = 0;
  return SQLITE_NOMEM;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %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 $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x1, -0x44(%rbp)
leaq 0x47b39(%rip), %rax     # 0xb2df5
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x6b2de
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x6b65f
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x84, -0x2c(%rbp)
jne 0x6b2fc
movq -0x18(%rbp), %rax
movzbl 0x37(%rax), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x9c, -0x2c(%rbp)
jne 0x6b351
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x81, %eax
je 0x6b329
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x82, %eax
jne 0x6b351
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
leaq 0x47737(%rip), %rax     # 0xb2a84
movq %rax, -0x50(%rbp)
cmpl $0x5e, -0x2c(%rbp)
je 0x6b36d
cmpl $0x82, -0x2c(%rbp)
je 0x6b36d
cmpl $0x81, -0x2c(%rbp)
jne 0x6b490
movq -0x10(%rbp), %rdi
callq 0x16f80
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x6b386
jmp 0x6b62f
movq -0x18(%rbp), %rax
movzwl 0x2(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x400, %eax            # imm = 0x400
jne 0x6b3b5
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq 0x8(%rax), %rsi
movslq -0x44(%rbp), %rax
imulq %rax, %rsi
callq 0x10c50
jmp 0x6b414
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
leaq 0x452c1(%rip), %rsi     # 0xb068d
movb $0x0, %al
callq 0x137f0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x6b3e3
jmp 0x6b62f
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %ecx
leaq -0x61a6c(%rip), %r8     # 0x9990
callq 0x16fd0
cmpl $0x82, -0x2c(%rbp)
jne 0x6b412
movq -0x40(%rbp), %rax
movb $0x2, 0x26(%rax)
jmp 0x6b414
cmpl $0x81, -0x2c(%rbp)
je 0x6b426
cmpl $0x82, -0x2c(%rbp)
jne 0x6b444
movzbl -0x1a(%rbp), %eax
cmpl $0x62, %eax
jne 0x6b444
movq -0x40(%rbp), %rdi
movl $0x63, %esi
movl $0x1, %edx
callq 0x6b670
jmp 0x6b456
movq -0x40(%rbp), %rdi
movl $0x1, %edx
movzbl -0x1a(%rbp), %esi
callq 0x6b670
movq -0x40(%rbp), %rax
movzwl 0x24(%rax), %eax
andl $0xc, %eax
cmpl $0x0, %eax
je 0x6b475
movq -0x40(%rbp), %rax
movzwl 0x24(%rax), %ecx
andl $-0x3, %ecx
movw %cx, 0x24(%rax)
movzbl -0x19(%rbp), %eax
cmpl $0x1, %eax
je 0x6b48b
movq -0x40(%rbp), %rdi
movzbl -0x19(%rbp), %esi
callq 0x312a0
jmp 0x6b60b
cmpl $0x9c, -0x2c(%rbp)
jne 0x6b569
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movb -0x19(%rbp), %al
leaq -0x40(%rbp), %r8
movzbl %al, %edx
movzbl -0x1a(%rbp), %ecx
callq 0x6b280
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x6b564
movq -0x40(%rbp), %rdi
callq 0x3b100
movq -0x40(%rbp), %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
cmpq %rcx, 0x18(%rax)
jne 0x6b516
movq -0x40(%rbp), %rax
movzwl 0x24(%rax), %ecx
andl $0x4, %ecx
movw %cx, 0x24(%rax)
movq -0x40(%rbp), %rax
movzwl 0x24(%rax), %ecx
orl $0x8, %ecx
movw %cx, 0x24(%rax)
movq -0x40(%rbp), %rax
movsd 0x42939(%rip), %xmm0    # 0xade48
movsd %xmm0, 0x10(%rax)
jmp 0x6b528
movq -0x40(%rbp), %rax
xorl %ecx, %ecx
subq 0x18(%rax), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, 0x10(%rax)
movq -0x40(%rbp), %rdi
movb -0x1a(%rbp), %al
movzbl %al, %esi
movzbl -0x19(%rbp), %edx
callq 0x6b670
jmp 0x6b609
cmpl $0x62, -0x2c(%rbp)
jne 0x6b58a
movq -0x10(%rbp), %rdi
callq 0x16f80
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x6b588
jmp 0x6b62f
jmp 0x6b607
cmpl $0x83, -0x2c(%rbp)
jne 0x6b605
movq -0x10(%rbp), %rdi
callq 0x16f80
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x6b5ac
jmp 0x6b62f
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x92f0
subl $0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x54(%rbp), %edx
callq 0x69b50
movq -0x60(%rbp), %rdi
movq %rax, %rsi
movl -0x54(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %edx
xorl %ecx, %ecx
leaq -0x61c70(%rip), %r8     # 0x9990
callq 0x10900
jmp 0x6b607
jmp 0x6b609
jmp 0x6b60b
cmpq $0x0, -0x40(%rbp)
je 0x6b61b
movq -0x40(%rbp), %rdi
callq 0x12e00
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x6b65f
movq -0x10(%rbp), %rax
movb $0x1, 0x50(%rax)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x9cd0
movq -0x40(%rbp), %rdi
callq 0x17020
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movl $0x7, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)