// File: /workspace/github_c_makefile_star2_O2/lucvoo[P]sparse-dev/evaluate.c
// Function: evaluate_sizeof
static struct symbol *evaluate_sizeof(struct expression *expr)
{
	struct symbol *type;
	int size;

	type = evaluate_type_information(expr);
	if (!type)
		return NULL;

	size = type->bit_size;

	if (size < 0 && is_void_type(type)) {
		if (Wpointer_arith)
			warning(expr->pos, "expression using sizeof(void)");
		size = bits_in_char;
	}

	if (is_bool_type(type)) {
		if (Wsizeof_bool)
			warning(expr->pos, "expression using sizeof _Bool");
		size = bits_to_bytes(bits_in_bool) * bits_in_char;
	}

	if (is_function(type->ctype.base_type)) {
		if (Wpointer_arith)
			warning(expr->pos, "expression using sizeof on a function");
		size = bits_in_char;
	}

	if (has_flexible_array(type) && Wflexible_array_sizeof)
		warning(expr->pos, "using sizeof on a flexible structure");

	if (is_array_type(type) && size < 0) {	// VLA, 1-dimension only
		struct expression *base, *size;
		struct symbol *base_type;

		if (type->type == SYM_NODE)
			type = type->ctype.base_type;	// strip the SYM_NODE
		base_type = get_base_type(type);
		if (!base_type)
			goto error;
		if (base_type->bit_size <= 0) {
			base = alloc_expression(expr->pos, EXPR_SIZEOF);
			base->cast_type = base_type;
			if (!evaluate_sizeof(base))
				goto error;
		} else {
			base = alloc_expression(expr->pos, EXPR_VALUE);
			base->value = bits_to_bytes(base_type->bit_size);
			base->ctype = size_t_ctype;
		}
		size = alloc_expression(expr->pos, EXPR_CAST);
		size->cast_type = size_t_ctype;
		size->cast_expression = type->array_size;
		if (!evaluate_expression(size))
			goto error;
		expr->left = size;
		expr->right = base;
		expr->type = EXPR_BINOP;
		expr->op = '*';
		return expr->ctype = size_t_ctype;
	}

error:
	if ((size < 0) || (size & (bits_in_char - 1)))
		expression_error(expr, "cannot size expression");

