// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/collection.c
// Function: subtilis_collection_copy_ref
void subtilis_collection_copy_ref(subtilis_parser_t *p, subtilis_exp_t *obj1,
				  subtilis_exp_t *obj2, subtilis_error_t *err)
{
	subtilis_ir_operand_t size1;
	subtilis_ir_operand_t size2;
	subtilis_ir_operand_t skip_label;
	subtilis_ir_operand_t no_skip_label;
	subtilis_ir_operand_t condee;
	subtilis_ir_operand_t final_size;
	size_t ptr1;
	size_t ptr2;
	subtilis_type_t el_type;

	skip_label.label = subtilis_ir_section_new_label(p->current);
	no_skip_label.label = subtilis_ir_section_new_label(p->current);

	if (obj1->type.type != obj2->type.type) {
		subtilis_error_set_array_type_mismatch(err, p->l->stream->name,
						       p->l->line);
		goto free_objs;
	}

	subtilis_type_if_element_type(p, &obj1->type, &el_type, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	size2.reg =
	    subtilis_reference_type_get_size(p, obj2->exp.ir_op.reg, 0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	ptr2 = subtilis_reference_get_data(p, obj2->exp.ir_op.reg, 0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	size1.reg =
	    subtilis_reference_type_get_size(p, obj1->exp.ir_op.reg, 0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	condee.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LTE_I32, size1, size2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	final_size.reg = p->current->reg_counter++;
	subtilis_ir_section_add_instr4(p->current, SUBTILIS_OP_INSTR_CMOV_I32,
				       final_size, condee, size1, size2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  final_size, no_skip_label, skip_label,
					  err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_label(p->current, no_skip_label.label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	ptr1 = subtilis_reference_get_data(p, obj1->exp.ir_op.reg, 0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_array_type_copy_els(p, &el_type, ptr1, final_size.reg, ptr2,
				     true, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_label(p->current, skip_label.label, err);

cleanup:
	subtilis_type_free(&el_type);

free_objs:
	subtilis_exp_delete(obj2);
	subtilis_exp_delete(obj1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
je 0x6f9f0
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %ecx
movl $0x41, %esi
leaq 0x3d105(%rip), %r8      # 0xacae5
movl $0x92, %r9d
callq 0x15930
jmp 0x6fbf4
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rcx
leaq -0x1a8(%rbp), %rdx
callq 0x47b70
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6fa16
jmp 0x6fbe8
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x20(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6dc00
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6fa44
jmp 0x6fbe8
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x20(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6d1e0
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6fa72
jmp 0x6fbe8
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x20(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6dc00
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6faa0
jmp 0x6fbe8
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl $0x37, %esi
callq 0x38230
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6fad0
jmp 0x6fbe8
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rcx
movq 0x18(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rcx)
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x20(%rbp), %rax
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
movl $0x8a, %esi
movq %rax, (%rsp)
callq 0x386c0
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6fb23
jmp 0x6fbe8
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x20(%rbp), %r9
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6fb53
jmp 0x6fbe8
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x40(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x39960
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6fb73
jmp 0x6fbe8
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x20(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6d1e0
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6fb9e
jmp 0x6fbe8
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x60(%rbp), %r8
movq -0x20(%rbp), %rax
leaq -0x1a8(%rbp), %rsi
movl $0x1, %r9d
movq %rax, (%rsp)
callq 0x60600
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6fbd3
jmp 0x6fbe8
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x39960
leaq -0x1a8(%rbp), %rdi
callq 0x3e100
movq -0x18(%rbp), %rdi
callq 0x36ee0
movq -0x10(%rbp), %rdi
callq 0x36ee0
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
nop