// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/arch/arm32/arm_sub_section.c
// Function: prv_add_link
static void prv_add_link(subtilis_arm_ss_t *ss, subtilis_arm_section_t *arm_s,
			 size_t ptr, size_t label, subtilis_error_t *err)
{
	subtilis_arm_ss_link_t *first_link;
	subtilis_arm_ss_link_t *link;
	subtilis_arm_op_t *from;
	subtilis_regs_used_virt_t regs_used;
	size_t max_int_regs;
	size_t max_real_regs;
	subtilis_arm_op_t *to;

	if (ss->num_links >= 2) {
		subtilis_error_set_assertion_failed(err);
		return;
	}

	to = &arm_s->op_pool->ops[ptr];
	subtilis_arm_section_max_regs(arm_s, &max_int_regs, &max_real_regs);
	subtilis_regs_used_virt_init(&regs_used);

	link = &ss->links[ss->num_links++];
	subtilis_bitset_init(&link->int_outputs);
	subtilis_bitset_init(&link->real_outputs);
	subtilis_bitset_init(&link->int_save);
	subtilis_bitset_init(&link->real_save);

	/*
	 * If the basic block has two links, the block essentially ends with
	 * conditional branch.  This branch will be followed by a label but
	 * this label doesn't affect the inputs of outputs.  Thus the inputs
	 * and outputs for both links will be identical.  There's no need to
	 * compute them twice, particularly as this is one of the most expensive
	 * parts of the compilation.
	 */

	if (ss->num_links == 1) {
		from = &arm_s->op_pool->ops[ss->start];
		subtilis_arm_regs_used_before_from_tov(
		    arm_s, from, to, max_int_regs, max_real_regs, &regs_used,
		    err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		subtilis_bitset_claim(&link->int_outputs, &regs_used.int_regs);
		subtilis_bitset_claim(&link->real_outputs,
				      &regs_used.real_regs);
	} else {
		first_link = &ss->links[0];
		subtilis_bitset_or(&link->int_outputs, &first_link->int_outputs,
				   err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		subtilis_bitset_or(&link->real_outputs,
				   &first_link->real_outputs, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	}

	link->link = label;
	link->op = ptr;

cleanup:

	subtilis_regs_used_virt_free(&regs_used);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, %r15
cmpq $0x2, 0x128(%rdi)
jb 0x5e7c6
leaq 0x18181(%rip), %rdx     # 0x76927
movq %r15, %rdi
movl $0xf, %esi
movl $0x6b, %ecx
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x145f4
movq %rsi, %r14
movq %rdi, %r13
movq %rcx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq 0x38(%rsi), %rax
movq (%rax), %rbx
leaq 0x30(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %r14, %rdi
callq 0x4f100
leaq 0x38(%rsp), %rdi
callq 0x52edc
movq 0x128(%r13), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x128(%r13)
imulq $0x70, %rax, %rbp
leaq 0x48(,%rbp), %r12
addq %r13, %r12
movq %r12, %rdi
callq 0x5db30
leaq 0x60(,%rbp), %rdi
addq %r13, %rdi
movq %rdi, 0x10(%rsp)
callq 0x5db30
leaq 0x78(,%rbp), %rdi
addq %r13, %rdi
callq 0x5db30
leaq 0x90(,%rbp), %rdi
addq %r13, %rdi
callq 0x5db30
cmpq $0x1, 0x128(%r13)
jne 0x5e8bb
movq 0x18(%rsp), %rbp
imulq $0x68, %rbp, %rax
addq %rax, %rbx
movq 0x38(%r14), %rax
imulq $0x68, 0x8(%r13), %rsi
addq (%rax), %rsi
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %r8
movq %r15, (%rsp)
leaq 0x38(%rsp), %r9
movq %r14, %rdi
movq %rbx, %rdx
callq 0x54a80
cmpl $0x0, (%r15)
jne 0x5e8fe
leaq 0x38(%rsp), %rsi
movq %r12, %rdi
callq 0x5df01
leaq 0x50(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x5df01
jmp 0x5e8ef
leaq 0x48(%r13), %rsi
movq %r12, %rdi
movq %r15, %rdx
callq 0x5dd9c
cmpl $0x0, (%r15)
movq 0x18(%rsp), %rbp
jne 0x5e8fe
addq $0x60, %r13
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x5dd9c
cmpl $0x0, (%r15)
jne 0x5e8fe
movq 0x20(%rsp), %rax
movq %rax, 0x60(%r12)
movq %rbp, 0x68(%r12)
leaq 0x38(%rsp), %rdi
callq 0x52ef2
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq