// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/backends/riscos_common/riscos_arm.c
// Function: subtilis_riscos_arm_block_free_space
void subtilis_riscos_arm_block_free_space(subtilis_ir_section_t *s,
					  size_t start, void *user_data,
					  subtilis_error_t *err)
{
	subtilis_arm_reg_t total;
	subtilis_arm_reg_t space_used;
	subtilis_arm_instr_t *instr;
	subtilis_arm_data_instr_t *datai;
	subtilis_arm_section_t *arm_s = user_data;
	subtilis_ir_inst_t *block_space = &s->ops[start]->op.instr;
	subtilis_arm_reg_t dest =
	    subtilis_arm_ir_to_arm_reg(block_space->operands[0].reg);
	subtilis_arm_reg_t block =
	    subtilis_arm_ir_to_arm_reg(block_space->operands[1].reg);

	total = subtilis_arm_ir_to_arm_reg(arm_s->reg_counter++);
	space_used = subtilis_arm_ir_to_arm_reg(arm_s->reg_counter++);

	subtilis_arm_add_stran_imm(arm_s, SUBTILIS_ARM_INSTR_LDR,
				   SUBTILIS_ARM_CCODE_AL, space_used, block, -4,
				   false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_stran_imm(arm_s, SUBTILIS_ARM_INSTR_LDR,
				   SUBTILIS_ARM_CCODE_AL, total, block, -16,
				   false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	instr =
	    subtilis_arm_section_add_instr(arm_s, SUBTILIS_ARM_INSTR_SUB, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	datai = &instr->operands.data;
	datai->ccode = SUBTILIS_ARM_CCODE_AL;
	datai->status = false;
	datai->dest = dest;
	datai->op1 = total;
	datai->op2.type = SUBTILIS_ARM_OP2_REG;
	datai->op2.op.reg = space_used;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq $0x8, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x6fe90
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x6fe90
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq %rdi, %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
callq 0x6fe90
movq %rax, -0x28(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq %rdi, %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
callq 0x6fe90
movq %rax, -0x30(%rbp)
movq -0x48(%rbp), %rdi
movq -0x30(%rbp), %rcx
movq -0x60(%rbp), %r8
movq -0x20(%rbp), %rax
movl $0x12, %esi
movl $0xe, %edx
movl $0xfffffffc, %r9d       # imm = 0xFFFFFFFC
xorl %r10d, %r10d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x72030
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa69a0
jmp 0xa6a4d
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rcx
movq -0x60(%rbp), %r8
movq -0x20(%rbp), %rax
movl $0x12, %esi
movl $0xe, %edx
movl $0xfffffff0, %r9d       # imm = 0xFFFFFFF0
xorl %r10d, %r10d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x72030
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa69df
jmp 0xa6a4d
movq -0x48(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0x2, %esi
callq 0x70b50
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa6a00
jmp 0xa6a4d
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl $0xe, (%rax)
movq -0x40(%rbp), %rax
movb $0x0, 0x4(%rax)
movq -0x58(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)