// File: /workspace/github_c_makefile_star2_O0/lucvoo[P]sparse-dev/expand.c
// Function: expand_dereference
static int expand_dereference(struct expression *expr)
{
	struct expression *unop = expr->unop;
	unsigned int offset;

	expand_expression(unop);

	/*
	 * NOTE! We get a bogus warning right now for some special
	 * cases: apparently I've screwed up the optimization of
	 * a zero-offset dereference, and the ctype is wrong.
	 *
	 * Leave the warning in anyway, since this is also a good
	 * test for me to get the type evaluation right..
	 */
	if (expr->ctype->ctype.modifiers & MOD_NODEREF)
		warning(unop->pos, "dereference of noderef expression");

	/*
	 * Is it "symbol" or "symbol + offset"?
	 */
	offset = 0;
	while (unop->type == EXPR_BINOP && unop->op == '+') {
		struct expression *right = unop->right;
		if (right->type != EXPR_VALUE)
			break;
		offset += right->value;
		unop = unop->left;
	}

	if (unop->type == EXPR_SYMBOL) {
		struct symbol *sym = unop->symbol;
		struct symbol *ctype = expr->ctype;
		struct expression *value = constant_symbol_value(sym, offset);

		/* Const symbol with a constant initializer? */
		if (value && value->ctype) {
			if (ctype->bit_size != value->ctype->bit_size)
				return UNSAFE;
			if (value->type == EXPR_VALUE) {
				if (!is_integral_type(ctype))
					return UNSAFE;
				if (is_bitfield_type(value->ctype))
					return UNSAFE;
				expr->type = EXPR_VALUE;
				expr->value = value->value;
				expr->taint = 0;
				return 0;
			} else if (value->type == EXPR_FVALUE) {
				if (!is_float_type(ctype))
					return UNSAFE;
				expr->type = EXPR_FVALUE;
				expr->fvalue = value->fvalue;
				return 0;
			}
		}

		/* Direct symbol dereference? Cheap and safe */
		return (sym->ctype.modifiers & (MOD_STATIC | MOD_EXTERN)) ? 2 : 1;
	}

	return UNSAFE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x11b30
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x68(%rax), %rax
andq $0x8000000, %rax        # imm = 0x8000000
cmpq $0x0, %rax
je 0x13faf
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x4e280(%rip), %rsi     # 0x62228
movb $0x0, %al
callq 0x16d80
movl $0x0, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $0xff, %ecx
xorl %eax, %eax
cmpl $0x5, %ecx
movb %al, -0x41(%rbp)
jne 0x13fda
movq -0x18(%rbp), %rax
cmpl $0x2b, 0x4(%rax)
sete %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x13fe3
jmp 0x14020
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0xff, %eax
cmpl $0x1, %eax
je 0x14001
jmp 0x14020
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rcx
movl -0x1c(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x13fb6
movq -0x18(%rbp), %rax
movl (%rax), %eax
andl $0xff, %eax
cmpl $0x3, %eax
jne 0x1417d
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x143b0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x1415b
movq -0x40(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x1415b
movq -0x38(%rbp), %rax
movl 0x50(%rax), %eax
movq -0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
cmpl 0x50(%rcx), %eax
je 0x14096
movl $0x64, -0x4(%rbp)
jmp 0x14184
movq -0x40(%rbp), %rax
movl (%rax), %eax
andl $0xff, %eax
cmpl $0x1, %eax
jne 0x14112
movq -0x38(%rbp), %rdi
callq 0x14530
testb $0x1, %al
jne 0x140bf
movl $0x64, -0x4(%rbp)
jmp 0x14184
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x145b0
cmpl $0xb, %eax
jne 0x140dd
movl $0x64, -0x4(%rbp)
jmp 0x14184
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
orl $0x1, %ecx
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x28(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x14184
movq -0x40(%rbp), %rax
movl (%rax), %eax
andl $0xff, %eax
cmpl $0x1c, %eax
jne 0x14157
movq -0x38(%rbp), %rdi
callq 0x11980
cmpl $0x0, %eax
jne 0x14139
movl $0x64, -0x4(%rbp)
jmp 0x14184
movq -0x10(%rbp), %rax
movb $0x1c, (%rax)
movq -0x40(%rbp), %rax
fldt 0x20(%rax)
movq -0x10(%rbp), %rax
fstpt 0x20(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x14184
jmp 0x14159
jmp 0x1415b
movq -0x30(%rbp), %rax
movq 0x68(%rax), %rdx
andq $0xc, %rdx
movl $0x1, %eax
movl $0x2, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x14184
movl $0x64, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)