// File: /workspace/github_c_makefile_star2_O0/lucvoo[P]sparse-dev/evaluate.c
// Function: evaluate_cast
static struct symbol *evaluate_cast(struct expression *expr)
{
	struct expression *source = expr->cast_expression;
	struct symbol *ctype;
	struct symbol *ttype, *stype;
	struct symbol *member;
	int tclass, sclass;
	struct ident *tas = NULL, *sas = NULL;

	if (!source)
		return NULL;

	/*
	 * Special case: a cast can be followed by an
	 * initializer, in which case we need to pass
	 * the type value down to that initializer rather
	 * than trying to evaluate it as an expression
	 * (cfr. compound literals: C99 & C11 6.5.2.5).
	 *
	 * A more complex case is when the initializer is
	 * dereferenced as part of a post-fix expression.
	 * We need to produce an expression that can be dereferenced.
	 */
	if (source->type == EXPR_INITIALIZER)
		return evaluate_compound_literal(expr, source);

	ctype = examine_symbol_type(expr->cast_type);
	ctype = unqualify_type(ctype);
	expr->ctype = ctype;
	expr->cast_type = ctype;

	evaluate_expression(source);
	degenerate(source);

	tclass = classify_type(ctype, &ttype);

	expr->flags = cast_flags(expr, source);

	/*
	 * You can always throw a value away by casting to
	 * "void" - that's an implicit "force". Note that
	 * the same is _not_ true of "void *".
	 */
	if (ttype == &void_ctype)
		goto out;

	stype = source->ctype;
	if (!stype) {
		expression_error(expr, "cast from unknown type");
		goto out;
	}
	sclass = classify_type(stype, &stype);

	if (expr->type == EXPR_FORCE_CAST)
		goto out;

	if (tclass & (TYPE_COMPOUND | TYPE_FN)) {
		/*
		 * Special case: cast to union type (GCC extension)
		 * The effect is similar to a compound literal except
		 * that the result is a rvalue.
		 */
		if ((member = find_member_type(ttype, stype))) {
			struct expression *item, *init;

			if (Wunion_cast)
				warning(expr->pos, "cast to union type");

			item = alloc_expression(source->pos, EXPR_IDENTIFIER);
			item->expr_ident = member->ident;
			item->ident_expression = source;

			init = alloc_expression(source->pos, EXPR_INITIALIZER);
			add_expression(&init->expr_list, item);

			// FIXME: this should be a rvalue
			evaluate_compound_literal(expr, init);
			return ctype;
		}

		warning(expr->pos, "cast to non-scalar");
	}

	if (sclass & TYPE_COMPOUND)
		warning(expr->pos, "cast from non-scalar");

	/* allowed cast unfouls */
	if (sclass & TYPE_FOULED)
		stype = unfoul(stype);

	if (ttype != stype) {
		if ((tclass & TYPE_RESTRICT) && restricted_value(source, ttype))
			warning(expr->pos, "cast to %s",
				show_typename(ttype));
		if (sclass & TYPE_RESTRICT) {
			if (ttype == &bool_ctype) {
				if (sclass & TYPE_FOULED)
					warning(expr->pos, "%s degrades to integer",
						show_typename(stype));
			} else {
				warning(expr->pos, "cast from %s",
					show_typename(stype));
			}
		}
	}

	if ((ttype == &ulong_ctype || ttype == uintptr_ctype) && !Wcast_from_as)
		tas = &bad_address_space;
	else if (tclass == TYPE_PTR) {
		examine_pointer_target(ttype);
		tas = ttype->ctype.as;
	}

	if ((stype == &ulong_ctype || stype == uintptr_ctype))
		sas = &bad_address_space;
	else if (sclass == TYPE_PTR) {
		examine_pointer_target(stype);
		sas = stype->ctype.as;
	}

	if (!tas && valid_as(sas))
		warning(expr->pos, "cast removes address space '%s' of expression", show_as(sas));
	if (valid_as(tas) && valid_as(sas) && tas != sas)
		warning(expr->pos, "cast between address spaces (%s -> %s)", show_as(sas), show_as(tas));
	if (valid_as(tas) && !sas &&
	    !is_null_pointer_constant(source) && Wcast_to_as)
		warning(expr->pos,
			"cast adds address space '%s' to expression", show_as(tas));

	if (!(ttype->ctype.modifiers & MOD_PTRINHERIT) && tclass == TYPE_PTR &&
	    !tas && (source->flags & CEF_ICE)) {
		if (ttype->ctype.base_type == &void_ctype) {
			if (is_zero_constant(source)) {
				/* NULL */
				expr->type = EXPR_VALUE;
				expr->ctype = &null_ctype;
				expr->value = 0;
				return expr->ctype;
			}
		}
	}

	if (ttype == &bool_ctype)
		cast_to_bool(expr);