	expr->type = EXPR_VALUE;
	expr->value = bits_to_bytes(size);
	expr->taint = 0;
	expr->ctype = size_t_ctype;
	return size_t_ctype;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
callq 0x316ee
testq %rax, %rax
je 0x2fad1
movq %rax, %r14
movl 0x50(%rax), %r13d
movzbl (%rax), %eax
testl %r13d, %r13d
jns 0x2fa7c
movq %r14, %rcx
cmpl $0x3, %eax
jne 0x2fa47
movq 0x60(%r14), %rcx
cmpq 0x2a4fa(%rip), %rcx     # 0x59f48
jne 0x2fa7c
leaq 0x313cd(%rip), %rcx     # 0x60e24
cmpl $0x0, (%rcx)
je 0x2fa72
movq 0x8(%rbx), %rdi
leaq 0x13bf0(%rip), %rsi     # 0x43657
xorl %eax, %eax
callq 0x1108a
movzbl (%r14), %eax
leaq 0x2ec87(%rip), %rcx     # 0x5e700
movl (%rcx), %r13d
movq %r14, %rcx
cmpl $0x3, %eax
jne 0x2fa88
movq 0x60(%r14), %rcx
cmpq 0x2a551(%rip), %rcx     # 0x59fe0
jne 0x2fadf
leaq 0x3139c(%rip), %rax     # 0x60e34
cmpl $0x0, (%rax)
je 0x2faaf
movq 0x8(%rbx), %rdi
leaq 0x13bcd(%rip), %rsi     # 0x43675
xorl %eax, %eax
callq 0x1108a
leaq 0x2ec46(%rip), %rax     # 0x5e6fc
movl (%rax), %eax
leaq 0x2ec41(%rip), %rcx     # 0x5e700
movl (%rcx), %r13d
testl %eax, %eax
js 0x2fad8
addl %r13d, %eax
decl %eax
cltd
idivl %r13d
jmp 0x2fadb
xorl %eax, %eax
jmp 0x2fc8f
pushq $-0x1
popq %rax
imull %eax, %r13d
movq 0x60(%r14), %rax
testq %rax, %rax
je 0x2fb15
cmpb $0x5, (%rax)
jne 0x2fb15
leaq 0x31330(%rip), %rax     # 0x60e24
cmpl $0x0, (%rax)
je 0x2fb0b
movq 0x8(%rbx), %rdi
leaq 0x13b8f(%rip), %rsi     # 0x43693
xorl %eax, %eax
callq 0x1108a
leaq 0x2ebee(%rip), %rax     # 0x5e700
movl (%rax), %r13d
cmpb $0x3, (%r14)
movq %r14, %rax
jne 0x2fb22
movq 0x60(%r14), %rax
testb $0x40, 0x55(%rax)
je 0x2fb46
leaq 0x312d5(%rip), %rax     # 0x60e04
cmpl $0x0, (%rax)
je 0x2fb46
movq 0x8(%rbx), %rdi
leaq 0x13b7a(%rip), %rsi     # 0x436b9
xorl %eax, %eax
callq 0x1108a
movq %r14, %rdi
callq 0x31508
testl %eax, %eax
je 0x2fba7
testl %r13d, %r13d
jns 0x2fba7
cmpb $0x3, (%r14)
jne 0x2fb61
movq 0x60(%r14), %r14
movq %r14, %rdi
callq 0x310b8
testq %rax, %rax
je 0x2fc47
movq %rax, %r12
cmpl $0x0, 0x50(%rax)
movq 0x8(%rbx), %rdi
jle 0x2fbcc
pushq $0x1
popq %rsi
callq 0x30712
movq %rax, %r15
movl 0x50(%r12), %eax
testl %eax, %eax
js 0x2fbea
leaq 0x2eb66(%rip), %rcx     # 0x5e700
movl (%rcx), %ecx
addl %ecx, %eax
decl %eax
cltd
idivl %ecx
cltq
jmp 0x2fbed
testl %r13d, %r13d
js 0x2fc47
leaq 0x2eb49(%rip), %rax     # 0x5e700
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addl (%rax), %ecx
testl %r13d, %ecx
jne 0x2fc47
jmp 0x2fc58
pushq $0xe
popq %rsi
callq 0x30712
movq %rax, %r15
movq %r12, 0x20(%rax)
movq %rax, %rdi
callq 0x2fa12
testq %rax, %rax
jne 0x2fbff
jmp 0x2fc47
pushq $-0x1
popq %rax
movq %rax, 0x20(%r15)
leaq 0x2ea28(%rip), %rax     # 0x5e620
movq (%rax), %rax
movq %rax, 0x10(%r15)
movq 0x8(%rbx), %rdi
pushq $0xb
popq %rsi
callq 0x30712
movq %rax, %r12
leaq 0x2ea0b(%rip), %rax     # 0x5e620
movq (%rax), %rax
movq %rax, 0x20(%r12)
movq 0x58(%r14), %rax
movq %rax, 0x28(%r12)
movq %r12, %rdi
callq 0x2d0ed
testq %rax, %rax
je 0x2fc47
movq %r12, 0x20(%rbx)
movq %r15, 0x28(%rbx)
movb $0x5, (%rbx)
movl $0x2a, 0x4(%rbx)
jmp 0x2fc81
leaq 0x13a90(%rip), %rsi     # 0x436de
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11292
movb $0x1, (%rbx)
testl %r13d, %r13d
js 0x2fc76
leaq 0x2ea99(%rip), %rax     # 0x5e700
movl (%rax), %ecx
leal (%rcx,%r13), %eax
decl %eax
cltd
idivl %ecx
cltq
jmp 0x2fc79
pushq $-0x1
popq %rax
movq %rax, 0x20(%rbx)
andl $0x0, 0x28(%rbx)
leaq 0x2e998(%rip), %rax     # 0x5e620
movq (%rax), %rax
movq %rax, 0x10(%rbx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq