// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/arch/arm32/arm_sub_section.c
// Function: subtilis_arm_subsections_calculate
void subtilis_arm_subsections_calculate(subtilis_arm_subsections_t *sss,
					subtilis_arm_section_t *arm_s,
					subtilis_error_t *err)
{
	size_t ptr;
	subtilis_arm_ss_t *ss;
	subtilis_arm_op_t *op;
	subtilis_arm_op_t *next;
	size_t count;
	size_t label;
	size_t ss_ptr;

	if (arm_s->first_op == arm_s->last_op) {
		subtilis_error_set_assertion_failed(err);
		return;
	}

	ptr = arm_s->first_op;
	ss_ptr = prv_add_new_sub_section(sss, arm_s, ptr, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	ss = &sss->sub_sections[ss_ptr];

	count = 0;
	while (ptr != SIZE_MAX) {
		op = &arm_s->op_pool->ops[ptr];
		if (op->type == SUBTILIS_ARM_OP_LABEL) {
			prv_finalize_sub_section(ss, arm_s, op->prev, count,
						 err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
			count = 0;
			ss_ptr = prv_add_new_sub_section(sss, arm_s, ptr, err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
			ss = &sss->sub_sections[ss_ptr];
			label = op->op.label;
			if (label >= arm_s->label_counter) {
				subtilis_error_set_assertion_failed(err);
				return;
			}
			prv_sss_link_map_insert(sss, ss_ptr, label, err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
		} else if ((op->type == SUBTILIS_ARM_OP_INSTR) &&
			   (op->op.instr.type == SUBTILIS_ARM_INSTR_B) &&
			   (!op->op.instr.operands.br.link) &&
			   (op->op.instr.operands.br.ccode !=
			    SUBTILIS_ARM_CCODE_NV)) {
			prv_add_link(ss, arm_s, ptr,
				     op->op.instr.operands.br.target.label,
				     err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
			if (op->next != SIZE_MAX) {
				next = &arm_s->op_pool->ops[op->next];
				if (next->type != SUBTILIS_ARM_OP_LABEL) {
					subtilis_arm_section_insert_label(
					    arm_s, arm_s->label_counter, next,
					    err);
					if (err->type != SUBTILIS_ERROR_OK)
						return;

					/*
					 * Inserting or adding an instruction
					 * could invalidate our pointer.  Let's
					 * refresh it.
					 */

					op = &arm_s->op_pool->ops[ptr];
				}
			}
		}

		count++;
		if (ptr == arm_s->last_op)
			break;

		ptr = op->next;
	}

	if (count > 0) {
		prv_finalize_sub_section(ss, arm_s, arm_s->last_op, count, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	/*
	 * We need to update the outputs for the first subsection if
	 * it has any arguments.
	 */

	prv_add_args(&sss->sub_sections[0], arm_s, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	prv_compute_must_save(sss, err);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %rbx
movq 0x20(%rsi), %r12
cmpq 0x28(%rsi), %r12
jne 0x59f10
leaq 0x169e5(%rip), %rdx     # 0x708d7
pushq $0xf
popq %rsi
movq %rbx, %rdi
movl $0x16f, %ecx            # imm = 0x16F
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1429e
movq %rsi, %r15
movq %rdi, 0x18(%rsp)
movq %r12, %rsi
movq %rbx, %rdx
callq 0x5a383
movq %rbx, 0x10(%rsp)
cmpl $0x0, (%rbx)
je 0x59f3c
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
imulq $0x130, %rax, %rdi      # imm = 0x130
movq 0x18(%rsp), %rax
addq (%rax), %rdi
xorl %r13d, %r13d
movq %r15, 0x28(%rsp)
cmpq $-0x1, %r12
je 0x5a131
movq 0x38(%r15), %rax
movq (%rax), %rbp
imulq $0x68, %r12, %r14
leaq (%r14,%rbp), %rbx
movl (%rbp,%r14), %eax
testl %eax, %eax
je 0x59ff3
cmpl $0x1, %eax
jne 0x5a11e
movq 0x60(%rbx), %rdx
movq %r15, %rsi
movq %r13, %rcx
movq 0x10(%rsp), %r13
movq %r13, %r8
callq 0x5a43f
cmpl $0x0, (%r13)
jne 0x59f2d
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movq 0x10(%rsp), %r15
movq %r15, %rdx
callq 0x5a383
movq %rax, %r13
cmpl $0x0, (%r15)
movq 0x28(%rsp), %rax
jne 0x59f2d
movq 0x8(%rbx), %rbx
cmpq 0x10(%rax), %rbx
jae 0x5a204
imulq $0x130, %r13, %rdi      # imm = 0x130
movq 0x18(%rsp), %r15
addq (%r15), %rdi
cmpq %rbx, 0x20(%r15)
jbe 0x5a09a
movq 0x28(%r15), %rax
jmp 0x5a0d9
cmpl $0x16, 0x8(%rbx)
jne 0x5a11e
cmpb $0x0, 0x14(%rbx)
jne 0x5a11e
cmpl $0xf, 0x10(%rbx)
je 0x5a11e
movq 0x20(%rbx), %rcx
movq %rdi, 0x20(%rsp)
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
movq 0x10(%rsp), %r15
movq %r15, %r8
callq 0x5a53f
movq 0x20(%rsp), %rdi
cmpl $0x0, (%r15)
movq 0x28(%rsp), %r15
jne 0x59f2d
movq 0x58(%rbx), %rax
cmpq $-0x1, %rax
je 0x5a11e
movq 0x38(%r15), %rcx
movq (%rcx), %rdx
imulq $0x68, %rax, %rax
cmpl $0x1, (%rdx,%rax)
je 0x5a11e
addq %rax, %rdx
movq 0x10(%r15), %rsi
movq %r15, %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rcx
callq 0x4c83f
movq 0x20(%rsp), %rdi
cmpl $0x0, (%rbx)
jne 0x59f2d
movq 0x38(%r15), %rax
movq (%rax), %rbp
jmp 0x5a11e
movq %rdi, 0x20(%rsp)
movq 0x28(%r15), %rdi
leaq 0x80(,%rbx,8), %rsi
callq 0x12210
testq %rax, %rax
je 0x5a0ec
leaq 0x10(%rbx), %rcx
movq 0x20(%r15), %rdx
movq 0x20(%rsp), %rdi
cmpq %rcx, %rdx
jae 0x5a0d1
orq $-0x1, (%rax,%rdx,8)
incq %rdx
jmp 0x5a0c2
movq %rax, 0x28(%r15)
movq %rcx, 0x20(%r15)
movq %r13, (%rax,%rbx,8)
cmpq %rbx, 0x18(%r15)
ja 0x5a108
incq %rbx
movq %rbx, 0x18(%r15)
jmp 0x5a108
movq 0x10(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0x167dc(%rip), %rdx     # 0x708d7
pushq $0x52
popq %rcx
callq 0x1429e
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
movq 0x28(%rsp), %r15
jne 0x59f2d
xorl %r13d, %r13d
incq %r13
cmpq 0x28(%r15), %r12
je 0x5a131
movq 0x58(%rbp,%r14), %r12
jmp 0x59f53
testq %r13, %r13
je 0x5a156
movq 0x28(%r15), %rdx
movq %r15, %rsi
movq %r13, %rcx
movq 0x10(%rsp), %rbx
movq %rbx, %r8
callq 0x5a43f
cmpl $0x0, (%rbx)
jne 0x59f2d
movq 0x18(%rsp), %rax
movq (%rax), %r14
leaq 0x48(%r14), %r13
xorl %ebp, %ebp
cmpq 0x128(%r14), %rbp
jae 0x5a21d
imulq $0x70, %rbp, %r12
addq %r13, %r12
xorl %ebx, %ebx
movq 0xa0(%r15), %rax
cmpq 0x158(%rax), %rbx
jae 0x5a1b1
leaq 0x10(%rbx), %rsi
movq %r12, %rdi
movq 0x10(%rsp), %r15
movq %r15, %rdx
callq 0x59a32
incq %rbx
cmpl $0x0, (%r15)
movq 0x28(%rsp), %r15
je 0x5a17a
jmp 0x59f2d
addq $0x18, %r12
xorl %ebx, %ebx
movq 0xa0(%r15), %rax
cmpq 0x160(%rax), %rbx
jae 0x5a1f7
movq 0xc0(%r15), %rax
movq (%rax), %rsi
addq %rbx, %rsi
movq %r12, %rdi
movq 0x10(%rsp), %r15
movq %r15, %rdx
callq 0x59a32
incq %rbx
cmpl $0x0, (%r15)
movq 0x28(%rsp), %r15
je 0x5a1b7
jmp 0x59f2d
incq %rbp
movq 0x18(%rsp), %rax
jmp 0x5a164
leaq 0x166cc(%rip), %rdx     # 0x708d7
pushq $0xf
popq %rsi
movq 0x10(%rsp), %rdi
movl $0x188, %ecx            # imm = 0x188
jmp 0x59efd
leaq 0x30(%rax), %rcx
movq %rcx, 0x20(%rsp)
leaq 0x48(%rax), %rcx
movq %rcx, 0x38(%rsp)
pushq $0x78
popq %rcx
movq %rcx, 0x30(%rsp)
xorl %ecx, %ecx
leaq 0x40(%rsp), %r13
movq %rcx, 0x28(%rsp)
cmpq 0x8(%rax), %rcx
jae 0x59f2d
movq 0x18(%rsp), %rax
movq (%rax), %r15
imulq $0x130, 0x28(%rsp), %r14 # imm = 0x130
addq %r15, %r14
addq 0x30(%rsp), %r15
pushq $-0x1
popq %r12
incq %r12
cmpq 0x128(%r14), %r12
jae 0x5a368
movq %r13, %rdi
callq 0x59a08
movq 0x30(%r15), %rsi
movq 0x18(%rsp), %rax
cmpq 0x18(%rax), %rsi
jae 0x5a319
movq %r13, %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rdx
callq 0x59a32
cmpl $0x0, (%rbx)
jne 0x5a335
movq 0x18(%rsp), %rdi
movq 0x28(%rdi), %rax
movq 0x30(%r15), %rcx
movq (%rax,%rcx,8), %rax
cmpq $-0x1, %rax
je 0x5a34f
leaq -0x30(%r15), %rdx
imulq $0x130, %rax, %rsi      # imm = 0x130
addq (%rdi), %rsi
leaq 0x18(%r15), %rbp
movq 0x10(%rsp), %rbx
movq %rbx, (%rsp)
movq %r15, %rcx
movq %rbp, %r8
movq %r13, %r9
callq 0x5a896
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x59c39
cmpl $0x0, (%rbx)
jne 0x5a335
movq 0x38(%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x59c39
jmp 0x5a335
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
pushq $0xf
popq %rsi
leaq 0x165ac(%rip), %rdx     # 0x708d7
movl $0x134, %ecx            # imm = 0x134
callq 0x1429e
addq $0x70, %r15
movq %r13, %rdi
callq 0x59db2
cmpl $0x0, (%rbx)
je 0x5a26a
jmp 0x59f2d
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
pushq $0xf
popq %rsi
leaq 0x16576(%rip), %rdx     # 0x708d7
movl $0x13d, %ecx            # imm = 0x13D
jmp 0x5a330
movq 0x28(%rsp), %rcx
incq %rcx
addq $0x130, 0x30(%rsp)      # imm = 0x130
movq 0x18(%rsp), %rax
jmp 0x5a23e