// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/backends/riscos_common/riscos_arm.c
// Function: subtilis_riscos_arm_syscall
void subtilis_riscos_arm_syscall(subtilis_ir_section_t *s, size_t start,
				 void *user_data,
				 const subtilis_arm_swi_t *swi_list,
				 size_t swi_count, subtilis_error_t *err)
{
	uint32_t out_regs;
	size_t in_reg;
	size_t out_reg;
	size_t i;
	subtilis_arm_reg_t one;
	subtilis_arm_ccode_type_t ccode = SUBTILIS_ARM_CCODE_AL;
	subtilis_arm_section_t *arm_s = user_data;
	subtilis_ir_sys_call_t *sys_call = &s->ops[start]->op.sys_call;
	size_t call_id = sys_call->call_id & ~(0x20000);

	out_regs = prv_check_out_regs(call_id, swi_list, swi_count, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	for (i = 0; i <= 10; i++) {
		if (!((1 << i) & sys_call->in_mask))
			continue;
		in_reg = subtilis_arm_ir_to_arm_reg(sys_call->in_regs[i]);
		subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_AL, false, i,
					 in_reg, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	subtilis_arm_add_swi(arm_s, SUBTILIS_ARM_CCODE_AL, sys_call->call_id,
			     sys_call->in_mask, out_regs, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	if ((sys_call->call_id & 0x20000) &&
	    (sys_call->flags_reg == SIZE_MAX)) {
		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);
		ccode = SUBTILIS_ARM_CCODE_VC;
	}

	for (i = 0; i <= 10; i++) {
		if (!((1 << i) & sys_call->out_mask))
			continue;
		out_reg = subtilis_arm_ir_to_arm_reg(sys_call->out_regs[i].reg);
		if (sys_call->out_regs[i].local)
			subtilis_arm_add_mov_reg(arm_s, ccode, false, out_reg,
						 i, err);
		else
			subtilis_arm_add_stran_imm(
			    arm_s, SUBTILIS_ARM_INSTR_STR, ccode, i, out_reg, 0,
			    false, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %rbx
movq %rdx, %r14
movq %rdi, 0x18(%rsp)
movq 0x48(%rdi), %rax
movq (%rax,%rsi,8), %r12
movq 0x8(%r12), %rax
movq %rax, %rdx
andq $-0x20001, %rdx         # imm = 0xFFFDFFFF
movq %rdx, 0x20(%rsp)
andq $-0x20100, %rax         # imm = 0xFFFDFF00
cmpq $0x100, %rax            # imm = 0x100
jne 0x6b1da
movl $0x0, 0x14(%rsp)
jmp 0x6b228
leaq -0x6f(%rip), %rax       # 0x6b172
leaq 0x20(%rsp), %rdi
pushq $0x18
popq %r9
movq %rcx, %rsi
movq %r8, %rdx
movq %r9, %rcx
movq %rax, %r8
callq 0x122a0
testq %rax, %rax
je 0x6b209
movl 0x14(%rax), %eax
movl %eax, 0x14(%rsp)
jmp 0x6b228
movl $0x0, 0x14(%rsp)
leaq 0x7fcc(%rip), %rdx      # 0x731e4
pushq $0xf
popq %rsi
movq %rbx, %rdi
movl $0x7f2, %ecx            # imm = 0x7F2
callq 0x1429e
cmpl $0x0, (%rbx)
je 0x6b23c
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
pushq $0xd
popq %rbp
pushq $0xe
popq %r15
cmpq $0xb, %r13
je 0x6b288
movl 0x10(%r12), %eax
btl %r13d, %eax
jae 0x6b283
movq 0x28(%r12), %rax
movq (%rax,%r13,8), %rdi
callq 0x4c214
movq %rbx, (%rsp)
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
xorl %ecx, %ecx
movq %r13, %r8
movq %rax, %r9
callq 0x4d518
cmpl $0x0, (%rbx)
jne 0x6b22d
incq %r13
jmp 0x6b246
movq 0x8(%r12), %rdx
movl 0x10(%r12), %ecx
pushq $0xe
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
movl 0x14(%rsp), %r8d
movq %rbx, %r9
callq 0x4d4d9
cmpl $0x0, (%rbx)
jne 0x6b22d
testb $0x2, 0xa(%r12)
je 0x6b2e4
cmpq $-0x1, 0x18(%r12)
jne 0x6b2e4
movq (%r14), %rdi
leaq 0x1(%rdi), %rax
movq %rax, (%r14)
callq 0x4c214
pushq $0x6
popq %rdx
movq %r14, %rdi
movq 0x18(%rsp), %rsi
movq %rax, %rcx
movq %rbx, %r8
callq 0x4f21a
pushq $0x7
popq %rbp
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpq $0xb, %r13
je 0x6b22d
movl 0x14(%r12), %eax
btl %r13d, %eax
jae 0x6b35d
movq 0x30(%r12), %rax
movq (%rax,%r15), %rdi
callq 0x4c214
movq 0x30(%r12), %rcx
cmpb $0x1, 0x8(%rcx,%r15)
jne 0x6b335
movq %rbx, (%rsp)
movq %r14, %rdi
pushq $0xd
popq %rsi
movl %ebp, %edx
xorl %ecx, %ecx
movq %rax, %r8
movq %r13, %r9
callq 0x4d518
jmp 0x6b354
andl $0x0, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r14, %rdi
pushq $0x13
popq %rsi
movl %ebp, %edx
movq %r13, %rcx
movq %rax, %r8
xorl %r9d, %r9d
callq 0x4d55b
cmpl $0x0, (%rbx)
jne 0x6b22d
incq %r13
addq $0x10, %r15
jmp 0x6b2ea