// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/backends/riscos_common/riscos_arm.c
// Function: prv_alloc
static void prv_alloc(subtilis_ir_section_t *s, subtilis_arm_section_t *arm_s,
		      subtilis_error_t *err)
{
	size_t good_label;
	size_t bad_label;
	subtilis_arm_reg_t heap_start = 0;
	subtilis_arm_reg_t requested_size = 1;
	subtilis_arm_reg_t scratch = 2;
	subtilis_arm_reg_t actual_size = 11;

	good_label = arm_s->label_counter++;
	bad_label = arm_s->label_counter++;

	/*
	 * We need to add 8 bytes for
	 * 1. The ref count.
	 * 2. The requested size + 16 bytes.  This information can be used to
	 *    determine how much data is actually left in the allocated block
	 *    which helps with re-alloc.
	 */

	subtilis_arm_add_add_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false,
				 requested_size, 0, 8, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_add_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false,
				 actual_size, requested_size, 8, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	prv_load_heap_pointer(arm_s, scratch, heap_start, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_heap_alloc(arm_s, good_label, bad_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_section_add_label(arm_s, good_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	/*
	 * Store reference count of 1 in first few bytes of new block
	 */

	subtilis_arm_add_mov_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false, scratch,
				 1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_stran_imm(arm_s, SUBTILIS_ARM_INSTR_STR,
				   SUBTILIS_ARM_CCODE_AL, scratch, 0, 0, false,
				   err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	/*
	 * Store actual size of block.  Real size is R0 - 8
	 */

	subtilis_arm_add_stran_imm(arm_s, SUBTILIS_ARM_INSTR_STR,
				   SUBTILIS_ARM_CCODE_AL, actual_size, 0, 4,
				   false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	/*
	 * We want to return allocated block + 8 to program.
	 */

	subtilis_arm_add_add_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false, 0, 0, 8,
				 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_AL, false, 15, 14,
				 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_section_add_label(arm_s, bad_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_gen_sete(arm_s, s, SUBTILIS_ARM_CCODE_AL, scratch,
			      SUBTILIS_ERROR_CODE_OOM, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_mov_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false, 0, 0,
				 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_AL, false, 15, 14,
				 err);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x1, -0x38(%rbp)
movq $0x2, -0x40(%rbp)
movq $0xb, -0x48(%rbp)
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x10(%rcx)
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x10(%rcx)
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %r9
movq -0x18(%rbp), %rax
movl $0x4, %esi
movl $0x2, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
xorl %r10d, %r10d
movq $0x0, (%rsp)
movl $0x8, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x71640
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa880b
jmp 0xa8a97
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %r9
movq -0x38(%rbp), %r10
movq -0x18(%rbp), %rax
movl $0x4, %esi
movl $0x2, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
movq %r10, (%rsp)
movl $0x8, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x71640
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa8851
jmp 0xa8a97
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rcx
callq 0xa6830
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa8874
jmp 0xa8a97
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rcx
callq 0x8dea0
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa8897
jmp 0xa8a97
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x70850
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa88b6
jmp 0xa8a97
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %r9
movq -0x18(%rbp), %rax
movl $0xd, %esi
movl $0xf, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
movl $0x1, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x71b10
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa88f3
jmp 0xa8a97
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
movl $0x13, %esi
movl $0xe, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x72030
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa892e
jmp 0xa8a97
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rcx
movq -0x18(%rbp), %rax
movl $0x13, %esi
movl $0xe, %edx
xorl %r8d, %r8d
movl $0x4, %r9d
xorl %r10d, %r10d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x72030
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa896f
jmp 0xa8a97
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl $0x4, %esi
movl $0x2, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
movq $0x0, (%rsp)
movl $0x8, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x71640
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa89b4
jmp 0xa8a97
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movl $0xf, %r8d
movl $0xe, %r9d
movq %rax, (%rsp)
callq 0x71fa0
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa89eb
jmp 0xa8a97
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x70850
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa8a0a
jmp 0xa8a97
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %r9
movl $0xe, %edx
movl $0xb, %r8d
callq 0x75bc0
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa8a35
jmp 0xa8a97
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl $0xd, %esi
movl $0xf, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x71b10
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa8a6e
jmp 0xa8a97
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movl $0xf, %r8d
movl $0xe, %r9d
movq %rax, (%rsp)
callq 0x71fa0
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)