// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/array_type.c
// Function: prv_grow_wrapper
static size_t prv_grow_wrapper(subtilis_parser_t *p,
			       const subtilis_type_t *el_type,
			       size_t a1_mem_reg, size_t a1_size_reg,
			       size_t gran_reg, size_t a2_size_reg,
			       subtilis_error_t *err)
{
	subtilis_ir_operand_t get_ref_label;
	subtilis_ir_operand_t empty_label;
	subtilis_ir_operand_t ref_label;
	subtilis_ir_operand_t skip_ref_label;
	subtilis_ir_operand_t a1_heap;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t op2;
	subtilis_ir_operand_t get_ref;
	subtilis_ir_operand_t get_new_ref;
	subtilis_ir_operand_t condee;
	subtilis_exp_t *e;
	size_t dest_reg;
	size_t data_reg;
	bool check_ref = subtilis_type_if_is_reference(el_type) ||
			 ((el_type->type == SUBTILIS_TYPE_REC) &&
			  subtilis_type_rec_need_deref(el_type));

	/*
	 * If we're dealing with a collection of references or structures that
	 * contain references and the reference count of the collection is > 1
	 * before the call to ref_grow and has fallen by 1 after the call to
	 * grow, we know a copy has taken place.  In this case we need to ref
	 * all the copied elements.  We can't do this in ref_grow as this
	 * function is type agnostic.
	 */

	/*
	 * TODO: It may be worth providing a specific builtin for growing
	 * collection of references.  RECs are trickier as they have custom
	 * reffers and dereffers.  But do we really want to duplicate all this
	 * code each time we append a string.
	 */

	if (check_ref) {
		get_ref_label.label = subtilis_ir_section_new_label(p->current);
		empty_label.label = subtilis_ir_section_new_label(p->current);

		op1.integer = 0;
		get_ref.reg = subtilis_ir_section_add_instr2(
		    p->current, SUBTILIS_OP_INSTR_MOVI_I32, op1, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;

		condee.reg = a1_size_reg;
		subtilis_ir_section_add_instr_reg(
		    p->current, SUBTILIS_OP_INSTR_JMPC, condee, get_ref_label,
		    empty_label, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;

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

		op1.reg = a1_mem_reg;
		op2.integer = SUBTIILIS_REFERENCE_HEAP_OFF;
		a1_heap.reg = subtilis_ir_section_add_instr(
		    p->current, SUBTILIS_OP_INSTR_LOADO_I32, op1, op2, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;

		subtilis_ir_section_add_instr_no_reg2(p->current,
						      SUBTILIS_OP_INSTR_GETREF,
						      get_ref, a1_heap, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;
		subtilis_ir_section_add_label(p->current, empty_label.label,
					      err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;
	}

	e = subtilis_builtin_ir_call_ref_grow(p, a1_mem_reg, a1_size_reg,
					      gran_reg, a2_size_reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;
	dest_reg = e->exp.ir_op.reg;
	subtilis_exp_delete(e);

	if (check_ref) {
		ref_label.label = subtilis_ir_section_new_label(p->current);
		skip_ref_label.label =
		    subtilis_ir_section_new_label(p->current);

		op1.reg = a1_mem_reg;
		op2.integer = SUBTIILIS_REFERENCE_HEAP_OFF;
		a1_heap.reg = subtilis_ir_section_add_instr(
		    p->current, SUBTILIS_OP_INSTR_LOADO_I32, op1, op2, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;

		get_new_ref.reg = subtilis_ir_section_add_instr2(
		    p->current, SUBTILIS_OP_INSTR_GETREF, a1_heap, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;

		condee.reg = subtilis_ir_section_add_instr(
		    p->current, SUBTILIS_OP_INSTR_LT_I32, get_new_ref, get_ref,
		    err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;

		subtilis_ir_section_add_instr_reg(
		    p->current, SUBTILIS_OP_INSTR_JMPC, condee, ref_label,
		    skip_ref_label, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;

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

		data_reg = subtilis_reference_get_data(p, a1_mem_reg, 0, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;
		subtilis_array_type_ref_els(p, el_type, data_reg, a1_size_reg,
					    err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;

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

	return dest_reg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4a090
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0xa2(%rbp)
jne 0x60e8b
movq -0x18(%rbp), %rcx
xorl %eax, %eax
cmpl $0x16, (%rcx)
movb %al, -0xa3(%rbp)
jne 0x60e7f
movq -0x18(%rbp), %rdi
callq 0x3f560
movb %al, -0xa3(%rbp)
movb -0xa3(%rbp), %al
movb %al, -0xa2(%rbp)
movb -0xa2(%rbp), %al
andb $0x1, %al
movb %al, -0xa1(%rbp)
testb $0x1, -0xa1(%rbp)
je 0x6101c
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x48(%rbp)
movl $0x0, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %rcx
movq -0x68(%rbp), %rdx
movl $0x1b, %esi
callq 0x38490
movq %rax, -0x78(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x60f03
movq $-0x1, -0x8(%rbp)
jmp 0x61255
movq -0x28(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %r9
movq -0x88(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x60f49
movq $-0x1, -0x8(%rbp)
jmp 0x61255
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x40(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x39960
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x60f74
movq $-0x1, -0x8(%rbp)
jmp 0x61255
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
movl $0x8, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %r8
movq -0x68(%rbp), %rdx
movq -0x70(%rbp), %rcx
movl $0x12, %esi
callq 0x38230
movq %rax, -0x60(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x60fbb
movq $-0x1, -0x8(%rbp)
jmp 0x61255
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %r8
movq -0x78(%rbp), %rdx
movq -0x60(%rbp), %rcx
movl $0x7a, %esi
callq 0x385a0
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x60fef
movq $-0x1, -0x8(%rbp)
jmp 0x61255
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x48(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x39960
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6101a
movq $-0x1, -0x8(%rbp)
jmp 0x61255
jmp 0x6101c
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq 0x10(%rbp), %r9
callq 0x42ca0
movq %rax, -0x90(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x61056
movq $-0x1, -0x8(%rbp)
jmp 0x61255
movq -0x90(%rbp), %rax
movq 0x148(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdi
callq 0x36ee0
testb $0x1, -0xa1(%rbp)
je 0x6124a
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
movl $0x8, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %r8
movq -0x68(%rbp), %rdx
movq -0x70(%rbp), %rcx
movl $0x12, %esi
callq 0x38230
movq %rax, -0x60(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x610ed
movq $-0x1, -0x8(%rbp)
jmp 0x61255
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %rcx
movq -0x60(%rbp), %rdx
movl $0x7a, %esi
callq 0x38490
movq %rax, -0x80(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x61121
movq $-0x1, -0x8(%rbp)
jmp 0x61255
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %r8
movq -0x80(%rbp), %rdx
movq -0x78(%rbp), %rcx
movl $0x3b, %esi
callq 0x38230
movq %rax, -0x88(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6115c
movq $-0x1, -0x8(%rbp)
jmp 0x61255
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %r9
movq -0x88(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x58(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x61197
movq $-0x1, -0x8(%rbp)
jmp 0x61255
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x50(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x39960
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x611c2
movq $-0x1, -0x8(%rbp)
jmp 0x61255
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq 0x10(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x6d1e0
movq %rax, -0xa0(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x611f1
movq $-0x1, -0x8(%rbp)
jmp 0x61255
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq 0x10(%rbp), %r8
callq 0x601c0
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x61220
movq $-0x1, -0x8(%rbp)
jmp 0x61255
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x58(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x39960
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x61248
movq $-0x1, -0x8(%rbp)
jmp 0x61255
jmp 0x6124a
movq -0x98(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)