// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/backends/riscos_common/riscos_arm.c
// Function: prv_add_escape_handler
static void prv_add_escape_handler(subtilis_arm_section_t *arm_s,
				   subtilis_error_t *err)
{
	size_t label;
	subtilis_arm_instr_t *instr;
	subtilis_arm_br_instr_t *br;

	subtilis_arm_add_mov_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false, 0, 9,
				 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	subtilis_arm_add_add_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false, 1, 15, 16,
				 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_AL, false, 2, 12,
				 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	/* I'm assuming that this call can't fail. */

	/* read_mask = 0x7 = R0, R1, R2 */
	/* write_mask = 0xe = R1, R2, R3 */
	subtilis_arm_add_swi(arm_s, SUBTILIS_ARM_CCODE_AL, 0x40, 0x7, 0xe, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_stran_imm(arm_s, SUBTILIS_ARM_INSTR_STR,
				   SUBTILIS_ARM_CCODE_AL, 1, 12,
				   RISCOS_ARM_GLOBAL_ESC_HANDLER, false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_stran_imm(arm_s, SUBTILIS_ARM_INSTR_STR,
				   SUBTILIS_ARM_CCODE_AL, 2, 12,
				   RISCOS_ARM_GLOBAL_ESC_R12, false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	label = arm_s->label_counter++;
	instr =
	    subtilis_arm_section_add_instr(arm_s, SUBTILIS_ARM_INSTR_B, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	br = &instr->operands.br;
	br->ccode = SUBTILIS_ARM_CCODE_AL;
	br->link = false;
	br->link_type = SUBTILIS_ARM_BR_LINK_VOID;
	br->target.label = label;

	/* Code for the handler */

	subtilis_arm_add_cmp_imm(arm_s, SUBTILIS_ARM_INSTR_TST,
				 SUBTILIS_ARM_CCODE_AL, 11, 1 << 6, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_EQ, false, 15, 14,
				 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	/*
	 * We're going to store the value of R11 into the escape variable.  If
	 * we get here we know that R11 is non zero, i.e., it has at least one
	 * bit set.  By using the value in R11 we don't need to corrupt any
	 * registers.
	 */

	subtilis_arm_add_stran_imm(arm_s, SUBTILIS_ARM_INSTR_STR,
				   SUBTILIS_ARM_CCODE_AL, 11, 12,
				   RISCOS_ARM_GLOBAL_ESC_FLAG, false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_AL, false, 15, 14,
				 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_section_add_label(arm_s, label, err);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl $0xd, %esi
movl $0xf, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
movl $0x9, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x71b10
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa834c
jmp 0xa85de
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl $0x4, %esi
movl $0x2, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
movl $0x1, %r9d
movq $0xf, (%rsp)
movl $0x10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x71640
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa8394
jmp 0xa85de
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movl $0x2, %r8d
movl $0xc, %r9d
movq %rax, (%rsp)
callq 0x71fa0
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa83cb
jmp 0xa85de
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %r9
movl $0xe, %r8d
movl $0x40, %edx
movl $0x7, %ecx
movl %r8d, %esi
callq 0x71f20
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa83f9
jmp 0xa85de
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl $0x13, %esi
movl $0xe, %edx
movl $0x1, %ecx
movl $0xc, %r8d
movl $0xfffffff8, %r9d       # imm = 0xFFFFFFF8
xorl %r10d, %r10d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x72030
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa843e
jmp 0xa85de
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl $0x13, %esi
movl $0xe, %edx
movl $0x2, %ecx
movl $0xc, %r8d
movl $0xfffffff4, %r9d       # imm = 0xFFFFFFF4
xorl %r10d, %r10d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x72030
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa8483
jmp 0xa85de
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x10(%rcx)
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl $0x16, %esi
callq 0x70b50
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa84be
jmp 0xa85de
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl $0xe, (%rax)
movq -0x28(%rbp), %rax
movb $0x0, 0x4(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %r9
movl $0x8, %esi
movl $0xe, %edx
movl $0xb, %ecx
movl $0x40, %r8d
callq 0x72620
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa8523
jmp 0xa85de
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl $0xd, %esi
xorl %ecx, %ecx
movl $0xf, %r8d
movl $0xe, %r9d
movl %ecx, %edx
movq %rax, (%rsp)
callq 0x71fa0
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa8557
jmp 0xa85de
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl $0x13, %esi
movl $0xe, %edx
movl $0xb, %ecx
movl $0xc, %r8d
movl $0xfffffffc, %r9d       # imm = 0xFFFFFFFC
xorl %r10d, %r10d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x72030
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa8599
jmp 0xa85de
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movl $0xf, %r8d
movl $0xe, %r9d
movq %rax, (%rsp)
callq 0x71fa0
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa85cd
jmp 0xa85de
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0x70850
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)