// File: /workspace/github_c_makefile_star2_O1/been-jamming[P]MinimalCC/expression.c
// Function: compile_dereference
void compile_dereference(value *v, FILE *output_file){
	type data_type;

	data_type = v->data_type;
	if(pop_type(&data_type) != type_pointer){
		snprintf(error_message, sizeof(error_message), "Cannot dereference non-pointer type");
		do_error(1);
	}
	if(peek_type(&data_type) == type_void){
		snprintf(error_message, sizeof(error_message), "Cannot dereference void pointer");
		do_error(1);
	}
	if(peek_type(&data_type) == type_list){
		pop_type(&data_type);
		data_type.current_index--;
		add_type_entry(&data_type, type_pointer);
	} else if(peek_type(&data_type) != type_function){
		if(v->data.type == data_register){
			if(type_size(&data_type, 0) == 1){
				fileprint(output_file, "lb $s%d, 0($s%d)\n", v->data.reg, v->data.reg);
			} else if(type_size(&data_type, 0) == 4){
				fileprint(output_file, "lw $s%d, 0($s%d)\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));
			if(type_size(&data_type, 0) == 1){
				fileprint(output_file, "lb $t0, 0($t0)\n");
				fileprint(output_file, "sb $t0, %d($sp)\n", get_stack_pos(v->data));
			} else if(type_size(&data_type, 0) == 4){
				fileprint(output_file, "lw $t0, 0($t0)\n");
				fileprint(output_file, "sw $t0, %d($sp)\n", get_stack_pos(v->data));
			}
		}
	}

	v->data_type = data_type;
	v->is_reference = 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x40, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movups 0x10(%rdi), %xmm0
movups 0x20(%rdi), %xmm1
movups 0x30(%rdi), %xmm2
movups 0x40(%rdi), %xmm3
movq %rsp, %rdi
movaps %xmm3, 0x30(%rdi)
movaps %xmm2, 0x20(%rdi)
movaps %xmm1, 0x10(%rdi)
movaps %xmm0, (%rdi)
callq 0x7a79
cmpl $0x4, %eax
je 0x373a
movups 0x6001(%rip), %xmm0     # 0x9715
leaq 0x9dc5(%rip), %rax      # 0xd4e0
movaps %xmm0, 0x10(%rax)
movups 0x5fdf(%rip), %xmm0     # 0x9705
movaps %xmm0, (%rax)
movl $0x657079, 0x20(%rax)   # imm = 0x657079
movl $0x1, %edi
callq 0x5ae0
movq %rsp, %rdi
callq 0x7a61
cmpl $0x1, %eax
jne 0x376d
movups 0x5feb(%rip), %xmm0     # 0x9739
leaq 0x9d8b(%rip), %rax      # 0xd4e0
movaps %xmm0, 0x10(%rax)
movups 0x5fc9(%rip), %xmm0     # 0x9729
movaps %xmm0, (%rax)
movl $0x1, %edi
callq 0x5ae0
leaq 0x10(%rbx), %r15
movq %rsp, %rdi
callq 0x7a61
cmpl $0x7, %eax
jne 0x379f
movq %rsp, %r14
movq %r14, %rdi
callq 0x7a79
decl 0x38(%r14)
movq %r14, %rdi
movl $0x4, %esi
callq 0x7568
jmp 0x3881
movq %rsp, %rdi
callq 0x7a61
cmpl $0x5, %eax
je 0x3881
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x37e3
testl %eax, %eax
jne 0x3881
movq %rsp, %rdi
xorl %esi, %esi
callq 0x1984
cmpl $0x4, %eax
je 0x383a
cmpl $0x1, %eax
jne 0x3881
movl 0x4(%rbx), %ecx
leaq 0x5f68(%rip), %rsi      # 0x9749
jmp 0x3844
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x15ba
leaq 0x5e71(%rip), %rsi      # 0x9666
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
movq %rsp, %rdi
xorl %esi, %esi
callq 0x1984
cmpl $0x4, %eax
je 0x3852
cmpl $0x1, %eax
jne 0x3881
leaq 0x5f51(%rip), %rsi      # 0x976d
movq %r14, %rdi
xorl %eax, %eax
callq 0x1710
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x15ba
leaq 0x5f45(%rip), %rsi      # 0x977d
jmp 0x3875
movl 0x4(%rbx), %ecx
leaq 0x5f17(%rip), %rsi      # 0x975b
movq %r14, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x1710
jmp 0x3881
leaq 0x5f35(%rip), %rsi      # 0x978e
movq %r14, %rdi
xorl %eax, %eax
callq 0x1710
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x15ba
leaq 0x5d60(%rip), %rsi      # 0x95d5
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
movaps (%rsp), %xmm0
movaps 0x10(%rsp), %xmm1
movaps 0x20(%rsp), %xmm2
movaps 0x30(%rsp), %xmm3
movups %xmm3, 0x30(%r15)
movups %xmm2, 0x20(%r15)
movups %xmm1, 0x10(%r15)
movups %xmm0, (%r15)
movb $0x0, 0x50(%rbx)
addq $0x40, %rsp
popq %rbx
popq %r14
popq %r15
retq