// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0xe, -0x5c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq $0x8, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq (%rax), %rax
andq $-0x20001, %rax         # imm = 0xFFFDFFFF
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0xa6f90
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa6d91
jmp 0xa6f7a
movq $0x0, -0x50(%rbp)
cmpq $0xa, -0x50(%rbp)
ja 0xa6e17
movq -0x50(%rbp), %rax
movl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
movq -0x70(%rbp), %rcx
andl 0x8(%rcx), %eax
cmpl $0x0, %eax
jne 0xa6dbb
jmp 0xa6e09
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x6fe90
movq %rax, -0x40(%rbp)
movq -0x68(%rbp), %rdi
movq -0x50(%rbp), %r8
movq -0x40(%rbp), %r9
movq -0x30(%rbp), %rax
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movq %rax, (%rsp)
callq 0x71fa0
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa6e07
jmp 0xa6f7a
jmp 0xa6e09
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xa6d99
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rax
movq (%rax), %rdx
movq -0x70(%rbp), %rax
movl 0x8(%rax), %ecx
movl -0x34(%rbp), %r8d
movq -0x30(%rbp), %r9
movl $0xe, %esi
callq 0x71f20
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa6e49
jmp 0xa6f7a
movq -0x70(%rbp), %rax
movq (%rax), %rax
andq $0x20000, %rax          # imm = 0x20000
cmpq $0x0, %rax
je 0xa6ea2
movq -0x70(%rbp), %rax
cmpq $-0x1, 0x10(%rax)
jne 0xa6ea2
movq -0x68(%rbp), %rax
movq (%rax), %rdi
movq %rdi, %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
callq 0x6fe90
movq %rax, -0x58(%rbp)
movq -0x68(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %r8
movl $0x6, %edx
callq 0x75ce0
movl $0x7, -0x5c(%rbp)
movq $0x0, -0x50(%rbp)
cmpq $0xa, -0x50(%rbp)
ja 0xa6f7a
movq -0x50(%rbp), %rax
movl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
movq -0x70(%rbp), %rcx
andl 0xc(%rcx), %eax
cmpl $0x0, %eax
jne 0xa6ed3
jmp 0xa6f69
movq -0x70(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x50(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x6fe90
movq %rax, -0x48(%rbp)
movq -0x70(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x50(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
testb $0x1, 0x8(%rax)
je 0xa6f30
movq -0x68(%rbp), %rdi
movl -0x5c(%rbp), %edx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
movq -0x30(%rbp), %rax
movl $0xd, %esi
xorl %ecx, %ecx
movq %rax, (%rsp)
callq 0x71fa0
jmp 0xa6f5c
movq -0x68(%rbp), %rdi
movl -0x5c(%rbp), %edx
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x30(%rbp), %rax
movl $0x13, %esi
xorl %r9d, %r9d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x72030
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa6f67
jmp 0xa6f7a
jmp 0xa6f69
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xa6eaa
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)