// File: /workspace/github_c_makefile_star2_O1/lucvoo[P]sparse-dev/simplify.c
// Function: simplify_cgoto
static int simplify_cgoto(struct instruction *insn)
{
	struct basic_block *target, *bb = insn->bb;
	struct basic_block *bbt, *bbf;
	struct instruction *def;
	struct multijmp *jmp;

	switch (DEF_OPCODE(def, insn->src)) {
	case OP_SEL:	// CGOTO(SEL(x, L1, L2)) --> CBR x, L1, L2
		if ((bbt = is_label(def->src2)) && (bbf = is_label(def->src3))) {
			insn->opcode = OP_CBR;
			insn->bb_true = bbt;
			insn->bb_false = bbf;
			return replace_pseudo(insn, &insn->src1, def->cond);
		}
		break;
	case OP_LABEL:
		target = def->bb_true;
		if (!target->ep)
			return 0;
		FOR_EACH_PTR(insn->multijmp_list, jmp) {
			if (jmp->target == target)
				continue;
			remove_bb_from_list(&jmp->target->parents, bb, 1);
			remove_bb_from_list(&bb->children, jmp->target, 1);
			DELETE_CURRENT_PTR(jmp);
		} END_FOR_EACH_PTR(jmp);
		kill_use(&insn->src);
		insn->opcode = OP_BR;
		insn->bb_true = target;
		return REPEAT_CSE|REPEAT_CFG_CLEANUP;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movq 0x30(%rdi), %r12
xorl %r15d, %r15d
cmpl $0x3, 0x4(%r12)
movl $0x0, %ecx
jne 0x28052
movq 0x18(%r12), %rax
testq %rax, %rax
je 0x2804e
movl (%rax), %ecx
andl $0x7f, %ecx
jmp 0x28052
xorl %eax, %eax
xorl %ecx, %ecx
leaq 0x30(%rbx), %r14
cmpl $0x47, %ecx
je 0x2808f
cmpl $0x41, %ecx
jne 0x28287
movq 0x38(%rax), %rcx
cmpl $0x3, 0x4(%rcx)
jne 0x281bb
movq 0x18(%rcx), %rcx
testq %rcx, %rcx
je 0x281bf
movl (%rcx), %edx
andl $0x7f, %edx
cmpl $0x47, %edx
sete %dl
jmp 0x281c3
movq 0x38(%rax), %r13
cmpq $0x0, 0x10(%r13)
je 0x28287
movq %r14, 0x18(%rsp)
movq %rbx, 0x8(%rsp)
movq 0x38(%rbx), %rax
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x28193
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
addq $0x20, %rax
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rbp
movzwl (%rbp), %eax
testb %al, %al
jle 0x28184
leaq 0x18(%rbp), %rbx
leaq 0x10(%rbp), %rcx
movq %rcx, 0x30(%rsp)
xorl %r15d, %r15d
movslq %r15d, %r12
movq (%rbx,%r12,8), %r14
movzwl %ax, %eax
cmpl $0x100, %eax            # imm = 0x100
jb 0x28108
testq %r14, %r14
je 0x28172
movq (%r14), %rdi
cmpq %r13, %rdi
je 0x28172
addq $0x18, %rdi
movq 0x28(%rsp), %rsi
movl $0x1, %edx
callq 0x2296b
movq (%r14), %rsi
movq 0x20(%rsp), %rdi
movl $0x1, %edx
callq 0x2296b
leaq (%rbx,%r12,8), %rax
movsbq (%rbp), %rcx
movq 0x30(%rsp), %rdx
leaq (%rdx,%rcx,8), %rcx
cmpq %rcx, %rax
jae 0x28161
leaq 0x8(%rax), %rdx
movq 0x8(%rax), %rsi
movq %rsi, (%rax)
movq %rdx, %rax
cmpq %rcx, %rdx
jb 0x2814c
jmp 0x28164
movq %rax, %rdx
movl $0xf0f0f0f0, %eax       # imm = 0xF0F0F0F0
movq %rax, (%rdx)
decb (%rbp)
decl %r15d
incl %r15d
movl (%rbp), %eax
movsbl %al, %ecx
cmpl %ecx, %r15d
jl 0x280f2
movq 0x10(%rbp), %rbp
cmpq 0x10(%rsp), %rbp
jne 0x280d6
movq 0x18(%rsp), %rdi
callq 0x24a58
movq 0x8(%rsp), %rcx
movl (%rcx), %eax
andl $-0x80, %eax
orl $0x3, %eax
movl %eax, (%rcx)
movq %r13, 0x38(%rcx)
movl $0x5, %r15d
jmp 0x28287
xorl %edx, %edx
jmp 0x281c3
xorl %ecx, %ecx
xorl %edx, %edx
xorl %r15d, %r15d
testb %dl, %dl
je 0x281d0
movq 0x38(%rcx), %rcx
jmp 0x281d2
xorl %ecx, %ecx
testq %rcx, %rcx
je 0x28287
movq 0x40(%rax), %rdx
cmpl $0x3, 0x4(%rdx)
jne 0x281fc
movq 0x18(%rdx), %rdx
testq %rdx, %rdx
je 0x28200
movl (%rdx), %esi
andl $0x7f, %esi
cmpl $0x47, %esi
sete %sil
jmp 0x28204
xorl %esi, %esi
jmp 0x28204
xorl %edx, %edx
xorl %esi, %esi
xorl %r15d, %r15d
testb %sil, %sil
je 0x28212
movq 0x38(%rdx), %rdx
jmp 0x28214
xorl %edx, %edx
testq %rdx, %rdx
je 0x28287
movl (%rbx), %esi
andl $-0x80, %esi
orl $0x4, %esi
movl %esi, (%rbx)
movq %rcx, 0x38(%rbx)
movq %rdx, 0x40(%rbx)
movq 0x30(%rax), %r15
movq %r15, 0x30(%rbx)
testq %r15, %r15
je 0x28268
movl 0x4(%r15), %eax
cmpl $0x6, %eax
ja 0x2824b
movl $0x43, %ecx
btl %eax, %ecx
jb 0x28268
xorl %edi, %edi
callq 0x12220
movq %r14, 0x8(%rax)
movq %rbx, (%rax)
addq $0x8, %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x2285b
movl $0x1, %r15d
testq %r12, %r12
je 0x28287
movl 0x4(%r12), %eax
cmpl $0x6, %eax
ja 0x28299
movl $0x43, %ecx
btl %eax, %ecx
jae 0x28299
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8(%r12), %rdi
movq %r14, %rsi
callq 0x2830b
cmpq $0x0, 0x8(%r12)
jne 0x28287
movl 0x4(%r12), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x28287
movq 0x18(%r12), %rdi
xorl %esi, %esi
callq 0x24adf
jmp 0x28287