// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/backends/riscos_common/riscos_arm.c
// Function: subtilis_riscos_palette
void subtilis_riscos_palette(subtilis_ir_section_t *s, size_t start,
			     void *user_data, subtilis_error_t *err)
{
	subtilis_arm_section_t *arm_s = user_data;
	subtilis_ir_inst_t *tcol = &s->ops[start]->op.instr;
	size_t col;
	size_t i;

	/* read_mask = 0 */
	/* write_mask = 0 */
	subtilis_arm_add_swi(arm_s, SUBTILIS_ARM_CCODE_AL, 256 + 19 + 0x20000,
			     0, 0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	col = subtilis_arm_ir_to_arm_reg(tcol->operands[0].reg);
	subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_VC, false, 0, col,
				 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	/* OS_WriteC */
	/* read_mask = 0x1 = r0 */
	/* write_mask = 0 */
	subtilis_arm_add_swi(arm_s, SUBTILIS_ARM_CCODE_VC, 0 + 0x20000, 1, 0,
			     err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	/* read_mask = 0 */
	/* write_mask = 0 */
	subtilis_arm_add_swi(arm_s, SUBTILIS_ARM_CCODE_VC, 256 + 16 + 0x20000,
			     0, 0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	for (i = 1; i < 4; i++) {
		col = subtilis_arm_ir_to_arm_reg(tcol->operands[i].reg);
		subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_VC, false, 0,
					 col, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		/* OS_WriteC */
		/* read_mask = 0x1 = r0 */
		/* write_mask = 0 */
		subtilis_arm_add_swi(arm_s, SUBTILIS_ARM_CCODE_VC, 0 + 0x20000,
				     1, 0, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	subtilis_riscos_handle_graphics_error(arm_s, s, err);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbx
movq %rdx, %r14
movq %rdi, %r15
movq 0x48(%rdi), %rax
movq (%rax,%rsi,8), %rbp
pushq $0xe
popq %rsi
movl $0x20113, %edx          # imm = 0x20113
movq %r14, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x4d4d9
cmpl $0x0, (%rbx)
jne 0x6ac17
movq 0x10(%rbp), %rdi
callq 0x4c214
movq %rbx, (%rsp)
pushq $0xd
popq %rsi
pushq $0x7
popq %rdx
movq %r14, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rax, %r9
callq 0x4d518
cmpl $0x0, (%rbx)
jne 0x6ac17
pushq $0x7
popq %rsi
pushq $0x1
popq %rcx
movl $0x20000, %edx          # imm = 0x20000
movq %r14, %rdi
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x4d4d9
cmpl $0x0, (%rbx)
jne 0x6ac17
pushq $0x7
popq %rsi
movl $0x20110, %edx          # imm = 0x20110
movq %r14, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x4d4d9
cmpl $0x0, (%rbx)
je 0x6ac26
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
pushq $0x7
popq %r12
cmpq $0x3, %r13
je 0x6ac7f
movq 0x18(%rbp,%r13,8), %rdi
callq 0x4c214
movq %rbx, (%rsp)
movq %r14, %rdi
pushq $0xd
popq %rsi
movl %r12d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rax, %r9
callq 0x4d518
cmpl $0x0, (%rbx)
jne 0x6ac17
movl $0x20000, %edx          # imm = 0x20000
movq %r14, %rdi
movl %r12d, %esi
pushq $0x1
popq %rcx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x4d4d9
incq %r13
cmpl $0x0, (%rbx)
je 0x6ac2d
jmp 0x6ac17
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x696e4