// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/reference_type.c
// Function: prv_resize_with_realloc
static size_t prv_resize_with_realloc(subtilis_parser_t *p, size_t loc,
				      size_t store_reg, size_t heap_reg,
				      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 diff;
	size_t dest_reg = p->current->reg_counter++;

	/*
	 * It's possible that even though our heap block is referenced only by
	 * one variable, that our data and heap pointers do not match.  This
	 * could happen if we sliced a string, for example, and the original
	 * string then went out of scope but the slice remained in scope.
	 */

	op1.reg = data_reg;
	op2.reg = heap_reg;
	diff.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_SUB_I32, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	op0.reg = heap_reg;
	op1.reg = size_reg;
	op2.reg = dest_reg;
	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_REALLOC,
					  op0, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	subtilis_exp_handle_errors(p, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	op0.reg = size_reg;
	op1.reg = store_reg;
	op2.integer = loc + SUBTIILIS_REFERENCE_SIZE_OFF;
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_STOREO_I32, op0, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	op2.integer = loc + SUBTIILIS_REFERENCE_ORIG_SIZE_OFF;
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_STOREO_I32, op0, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	op0.reg = dest_reg;
	op2.integer = loc + SUBTIILIS_REFERENCE_HEAP_OFF;
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_STOREO_I32, op0, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	dest_reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_ADD_I32, op0, diff, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	op0.reg = dest_reg;
	op2.integer = loc + SUBTIILIS_REFERENCE_DATA_OFF;
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_STOREO_I32, op0, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	return dest_reg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %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 -0x10(%rbp), %rax
movq 0x48(%rax), %rcx
movq 0x18(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rcx)
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %r8
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
movl $0x2, %esi
callq 0x38230
movq %rax, -0x58(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6e6c7
movq $-0x1, -0x8(%rbp)
jmp 0x6e89d
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %r9
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %r8
movl $0x77, %esi
callq 0x38360
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6e717
movq $-0x1, -0x8(%rbp)
jmp 0x6e89d
movq -0x10(%rbp), %rdi
movq 0x10(%rbp), %rsi
callq 0x36ce0
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6e73a
movq $-0x1, -0x8(%rbp)
jmp 0x6e89d
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
addq $0x0, %rax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %r9
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %r8
movl $0x17, %esi
callq 0x38360
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6e78d
movq $-0x1, -0x8(%rbp)
jmp 0x6e89d
movq -0x18(%rbp), %rax
addq $0xc, %rax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %r9
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %r8
movl $0x17, %esi
callq 0x38360
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6e7d0
movq $-0x1, -0x8(%rbp)
jmp 0x6e89d
movq -0x60(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
addq $0x8, %rax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %r9
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %r8
movl $0x17, %esi
callq 0x38360
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6e81b
movq $-0x1, -0x8(%rbp)
jmp 0x6e89d
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %r8
movq -0x40(%rbp), %rdx
movq -0x58(%rbp), %rcx
xorl %esi, %esi
callq 0x38230
movq %rax, -0x60(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6e84d
movq $-0x1, -0x8(%rbp)
jmp 0x6e89d
movq -0x60(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %r9
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %r8
movl $0x17, %esi
callq 0x38360
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6e895
movq $-0x1, -0x8(%rbp)
jmp 0x6e89d
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)