// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/backends/riscos_common/riscos_arm.c
// Function: prv_add_section
static void prv_add_section(subtilis_ir_section_t *s,
			    subtilis_arm_section_t *arm_s,
			    subtilis_ir_rule_t *parsed, size_t rule_count,
			    subtilis_error_t *err)
{
	size_t spill_regs;
	size_t stack_space;
	subtilis_arm_instr_t *stack_sub;
	subtilis_arm_data_instr_t *datai;
	uint32_t encoded;
	subtilis_arm_reg_t dest;
	subtilis_arm_reg_t op2;
	size_t move_instr;

	stack_sub =
	    subtilis_arm_section_add_instr(arm_s, SUBTILIS_ARM_INSTR_SUB, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	move_instr = arm_s->last_op;

	datai = &stack_sub->operands.data;
	datai->status = false;
	datai->ccode = SUBTILIS_ARM_CCODE_AL;
	datai->dest = 13;
	datai->op1 = datai->dest;
	datai->op2.type = SUBTILIS_ARM_OP2_I32;
	datai->op2.op.integer = 0;

	dest = 11;
	op2 = 13;

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

	subtilis_ir_match(s, parsed, rule_count, arm_s, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	prv_compute_sss(arm_s, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	spill_regs = subtilis_arm_reg_alloc(arm_s, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	stack_space = spill_regs + arm_s->locals;

	encoded = subtilis_arm_encode_nearest(stack_space, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	/*
	 * The original datai pointer may have become invalidated by a realloc
	 * on the ops pool.
	 */

	stack_sub = &arm_s->op_pool->ops[move_instr].op.instr;
	datai = &stack_sub->operands.data;
	datai->op2.op.integer = encoded;

	subtilis_arm_save_regs(arm_s, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	subtilis_arm_restore_stack(arm_s, encoded, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	subtilis_arm_peephole(arm_s, err);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, %rbx
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %r13
pushq $0x2
popq %rsi
movq %r14, %rdi
movq %r8, %rdx
callq 0x4c92b
cmpl $0x0, (%rbx)
jne 0x696d5
movq 0x28(%r14), %rbp
movb $0x0, 0xc(%rax)
movl $0xe, 0x8(%rax)
pushq $0xd
popq %r9
movq %r9, 0x10(%rax)
movq %r9, 0x18(%rax)
movl $0x1, 0x20(%rax)
andl $0x0, 0x28(%rax)
movq %rbx, (%rsp)
pushq $0xd
popq %rsi
pushq $0xe
popq %rdx
pushq $0xb
popq %r8
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x4d518
cmpl $0x0, (%rbx)
jne 0x696d5
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x2c142
cmpl $0x0, (%rbx)
jne 0x696d5
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x59ea8
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x59ed0
movq %r15, %rdi
callq 0x5a6ce
cmpl $0x0, (%rbx)
jne 0x696d5
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4ff53
cmpl $0x0, (%rbx)
jne 0x696d5
addl 0x30(%r14), %eax
movl %eax, %edi
movq %rbx, %rsi
callq 0x4c9ef
cmpl $0x0, (%rbx)
jne 0x696d5
movl %eax, %r15d
movq 0x38(%r14), %rax
movq (%rax), %rax
imulq $0x68, %rbp, %rcx
movl %r15d, 0x30(%rax,%rcx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x51969
cmpl $0x0, (%rbx)
jne 0x696d5
movl %r15d, %esi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x4db46
cmpl $0x0, (%rbx)
jne 0x696d5
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5acc8
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq