// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/frontend/array_type.c
// Function: subtilis_array_type_deref_recs
void subtilis_array_type_deref_recs(subtilis_parser_t *p, size_t data_reg,
				    size_t size_reg, size_t el_size_reg,
				    size_t el_destruct_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;
	subtilis_ir_arg_t *ir_args;

	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;

	ir_args = malloc(sizeof(*ir_args));
	if (!ir_args) {
		subtilis_error_set_oom(err);
		return;
	}

	ir_args[0].type = SUBTILIS_IR_REG_TYPE_INTEGER;
	ir_args[0].reg = counter.reg;
	ir_args[0].nop = SIZE_MAX;

	subtilis_ir_section_add_call_ptr(p->current, 1, ir_args,
					 el_destruct_reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op2.reg = el_size_reg;
	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_ADD_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
subq $0x18, %rsp
movq %r9, %rbx
movq %r8, %r15
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %r14
movq 0x48(%rdi), %rdi
callq 0x2cc99
movq %rax, 0x10(%rsp)
movq 0x48(%r14), %rdi
callq 0x2cc99
movq %rax, 0x8(%rsp)
movq 0x48(%r14), %rdi
movl $0x1d, %esi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x2be09
cmpl $0x0, (%rbx)
jne 0x4460e
movq %rax, %rbp
movq 0x48(%r14), %rdi
xorl %esi, %esi
movq %rax, %rdx
movq %r12, %rcx
movq %rbx, %r8
callq 0x2bc8f
cmpl $0x0, (%rbx)
jne 0x4460e
movq %rax, %r12
movq 0x48(%r14), %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x2cca6
cmpl $0x0, (%rbx)
je 0x4461d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x18, %edi
callq 0x121d0
testq %rax, %rax
je 0x446e0
movl $0x0, (%rax)
movq %rbp, 0x8(%rax)
movq $-0x1, 0x10(%rax)
movq 0x48(%r14), %rdi
movl $0x1, %esi
movq %rax, %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x2d037
cmpl $0x0, (%rbx)
jne 0x4460e
movq 0x48(%r14), %rdi
xorl %esi, %esi
movq %rbp, %rdx
movq %rbp, %rcx
movq %r13, %r8
movq %rbx, %r9
callq 0x2bd42
cmpl $0x0, (%rbx)
jne 0x4460e
movq 0x48(%r14), %rdi
movl $0x3b, %esi
movq %rbp, %rdx
movq %r12, %rcx
movq %rbx, %r8
callq 0x2bc8f
cmpl $0x0, (%rbx)
jne 0x4460e
movq 0x48(%r14), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %r8
movq %rbx, %r9
callq 0x2bd42
cmpl $0x0, (%rbx)
jne 0x4460e
movq 0x48(%r14), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2cca6
leaq 0x3131f(%rip), %rdx     # 0x75a06
movq %rbx, %rdi
movl $0x1, %esi
movl $0x973, %ecx            # imm = 0x973
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x145a4