// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/reference_type.c
// Function: subtilis_reference_type_copy_ret
void subtilis_reference_type_copy_ret(subtilis_parser_t *p,
				      const subtilis_type_t *t, size_t dest_reg,
				      size_t source_reg, subtilis_error_t *err)
{
	subtilis_ir_operand_t op0;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t op2;
	subtilis_ir_operand_t d;
	subtilis_ir_operand_t s;

	d.reg = dest_reg;
	s.reg = source_reg;

	op2.integer = SUBTIILIS_REFERENCE_SIZE_OFF;
	op0.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LOADO_I32, s, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_STOREO_I32, op0, d, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.reg = subtilis_reference_get_data(p, source_reg, 0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op2.integer = SUBTIILIS_REFERENCE_DATA_OFF;
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_STOREO_I32, op1, d, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.reg = subtilis_reference_get_heap(p, source_reg, 0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op2.integer = SUBTIILIS_REFERENCE_HEAP_OFF;
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_STOREO_I32, op1, d, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op2.integer = SUBTIILIS_REFERENCE_ORIG_SIZE_OFF;
	op1.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LOADO_I32, s, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_STOREO_I32, op1, d, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	/*
	 * It's important that this comes last as the reference we're
	 * copying might be left on the stack of a previous function.
	 * We don't want to overwrite the data before we've copied it.
	 */

	subtilis_reference_push_ref(p, t, d.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_reference_inc_cleanup_stack(p, t, err);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x28(%rbp), %r8
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl $0x12, %esi
callq 0x38230
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6d053
jmp 0x6d1d1
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x28(%rbp), %r9
movq -0x30(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %r8
movl $0x17, %esi
callq 0x38360
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6d083
jmp 0x6d1d1
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6d1e0
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6d0aa
jmp 0x6d1d1
movl $0x4, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x28(%rbp), %r9
movq -0x38(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %r8
movl $0x17, %esi
callq 0x38360
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6d0e1
jmp 0x6d1d1
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6d230
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6d108
jmp 0x6d1d1
movl $0x8, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x28(%rbp), %r9
movq -0x38(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %r8
movl $0x17, %esi
callq 0x38360
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6d13f
jmp 0x6d1d1
movl $0xc, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x28(%rbp), %r8
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl $0x12, %esi
callq 0x38230
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6d173
jmp 0x6d1d1
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x28(%rbp), %r9
movq -0x38(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %r8
movl $0x17, %esi
callq 0x38360
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6d1a0
jmp 0x6d1d1
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x6ce80
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6d1c0
jmp 0x6d1d1
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x6d280
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)