// File: /workspace/github_c_makefile_star2_O1/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 0x4f73a
cmpl $0x0, (%rbx)
jne 0x6e8e2
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 0x5060d
cmpl $0x0, (%rbx)
jne 0x6e8e2
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x2db2a
cmpl $0x0, (%rbx)
jne 0x6e8e2
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x5e058
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x5e080
movq %r15, %rdi
callq 0x5e917
cmpl $0x0, (%rbx)
jne 0x6e8e2
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5349e
cmpl $0x0, (%rbx)
jne 0x6e8e2
addl 0x30(%r14), %eax
movl %eax, %edi
movq %rbx, %rsi
callq 0x4f80b
cmpl $0x0, (%rbx)
jne 0x6e8e2
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 0x55067
cmpl $0x0, (%rbx)
jne 0x6e8e2
movl %r15d, %esi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x50dc8
cmpl $0x0, (%rbx)
jne 0x6e8e2
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5ef4c
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq