// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/reference_type.c
// Function: subtilis_reference_type_grow
void subtilis_reference_type_grow(subtilis_parser_t *p, size_t a1_loc,
				  size_t a1_mem_reg, size_t a1_size_reg,
				  size_t gran_reg, size_t a2_size_reg,
				  size_t ret_reg, subtilis_error_t *err)
{
	subtilis_ir_operand_t a1_size;
	subtilis_ir_operand_t a2_size;
	subtilis_ir_operand_t new_size;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t op2;
	subtilis_ir_operand_t a1_data;
	subtilis_ir_operand_t a1_heap;
	subtilis_ir_operand_t store;
	subtilis_ir_operand_t ref_count;
	subtilis_ir_operand_t a1_gt_zero_label;
	subtilis_ir_operand_t malloc_label;
	subtilis_ir_operand_t realloc_label;
	subtilis_ir_operand_t copy_label;
	subtilis_ir_operand_t alloc_only_label;
	subtilis_ir_operand_t ptr;
	subtilis_ir_operand_t gran;
	size_t alloc_size_reg;
	size_t dest_reg;

	a1_size.reg = a1_size_reg;
	a2_size.reg = a2_size_reg;
	store.reg = a1_mem_reg;
	gran.reg = gran_reg;
	ptr.reg = p->current->reg_counter++;

	a1_gt_zero_label.label = subtilis_ir_section_new_label(p->current);
	malloc_label.label = subtilis_ir_section_new_label(p->current);
	realloc_label.label = subtilis_ir_section_new_label(p->current);
	copy_label.label = subtilis_ir_section_new_label(p->current);
	alloc_only_label.label = subtilis_ir_section_new_label(p->current);

	new_size.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_ADD_I32, a1_size, a2_size, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	if (gran_reg == SIZE_MAX) {
		alloc_size_reg = new_size.reg;
	} else {
		alloc_size_reg = subtilis_ir_section_add_instr(
		    p->current, SUBTILIS_OP_INSTR_ADD_I32, a1_size, gran, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	/*
	 * Our target reference type may have a size of zero.  If so no getref
	 */

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  a1_size, a1_gt_zero_label,
					  alloc_only_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

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

	op2.integer = a1_loc + SUBTIILIS_REFERENCE_DATA_OFF;
	a1_data.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LOADO_I32, store, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op2.integer = a1_loc + SUBTIILIS_REFERENCE_HEAP_OFF;
	a1_heap.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LOADO_I32, store, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	/*
	 * If our object only has one reference we can realloc it.  Otherwise
	 * we need to malloc and copy.
	 */

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

	op2.integer = 1;
	ref_count.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_EQI_I32, ref_count, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC_NF,
					  ref_count, realloc_label,
					  malloc_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

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

	dest_reg = subtilis_reference_type_re_malloc(
	    p, a1_mem_reg, a1_loc, a1_heap.reg, a1_data.reg, a1_size.reg,
	    new_size.reg, alloc_size_reg, true, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.reg = dest_reg;
	subtilis_ir_section_add_instr_no_reg2(p->current, SUBTILIS_OP_INSTR_MOV,
					      ptr, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_no_reg(p->current, SUBTILIS_OP_INSTR_JMP,
					     copy_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

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

	dest_reg = subtilis_reference_type_raw_alloc(p, alloc_size_reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_reference_type_set_size(p, a1_mem_reg, a1_loc, new_size.reg,
					 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_reference_type_set_orig_size(p, a1_mem_reg, a1_loc,
					      new_size.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_reference_set_data(p, dest_reg, a1_mem_reg, a1_loc, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_reference_set_heap(p, dest_reg, a1_mem_reg, a1_loc, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.reg = dest_reg;
	subtilis_ir_section_add_instr_no_reg2(p->current, SUBTILIS_OP_INSTR_MOV,
					      ptr, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_ir_section_add_instr_no_reg(p->current, SUBTILIS_OP_INSTR_JMP,
					     copy_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

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

	dest_reg = subtilis_reference_type_realloc(
	    p, a1_loc, a1_mem_reg, a1_heap.reg, a1_data.reg, a1_size.reg,
	    new_size.reg, a2_size.reg, alloc_size_reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	op1.reg = dest_reg;
	subtilis_ir_section_add_instr_no_reg2(p->current, SUBTILIS_OP_INSTR_MOV,
					      ptr, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

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

	op1.reg = ret_reg;
	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_ADD_I32,
					  op1, ptr, a1_size, err);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0xe8, %rsp
movq 0x18(%rbp), %rax
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 -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rcx
movq 0x18(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rcx)
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x18(%rbp), %r8
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
xorl %esi, %esi
callq 0x38230
movq %rax, -0x50(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6ee5e
jmp 0x6f34c
cmpq $-0x1, -0x30(%rbp)
jne 0x6ee72
movq -0x50(%rbp), %rax
movq %rax, -0xc0(%rbp)
jmp 0x6eea7
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x18(%rbp), %r8
movq -0x40(%rbp), %rdx
movq -0xb8(%rbp), %rcx
xorl %esi, %esi
callq 0x38230
movq %rax, -0xc0(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6eea5
jmp 0x6f34c
jmp 0x6eea7
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x18(%rbp), %r9
movq -0x40(%rbp), %rdx
movq -0x88(%rbp), %rcx
movq -0xa8(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6eedd
jmp 0x6f34c
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x88(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0x39960
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6ef03
jmp 0x6f34c
movq -0x18(%rbp), %rax
addq $0x4, %rax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x18(%rbp), %r8
movq -0x78(%rbp), %rdx
movq -0x60(%rbp), %rcx
movl $0x12, %esi
callq 0x38230
movq %rax, -0x68(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6ef3e
jmp 0x6f34c
movq -0x18(%rbp), %rax
addq $0x8, %rax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x18(%rbp), %r8
movq -0x78(%rbp), %rdx
movq -0x60(%rbp), %rcx
movl $0x12, %esi
callq 0x38230
movq %rax, -0x70(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6ef79
jmp 0x6f34c
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x18(%rbp), %rcx
movq -0x70(%rbp), %rdx
movl $0x7a, %esi
callq 0x38490
movq %rax, -0x80(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6efa5
jmp 0x6f34c
movl $0x1, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x18(%rbp), %r8
movq -0x80(%rbp), %rdx
movq -0x60(%rbp), %rcx
movl $0x2d, %esi
callq 0x38230
movq %rax, -0x80(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6efdc
jmp 0x6f34c
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x18(%rbp), %r9
movq -0x80(%rbp), %rdx
movq -0x98(%rbp), %rcx
movq -0x90(%rbp), %r8
movl $0x44, %esi
callq 0x38360
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f012
jmp 0x6f34c
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x90(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0x39960
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f038
jmp 0x6f34c
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x70(%rbp), %rcx
movq -0x68(%rbp), %r8
movq -0x40(%rbp), %r9
movq -0x50(%rbp), %r11
movq -0xc0(%rbp), %r10
movq 0x18(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x6dcb0
movq %rax, -0xc8(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f08f
jmp 0x6f34c
movq -0xc8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x18(%rbp), %r8
movq -0xb0(%rbp), %rdx
movq -0x58(%rbp), %rcx
movl $0x1d, %esi
callq 0x385a0
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f0c9
jmp 0x6f34c
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x18(%rbp), %rcx
movq -0xa0(%rbp), %rdx
movl $0x45, %esi
callq 0x38540
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f0f4
jmp 0x6f34c
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0xa8(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0x39960
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f11a
jmp 0x6f34c
movq -0x10(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0x6de60
movq %rax, -0xc8(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f143
jmp 0x6f34c
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq 0x18(%rbp), %r8
callq 0x6dc50
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f16a
jmp 0x6f34c
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq 0x18(%rbp), %r8
callq 0x6dfa0
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f191
jmp 0x6f34c
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq 0x18(%rbp), %r8
callq 0x6d9a0
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f1bb
jmp 0x6f34c
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq 0x18(%rbp), %r8
callq 0x6da00
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f1e5
jmp 0x6f34c
movq -0xc8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x18(%rbp), %r8
movq -0xb0(%rbp), %rdx
movq -0x58(%rbp), %rcx
movl $0x1d, %esi
callq 0x385a0
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f21f
jmp 0x6f34c
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x18(%rbp), %rcx
movq -0xa0(%rbp), %rdx
movl $0x45, %esi
callq 0x38540
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f24a
jmp 0x6f34c
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x98(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0x39960
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f270
jmp 0x6f34c
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x70(%rbp), %rcx
movq -0x68(%rbp), %r8
movq -0x40(%rbp), %r9
movq -0x50(%rbp), %rbx
movq -0x48(%rbp), %r11
movq -0xc0(%rbp), %r10
movq 0x18(%rbp), %rax
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x6e580
movq %rax, -0xc8(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f2c8
jmp 0x6f34c
movq -0xc8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x18(%rbp), %r8
movq -0xb0(%rbp), %rdx
movq -0x58(%rbp), %rcx
movl $0x1d, %esi
callq 0x385a0
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f2ff
jmp 0x6f34c
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0xa0(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0x39960
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f322
jmp 0x6f34c
movq 0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x18(%rbp), %r9
movq -0x58(%rbp), %rdx
movq -0xb0(%rbp), %rcx
movq -0x40(%rbp), %r8
xorl %esi, %esi
callq 0x38360
addq $0xe8, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)