// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/array_type.c
// Function: subtilis_array_type_copy_els
void subtilis_array_type_copy_els(subtilis_parser_t *p,
				  const subtilis_type_t *el_type,
				  size_t data_reg, size_t size_reg,
				  size_t src_reg, bool deref,
				  subtilis_error_t *err)
{
	subtilis_ir_operand_t op0;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t op2;
	subtilis_ir_operand_t data_end;
	subtilis_ir_operand_t counter;
	subtilis_ir_operand_t counter2;
	subtilis_ir_operand_t conde;
	subtilis_ir_operand_t start;
	subtilis_ir_operand_t end;

	start.label = subtilis_ir_section_new_label(p->current);
	end.label = subtilis_ir_section_new_label(p->current);

	/* size_reg must be > 0 */

	op0.reg = data_reg;
	counter.reg = subtilis_ir_section_add_instr2(
	    p->current, SUBTILIS_OP_INSTR_MOV, op0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op0.reg = src_reg;
	counter2.reg = subtilis_ir_section_add_instr2(
	    p->current, SUBTILIS_OP_INSTR_MOV, op0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.reg = size_reg;
	data_end.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_ADD_I32, counter, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_label(p->current, start.label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	/*
	 * RECords are a special case.  They're not reference types but
	 * they can hold references.  If we get here, our RECord is not
	 * scalar.
	 */
	if (el_type->type == SUBTILIS_TYPE_REC) {
		subtilis_builtin_ir_rec_copy(p, el_type, counter.reg,
					     counter2.reg, !deref, err);
	} else {
		if (deref) {
			subtilis_reference_type_deref(p, counter.reg, 0, err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
		}

		subtilis_reference_type_init_ref(p, counter.reg, 0,
						 counter2.reg, true, true, err);
	}
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op2.integer = subtilis_type_if_size(el_type, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_ADDI_I32, counter, counter, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_reg(p->current,
					  SUBTILIS_OP_INSTR_ADDI_I32, counter2,
					  counter2, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	conde.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LT_I32, counter, data_end, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  conde, start, end, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_label(p->current, end.label, err);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %r15d
movq %r8, %r13
movq %rcx, %r12
movq %rdx, %rbp
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
movq 0x60(%rsp), %rbx
movq 0x48(%rdi), %rdi
callq 0x2d00a
movq %rax, 0x20(%rsp)
movq 0x48(%r14), %rdi
callq 0x2d00a
movq %rax, 0x10(%rsp)
movq 0x48(%r14), %rdi
movl $0x1d, %esi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x2c189
cmpl $0x0, (%rbx)
jne 0x4496c
movq %rax, %rbp
movq 0x48(%r14), %rdi
movl $0x1d, %esi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x2c189
cmpl $0x0, (%rbx)
jne 0x4496c
movq %rax, %r13
movq 0x48(%r14), %rdi
xorl %esi, %esi
movq %rbp, %rdx
movq %r12, %rcx
movq %rbx, %r8
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x4496c
movq %rax, %r12
movq 0x48(%r14), %rdi
movq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x2d017
cmpl $0x0, (%rbx)
jne 0x4496c
movq 0x18(%rsp), %rsi
cmpl $0x16, (%rsi)
jne 0x4488f
xorb $0x1, %r15b
movzbl %r15b, %r8d
movq %r14, %rdi
movq %rbp, %rdx
movq %r13, %rcx
movq %rbx, %r9
callq 0x34d0a
jmp 0x448cd
testb %r15b, %r15b
je 0x448ad
movq %r14, %rdi
movq %rbp, %rsi
xorl %edx, %edx
movq %rbx, %rcx
callq 0x4db70
cmpl $0x0, (%rbx)
jne 0x4496c
movq %rbx, (%rsp)
movq %r14, %rdi
movq %rbp, %rsi
xorl %edx, %edx
movq %r13, %rcx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x4ce10
cmpl $0x0, (%rbx)
jne 0x4496c
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x35ed8
cmpl $0x0, (%rbx)
jne 0x4496c
movq 0x48(%r14), %rdi
movl %eax, %r15d
movl $0x9, %esi
movq %rbp, %rdx
movq %rbp, %rcx
movq %r15, %r8
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x4496c
movq 0x48(%r14), %rdi
movl $0x9, %esi
movq %r13, %rdx
movq %r13, %rcx
movq %r15, %r8
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
jne 0x4496c
movq 0x48(%r14), %rdi
movl $0x3b, %esi
movq %rbp, %rdx
movq %r12, %rcx
movq %rbx, %r8
callq 0x2c00f
cmpl $0x0, (%rbx)
jne 0x4496c
movq 0x48(%r14), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq 0x20(%rsp), %rcx
movq 0x10(%rsp), %r8
movq %rbx, %r9
callq 0x2c0c2
cmpl $0x0, (%rbx)
je 0x4497b
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x48(%r14), %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d017