// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movq %r9, -0x30(%rbp)
leaq 0x66ab7(%rip), %rax     # 0xac2e5
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3f560
testb $0x1, %al
jne 0x45841
jmp 0x45852
testb $0x1, -0x21(%rbp)
je 0x45852
leaq 0x66a9d(%rip), %rax     # 0xac2eb
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x120d0
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rdi
callq 0x120d0
movq -0x68(%rbp), %rdi
addq %rax, %rdi
addq $0x1, %rdi
addq $0x1, %rdi
callq 0x121b0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x458aa
movq -0x30(%rbp), %rdi
movl $0x1, %esi
leaq 0x669b7(%rip), %rdx     # 0xac252
movl $0xe56, %ecx            # imm = 0xE56
callq 0x158e0
jmp 0x4598c
movq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x58(%rbp), %rcx
leaq 0x66a1e(%rip), %rsi     # 0xac2df
movb $0x0, %al
callq 0x12250
leaq 0x66001(%rip), %rax     # 0xab8d0
movq %rax, -0x50(%rbp)
leaq 0x65ff6(%rip), %rax     # 0xab8d0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
leaq -0x50(%rbp), %rcx
movq -0x30(%rbp), %r9
movl $0x2, %edx
leaq 0x663ae(%rip), %r8      # 0xabca8
callq 0x42960
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x45922
movq -0x30(%rbp), %rax
cmpl $0x20, (%rax)
je 0x45917
jmp 0x45983
movq -0x30(%rbp), %rdi
callq 0x15670
jmp 0x4594c
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movb -0x21(%rbp), %al
movq -0x30(%rbp), %r8
andb $0x1, %al
movzbl %al, %ecx
callq 0x459a0
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x4594a
jmp 0x45983
jmp 0x4594c
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
xorl %r9d, %r9d
leaq 0x6633e(%rip), %r10     # 0xabca8
movl %r9d, %r8d
movq %r10, (%rsp)
movl $0x1, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x248d0
movq -0x60(%rbp), %rdi
callq 0x12290
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)