// File: /workspace/github_c_makefile_star2_O1/been-jamming[P]MinimalCC/expression.c
// Function: cast
void cast(value *v, type t, unsigned char do_warn, FILE *output_file){
	type t_copy;
	type_entry entry1;
	type_entry entry2;

	if(types_equal(&(v->data_type), &VOID_TYPE) && !types_equal(&t, &VOID_TYPE)){
		snprintf(error_message, sizeof(error_message), "Can't cast void type to non-void type");
		do_error(1);
	}

	if(peek_type(&t) == type_list){
		snprintf(error_message, sizeof(error_message), "Can't cast to an array");
		do_error(1);
	}

	if(type_size(&(v->data_type), 0) == 4 && type_size(&t, 0) == 1){
		if(v->data.type == data_register){
			fileprint(output_file, "sll $s%d, $s%d, 24\n", v->data.reg, v->data.reg);
			fileprint(output_file, "sra $s%d, $s%d, 24\n", v->data.reg, v->data.reg);
		} else if(v->data.type == data_stack){
			fileprint(output_file, "lw $t0, %d($sp)\n", get_stack_pos(v->data));
			fileprint(output_file, "sll $t0, $t0, 24\n");
			fileprint(output_file, "sra $t0, $t0, 24\n");
			fileprint(output_file, "sw $t0, %d($sp)\n", get_stack_pos(v->data));
		}
	} else if(type_size(&(v->data_type), 0) == 1 && type_size(&t, 0) == 4){
		if(v->data.type == data_stack){
			fileprint(output_file, "lb $t0, %d($sp)\n", get_stack_pos(v->data));
			fileprint(output_file, "sw $t0, %d($sp)\n", get_stack_pos(v->data));
		}
	}

	t_copy = t;
	entry1 = pop_type(&t_copy);
	entry2 = pop_type(&(v->data_type));
	if((entry1 == type_pointer) != (entry2 == type_pointer) && do_warn){
		snprintf(warning_message, sizeof(warning_message), "Casting between pointer and non-pointer types");
		do_warning();
	} else if(entry1 == type_pointer && !types_equal(&t_copy, &(v->data_type)) && !types_equal(&t_copy, &VOID_TYPE) && !types_equal(&(v->data_type), &VOID_TYPE) && do_warn){
		snprintf(warning_message, sizeof(warning_message), "Casting between incompatible pointer types");
		do_warning();
	}

	v->data_type = t;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %r12
leaq 0x80(%rsp), %r14
leaq 0x10(%rdi), %rbx
leaq 0x9daf(%rip), %rsi      # 0xd1c0
movq %rbx, %rdi
callq 0x7ab1
testb %al, %al
je 0x3464
leaq 0x9d9c(%rip), %rsi      # 0xd1c0
movq %r14, %rdi
callq 0x7ab1
testb %al, %al
jne 0x3464
movups 0x61da(%rip), %xmm0     # 0x9611
leaq 0xa0a2(%rip), %rax      # 0xd4e0
movaps %xmm0, 0x10(%rax)
movups 0x61b8(%rip), %xmm0     # 0x9601
movaps %xmm0, (%rax)
movabsq $0x65707974206469, %rcx # imm = 0x65707974206469
movq %rcx, 0x1e(%rax)
movl $0x1, %edi
callq 0x5ae0
movq %r14, %rdi
callq 0x7a61
cmpl $0x7, %eax
jne 0x349a
movups 0x61af(%rip), %xmm0     # 0x9627
leaq 0xa061(%rip), %rax      # 0xd4e0
movaps %xmm0, (%rax)
movabsq $0x7961727261206e, %rcx # imm = 0x7961727261206E
movq %rcx, 0xf(%rax)
movl $0x1, %edi
callq 0x5ae0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1984
cmpl $0x1, %eax
je 0x3518
movl %eax, %r13d
cmpl $0x4, %eax
jne 0x35bd
movq %r14, %rdi
xorl %esi, %esi
callq 0x1984
cmpl $0x1, %eax
jne 0x350e
movl (%r12), %eax
cmpl $0x1, %eax
je 0x3559
testl %eax, %eax
jne 0x35bd
movl 0x4(%r12), %ecx
leaq 0x6159(%rip), %rsi      # 0x963e
movq %r15, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x1710
movl 0x4(%r12), %ecx
leaq 0x6155(%rip), %rsi      # 0x9652
movq %r15, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x1710
jmp 0x35bd
cmpl $0x1, %r13d
jne 0x35bd
movq %r14, %rdi
xorl %esi, %esi
callq 0x1984
cmpl $0x4, %eax
jne 0x35bd
cmpl $0x1, (%r12)
jne 0x35bd
movq (%r12), %rdi
movl 0x8(%r12), %esi
callq 0x15ba
leaq 0x6150(%rip), %rsi      # 0x969b
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
jmp 0x359c
movq (%r12), %rdi
movl 0x8(%r12), %esi
callq 0x15ba
leaq 0x60f8(%rip), %rsi      # 0x9666
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
leaq 0x60f6(%rip), %rsi      # 0x9677
movq %r15, %rdi
xorl %eax, %eax
callq 0x1710
leaq 0x60f7(%rip), %rsi      # 0x9689
movq %r15, %rdi
xorl %eax, %eax
callq 0x1710
movq (%r12), %rdi
movl 0x8(%r12), %esi
callq 0x15ba
leaq 0x6024(%rip), %rsi      # 0x95d5
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups 0x30(%r14), %xmm3
movq %rsp, %rdi
movaps %xmm3, 0x30(%rdi)
movaps %xmm2, 0x20(%rdi)
movaps %xmm1, 0x10(%rdi)
movaps %xmm0, (%rdi)
callq 0x7a79
movl %eax, %r15d
movq %rbx, %rdi
callq 0x7a79
cmpl $0x4, %r15d
sete %cl
cmpl $0x4, %eax
sete %al
testb %bpl, %bpl
je 0x3638
xorb %al, %cl
je 0x3638
movups 0x60bb(%rip), %xmm0     # 0x96ca
leaq 0x9dca(%rip), %rax      # 0xd3e0
movups %xmm0, 0x1e(%rax)
movups 0x609b(%rip), %xmm0     # 0x96bc
movaps %xmm0, 0x10(%rax)
movups 0x6080(%rip), %xmm0     # 0x96ac
movaps %xmm0, (%rax)
xorl %eax, %eax
callq 0x5ac8
jmp 0x3660
cmpl $0x4, %r15d
jne 0x3660
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x7ab1
testb %al, %al
jne 0x3660
leaq 0x9b6c(%rip), %rsi      # 0xd1c0
movq %rsp, %rdi
callq 0x7ab1
testb %al, %al
je 0x3691
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups 0x30(%r14), %xmm3
movups %xmm3, 0x30(%rbx)
movups %xmm2, 0x20(%rbx)
movups %xmm1, 0x10(%rbx)
movups %xmm0, (%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9b28(%rip), %rsi      # 0xd1c0
movq %rbx, %rdi
callq 0x7ab1
testb %bpl, %bpl
je 0x3660
testb %al, %al
jne 0x3660
movups 0x6045(%rip), %xmm0     # 0x96f5
leaq 0x9d29(%rip), %rax      # 0xd3e0
movups %xmm0, 0x1b(%rax)
movups 0x6028(%rip), %xmm0     # 0x96ea
movaps %xmm0, 0x10(%rax)
movups 0x600d(%rip), %xmm0     # 0x96da
jmp 0x362c