// File: /workspace/github_c_makefile_star2_O3/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 0x7070a
leaq -0x6d(%rip), %r9        # 0x70661
leaq 0x20(%rsp), %rdi
movl $0x18, %ecx
movq %rax, %rsi
movq %r8, %rdx
movq %r9, %r8
callq 0x122a0
testq %rax, %rax
je 0x706f1
movl 0x14(%rax), %r15d
jmp 0x7070a
leaq 0x8b7c(%rip), %rdx      # 0x79274
movq %rbx, %rdi
movl $0xf, %esi
movl $0x7f2, %ecx            # imm = 0x7F2
callq 0x145a4
cmpl $0x0, (%rbx)
je 0x7071e
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 0x7075d
movq 0x28(%r12), %rax
movq (%rax,%r13,8), %rdi
callq 0x4efba
movq %rbx, (%rsp)
movq %r14, %rdi
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movq %r13, %r8
movq %rax, %r9
callq 0x504b3
cmpl $0x0, (%rbx)
jne 0x7070f
incq %r13
cmpq $0xb, %r13
jne 0x70721
movq 0x8(%r12), %rdx
movl 0x10(%r12), %ecx
movl $0xe, %ebp
movq %r14, %rdi
movl $0xe, %esi
movl %r15d, %r8d
movq %rbx, %r9
callq 0x50463
cmpl $0x0, (%rbx)
jne 0x7070f
testb $0x2, 0xa(%r12)
je 0x707c9
cmpq $-0x1, 0x18(%r12)
jne 0x707c9
movq (%r14), %rdi
leaq 0x1(%rdi), %rax
movq %rax, (%r14)
callq 0x4efba
movq %r14, %rdi
movq 0x18(%rsp), %rsi
movl $0x6, %edx
movq %rax, %rcx
movq %rbx, %r8
callq 0x52560
movl $0x7, %ebp
xorl %r15d, %r15d
movl 0x14(%r12), %eax
btl %r15d, %eax
jae 0x70843
movq 0x30(%r12), %rax
movq %r15, %r13
shlq $0x4, %r13
movq (%rax,%r13), %rdi
callq 0x4efba
movq 0x30(%r12), %rcx
cmpb $0x1, 0x8(%rcx,%r13)
jne 0x70816
movq %rbx, (%rsp)
movq %r14, %rdi
movl $0xd, %esi
movl %ebp, %edx
xorl %ecx, %ecx
movq %rax, %r8
movq %r15, %r9
callq 0x504b3
jmp 0x7083a
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 0x50516
cmpl $0x0, (%rbx)
jne 0x7070f
incq %r15
cmpq $0xb, %r15
jne 0x707cc
jmp 0x7070f