// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/frontend/builtins_ir.c
// Function: subtilis_builtin_ir_rec_copy
void subtilis_builtin_ir_rec_copy(subtilis_parser_t *p,
				  const subtilis_type_t *type,
				  size_t dest_reg, size_t src_reg,
				  bool new_rec, subtilis_error_t *err)
{
	subtilis_ir_section_t *fn;
	const subtilis_type_t *ptype[2];
	const char *copy = "_copy";
	char *name;

	if (subtilis_type_rec_need_deref(type) && new_rec)
		/*
		 * Then we want to do an init rather than a copy.
		 * As these are two different actions we'll need
		 * separate functions with different names.
		 */

		copy = "_new";

	/*
	 * If new_rec is true but the structure contains no references
	 * we can just leave it set to true as it will be ignored.
	 */

	name = malloc(strlen(type->params.rec.name) + strlen(copy)
		      + 1 + 1);
	if (!name) {
		subtilis_error_set_oom(err);
		return;
	}
	sprintf(name, "_%s%s", type->params.rec.name, copy);

	ptype[0] = &subtilis_type_integer;
	ptype[1] = &subtilis_type_integer;

	fn = prv_add_args(p, name, 2, ptype, &subtilis_type_void, err);
	if (err->type != SUBTILIS_ERROR_OK) {
		if (err->type != SUBTILIS_ERROR_ALREADY_DEFINED)
			goto cleanup;
		subtilis_error_init(err);
	} else {
		prv_builtins_ir_gen_rec_copy(p, type, fn, new_rec, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	}

	(void)subtilis_parser_call_2_arg_fn(
		p, name, dest_reg, src_reg, SUBTILIS_IR_REG_TYPE_INTEGER,
		SUBTILIS_IR_REG_TYPE_INTEGER, &subtilis_type_void, true, err);

cleanup:

	free(name);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %rbx
movl %r8d, %r15d
movq %rcx, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, %rbp
movq %rdi, %r14
movq %rsi, %rdi
callq 0x2e7c9
movl %eax, %r12d
movl %r15d, 0xc(%rsp)
andb %r15b, %r12b
movq 0x10(%rbp), %r15
movq %r15, %rdi
callq 0x120f0
movzbl %r12b, %edi
xorq $0x7, %rdi
addq %rax, %rdi
callq 0x121d0
testq %rax, %rax
je 0x33564
movq %rax, %r13
leaq 0x3bde2(%rip), %rax     # 0x6f2b2
leaq 0x3bdd5(%rip), %rcx     # 0x6f2ac
testb %r12b, %r12b
cmovneq %rax, %rcx
leaq 0x3bdc1(%rip), %rsi     # 0x6f2a6
movq %r13, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x12280
leaq 0x3b3cf(%rip), %rax     # 0x6e8c8
leaq 0x20(%rsp), %rcx
movq %rax, (%rcx)
movq %rax, 0x8(%rcx)
leaq 0x3b794(%rip), %r12     # 0x6eca0
pushq $0x2
popq %rdx
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %r8
movq %rbx, %r9
callq 0x314be
movl (%rbx), %ecx
testl %ecx, %ecx
je 0x33589
cmpl $0x20, %ecx
jne 0x335ec
movq %rbx, %rdi
callq 0x140a4
subq $0x8, %rsp
movq %r14, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rbx
pushq $0x1
pushq %r12
callq 0x1deea
addq $0x20, %rsp
jmp 0x335ec
leaq 0x3bcae(%rip), %rdx     # 0x6f219
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl $0xe56, %ecx            # imm = 0xE56
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1429e
movq 0x48(%r14), %r15
movq %rax, 0x48(%r14)
subq $0x8, %rsp
movzbl 0x14(%rsp), %r9d
pushq $0x4
popq %rdx
pushq $0x5
popq %r8
movq %r14, %rdi
movq %rbp, %rsi
xorl %ecx, %ecx
pushq %rbx
callq 0x434d3
popq %rax
popq %rcx
movq 0x48(%r14), %rdi
movq 0x98(%rdi), %rsi
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
je 0x335d0
movq %r15, 0x48(%r14)
jmp 0x335ec
movq 0x48(%r14), %rdi
pushq $0x46
popq %rsi
movq %rbx, %rdx
callq 0x2a9af
cmpl $0x0, (%rbx)
movq %r15, 0x48(%r14)
je 0x33537
movq %r13, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x122c0