	// checks pointers to restricted
	while (Wbitwise_pointer && tclass == TYPE_PTR && sclass == TYPE_PTR) {
		tclass = classify_type(ttype->ctype.base_type, &ttype);
		sclass = classify_type(stype->ctype.base_type, &stype);
		if (ttype == stype)
			break;
		if (!ttype || !stype)
			break;
		if (ttype == &void_ctype || stype == &void_ctype)
			break;
		if (tclass & TYPE_RESTRICT) {
			warning(expr->pos, "cast to %s", show_typename(ctype));
			break;
		}
		if (sclass & TYPE_RESTRICT) {
			warning(expr->pos, "cast from %s", show_typename(source->ctype));
			break;
		}
	}
out:
	return ctype;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x4d88f
movq $0x0, -0x8(%rbp)
jmp 0x4df0e
movq -0x18(%rbp), %rax
movl (%rax), %eax
andl $0xff, %eax
cmpl $0x18, %eax
jne 0x4d8b5
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x534a0
movq %rax, -0x8(%rbp)
jmp 0x4df0e
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x3f650
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x50150
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rdi
callq 0x4bb70
movq -0x18(%rbp), %rdi
callq 0x4c1c0
movq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x4bf20
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x50b10
movl %eax, %edx
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $0xff, %edx
shll $0x8, %edx
andl $0xffff00ff, %ecx       # imm = 0xFFFF00FF
orl %edx, %ecx
movl %ecx, (%rax)
leaq 0x43bbc(%rip), %rax     # 0x914f8
cmpq %rax, -0x28(%rbp)
jne 0x4d947
jmp 0x4df06
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x4d971
movq -0x10(%rbp), %rdi
leaq 0x1e6d6(%rip), %rsi     # 0x6c03b
movb $0x0, %al
callq 0x17030
jmp 0x4df06
movq -0x30(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4bf20
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xff, %eax
cmpl $0xc, %eax
jne 0x4d996
jmp 0x4df06
movl -0x3c(%rbp), %eax
andl $0xa0, %eax
cmpl $0x0, %eax
je 0x4da6d
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x53580
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x4da57
leaq 0x3f85f(%rip), %rax     # 0x8d228
cmpl $0x0, (%rax)
je 0x4d9e4
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1e675(%rip), %rsi     # 0x6c052
movb $0x0, %al
callq 0x16d80
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x19, %esi
callq 0x50ab0
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x18, %esi
callq 0x50ab0
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
addq $0x20, %rdi
movq -0x58(%rbp), %rsi
callq 0x53680
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x534a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4df0e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1e5ff(%rip), %rsi     # 0x6c065
movb $0x0, %al
callq 0x16d80
movl -0x40(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x4da8e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1e5f1(%rip), %rsi     # 0x6c078
movb $0x0, %al
callq 0x16d80
movl -0x40(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x4daa6
movq -0x30(%rbp), %rdi
callq 0x512d0
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0x4db78
movl -0x3c(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x4dafb
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x512f0
cmpl $0x0, %eax
je 0x4dafb
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rdi
callq 0x33340
movq %rax, %rdx
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1e599(%rip), %rsi     # 0x6c08d
movb $0x0, %al
callq 0x16d80
movl -0x40(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x4db76
leaq 0x4390b(%rip), %rax     # 0x91418
cmpq %rax, -0x28(%rbp)
jne 0x4db4a
movl -0x40(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x4db48
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rdi
callq 0x33340
movq %rax, %rdx
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1e072(%rip), %rsi     # 0x6bbb3
movb $0x0, %al
callq 0x16d80
jmp 0x4db74
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rdi
callq 0x33340
movq %rax, %rdx
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1e52b(%rip), %rsi     # 0x6c098
movb $0x0, %al
callq 0x16d80
jmp 0x4db76
jmp 0x4db78
leaq 0x443f9(%rip), %rax     # 0x91f78
cmpq %rax, -0x28(%rbp)
je 0x4db95
movq -0x28(%rbp), %rax
leaq 0x467e0(%rip), %rcx     # 0x94370
cmpq (%rcx), %rax
jne 0x4dbae
leaq 0x3f62c(%rip), %rax     # 0x8d1c8
cmpl $0x0, (%rax)
jne 0x4dbae
leaq 0x3db28(%rip), %rax     # 0x8b6d0
movq %rax, -0x48(%rbp)
jmp 0x4dbce
cmpl $0x10, -0x3c(%rbp)
jne 0x4dbcc
movq -0x28(%rbp), %rdi
callq 0x40260
movq -0x28(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x4dbce
leaq 0x443a3(%rip), %rax     # 0x91f78
cmpq %rax, -0x30(%rbp)
je 0x4dbeb
movq -0x30(%rbp), %rax
leaq 0x4678a(%rip), %rcx     # 0x94370
cmpq (%rcx), %rax
jne 0x4dbf8
leaq 0x3dade(%rip), %rax     # 0x8b6d0
movq %rax, -0x50(%rbp)
jmp 0x4dc18
cmpl $0x10, -0x40(%rbp)
jne 0x4dc16
movq -0x30(%rbp), %rdi
callq 0x40260
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x4dc18
cmpq $0x0, -0x48(%rbp)
jne 0x4dc58
movq -0x50(%rbp), %rdi
callq 0x536b0
testb $0x1, %al
jne 0x4dc2e
jmp 0x4dc58
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x50(%rbp), %rdi
callq 0x32b40
movq %rax, %rdx
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1e454(%rip), %rsi     # 0x6c0a5
movb $0x0, %al
callq 0x16d80
movq -0x48(%rbp), %rdi
callq 0x536b0
testb $0x1, %al
jne 0x4dc67
jmp 0x4dcc7
movq -0x50(%rbp), %rdi
callq 0x536b0
testb $0x1, %al
jne 0x4dc76
jmp 0x4dcc7
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
je 0x4dcc7
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x50(%rbp), %rdi
callq 0x32b40
movq %rax, -0x90(%rbp)
movq -0x48(%rbp), %rdi
callq 0x32b40
movq -0x90(%rbp), %rdx
movq %rax, %rcx
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1e413(%rip), %rsi     # 0x6c0d3
movb $0x0, %al
callq 0x16d80
movq -0x48(%rbp), %rdi
callq 0x536b0
testb $0x1, %al
jne 0x4dcd6
jmp 0x4dd27
cmpq $0x0, -0x50(%rbp)
jne 0x4dd27
movq -0x18(%rbp), %rdi
callq 0x51c70
cmpl $0x0, %eax
jne 0x4dd27
leaq 0x3f4da(%rip), %rax     # 0x8d1cc
cmpl $0x0, (%rax)
je 0x4dd27
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x48(%rbp), %rdi
callq 0x32b40
movq %rax, %rdx
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1e3da(%rip), %rsi     # 0x6c0fa
movb $0x0, %al
callq 0x16d80
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
andq $0x1c001e00, %rax       # imm = 0x1C001E00
cmpq $0x0, %rax
jne 0x4ddc2
cmpl $0x10, -0x3c(%rbp)
jne 0x4ddc2
cmpq $0x0, -0x48(%rbp)
jne 0x4ddc2
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x8, %eax
andl $0xff, %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x4ddc2
movq -0x28(%rbp), %rax
leaq 0x4378b(%rip), %rcx     # 0x914f8
cmpq %rcx, 0x60(%rax)
jne 0x4ddc0
movq -0x18(%rbp), %rdi
callq 0x12290
cmpl $0x0, %eax
je 0x4ddbe
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
orl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
leaq 0x44fdb(%rip), %rcx     # 0x92d78
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x4df0e
jmp 0x4ddc0
jmp 0x4ddc2
leaq 0x4364f(%rip), %rax     # 0x91418
cmpq %rax, -0x28(%rbp)
jne 0x4ddd8
movq -0x10(%rbp), %rdi
callq 0x50c30
jmp 0x4ddda
xorl %eax, %eax
leaq 0x3f3e1(%rip), %rcx     # 0x8d1c4
cmpl $0x0, (%rcx)
movb %al, -0x99(%rbp)
je 0x4de09
xorl %eax, %eax
cmpl $0x10, -0x3c(%rbp)
movb %al, -0x99(%rbp)
jne 0x4de09
cmpl $0x10, -0x40(%rbp)
sete %al
movb %al, -0x99(%rbp)
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0x4de18
jmp 0x4df04
movq -0x28(%rbp), %rax
movq 0x60(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x4bf20
movl %eax, -0x3c(%rbp)
movq -0x30(%rbp), %rax
movq 0x60(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4bf20
movl %eax, -0x40(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jne 0x4de4f
jmp 0x4df04
cmpq $0x0, -0x28(%rbp)
je 0x4de5d
cmpq $0x0, -0x30(%rbp)
jne 0x4de62
jmp 0x4df04
leaq 0x4368f(%rip), %rax     # 0x914f8
cmpq %rax, -0x28(%rbp)
je 0x4de7c
leaq 0x43682(%rip), %rax     # 0x914f8
cmpq %rax, -0x30(%rbp)
jne 0x4de81
jmp 0x4df04
movl -0x3c(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x4debe
movq -0x10(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x20(%rbp), %rdi
callq 0x33340
movq %rax, %rdx
movq -0xa8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1e1d8(%rip), %rsi     # 0x6c08d
movb $0x0, %al
callq 0x16d80
jmp 0x4df04
movl -0x40(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x4deff
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x33340
movq %rax, %rdx
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1e1a2(%rip), %rsi     # 0x6c098
movb $0x0, %al
callq 0x16d80
jmp 0x4df04
jmp 0x4ddda
jmp 0x4df06
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax,%rax)