// File: /workspace/github_c_makefile_star2_O2/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 0x761b
cmpl $0x4, %eax
je 0x3463
movups 0x52b6(%rip), %xmm0     # 0x86f5
leaq 0x909a(%rip), %rax      # 0xc4e0
movaps %xmm0, 0x10(%rax)
movups 0x5294(%rip), %xmm0     # 0x86e5
movaps %xmm0, (%rax)
movl $0x657079, 0x20(%rax)   # imm = 0x657079
pushq $0x1
popq %rdi
callq 0x56c5
movq %rsp, %rdi
callq 0x7603
cmpl $0x1, %eax
jne 0x3494
movups 0x52a2(%rip), %xmm0     # 0x8719
leaq 0x9062(%rip), %rax      # 0xc4e0
movaps %xmm0, 0x10(%rax)
movups 0x5280(%rip), %xmm0     # 0x8709
movaps %xmm0, (%rax)
pushq $0x1
popq %rdi
callq 0x56c5
leaq 0x10(%rbx), %r15
movq %rsp, %rdi
callq 0x7603
cmpl $0x7, %eax
jne 0x34c4
movq %rsp, %r14
movq %r14, %rdi
callq 0x761b
decl 0x38(%r14)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x7204
jmp 0x35a6
movq %rsp, %rdi
callq 0x7603
cmpl $0x5, %eax
je 0x35a6
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x3508
testl %eax, %eax
jne 0x35a6
movq %rsp, %rdi
xorl %esi, %esi
callq 0x1756
cmpl $0x4, %eax
je 0x355f
cmpl $0x1, %eax
jne 0x35a6
movl 0x4(%rbx), %ecx
leaq 0x5223(%rip), %rsi      # 0x8729
jmp 0x3569
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x1393
leaq 0x512c(%rip), %rsi      # 0x8646
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x14e8
movq %rsp, %rdi
xorl %esi, %esi
callq 0x1756
cmpl $0x4, %eax
je 0x3577
cmpl $0x1, %eax
jne 0x35a6
leaq 0x520c(%rip), %rsi      # 0x874d
movq %r14, %rdi
xorl %eax, %eax
callq 0x14e8
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x1393
leaq 0x5200(%rip), %rsi      # 0x875d
jmp 0x359a
movl 0x4(%rbx), %ecx
leaq 0x51d2(%rip), %rsi      # 0x873b
movq %r14, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x14e8
jmp 0x35a6
leaq 0x51f0(%rip), %rsi      # 0x876e
movq %r14, %rdi
xorl %eax, %eax
callq 0x14e8
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x1393
leaq 0x501b(%rip), %rsi      # 0x85b5
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x14e8
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