// File: /workspace/github_c_makefile_star2_O3/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
movq %rsi, %rdi
movl $0x2, %esi
movq %r8, %rdx
callq 0x4f6e2
cmpl $0x0, (%rbx)
jne 0x6e4da
movq 0x28(%r14), %rbp
movb $0x0, 0xc(%rax)
movl $0xe, 0x8(%rax)
movl $0xd, %ecx
movq %rcx, 0x10(%rax)
movq %rcx, 0x18(%rax)
movl $0x1, 0x20(%rax)
movl $0x0, 0x28(%rax)
movq %rbx, (%rsp)
movl $0xb, %r8d
movl $0xd, %r9d
movq %r14, %rdi
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
callq 0x504b3
cmpl $0x0, (%rbx)
jne 0x6e4da
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x2d834
cmpl $0x0, (%rbx)
jne 0x6e4da
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x5e060
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x5e088
movq %r15, %rdi
callq 0x5e927
cmpl $0x0, (%rbx)
jne 0x6e4da
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5330a
cmpl $0x0, (%rbx)
jne 0x6e4da
addl 0x30(%r14), %eax
movl %eax, %edi
movq %rbx, %rsi
callq 0x4f7b7
cmpl $0x0, (%rbx)
jne 0x6e4da
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 0x54f56
cmpl $0x0, (%rbx)
jne 0x6e4da
movl %r15d, %esi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x50bf6
cmpl $0x0, (%rbx)
jne 0x6e4da
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5ef64
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq