// File: /workspace/github_c_makefile_star2_O1/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 %rcx, %rax
movq %rdx, %r14
movq %rdi, 0x18(%rsp)
movq 0x48(%rdi), %rcx
movq (%rcx,%rsi,8), %r12
movq 0x8(%r12), %rcx
movq %rcx, %rdx
andq $-0x20001, %rdx         # imm = 0xFFFDFFFF
movq %rdx, 0x20(%rsp)
andq $-0x20100, %rcx         # imm = 0xFFFDFF00
xorl %r15d, %r15d
cmpq $0x100, %rcx            # imm = 0x100
je 0x70b05
leaq -0x6d(%rip), %r9        # 0x70a5c
leaq 0x20(%rsp), %rdi
movl $0x18, %ecx
movq %rax, %rsi
movq %r8, %rdx
movq %r9, %r8
callq 0x122a0
testq %rax, %rax
je 0x70aec
movl 0x14(%rax), %r15d
jmp 0x70b05
leaq 0x8721(%rip), %rdx      # 0x79214
movq %rbx, %rdi
movl $0xf, %esi
movl $0x7f2, %ecx            # imm = 0x7F2
callq 0x145f4
cmpl $0x0, (%rbx)
je 0x70b19
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
movl 0x10(%r12), %eax
btl %r13d, %eax
jae 0x70b58
movq 0x28(%r12), %rax
movq (%rax,%r13,8), %rdi
callq 0x4eff7
movq %rbx, (%rsp)
movq %r14, %rdi
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movq %r13, %r8
movq %rax, %r9
callq 0x5060d
cmpl $0x0, (%rbx)
jne 0x70b0a
incq %r13
cmpq $0xb, %r13
jne 0x70b1c
movq 0x8(%r12), %rdx
movl 0x10(%r12), %ecx
movl $0xe, %ebp
movq %r14, %rdi
movl $0xe, %esi
movl %r15d, %r8d
movq %rbx, %r9
callq 0x505b2
cmpl $0x0, (%rbx)
jne 0x70b0a
testb $0x2, 0xa(%r12)
je 0x70bc4
cmpq $-0x1, 0x18(%r12)
jne 0x70bc4
movq (%r14), %rdi
leaq 0x1(%rdi), %rax
movq %rax, (%r14)
callq 0x4eff7
movq %r14, %rdi
movq 0x18(%rsp), %rsi
movl $0x6, %edx
movq %rax, %rcx
movq %rbx, %r8
callq 0x526e6
movl $0x7, %ebp
xorl %r15d, %r15d
movl 0x14(%r12), %eax
btl %r15d, %eax
jae 0x70c3e
movq 0x30(%r12), %rax
movq %r15, %r13
shlq $0x4, %r13
movq (%rax,%r13), %rdi
callq 0x4eff7
movq 0x30(%r12), %rcx
cmpb $0x1, 0x8(%rcx,%r13)
jne 0x70c11
movq %rbx, (%rsp)
movq %r14, %rdi
movl $0xd, %esi
movl %ebp, %edx
xorl %ecx, %ecx
movq %rax, %r8
movq %r15, %r9
callq 0x5060d
jmp 0x70c35
movq %rbx, 0x8(%rsp)
movl $0x0, (%rsp)
movq %r14, %rdi
movl $0x13, %esi
movl %ebp, %edx
movq %r15, %rcx
movq %rax, %r8
xorl %r9d, %r9d
callq 0x5067b
cmpl $0x0, (%rbx)
jne 0x70b0a
incq %r15
cmpq $0xb, %r15
jne 0x70bc7
jmp 0x70b0a