// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/backends/riscos_common/riscos_arm.c
// Function: subtilis_riscos_arm_origin
void subtilis_riscos_arm_origin(subtilis_ir_section_t *s, size_t start,
				void *user_data, subtilis_error_t *err)
{
	subtilis_arm_reg_t dest;
	subtilis_arm_reg_t op2;
	subtilis_arm_instr_t *instr;
	subtilis_arm_data_instr_t *mov;
	subtilis_arm_section_t *arm_s = user_data;
	subtilis_ir_inst_t *origin = &s->ops[start]->op.instr;
	const size_t vdu = 256 + 0x20000;
	size_t i;

	/* read_mask = 0 */
	/* write_mask = 0 */
	subtilis_arm_add_swi(arm_s, SUBTILIS_ARM_CCODE_AL, vdu + 29, 0, 0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_riscos_handle_graphics_error(arm_s, s, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	for (i = 0; i < 2; i++) {
		dest = 0;
		op2 = subtilis_arm_ir_to_arm_reg(origin->operands[i].reg);

		subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_VC, false,
					 dest, op2, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		/* OS_WriteC */
		/* read_mask = 0x1 = r0 */
		/* write_mask = 0 */
		subtilis_arm_add_swi(arm_s, SUBTILIS_ARM_CCODE_VC, 0 + 0x20000,
				     1, 0, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		instr = subtilis_arm_section_add_instr(
		    arm_s, SUBTILIS_ARM_INSTR_MOV, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
		mov = &instr->operands.data;

		mov->status = false;
		mov->ccode = SUBTILIS_ARM_CCODE_VC;
		mov->dest = dest;
		mov->op2.type = SUBTILIS_ARM_OP2_SHIFTED;
		mov->op2.op.shift.type = SUBTILIS_ARM_SHIFT_LSR;
		mov->op2.op.shift.reg =
		    subtilis_arm_ir_to_arm_reg(origin->operands[i].reg);
		mov->op2.op.shift.shift_reg = false;
		mov->op2.op.shift.shift.integer = 8;

		/* OS_WriteC */
		/* read_mask = 0x1 = r0 */
		/* write_mask = 0 */
		subtilis_arm_add_swi(arm_s, SUBTILIS_ARM_CCODE_VC, 0 + 0x20000,
				     1, 0, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		subtilis_riscos_handle_graphics_error(arm_s, s, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rdi, %r15
movq 0x48(%rdi), %rax
movq (%rax,%rsi,8), %rax
movq %rax, 0x10(%rsp)
movl $0x2011d, %edx          # imm = 0x2011D
movq %r14, %rdi
movl $0xe, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x50463
cmpl $0x0, (%rbx)
jne 0x6efa8
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x6e975
cmpl $0x0, (%rbx)
je 0x6efb7
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bpl
xorl %r13d, %r13d
movq 0x10(%rsp), %rax
movq 0x10(%rax,%r13,8), %rdi
callq 0x4efba
movq %rbx, (%rsp)
movq %r14, %rdi
movl $0xd, %esi
movl $0x7, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rax, %r9
callq 0x504b3
cmpl $0x0, (%rbx)
jne 0x6efa8
movl $0x20000, %edx          # imm = 0x20000
movq %r14, %rdi
movl $0x7, %esi
movl $0x1, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x50463
cmpl $0x0, (%rbx)
jne 0x6efa8
movq %r14, %rdi
movl $0xd, %esi
movq %rbx, %rdx
callq 0x4f6e2
cmpl $0x0, (%rbx)
jne 0x6efa8
movq %rax, %r12
xorl %eax, %eax
movb %al, 0xc(%r12)
movl $0x7, 0x8(%r12)
movq $0x0, 0x10(%r12)
movl $0x2, %eax
movl %eax, 0x20(%r12)
movl %eax, 0x30(%r12)
movq 0x10(%rsp), %rax
movq 0x10(%rax,%r13,8), %rdi
callq 0x4efba
movq %rax, 0x28(%r12)
xorl %eax, %eax
movb %al, 0x40(%r12)
movl $0x8, 0x38(%r12)
movl $0x20000, %edx          # imm = 0x20000
movq %r14, %rdi
movl $0x7, %esi
movl $0x1, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x50463
cmpl $0x0, (%rbx)
jne 0x6efa8
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x6e975
cmpl $0x0, (%rbx)
sete %al
movl $0x1, %r13d
testb %bpl, %al
movl $0x0, %ebp
jne 0x6efbd
jmp 0x6efa8