// File: /workspace/github_c_makefile_star2_O1/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 0x46020
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 0x30118
movl %eax, %ebp
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
leaq (%rax,%r13), %r15
cmpl $0x16, (%rax,%r13)
jne 0x45e90
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 0x2c00f
cmpl $0x0, (%rbx)
jne 0x46020
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 0x46056
cmpl $0x0, (%rbx)
je 0x45fa5
jmp 0x46020
movq %r15, %rdi
callq 0x37833
testb %al, %al
je 0x45f26
movl %ebp, %r14d
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x4d763
cmpl $0x0, (%rbx)
jne 0x46020
movq %r15, %rdi
movl %eax, %esi
movq %rbx, %rdx
callq 0x2b971
cmpl $0x0, (%rbx)
jne 0x46020
movq %rax, %rbp
cmpb $0x0, 0x24(%rsp)
je 0x45fc0
movq %r15, %rdi
callq 0x377f7
testb %al, %al
jne 0x45f01
movq %r15, %rdi
callq 0x37815
testb %al, %al
je 0x45fe5
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 0x43001
jmp 0x45e82
cmpl $0x9, (%r15)
je 0x45f3c
movq %r15, %rdi
callq 0x37676
testb %al, %al
je 0x4602f
movl %ebp, %r14d
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq 0x28(%rsp), %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x364c2
cmpl $0x0, (%rbx)
jne 0x46020
movq %rax, %rbp
movl 0x148(%rax), %esi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x2b971
movq %rax, %r15
movq %rbp, %rdi
callq 0x2b4c3
cmpl $0x0, (%rbx)
jne 0x46020
addq 0x18(%rsp), %r14
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x36416
incq %r12
addq $0x148, %r13            # imm = 0x148
movq 0x30(%rsp), %rax
cmpq 0x28(%rax), %r12
jb 0x45e0f
jmp 0x46020
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 0x36040
jmp 0x45e82
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 0x4ce10
movq %rbp, %rdi
callq 0x2b4c3
jmp 0x45e82
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2f9f1(%rip), %rdx     # 0x75a27
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 0x145f4