// File: /workspace/github_c_makefile_star2_O1/lucvoo[P]sparse-dev/flow.c
// Function: pack_basic_blocks
void pack_basic_blocks(struct entrypoint *ep)
{
	struct basic_block *bb;

	/* See if we can merge a bb into another one.. */
	FOR_EACH_PTR(ep->bbs, bb) {
		struct instruction *first;
		struct basic_block *parent, *child, *last;

		if (!bb_reachable(bb))
			continue;

		/*
		 * Just a branch?
		 */
		FOR_EACH_PTR(bb->insns, first) {
			if (!first->bb)
				continue;
			switch (first->opcode) {
			case OP_NOP:
			case OP_INLINED_CALL:
				continue;
			case OP_CBR:
			case OP_BR: {
				struct basic_block *replace;
				replace = rewrite_branch_bb(bb, first);
				if (replace) {
					kill_bb(bb);
					goto no_merge;
				}
			}
			/* fallthrough */
			default:
				goto out;
			}
		} END_FOR_EACH_PTR(first);

out:
		/*
		 * See if we only have one parent..
		 */
		last = NULL;
		FOR_EACH_PTR(bb->parents, parent) {
			if (last) {
				if (last != parent)
					goto no_merge;
				continue;
			}
			last = parent;
		} END_FOR_EACH_PTR(parent);

		parent = last;
		if (!parent || parent == bb)
			continue;

		/*
		 * Goodie. See if the parent can merge..
		 */
		FOR_EACH_PTR(parent->children, child) {
			if (child != bb)
				goto no_merge;
		} END_FOR_EACH_PTR(child);

		repeat_phase |= merge_bb(parent, bb);

	no_merge:
		/* nothing to do */;
	} END_FOR_EACH_PTR(bb);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x18(%rdi), %rax
movq %rax, (%rsp)
testq %rax, %rax
je 0x3d5ef
movl $0x40201, %ebp          # imm = 0x40201
movq (%rsp), %r13
cmpb $0x0, (%r13)
jle 0x3d5e1
xorl %r12d, %r12d
movq 0x18(%r13,%r12,8), %rbx
testq %rbx, %rbx
je 0x3d5d0
movq 0x28(%rbx), %rax
testq %rax, %rax
je 0x3d4ba
movq %rax, %rcx
movzwl (%rcx), %edx
movsbl %dl, %esi
testw %si, %si
jle 0x3d42e
movzwl %si, %edi
xorl %r8d, %r8d
movzwl %dx, %r9d
movq 0x18(%rcx,%r8,8), %rsi
cmpl $0x100, %r9d            # imm = 0x100
jb 0x3d40e
testq %rsi, %rsi
je 0x3d426
cmpq $0x0, 0x8(%rsi)
je 0x3d426
movl (%rsi), %r9d
andl $0x7f, %r9d
leal -0x4b(%r9), %r10d
cmpl $0x2, %r10d
jae 0x3d43e
incq %r8
cmpq %r8, %rdi
jne 0x3d3f7
movq 0x10(%rcx), %rcx
cmpq %rax, %rcx
jne 0x3d3e6
xorl %eax, %eax
jmp 0x3d4bf
leal -0x3(%r9), %eax
cmpl $0x1, %eax
ja 0x3d4b3
movq 0x38(%rsi), %r14
cmpl $0x4, %r9d
jne 0x3d470
movq 0x30(%rsi), %rcx
movl 0x4(%rcx), %eax
cmpl $0x6, %eax
jne 0x3d468
cmpq $0x0, 0x18(%rcx)
jne 0x3d468
movq 0x40(%rsi), %r14
movb $0x1, %r15b
cmpl $0x6, %eax
jne 0x3d49a
movq 0x18(%rbx), %rdi
callq 0x22634
testq %rax, %rax
je 0x3d493
movq %rax, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3d954
testl %eax, %eax
jne 0x3d470
xorl %r14d, %r14d
testq %r14, %r14
sete %r15b
xorl %eax, %eax
testb %r15b, %r15b
jne 0x3d4ae
movq %rbx, %rdi
callq 0x3c74a
movl $0x11, %eax
testb %r15b, %r15b
je 0x3d4bf
movl $0x12, %eax
jmp 0x3d4bf
movl $0x9, %eax
cmpl $0x12, %eax
ja 0x3d5d0
btl %eax, %ebp
jae 0x3d5d0
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x3d532
xorl %edi, %edi
movq %rax, %rcx
movzwl (%rcx), %edx
movsbl %dl, %esi
testw %si, %si
jle 0x3d51e
movzwl %si, %esi
xorl %r8d, %r8d
movzwl %dx, %r10d
movq 0x18(%rcx,%r8,8), %r9
cmpl $0x100, %r10d           # imm = 0x100
jb 0x3d507
testq %r9, %r9
je 0x3d516
testq %rdi, %rdi
je 0x3d513
cmpq %r9, %rdi
je 0x3d516
jmp 0x3d52b
movq %r9, %rdi
incq %r8
cmpq %r8, %rsi
jne 0x3d4f0
movq 0x10(%rcx), %rcx
cmpq %rax, %rcx
jne 0x3d4df
xorl %eax, %eax
jmp 0x3d539
movl $0x11, %eax
jmp 0x3d539
movl $0x13, %eax
xorl %edi, %edi
cmpl $0x13, %eax
je 0x3d546
testl %eax, %eax
jne 0x3d5d0
testq %rdi, %rdi
je 0x3d5d0
cmpq %rbx, %rdi
je 0x3d5d0
movq 0x20(%rdi), %rax
testq %rax, %rax
je 0x3d5b1
movq %rax, %rcx
movzwl (%rcx), %esi
movsbl %sil, %edx
testw %dx, %dx
jle 0x3d59d
movzwl %dx, %edx
movzwl %si, %esi
xorl %r8d, %r8d
cmpl $0x100, %esi            # imm = 0x100
setae %r10b
movq 0x18(%rcx,%r8,8), %r9
testq %r9, %r9
sete %r11b
testb %r11b, %r10b
jne 0x3d595
cmpq %rbx, %r9
jne 0x3d5aa
incq %r8
cmpq %r8, %rdx
jne 0x3d575
movq 0x10(%rcx), %rcx
cmpq %rax, %rcx
jne 0x3d560
xorl %eax, %eax
jmp 0x3d5b6
movl $0x11, %eax
jmp 0x3d5b6
movl $0x1a, %eax
cmpl $0x1a, %eax
je 0x3d5bf
testl %eax, %eax
jne 0x3d5d0
movq %rbx, %rsi
callq 0x3d03f
leaq 0x2a7a6(%rip), %rcx     # 0x67d74
orl %eax, (%rcx)
incq %r12
movsbq (%r13), %rax
cmpq %rax, %r12
jl 0x3d3c8
movq 0x10(%r13), %r13
cmpq (%rsp), %r13
jne 0x3d3ba
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq