// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rdx, %r15
movq %rdi, %r13
movq 0x48(%rdi), %rax
movq (%rax,%rsi,8), %r12
movq 0x10(%r12), %rdi
callq 0x4eff7
movq %rax, 0x10(%rsp)
movq 0x18(%r12), %rdi
callq 0x4eff7
movq %rax, %r14
movq 0x20(%r12), %rdi
callq 0x4eff7
movq %rax, %rbp
movq 0x28(%r12), %rdi
callq 0x4eff7
movq %rax, %r12
movq %rbx, 0x8(%rsp)
movl $0x4, (%rsp)
movq %r15, %rdi
movl $0xd, %esi
movl $0xf, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x50249
cmpl $0x0, (%rbx)
jne 0x711bc
movq %rbx, (%rsp)
movl $0x1, %r8d
movq %r15, %rdi
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movq %r14, %r9
callq 0x5060d
cmpl $0x0, (%rbx)
jne 0x711bc
movq %rbx, (%rsp)
movl $0x2, %r8d
movq %r15, %rdi
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movq %rbp, %r9
callq 0x5060d
cmpl $0x0, (%rbx)
jne 0x711bc
movq %rbx, (%rsp)
movl $0x3, %r8d
movq %r15, %rdi
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movq %r12, %r9
callq 0x5060d
cmpl $0x0, (%rbx)
jne 0x711bc
movl $0x2000c, %edx          # imm = 0x2000C
movq %r15, %rdi
movl $0xe, %esi
movl $0xf, %ecx
movl $0x1c, %r8d
movq %rbx, %r9
callq 0x505b2
cmpl $0x0, (%rbx)
jne 0x711bc
movq (%r15), %rdi
leaq 0x1(%rdi), %rax
movq %rax, (%r15)
callq 0x4eff7
movq %r15, %rdi
movq %r13, %rsi
movl $0x6, %edx
movq %rax, %rcx
movq %rbx, %r8
callq 0x526e6
cmpl $0x0, (%rbx)
jne 0x711bc
movq %r15, %rdi
movl $0x2, %esi
movq %rbx, %rdx
callq 0x4f73a
cmpl $0x0, (%rbx)
jne 0x711bc
movl $0x7, 0x8(%rax)
movb $0x0, 0xc(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq %r12, 0x18(%rax)
movl $0x0, 0x20(%rax)
movq $0x3, 0x28(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq