// File: /workspace/github_c_makefile_star2_O2/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 0x4c214
movq %rax, 0x10(%rsp)
movq 0x18(%r12), %rdi
callq 0x4c214
movq %rax, %r14
movq 0x20(%r12), %rdi
callq 0x4c214
movq %rax, %rbp
movq 0x28(%r12), %rdi
callq 0x4c214
movq %rax, %r12
movq %rbx, 0x8(%rsp)
movl $0x4, (%rsp)
pushq $0xd
popq %rsi
pushq $0xf
popq %rdx
pushq $0xe
popq %rcx
movq %r15, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x4d213
cmpl $0x0, (%rbx)
jne 0x6b857
movq %rbx, (%rsp)
pushq $0xd
popq %rsi
pushq $0xe
popq %rdx
pushq $0x1
popq %r8
movq %r15, %rdi
xorl %ecx, %ecx
movq %r14, %r9
callq 0x4d518
cmpl $0x0, (%rbx)
jne 0x6b857
movq %rbx, (%rsp)
pushq $0xd
popq %rsi
pushq $0xe
popq %rdx
pushq $0x2
popq %r8
movq %r15, %rdi
xorl %ecx, %ecx
movq %rbp, %r9
callq 0x4d518
cmpl $0x0, (%rbx)
jne 0x6b857
movq %rbx, (%rsp)
pushq $0xd
popq %rsi
pushq $0xe
popq %rdx
pushq $0x3
popq %r8
movq %r15, %rdi
xorl %ecx, %ecx
movq %r12, %r9
callq 0x4d518
cmpl $0x0, (%rbx)
jne 0x6b857
pushq $0xe
popq %rsi
pushq $0xf
popq %rcx
pushq $0x1c
popq %r8
movl $0x2000c, %edx          # imm = 0x2000C
movq %r15, %rdi
movq %rbx, %r9
callq 0x4d4d9
cmpl $0x0, (%rbx)
jne 0x6b857
movq (%r15), %rdi
leaq 0x1(%rdi), %rax
movq %rax, (%r15)
callq 0x4c214
pushq $0x6
popq %rdx
movq %r15, %rdi
movq %r13, %rsi
movq %rax, %rcx
movq %rbx, %r8
callq 0x4f21a
cmpl $0x0, (%rbx)
jne 0x6b857
pushq $0x2
popq %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x4c92b
cmpl $0x0, (%rbx)
jne 0x6b857
movl $0x7, 0x8(%rax)
movb $0x0, 0xc(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq %r12, 0x18(%rax)
andl $0x0, 0x20(%rax)
movq $0x3, 0x28(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq