// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/frontend/rec_type.c
// Function: subtilis_type_rec_copy_ref
void subtilis_type_rec_copy_ref(subtilis_parser_t *p,
				const subtilis_type_t *type, size_t dest_reg,
				size_t loc, size_t src_reg, bool new_rec,
				subtilis_error_t *err)
{
	size_t i;
	uint32_t offset;
	subtilis_exp_t *e;
	subtilis_exp_t *e1;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t op2;
	size_t ptr_reg;
	const subtilis_type_t *field_type;
	const subtilis_type_rec_t *rec = &type->params.rec;

	/*
	 * We only need to initialise fields that cannot be zero initialised.
	 */

	for (i = 0; i < rec->num_fields; i++) {
		offset = subtilis_type_rec_field_offset_id(rec, i);
		field_type = &rec->field_types[i];
		if (field_type->type == SUBTILIS_TYPE_REC) {
			op1.reg = src_reg;
			op2.integer = offset;
			ptr_reg = subtilis_ir_section_add_instr(
			    p->current, SUBTILIS_OP_INSTR_ADDI_I32, op1, op2,
			    err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;

			subtilis_rec_type_copy(p, field_type, dest_reg,
					       loc + offset, ptr_reg, new_rec,
					       err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
		} else if (subtilis_type_if_is_reference(field_type)) {
			ptr_reg = subtilis_reference_get_pointer(p, src_reg,
								 offset, err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
			e = subtilis_exp_new_var(field_type, ptr_reg, err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
			if (new_rec) {
				if (subtilis_type_if_is_array(field_type) ||
				    subtilis_type_if_is_vector(field_type)) {
					subtilis_array_type_init_field(
					    p, field_type, dest_reg,
					    loc + offset, e, err);
				} else {
					subtilis_reference_type_init_ref(
					    p, dest_reg, loc + offset,
					    e->exp.ir_op.reg, true, true, err);
					subtilis_exp_delete(e);
				}
			} else {
				subtilis_type_if_assign_ref(
				    p, field_type, dest_reg, loc + offset, e,
				    err);
			}
			if (err->type != SUBTILIS_ERROR_OK)
				return;
		} else if (field_type->type == SUBTILIS_TYPE_FN ||
			   subtilis_type_if_is_numeric(field_type)) {
			e = subtilis_type_if_load_from_mem(
			    p, field_type, src_reg, offset, err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
			e1 = subtilis_exp_new_var(field_type, e->exp.ir_op.reg,
						  err);
			subtilis_exp_delete(e);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
			subtilis_type_if_assign_to_mem(p, dest_reg,
						       loc + offset, e1, err);
		} else {
			subtilis_error_set_assertion_failed(err);
			return;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, 0x24(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movq %rsi, 0x30(%rsp)
cmpq $0x0, 0x28(%rsi)
je 0x45f78
movq 0x80(%rsp), %rbx
movq 0x30(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x40(%rsp)
xorl %r13d, %r13d
movzbl 0x24(%rsp), %eax
movl %eax, 0x3c(%rsp)
xorl %r12d, %r12d
movq 0x40(%rsp), %rdi
movq %r12, %rsi
callq 0x2fe6a
movl %eax, %ebp
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
leaq (%rax,%r13), %r15
cmpl $0x16, (%rax,%r13)
jne 0x45de8
movq 0x8(%rsp), %rax
movq 0x48(%rax), %rdi
movl %ebp, %r14d
movl $0x9, %esi
movq 0x28(%rsp), %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x2bc8f
cmpl $0x0, (%rbx)
jne 0x45f78
addq 0x18(%rsp), %r14
movq %rbx, (%rsp)
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rcx
movq %rax, %r8
movl 0x3c(%rsp), %r9d
callq 0x45fae
cmpl $0x0, (%rbx)
je 0x45efd
jmp 0x45f78
movq %r15, %rdi
callq 0x376f1
testb %al, %al
je 0x45e7e
movl %ebp, %r14d
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x4d71f
cmpl $0x0, (%rbx)
jne 0x45f78
movq %r15, %rdi
movl %eax, %esi
movq %rbx, %rdx
callq 0x2b5fb
cmpl $0x0, (%rbx)
jne 0x45f78
movq %rax, %rbp
cmpb $0x0, 0x24(%rsp)
je 0x45f18
movq %r15, %rdi
callq 0x376b5
testb %al, %al
jne 0x45e59
movq %r15, %rdi
callq 0x376d3
testb %al, %al
je 0x45f3d
addq 0x18(%rsp), %r14
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rcx
movq %rbp, %r8
movq %rbx, %r9
callq 0x42f54
jmp 0x45dda
cmpl $0x9, (%r15)
je 0x45e94
movq %r15, %rdi
callq 0x37534
testb %al, %al
je 0x45f87
movl %ebp, %r14d
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq 0x28(%rsp), %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x36372
cmpl $0x0, (%rbx)
jne 0x45f78
movq %rax, %rbp
movl 0x148(%rax), %esi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x2b5fb
movq %rax, %r15
movq %rbp, %rdi
callq 0x2b166
cmpl $0x0, (%rbx)
jne 0x45f78
addq 0x18(%rsp), %r14
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x362c6
incq %r12
addq $0x148, %r13            # imm = 0x148
movq 0x30(%rsp), %rax
cmpq 0x28(%rax), %r12
jb 0x45d67
jmp 0x45f78
addq 0x18(%rsp), %r14
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rcx
movq %rbp, %r8
movq %rbx, %r9
callq 0x35ef0
jmp 0x45dda
addq 0x18(%rsp), %r14
movq 0x148(%rbp), %rcx
movq %rbx, (%rsp)
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x4cdcc
movq %rbp, %rdi
callq 0x2b166
jmp 0x45dda
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2fadd(%rip), %rdx     # 0x75a6b
movq %rbx, %rdi
movl $0xf, %esi
movl $0x122, %ecx            # imm = 0x122
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x145a4