// File: /workspace/github_c_makefile_star2_O0/lucvoo[P]sparse-dev/expand.c
// Function: cast_value
void cast_value(struct expression *expr, struct symbol *newtype, struct expression *old)
{
	struct symbol *oldtype = old->ctype;
	int old_size = oldtype->bit_size;
	int new_size = newtype->bit_size;
	long long value, mask, signmask;
	long long oldmask, oldsignmask, dropped;

	if (is_float_type(newtype) || is_float_type(oldtype))
		goto Float;

	// For pointers and integers, we can just move the value around
	expr->type = EXPR_VALUE;
	expr->taint = old->taint;
	if (old_size == new_size) {
		expr->value = old->value;
		expr->ctype = newtype;
		return;
	}

	// expand it to the full "long long" value
	value = get_longlong(old);
	expr->ctype = newtype;

Int:
	// _Bool requires a zero test rather than truncation.
	if (is_bool_type(newtype)) {
		expr->value = !!value;
		if (!conservative && value != 0 && value != 1)
			warning(old->pos, "odd constant _Bool cast (%llx becomes 1)", value);
		return;
	}

	// Truncate it to the new size
	signmask = 1ULL << (new_size-1);
	mask = signmask | (signmask-1);
	expr->value = value & mask;

	// Stop here unless checking for truncation
	if (!Wcast_truncate || conservative)
		return;
	
	// Check if we dropped any bits..
	oldsignmask = 1ULL << (old_size-1);
	oldmask = oldsignmask | (oldsignmask-1);
	dropped = oldmask & ~mask;

	// OK if the bits were (and still are) purely sign bits
	if (value & dropped) {
		if (!(value & oldsignmask) || !(value & signmask) || (value & dropped) != dropped)
			warning(old->pos, "cast truncates bits from constant value (%llx becomes %llx)",
				value & oldmask,
				value & mask);
	}
	return;

Float:
	if (!is_float_type(newtype)) {
		value = (long long)old->fvalue;
		expr->type = EXPR_VALUE;
		expr->taint = 0;
		expr->ctype = newtype;
		goto Int;
	}

	if (!is_float_type(oldtype))
		expr->fvalue = (long double)get_longlong(old);
	else
		expr->fvalue = old->fvalue;

	if (newtype->rank <= 0) {
		if (newtype->rank == 0)
			expr->fvalue = (double)expr->fvalue;
		else
			expr->fvalue = (float)expr->fvalue;
	}
	expr->type = EXPR_FVALUE;
	expr->ctype = newtype;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x11980
cmpl $0x0, %eax
jne 0x11693
movq -0x20(%rbp), %rdi
callq 0x11980
cmpl $0x0, %eax
je 0x11698
jmp 0x1184d
movq -0x8(%rbp), %rax
movl (%rax), %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
orl $0x1, %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x28(%rax)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jne 0x116e0
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x1196d
movq -0x18(%rbp), %rdi
callq 0x119c0
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rdi
callq 0x11a60
cmpl $0x0, %eax
je 0x11759
cmpq $0x0, -0x30(%rbp)
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x20(%rax)
cmpl $0x0, 0x7a146(%rip)     # 0x8b870
jne 0x11754
cmpq $0x0, -0x30(%rbp)
je 0x11754
cmpq $0x1, -0x30(%rbp)
je 0x11754
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rdx
movq 0x8(%rax), %rdi
leaq 0x509b3(%rip), %rsi     # 0x62100
movb $0x0, %al
callq 0x16d80
jmp 0x1196d
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x40(%rbp), %rcx
subq $0x1, %rcx
orq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rcx
andq -0x38(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x20(%rax)
leaq 0x73077(%rip), %rax     # 0x84810
cmpl $0x0, (%rax)
je 0x117a7
cmpl $0x0, 0x7a0cb(%rip)     # 0x8b870
je 0x117ac
jmp 0x1196d
movl -0x24(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x50(%rbp), %rcx
subq $0x1, %rcx
orq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
andq -0x58(%rbp), %rax
cmpq $0x0, %rax
je 0x11848
movq -0x30(%rbp), %rax
andq -0x50(%rbp), %rax
cmpq $0x0, %rax
je 0x11820
movq -0x30(%rbp), %rax
andq -0x40(%rbp), %rax
cmpq $0x0, %rax
je 0x11820
movq -0x30(%rbp), %rax
andq -0x58(%rbp), %rax
cmpq -0x58(%rbp), %rax
je 0x11846
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rdx
andq -0x48(%rbp), %rdx
movq -0x30(%rbp), %rcx
andq -0x38(%rbp), %rcx
movq 0x8(%rax), %rdi
leaq 0x508ea(%rip), %rsi     # 0x62129
movb $0x0, %al
callq 0x16d80
jmp 0x11848
jmp 0x1196d
movq -0x10(%rbp), %rdi
callq 0x11980
cmpl $0x0, %eax
jne 0x118bf
movq -0x18(%rbp), %rax
fldt 0x20(%rax)
fnstcw -0x82(%rbp)
movzwl -0x82(%rbp), %eax
orl $0xc00, %eax            # imm = 0xC00
movw %ax, -0x84(%rbp)
fldcw -0x84(%rbp)
fistpll -0x60(%rbp)
fldcw -0x82(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
orl $0x1, %ecx
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x116f9
movq -0x20(%rbp), %rdi
callq 0x11980
cmpl $0x0, %eax
jne 0x118e6
movq -0x18(%rbp), %rdi
callq 0x119c0
movq %rax, -0x68(%rbp)
fildll -0x68(%rbp)
movq -0x8(%rbp), %rax
fstpt 0x20(%rax)
jmp 0x118f4
movq -0x18(%rbp), %rax
fldt 0x20(%rax)
movq -0x8(%rbp), %rax
fstpt 0x20(%rax)
movq -0x10(%rbp), %rax
movl 0x54(%rax), %eax
shll $0x6, %eax
sarl $0x1d, %eax
cmpl $0x0, %eax
jg 0x11950
movq -0x10(%rbp), %rax
movl 0x54(%rax), %eax
shll $0x6, %eax
sarl $0x1d, %eax
cmpl $0x0, %eax
jne 0x11934
movq -0x8(%rbp), %rax
fldt 0x20(%rax)
fstpl -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
fldl -0x80(%rbp)
fstpt 0x20(%rax)
jmp 0x1194e
movq -0x8(%rbp), %rax
fldt 0x20(%rax)
fstps -0x6c(%rbp)
movss -0x6c(%rbp), %xmm0
movss %xmm0, -0x70(%rbp)
flds -0x70(%rbp)
fstpt 0x20(%rax)
jmp 0x11950
movq -0x8(%rbp), %rax
movl (%rax), %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
orl $0x1c, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)