// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %r9, %r15
movl %r8d, %r14d
movq %rcx, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, %rbp
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x3041c
movl %eax, %r12d
movl %r14d, 0x1c(%rsp)
andb %r14b, %r12b
movq 0x10(%rbp), %r14
movq %r14, %rdi
callq 0x120f0
movzbl %r12b, %edi
xorq $0x7, %rdi
addq %rax, %rdi
callq 0x121d0
testq %rax, %rax
je 0x34ddf
movq %rax, %r13
leaq 0x40576(%rip), %rax     # 0x752e2
leaq 0x40569(%rip), %rcx     # 0x752dc
testb %r12b, %r12b
cmovneq %rax, %rcx
leaq 0x40555(%rip), %rsi     # 0x752d6
movq %r13, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x12280
leaq 0x3fb63(%rip), %rax     # 0x748f8
leaq 0x30(%rsp), %rcx
movq %rax, (%rcx)
movq %rax, 0x8(%rcx)
movq %r15, (%rsp)
leaq 0x3ff24(%rip), %r12     # 0x74cd0
movl $0x2, %edx
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %r8
xorl %r9d, %r9d
callq 0x34307
movl (%r15), %ecx
testl %ecx, %ecx
je 0x34e06
cmpl $0x20, %ecx
jne 0x34e90
movq %r15, %rdi
callq 0x14404
jmp 0x34e64
leaq 0x40463(%rip), %rdx     # 0x75249
movq %r15, %rdi
movl $0x1, %esi
movl $0xe56, %ecx            # imm = 0xE56
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x145f4
movq 0x48(%rbx), %r14
movq %rax, 0x48(%rbx)
movq %r15, (%rsp)
movzbl 0x1c(%rsp), %r9d
movl $0x4, %edx
movl $0x5, %r8d
movq %rbx, %rdi
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0x45db3
movq 0x48(%rbx), %rdi
movq 0x98(%rdi), %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
jne 0x34e5a
movq 0x48(%rbx), %rdi
movl $0x46, %esi
movq %r15, %rdx
callq 0x2c1b7
movq %r14, 0x48(%rbx)
cmpl $0x0, (%r15)
jne 0x34e90
movq %r15, 0x10(%rsp)
movq %r12, (%rsp)
movl $0x1, 0x8(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1ea95
movq %r13, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x122c0