// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/backends/riscos_common/riscos_arm.c
// Function: subtilis_riscos_block_get
void subtilis_riscos_block_get(subtilis_ir_section_t *s, size_t start,
			       void *user_data, subtilis_error_t *err)
{
	subtilis_arm_reg_t dest;
	subtilis_arm_reg_t handle;
	subtilis_arm_reg_t buffer;
	subtilis_arm_reg_t length;
	subtilis_arm_reg_t one;
	subtilis_arm_instr_t *instr;
	subtilis_arm_data_instr_t *datai;
	subtilis_arm_section_t *arm_s = user_data;
	subtilis_ir_inst_t *blockget = &s->ops[start]->op.instr;

	dest = subtilis_arm_ir_to_arm_reg(blockget->operands[0].reg);
	handle = subtilis_arm_ir_to_arm_reg(blockget->operands[1].reg);
	buffer = subtilis_arm_ir_to_arm_reg(blockget->operands[2].reg);
	length = subtilis_arm_ir_to_arm_reg(blockget->operands[3].reg);

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

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

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

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

	/* OS_GBPB  4 */
	/* read_mask = 0xf = r0, r1, r2, r3 */
	/* write_mask = 0x1c = r2, r3, r4 */
	subtilis_arm_add_swi(arm_s, SUBTILIS_ARM_CCODE_AL, 0x20000 + 0x0c, 0xf,
			     0x1c, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	one = subtilis_arm_ir_to_arm_reg(arm_s->reg_counter++);
	subtilis_arm_gen_sete_load_reg(arm_s, s, SUBTILIS_ARM_CCODE_VS, one,
				       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_VC;
	datai->status = false;
	datai->dest = dest;
	datai->op1 = length;
	datai->op2.type = SUBTILIS_ARM_OP2_REG;
	datai->op2.op.reg = 3;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq $0x8, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x6fe90
movq %rax, -0x28(%rbp)
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x6fe90
movq %rax, -0x30(%rbp)
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x6fe90
movq %rax, -0x38(%rbp)
movq -0x68(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x6fe90
movq %rax, -0x40(%rbp)
movq -0x60(%rbp), %rdi
movq -0x20(%rbp), %rax
movl $0xd, %esi
movl $0xf, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
movl $0x4, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x71b10
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa769b
jmp 0xa7817
movq -0x60(%rbp), %rdi
movq -0x30(%rbp), %r9
movq -0x20(%rbp), %rax
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movq %rax, (%rsp)
callq 0x71fa0
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa76d0
jmp 0xa7817
movq -0x60(%rbp), %rdi
movq -0x38(%rbp), %r9
movq -0x20(%rbp), %rax
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movl $0x2, %r8d
movq %rax, (%rsp)
callq 0x71fa0
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa7705
jmp 0xa7817
movq -0x60(%rbp), %rdi
movq -0x40(%rbp), %r9
movq -0x20(%rbp), %rax
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movl $0x3, %r8d
movq %rax, (%rsp)
callq 0x71fa0
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa773a
jmp 0xa7817
movq -0x60(%rbp), %rdi
movq -0x20(%rbp), %r9
movl $0xe, %esi
movl $0x2000c, %edx          # imm = 0x2000C
movl $0xf, %ecx
movl $0x1c, %r8d
callq 0x71f20
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa776a
jmp 0xa7817
movq -0x60(%rbp), %rax
movq (%rax), %rdi
movq %rdi, %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
callq 0x6fe90
movq %rax, -0x48(%rbp)
movq -0x60(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x48(%rbp), %rcx
movq -0x20(%rbp), %r8
movl $0x6, %edx
callq 0x75ce0
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa77a9
jmp 0xa7817
movq -0x60(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0x2, %esi
callq 0x70b50
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa77ca
jmp 0xa7817
movq -0x50(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl $0x7, (%rax)
movq -0x58(%rbp), %rax
movb $0x0, 0x4(%rax)
movq -0x28(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x58(%rbp), %rax
movq $0x3, 0x20(%rax)
addq $0x80, %rsp
popq %rbp
retq