// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xc8, %rsp
movb %sil, %al
leaq 0xd0(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movq %rdi, 0xc0(%rsp)
movb %al, 0xbf(%rsp)
movq %rdx, 0xb0(%rsp)
movq 0xc0(%rsp), %rdi
addq $0x10, %rdi
leaq 0xd1f7(%rip), %rsi      # 0x11208
callq 0xbec0
movzbl %al, %eax
cmpl $0x0, %eax
je 0x4057
movq 0x20(%rsp), %rdi
leaq 0xd1de(%rip), %rsi      # 0x11208
callq 0xbec0
cmpb $0x0, %al
jne 0x4057
leaq 0xd4f6(%rip), %rdi      # 0x11530
movl $0x100, %esi            # imm = 0x100
leaq 0x97bf(%rip), %rdx      # 0xd805
movb $0x0, %al
callq 0x10b0
movl $0x1, %edi
callq 0x87b0
movq 0x20(%rsp), %rdi
callq 0xbdb0
cmpl $0x7, %eax
jne 0x408a
leaq 0xd4c3(%rip), %rdi      # 0x11530
movl $0x100, %esi            # imm = 0x100
leaq 0x97b2(%rip), %rdx      # 0xd82b
movb $0x0, %al
callq 0x10b0
movl $0x1, %edi
callq 0x87b0
movq 0xc0(%rsp), %rdi
addq $0x10, %rdi
xorl %esi, %esi
callq 0x1a40
cmpl $0x4, %eax
jne 0x41f7
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x1a40
cmpl $0x1, %eax
jne 0x41f7
movq 0xc0(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x4125
movq 0xb0(%rsp), %rdi
movq 0xc0(%rsp), %rax
movl 0x4(%rax), %edx
movq 0xc0(%rsp), %rax
movl 0x4(%rax), %ecx
leaq 0x9755(%rip), %rsi      # 0xd842
movb $0x0, %al
callq 0x16f0
movq 0xb0(%rsp), %rdi
movq 0xc0(%rsp), %rax
movl 0x4(%rax), %edx
movq 0xc0(%rsp), %rax
movl 0x4(%rax), %ecx
leaq 0x973d(%rip), %rsi      # 0xd856
movb $0x0, %al
callq 0x16f0
jmp 0x41f2
movq 0xc0(%rsp), %rax
cmpl $0x1, (%rax)
jne 0x41f0
movq 0xb0(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xc0(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x58(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x60(%rsp)
movq 0x58(%rsp), %rdi
movl 0x60(%rsp), %esi
callq 0x1490
movq 0x10(%rsp), %rdi
movl %eax, %edx
leaq 0x96f4(%rip), %rsi      # 0xd86a
movb $0x0, %al
callq 0x16f0
movq 0xb0(%rsp), %rdi
leaq 0x96ef(%rip), %rsi      # 0xd87b
movb $0x0, %al
callq 0x16f0
movq 0xb0(%rsp), %rdi
leaq 0x96eb(%rip), %rsi      # 0xd88d
movb $0x0, %al
callq 0x16f0
movq 0xb0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xc0(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x48(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rdi
movl 0x50(%rsp), %esi
callq 0x1490
movq 0x18(%rsp), %rdi
movl %eax, %edx
leaq 0x95f0(%rip), %rsi      # 0xd7d9
movb $0x0, %al
callq 0x16f0
jmp 0x41f2
jmp 0x42c9
movq 0xc0(%rsp), %rdi
addq $0x10, %rdi
xorl %esi, %esi
callq 0x1a40
cmpl $0x1, %eax
jne 0x42c7
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x1a40
cmpl $0x4, %eax
jne 0x42c7
movq 0xc0(%rsp), %rax
cmpl $0x1, (%rax)
jne 0x42c5
movq 0xb0(%rsp), %rax
movq %rax, (%rsp)
movq 0xc0(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x38(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x40(%rsp)
movq 0x38(%rsp), %rdi
movl 0x40(%rsp), %esi
callq 0x1490
movq (%rsp), %rdi
movl %eax, %edx
leaq 0x9628(%rip), %rsi      # 0xd89f
movb $0x0, %al
callq 0x16f0
movq 0xb0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xc0(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x28(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x30(%rsp)
movq 0x28(%rsp), %rdi
movl 0x30(%rsp), %esi
callq 0x1490
movq 0x8(%rsp), %rdi
movl %eax, %edx
leaq 0x951b(%rip), %rsi      # 0xd7d9
movb $0x0, %al
callq 0x16f0
jmp 0x42c7
jmp 0x42c9
movq 0x20(%rsp), %rsi
leaq 0x70(%rsp), %rdi
movl $0x40, %edx
callq 0x1120
leaq 0x70(%rsp), %rdi
callq 0xbe20
movl %eax, 0x6c(%rsp)
movq 0xc0(%rsp), %rdi
addq $0x10, %rdi
callq 0xbe20
movl %eax, 0x68(%rsp)
cmpl $0x4, 0x6c(%rsp)
sete %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x4, 0x68(%rsp)
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x4352
movzbl 0xbf(%rsp), %eax
cmpl $0x0, %eax
je 0x4352
leaq 0xd0fd(%rip), %rdi      # 0x11430
movl $0x100, %esi            # imm = 0x100
leaq 0x9571(%rip), %rdx      # 0xd8b0
movb $0x0, %al
callq 0x10b0
movb $0x0, %al
callq 0x8770
jmp 0x43d4
cmpl $0x4, 0x6c(%rsp)
jne 0x43d2
movq 0xc0(%rsp), %rsi
addq $0x10, %rsi
leaq 0x70(%rsp), %rdi
callq 0xbec0
cmpb $0x0, %al
jne 0x43d2
leaq 0x70(%rsp), %rdi
leaq 0xce89(%rip), %rsi      # 0x11208
callq 0xbec0
cmpb $0x0, %al
jne 0x43d2
movq 0xc0(%rsp), %rdi
addq $0x10, %rdi
leaq 0xce6d(%rip), %rsi      # 0x11208
callq 0xbec0
cmpb $0x0, %al
jne 0x43d2
movzbl 0xbf(%rsp), %eax
cmpl $0x0, %eax
je 0x43d2
leaq 0xd078(%rip), %rdi      # 0x11430
movl $0x100, %esi            # imm = 0x100
leaq 0x951a(%rip), %rdx      # 0xd8de
movb $0x0, %al
callq 0x10b0
movb $0x0, %al
callq 0x8770
jmp 0x43d4
movq 0x20(%rsp), %rsi
movq 0xc0(%rsp), %rdi
addq $0x10, %rdi
movl $0x40, %edx
callq 0x1120
addq $0xc8, %rsp
retq
nopw (%rax,%rax)