// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/backends/ptd/ptd.c
// Function: subtilis_ptd_syscall
void subtilis_ptd_syscall(subtilis_ir_section_t *s, size_t start,
			  void *user_data, subtilis_error_t *err)
{
	size_t flags_reg;
	subtilis_arm_instr_t *instr;
	subtilis_arm_data_instr_t *datai;
	subtilis_ir_sys_call_t *sys_call = &s->ops[start]->op.sys_call;
	subtilis_arm_section_t *arm_s = user_data;

	subtilis_riscos_arm_syscall(s, start, user_data, subtilis_ptd_swi_list,
				    subtilis_ptd_known_swis, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	if (sys_call->flags_reg != SIZE_MAX) {
		if (sys_call->flags_local)
			flags_reg =
			    subtilis_arm_ir_to_arm_reg(sys_call->flags_reg);
		else
			flags_reg =
			    subtilis_arm_ir_to_arm_reg(arm_s->reg_counter++);

		subtilis_arm_add_flags(
		    arm_s, SUBTILIS_ARM_INSTR_MRS, SUBTILIS_ARM_CCODE_AL,
		    SUBTILIS_ARM_FLAGS_CPSR, 0, flags_reg, 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;
		datai = &instr->operands.data;
		datai->ccode = SUBTILIS_ARM_CCODE_AL;
		datai->status = false;
		datai->dest = flags_reg;
		datai->op2.type = SUBTILIS_ARM_OP2_SHIFTED;
		datai->op2.op.shift.reg = flags_reg;
		datai->op2.op.shift.shift_reg = false;
		datai->op2.op.shift.shift.integer = 28;
		datai->op2.op.shift.type = SUBTILIS_ARM_SHIFT_LSR;

		if (!sys_call->flags_local)
			subtilis_arm_add_stran_imm(
			    arm_s, SUBTILIS_ARM_INSTR_STR,
			    SUBTILIS_ARM_CCODE_AL, flags_reg,
			    subtilis_arm_ir_to_arm_reg(sys_call->flags_reg), 0,
			    false, err);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0xb755(%rip), %rax      # 0xae910
movq (%rax), %r8
movq -0x20(%rbp), %r9
leaq 0x2d8e7(%rip), %rcx     # 0xd0ab0
callq 0xa6d80
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa31dc
jmp 0xa332e
movq -0x40(%rbp), %rax
cmpq $-0x1, 0x10(%rax)
je 0xa332e
movq -0x40(%rbp), %rax
testb $0x1, 0x18(%rax)
je 0xa3208
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x6eea0
movq %rax, -0x28(%rbp)
jmp 0xa3222
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq %rdi, %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
callq 0x6eea0
movq %rax, -0x28(%rbp)
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %r9
movq -0x20(%rbp), %rax
movl $0x1d, %esi
movl $0xe, %edx
xorl %r8d, %r8d
movl %r8d, %ecx
movq %rax, (%rsp)
callq 0x71cb0
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa3255
jmp 0xa332e
movq -0x48(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0xd, %esi
callq 0x6fb60
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa3279
jmp 0xa332e
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl $0xe, (%rax)
movq -0x38(%rbp), %rax
movb $0x0, 0x4(%rax)
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl $0x2, 0x18(%rax)
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x38(%rbp), %rax
movb $0x0, 0x38(%rax)
movq -0x38(%rbp), %rax
movl $0x1c, 0x30(%rax)
movq -0x38(%rbp), %rax
movl $0x2, 0x28(%rax)
movq -0x40(%rbp), %rax
testb $0x1, 0x18(%rax)
jne 0xa332c
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x6eea0
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rcx
movq %rax, %r8
movq -0x20(%rbp), %rax
movl $0x13, %esi
movl $0xe, %edx
xorl %r9d, %r9d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x71040
jmp 0xa332e
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)