// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/backends/riscos_common/riscos_arm.c
// Function: subtilis_riscos_arm_testesc
void subtilis_riscos_arm_testesc(subtilis_ir_section_t *s, size_t start,
				 void *user_data, subtilis_error_t *err)
{
	size_t label;
	subtilis_arm_instr_t *instr;
	subtilis_arm_br_instr_t *br;
	subtilis_arm_section_t *arm_s = user_data;

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

	subtilis_arm_add_cmp_imm(arm_s, SUBTILIS_ARM_INSTR_TEQ,
				 SUBTILIS_ARM_CCODE_AL, 0, 0, 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_EQ;
	br->link = false;
	br->link_type = SUBTILIS_ARM_BR_LINK_VOID;
	br->target.label = label;

	/* Clear escape variable */

	subtilis_arm_add_mov_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false, 0, 0,
				 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

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

	/* Clear the escape condition */

	subtilis_arm_add_mov_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false, 0, 124,
				 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	/* OS_Byte */
	/* read_mask = 1 = r0  */
	/* write_mask = 6 = r1, r2 */
	subtilis_arm_add_swi(arm_s, SUBTILIS_ARM_CCODE_AL, 0x6 + 0x20000, 1, 6,
			     err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_gen_sete(arm_s, s, SUBTILIS_ARM_CCODE_AL, 0,
			      SUBTILIS_ERROR_CODE_ESCAPE, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_section_add_label(arm_s, label, err);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rcx, %rbx
movq %rdx, %r14
movq %rdi, %r15
movl $0xc, %r8d
movq %rdx, %rdi
movl $0x12, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movl $0xfffffffc, %r9d       # imm = 0xFFFFFFFC
pushq %rbx
pushq $0x0
callq 0x50516
addq $0x10, %rsp
cmpl $0x0, (%rbx)
jne 0x6fd9f
movq %r14, %rdi
movl $0x9, %esi
movl $0xe, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x508d6
cmpl $0x0, (%rbx)
jne 0x6fd9f
movq 0x10(%r14), %r12
leaq 0x1(%r12), %rax
movq %rax, 0x10(%r14)
movq %r14, %rdi
movl $0x16, %esi
movq %rbx, %rdx
callq 0x4f6e2
cmpl $0x0, (%rbx)
jne 0x6fd9f
xorl %r13d, %r13d
movl %r13d, 0x8(%rax)
movb $0x0, 0xc(%rax)
movl %r13d, 0x10(%rax)
movq %r12, 0x18(%rax)
movq %r14, %rdi
movl $0xd, %esi
movl $0xf, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rbx
pushq %r13
callq 0x50130
addq $0x10, %rsp
cmpl %r13d, (%rbx)
jne 0x6fd9f
movl $0xc, %r8d
movq %r14, %rdi
movl $0x13, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movl $0xfffffffc, %r9d       # imm = 0xFFFFFFFC
pushq %rbx
pushq $0x0
callq 0x50516
addq $0x10, %rsp
cmpl $0x0, (%rbx)
jne 0x6fd9f
movq %r14, %rdi
movl $0xd, %esi
movl $0xf, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rbx
pushq $0x7c
callq 0x50130
addq $0x10, %rsp
cmpl $0x0, (%rbx)
jne 0x6fd9f
movl $0x20006, %edx          # imm = 0x20006
movq %r14, %rdi
movl $0xe, %esi
movl $0x1, %ecx
movl $0x6, %r8d
movq %rbx, %r9
callq 0x50463
cmpl $0x0, (%rbx)
jne 0x6fd9f
movq %r14, %rdi
movq %r15, %rsi
movl $0xe, %edx
xorl %ecx, %ecx
movl $0x11, %r8d
movq %rbx, %r9
callq 0x52497
cmpl $0x0, (%rbx)
je 0x6fda9
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x4f530