// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/backends/riscos_common/riscos_arm.c
// Function: subtilis_riscos_arm_inkey
void subtilis_riscos_arm_inkey(subtilis_ir_section_t *s, size_t start,
			       void *user_data, subtilis_error_t *err)
{
	subtilis_arm_reg_t one;
	subtilis_arm_section_t *arm_s = user_data;
	subtilis_ir_inst_t *inkey = &s->ops[start]->op.instr;
	size_t ir_dest = inkey->operands[0].reg;
	subtilis_arm_reg_t dest = subtilis_arm_ir_to_arm_reg(ir_dest);
	size_t ir_op1 = inkey->operands[1].reg;
	subtilis_arm_reg_t op1 = subtilis_arm_ir_to_arm_reg(ir_op1);

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

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

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

	/* OS_Byte */
	/* read_mask = 7 = r0, r1, r2  */
	/* write_mask = 6 = r1, r2 */
	subtilis_arm_add_swi(arm_s, SUBTILIS_ARM_CCODE_AL, 0x6 + 0x20000, 7, 6,
			     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;

	subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_VC, true, dest, 1,
				 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	subtilis_arm_add_mvn_imm(arm_s, SUBTILIS_ARM_CCODE_NE, false, dest, 0,
				 err);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movq %rdi, %r12
movq 0x48(%rdi), %rax
movq (%rax,%rsi,8), %r13
movq 0x10(%r13), %rdi
callq 0x4c214
movq %rax, %r15
movq 0x18(%r13), %rdi
callq 0x4c214
movq %rax, %r13
movq %r14, 0x8(%rsp)
movl $0x81, (%rsp)
pushq $0xd
popq %rsi
pushq $0xf
popq %rdx
pushq $0xe
popq %rcx
movq %rbx, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x4d213
cmpl $0x0, (%r14)
jne 0x6a3d0
movq %r14, (%rsp)
pushq $0xd
popq %rsi
pushq $0xe
popq %rdx
pushq $0x1
popq %r8
movq %rbx, %rdi
xorl %ecx, %ecx
movq %r13, %r9
callq 0x4d518
cmpl $0x0, (%r14)
jne 0x6a3d0
movq %r14, 0x8(%rsp)
movl $0xff, (%rsp)
pushq $0xd
popq %rsi
pushq $0xf
popq %rdx
pushq $0xe
popq %rcx
pushq $0x2
popq %r9
movq %rbx, %rdi
xorl %r8d, %r8d
callq 0x4d213
cmpl $0x0, (%r14)
jne 0x6a3d0
pushq $0xe
popq %rsi
pushq $0x7
popq %rcx
pushq $0x6
popq %r8
movl $0x20006, %edx          # imm = 0x20006
movq %rbx, %rdi
movq %r14, %r9
callq 0x4d4d9
cmpl $0x0, (%r14)
jne 0x6a3d0
movq (%rbx), %rdi
leaq 0x1(%rdi), %rax
movq %rax, (%rbx)
callq 0x4c214
pushq $0x6
popq %rdx
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rcx
movq %r14, %r8
callq 0x4f21a
cmpl $0x0, (%r14)
jne 0x6a3d0
movq %r14, (%rsp)
pushq $0xd
popq %rsi
pushq $0x7
popq %rdx
pushq $0x1
popq %rcx
pushq $0x1
popq %r9
movq %rbx, %rdi
movq %r15, %r8
callq 0x4d518
cmpl $0x0, (%r14)
jne 0x6a3d0
movq %r14, 0x8(%rsp)
andl $0x0, (%rsp)
pushq $0xf
popq %rsi
pushq $0xd
popq %rdx
pushq $0x1
popq %rcx
movq %rbx, %rdi
xorl %r8d, %r8d
movq %r15, %r9
callq 0x4d213
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq