// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %r8, %rbx
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq 0x48(%rdi), %rdi
movl $0x12, %esi
movq %rcx, %rdx
xorl %ecx, %ecx
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x4d27e
movq 0x48(%r14), %rdi
movl $0x17, %esi
movq %rax, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x4d27e
movq 0x48(%r14), %rdi
movl $0x4, %ecx
movl $0x12, %esi
movq %r13, %rdx
movq %rbx, %r8
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x4d27e
movq 0x48(%r14), %rdi
movl $0x4, %r8d
movl $0x17, %esi
movq %rax, %rdx
movq %r15, %rcx
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x4d27e
movq 0x48(%r14), %rdi
movl $0x8, %ecx
movl $0x12, %esi
movq %r13, %rdx
movq %rbx, %r8
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x4d27e
movq 0x48(%r14), %rdi
movl $0x8, %r8d
movl $0x17, %esi
movq %rax, %rdx
movq %r15, %rcx
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x4d27e
movq 0x48(%r14), %rdi
movl $0xc, %ecx
movl $0x12, %esi
movq %r13, %rdx
movq %rbx, %r8
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x4d27e
movq 0x48(%r14), %rdi
movl $0xc, %r8d
movl $0x17, %esi
movq %rax, %rdx
movq %r15, %rcx
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x4d27e
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x4d02d
cmpl $0x0, (%rbx)
je 0x4d288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r14, %rdi
movq %rbx, %rdx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x4d2d0