// File: /workspace/github_c_makefile_star2_O2/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)
pushq $0xe
popq %rsi
movl $0x2011d, %edx          # imm = 0x2011D
movq %r14, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x4d4d9
cmpl $0x0, (%rbx)
jne 0x69c9a
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x696e4
cmpl $0x0, (%rbx)
je 0x69ca9
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0xd
popq %rbp
xorl %r12d, %r12d
cmpq $0x2, %r12
je 0x69c9a
movq 0x10(%rsp), %rax
movq 0x10(%rax,%r12,8), %rdi
callq 0x4c214
movq %rbx, (%rsp)
movq %r14, %rdi
movl %ebp, %esi
pushq $0x7
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rax, %r9
callq 0x4d518
cmpl $0x0, (%rbx)
jne 0x69c9a
movl $0x20000, %edx          # imm = 0x20000
movq %r14, %rdi
pushq $0x7
popq %rsi
pushq $0x1
popq %rcx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x4d4d9
cmpl $0x0, (%rbx)
jne 0x69c9a
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x4c92b
cmpl $0x0, (%rbx)
jne 0x69c9a
movq %rax, %r13
xorl %eax, %eax
movb %al, 0xc(%r13)
movl $0x7, 0x8(%r13)
andq $0x0, 0x10(%r13)
pushq $0x2
popq %rax
movl %eax, 0x20(%r13)
movl %eax, 0x30(%r13)
movq 0x10(%rsp), %rax
movq 0x10(%rax,%r12,8), %rdi
callq 0x4c214
movq %rax, 0x28(%r13)
xorl %eax, %eax
movb %al, 0x40(%r13)
movl $0x8, 0x38(%r13)
movl $0x20000, %edx          # imm = 0x20000
movq %r14, %rdi
pushq $0x7
popq %rsi
pushq $0x1
popq %rcx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x4d4d9
cmpl $0x0, (%rbx)
jne 0x69c9a
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x696e4
incq %r12
cmpl $0x0, (%rbx)
je 0x69caf
jmp 0x69c9a