// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x40, %rsp
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %r12
leaq 0x70(%rsp), %r14
leaq 0x10(%rdi), %rbx
leaq 0x9071(%rip), %rsi      # 0xc1c0
movq %rbx, %rdi
callq 0x7653
testb %al, %al
je 0x31a0
leaq 0x905e(%rip), %rsi      # 0xc1c0
movq %r14, %rdi
callq 0x7653
testb %al, %al
jne 0x31a0
movups 0x547c(%rip), %xmm0     # 0x85f1
leaq 0x9364(%rip), %rax      # 0xc4e0
movaps %xmm0, 0x10(%rax)
movups 0x545a(%rip), %xmm0     # 0x85e1
movaps %xmm0, (%rax)
movabsq $0x65707974206469, %rcx # imm = 0x65707974206469
movq %rcx, 0x1e(%rax)
pushq $0x1
popq %rdi
callq 0x56c5
movq %r14, %rdi
callq 0x7603
cmpl $0x7, %eax
jne 0x31d4
movups 0x5453(%rip), %xmm0     # 0x8607
leaq 0x9325(%rip), %rax      # 0xc4e0
movaps %xmm0, (%rax)
movabsq $0x7961727261206e, %rcx # imm = 0x7961727261206E
movq %rcx, 0xf(%rax)
pushq $0x1
popq %rdi
callq 0x56c5
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1756
cmpl $0x1, %eax
je 0x3245
cmpl $0x4, %eax
jne 0x32ea
movq %r14, %rdi
xorl %esi, %esi
callq 0x1756
cmpl $0x1, %eax
jne 0x32ea
movl (%r12), %eax
cmpl $0x1, %eax
je 0x3286
testl %eax, %eax
jne 0x32ea
movl 0x4(%r12), %ecx
leaq 0x5402(%rip), %rsi      # 0x861e
movq %r15, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x14e8
movl 0x4(%r12), %ecx
leaq 0x53fe(%rip), %rsi      # 0x8632
movq %r15, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x14e8
jmp 0x32ea
movq %r14, %rdi
xorl %esi, %esi
callq 0x1756
cmpl $0x4, %eax
jne 0x32ea
cmpl $0x1, (%r12)
jne 0x32ea
movq (%r12), %rdi
movl 0x8(%r12), %esi
callq 0x1393
leaq 0x5403(%rip), %rsi      # 0x867b
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x14e8
jmp 0x32c9
movq (%r12), %rdi
movl 0x8(%r12), %esi
callq 0x1393
leaq 0x53ab(%rip), %rsi      # 0x8646
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x14e8
leaq 0x53a9(%rip), %rsi      # 0x8657
movq %r15, %rdi
xorl %eax, %eax
callq 0x14e8
leaq 0x53aa(%rip), %rsi      # 0x8669
movq %r15, %rdi
xorl %eax, %eax
callq 0x14e8
movq (%r12), %rdi
movl 0x8(%r12), %esi
callq 0x1393
leaq 0x52d7(%rip), %rsi      # 0x85b5
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x14e8
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 0x761b
movl %eax, %r15d
movq %rbx, %rdi
callq 0x761b
cmpl $0x4, %r15d
sete %cl
cmpl $0x4, %eax
sete %al
testb %bpl, %bpl
je 0x3365
xorb %al, %cl
je 0x3365
movups 0x536e(%rip), %xmm0     # 0x86aa
leaq 0x909d(%rip), %rax      # 0xc3e0
movups %xmm0, 0x1e(%rax)
movups 0x534e(%rip), %xmm0     # 0x869c
movaps %xmm0, 0x10(%rax)
movups 0x5333(%rip), %xmm0     # 0x868c
movaps %xmm0, (%rax)
xorl %eax, %eax
callq 0x5688
jmp 0x338d
cmpl $0x4, %r15d
jne 0x338d
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x7653
testb %al, %al
jne 0x338d
leaq 0x8e3f(%rip), %rsi      # 0xc1c0
movq %rsp, %rdi
callq 0x7653
testb %al, %al
je 0x33bc
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 $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8dfd(%rip), %rsi      # 0xc1c0
movq %rbx, %rdi
callq 0x7653
testb %bpl, %bpl
je 0x338d
testb %al, %al
jne 0x338d
movups 0x52fa(%rip), %xmm0     # 0x86d5
leaq 0x8ffe(%rip), %rax      # 0xc3e0
movups %xmm0, 0x1b(%rax)
movups 0x52dd(%rip), %xmm0     # 0x86ca
movaps %xmm0, 0x10(%rax)
movups 0x52c2(%rip), %xmm0     # 0x86ba
jmp 0x3359