// File: /workspace/github_c_makefile_star2_O2/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
subq $0x10, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rdi, %r15
andl $0x0, (%rsp)
movq %rcx, 0x8(%rsp)
pushq $0x12
popq %rsi
pushq $0xe
popq %rdx
pushq $0xc
popq %r8
pushq $-0x4
popq %r9
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x4d55b
cmpl $0x0, (%rbx)
jne 0x6a961
pushq $0x9
popq %rsi
pushq $0xe
popq %rdx
movq %r14, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x4d87e
cmpl $0x0, (%rbx)
jne 0x6a961
movq 0x10(%r14), %r12
leaq 0x1(%r12), %rax
movq %rax, 0x10(%r14)
pushq $0x16
popq %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x4c92b
cmpl $0x0, (%rbx)
jne 0x6a961
andl $0x0, 0x8(%rax)
movb $0x0, 0xc(%rax)
andl $0x0, 0x10(%rax)
movq %r12, 0x18(%rax)
andl $0x0, (%rsp)
movq %rbx, 0x8(%rsp)
xorl %r13d, %r13d
pushq $0xd
popq %rsi
pushq $0xf
popq %rdx
pushq $0xe
popq %rcx
movq %r14, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x4d213
cmpl %r13d, (%rbx)
jne 0x6a961
andl $0x0, (%rsp)
movq %rbx, 0x8(%rsp)
pushq $0x13
popq %rsi
pushq $0xe
popq %rdx
pushq $0xc
popq %r8
pushq $-0x4
popq %r9
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x4d55b
cmpl $0x0, (%rbx)
jne 0x6a961
movq %rbx, 0x8(%rsp)
movl $0x7c, (%rsp)
pushq $0xd
popq %rsi
pushq $0xf
popq %rdx
pushq $0xe
popq %rcx
movq %r14, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x4d213
cmpl $0x0, (%rbx)
jne 0x6a961
pushq $0xe
popq %rsi
pushq $0x1
popq %rcx
pushq $0x6
popq %r8
movl $0x20006, %edx          # imm = 0x20006
movq %r14, %rdi
movq %rbx, %r9
callq 0x4d4d9
cmpl $0x0, (%rbx)
jne 0x6a961
pushq $0xe
popq %rdx
pushq $0x11
popq %r8
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
movq %rbx, %r9
callq 0x4f15d
cmpl $0x0, (%rbx)
je 0x6a96f
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x4c77f