// File: /workspace/github_c_makefile_star2_O3/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 0x9d8f(%rip), %rsi      # 0xd1c0
movq %rbx, %rdi
callq 0x7aec
testb %al, %al
je 0x3484
leaq 0x9d7c(%rip), %rsi      # 0xd1c0
movq %r14, %rdi
callq 0x7aec
testb %al, %al
jne 0x3484
movups 0x61ba(%rip), %xmm0     # 0x9611
leaq 0xa082(%rip), %rax      # 0xd4e0
movaps %xmm0, 0x10(%rax)
movups 0x6198(%rip), %xmm0     # 0x9601
movaps %xmm0, (%rax)
movabsq $0x65707974206469, %rcx # imm = 0x65707974206469
movq %rcx, 0x1e(%rax)
movl $0x1, %edi
callq 0x5b10
movq %r14, %rdi
callq 0x7a9c
cmpl $0x7, %eax
jne 0x34ba
movups 0x618f(%rip), %xmm0     # 0x9627
leaq 0xa041(%rip), %rax      # 0xd4e0
movaps %xmm0, (%rax)
movabsq $0x7961727261206e, %rcx # imm = 0x7961727261206E
movq %rcx, 0xf(%rax)
movl $0x1, %edi
callq 0x5b10
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1990
cmpl $0x1, %eax
je 0x352b
cmpl $0x4, %eax
jne 0x35d0
movq %r14, %rdi
xorl %esi, %esi
callq 0x1990
cmpl $0x1, %eax
jne 0x35d0
movl (%r12), %eax
cmpl $0x1, %eax
je 0x356c
testl %eax, %eax
jne 0x35d0
movl 0x4(%r12), %ecx
leaq 0x613c(%rip), %rsi      # 0x963e
movq %r15, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x171c
movl 0x4(%r12), %ecx
leaq 0x6138(%rip), %rsi      # 0x9652
movq %r15, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x171c
jmp 0x35d0
movq %r14, %rdi
xorl %esi, %esi
callq 0x1990
cmpl $0x4, %eax
jne 0x35d0
cmpl $0x1, (%r12)
jne 0x35d0
movq (%r12), %rdi
movl 0x8(%r12), %esi
callq 0x15ba
leaq 0x613d(%rip), %rsi      # 0x969b
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
jmp 0x35af
movq (%r12), %rdi
movl 0x8(%r12), %esi
callq 0x15ba
leaq 0x60e5(%rip), %rsi      # 0x9666
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
leaq 0x60e3(%rip), %rsi      # 0x9677
movq %r15, %rdi
xorl %eax, %eax
callq 0x171c
leaq 0x60e4(%rip), %rsi      # 0x9689
movq %r15, %rdi
xorl %eax, %eax
callq 0x171c
movq (%r12), %rdi
movl 0x8(%r12), %esi
callq 0x15ba
leaq 0x6011(%rip), %rsi      # 0x95d5
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
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 0x7ab4
movl %eax, %r15d
movq %rbx, %rdi
callq 0x7ab4
cmpl $0x4, %r15d
sete %cl
cmpl $0x4, %eax
sete %al
testb %bpl, %bpl
je 0x364b
xorb %al, %cl
je 0x364b
movups 0x60a8(%rip), %xmm0     # 0x96ca
leaq 0x9db7(%rip), %rax      # 0xd3e0
movups %xmm0, 0x1e(%rax)
movups 0x6088(%rip), %xmm0     # 0x96bc
movaps %xmm0, 0x10(%rax)
movups 0x606d(%rip), %xmm0     # 0x96ac
movaps %xmm0, (%rax)
xorl %eax, %eax
callq 0x5af8
jmp 0x3673
cmpl $0x4, %r15d
jne 0x3673
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x7aec
testb %al, %al
jne 0x3673
leaq 0x9b59(%rip), %rsi      # 0xd1c0
movq %rsp, %rdi
callq 0x7aec
testb %al, %al
je 0x36a2
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 0x9b17(%rip), %rsi      # 0xd1c0
movq %rbx, %rdi
callq 0x7aec
testb %bpl, %bpl
je 0x3673
testb %al, %al
jne 0x3673
movups 0x6034(%rip), %xmm0     # 0x96f5
leaq 0x9d18(%rip), %rax      # 0xd3e0
movups %xmm0, 0x1b(%rax)
movups 0x6017(%rip), %xmm0     # 0x96ea
movaps %xmm0, 0x10(%rax)
movups 0x5ffc(%rip), %xmm0     # 0x96da
jmp 0x363f