// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/frontend/reference_type.c
// Function: subtilis_reference_type_re_malloc
size_t subtilis_reference_type_re_malloc(subtilis_parser_t *p, size_t store_reg,
					 size_t loc, size_t heap_reg,
					 size_t data_reg, size_t size_reg,
					 size_t new_size_reg,
					 size_t alloc_size_reg,
					 bool heap_known_valid,
					 subtilis_error_t *err)

/* clang-format on */
{
	size_t dest_reg;
	subtilis_ir_operand_t data;

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

	/*
	 * There's no leak potential here as mempcy and deref cannot fail.
	 */

	subtilis_reference_type_memcpy_dest(p, dest_reg, data_reg, size_reg,
					    err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	if (heap_known_valid) {
		data.reg = heap_reg;
		reference_type_call_deref(p, data, err);
	} else {
		subtilis_reference_type_deref(p, store_reg, loc, err);
	}
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	subtilis_reference_set_data(p, dest_reg, store_reg, loc, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	subtilis_reference_set_heap(p, dest_reg, store_reg, loc, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	if (size_reg != new_size_reg) {
		subtilis_reference_type_set_size(p, store_reg, loc,
						 new_size_reg, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;
		subtilis_reference_type_set_orig_size(p, store_reg, loc,
						      new_size_reg, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;
	}

	return dest_reg;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r14
movq %r8, (%rsp)
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %rbp
movq 0x68(%rsp), %r13
movq 0x58(%rsp), %rsi
movq %r13, %rdx
callq 0x4da8d
movq $-0x1, %rcx
cmpl $0x0, (%r13)
jne 0x4d9b8
movq %r12, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
movq %rbp, %rdi
movq %rax, %rbx
movq %rax, %rsi
movq (%rsp), %rdx
movq %r14, %rcx
movq %r13, %r8
callq 0x4d7ec
cmpl $0x0, (%r13)
je 0x4d96d
movq $-0x1, %rcx
jmp 0x4d9b8
movq %rbx, (%rsp)
movq %rbp, %rdi
cmpb $0x0, 0x60(%rsp)
je 0x4d992
movq 0x10(%rsp), %rsi
movq 0x68(%rsp), %r12
movq %r12, %rdx
callq 0x4d56b
movq %r15, %rbx
jmp 0x4d9aa
movq 0x8(%rsp), %rsi
movq %r15, %rbx
movq %r15, %rdx
movq 0x68(%rsp), %r12
movq %r12, %rcx
callq 0x4d642
cmpl $0x0, (%r12)
movq $-0x1, %rcx
je 0x4d9ca
movq %rcx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leal 0x4(%rbx), %r8d
movq 0x48(%rbp), %rdi
movl $0x17, %esi
movq (%rsp), %r15
movq %r15, %rdx
movq 0x8(%rsp), %r13
movq %r13, %rcx
movq %r12, %r9
callq 0x2bd42
cmpl $0x0, (%r12)
jne 0x4d964
leal 0x8(%rbx), %r8d
movq 0x48(%rbp), %rdi
movl $0x17, %esi
movq %r15, %rdx
movq %r13, %rcx
movq %r12, %r9
callq 0x2bd42
cmpl $0x0, (%r12)
jne 0x4d964
movq 0x50(%rsp), %r13
cmpq %r13, %r14
jne 0x4da2f
movq (%rsp), %rcx
jmp 0x4d9b8
movq 0x48(%rbp), %rdi
movl %ebx, %r8d
movl $0x17, %esi
movq %r13, %rdx
movq 0x8(%rsp), %r15
movq %r15, %rcx
movq 0x68(%rsp), %r14
movq %r14, %r9
callq 0x2bd42
cmpl $0x0, (%r14)
jne 0x4d964
addl $0xc, %ebx
movq 0x48(%rbp), %rdi
movl $0x17, %esi
movq %r13, %rdx
movq %r15, %rcx
movq %rbx, %r8
movq %r14, %r9
callq 0x2bd42
cmpl $0x0, (%r14)
movq $-0x1, %rcx
jne 0x4d9b8
jmp 0x4da29