// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/frontend/array_type.c
// Function: subtilis_array_type_ref_els
void subtilis_array_type_ref_els(subtilis_parser_t *p,
				 const subtilis_type_t *type, size_t data_reg,
				 size_t size_reg, 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 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;

	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;

	if (type->type == SUBTILIS_TYPE_REC) {
		if (!subtilis_type_rec_need_deref(type)) {
			subtilis_error_set_assertion_failed(err);
			return;
		}
		subtilis_rec_type_ref(p, type, counter.reg, 0, err);
	} else {
		if (!subtilis_type_if_is_reference(type)) {
			subtilis_error_set_assertion_failed(err);
			return;
		}
		subtilis_reference_type_ref(
		    p, counter.reg, 0, type->type == SUBTILIS_TYPE_STRING, err);
	}
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op2.integer = subtilis_type_if_size(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;

	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
pushq %rax
movq %r8, %rbx
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %r14
movq 0x48(%rdi), %rdi
callq 0x2b774
movq %rax, %r12
movq 0x48(%r14), %rdi
callq 0x2b774
movq %rax, (%rsp)
movq 0x48(%r14), %rdi
pushq $0x1d
popq %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x2a981
cmpl $0x0, (%rbx)
jne 0x41cfe
movq %rax, %r13
movq 0x48(%r14), %rdi
xorl %esi, %esi
movq %rax, %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x2a819
cmpl $0x0, (%rbx)
jne 0x41cfe
movq %rax, %r15
movq 0x48(%r14), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
je 0x41d0d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x16, (%rbp)
jne 0x41d38
movq %rbp, %rdi
callq 0x2e7c9
testb %al, %al
je 0x41df5
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
movq %rbx, %r8
callq 0x43a80
jmp 0x41d61
movq %rbp, %rdi
callq 0x35808
testb %al, %al
je 0x41e09
xorl %ecx, %ecx
cmpl $0x7, (%rbp)
sete %cl
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %rbx, %r8
callq 0x4a76b
cmpl $0x0, (%rbx)
jne 0x41cfe
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x33df0
cmpl $0x0, (%rbx)
jne 0x41cfe
movq 0x48(%r14), %rdi
movl %eax, %r8d
pushq $0x9
popq %rsi
movq %r13, %rdx
movq %r13, %rcx
movq %rbx, %r9
callq 0x2a8c1
cmpl $0x0, (%rbx)
jne 0x41cfe
movq 0x48(%r14), %rdi
pushq $0x3b
popq %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x2a819
cmpl $0x0, (%rbx)
jne 0x41cfe
movq 0x48(%r14), %rdi
pushq $0x43
popq %rsi
movq %rax, %rdx
movq %r12, %rcx
movq (%rsp), %r8
movq %rbx, %r9
callq 0x2a8c1
cmpl $0x0, (%rbx)
jne 0x41cfe
movq 0x48(%r14), %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b781
leaq 0x2db96(%rip), %rdx     # 0x6f992
pushq $0xf
popq %rsi
movq %rbx, %rdi
movl $0x928, %ecx            # imm = 0x928
jmp 0x41e1b
leaq 0x2db82(%rip), %rdx     # 0x6f992
pushq $0xf
popq %rsi
movq %rbx, %rdi
movl $0x92e, %ecx            # imm = 0x92E
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1429e