// File: /workspace/github_c_makefile_star2_O3/lucvoo[P]sparse-dev/simplify.c
// Function: simplify_branch
static int simplify_branch(struct instruction *insn)
{
	pseudo_t cond = insn->cond;

	/* Constant conditional */
	if (constant(cond))
		return convert_to_jump(insn, cond->value ? insn->bb_true : insn->bb_false);

	/* Same target? */
	if (insn->bb_true == insn->bb_false)
		return convert_to_jump(insn, insn->bb_true);

	/* Conditional on a SETNE $0 or SETEQ $0 */
	if (cond->type == PSEUDO_REG) {
		struct instruction *def = cond->def;

		if (def->opcode == OP_SET_NE || def->opcode == OP_SET_EQ) {
			if (constant(def->src1) && !def->src1->value)
				return simplify_cond_branch(insn, def, def->src2);
			if (constant(def->src2) && !def->src2->value)
				return simplify_cond_branch(insn, def, def->src1);
		}
		if (def->opcode == OP_SEL) {
			if (constant(def->src2) && constant(def->src3)) {
				long long val1 = def->src2->value;
				long long val2 = def->src3->value;
				if (!val1 && !val2)
					return convert_to_jump(insn, insn->bb_false);
				if (val1 && val2)
					return convert_to_jump(insn, insn->bb_true);
				if (val2) {
					struct basic_block *tmp = insn->bb_true;
					insn->bb_true = insn->bb_false;
					insn->bb_false = tmp;
				}
				return replace_pseudo(insn, &insn->cond, def->src1);
			}
		}
		if (def->opcode == OP_SEXT || def->opcode == OP_ZEXT)
			return replace_pseudo(insn, &insn->cond, def->src);
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movq 0x30(%rdi), %r12
movl 0x4(%r12), %edx
cmpl $0x6, %edx
jne 0x27b4a
xorl %eax, %eax
cmpq $0x0, 0x18(%r12)
sete %al
movq 0x38(%rbx,%rax,8), %rsi
movq %rbx, %rdi
jmp 0x27c0c
movq 0x38(%rbx), %rax
movq 0x40(%rbx), %rcx
cmpq %rcx, %rax
je 0x27c06
xorl %ebp, %ebp
cmpl $0x3, %edx
jne 0x27cbb
movq 0x18(%r12), %rsi
movl (%rsi), %edx
andl $0x7f, %edx
cmpl $0x27, %edx
je 0x27b87
leaq 0x30(%rbx), %r14
cmpl $0x41, %edx
je 0x27bba
cmpl $0x30, %edx
jne 0x27c19
movq 0x30(%rsi), %rdx
cmpl $0x6, 0x4(%rdx)
jne 0x27b9c
cmpq $0x0, 0x18(%rdx)
je 0x27caa
movq 0x38(%rsi), %rax
cmpl $0x6, 0x4(%rax)
jne 0x27cbb
cmpq $0x0, 0x18(%rax)
jne 0x27cbb
jmp 0x27cae
movq 0x38(%rsi), %rdx
cmpl $0x6, 0x4(%rdx)
jne 0x27cbb
movq 0x40(%rsi), %r8
cmpl $0x6, 0x4(%r8)
jne 0x27cbb
movq 0x18(%rdx), %rdi
movq 0x18(%r8), %rdx
movq %rdi, %r8
orq %rdx, %r8
je 0x27cc6
testq %rdx, %rdx
setne %r8b
testq %rdi, %rdi
setne %dil
andb %r8b, %dil
cmpb $0x1, %dil
jne 0x27cd1
movq %rbx, %rdi
movq %rax, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x3bd75
addl $-0x35, %edx
cmpl $0x1, %edx
ja 0x27cbb
movq 0x30(%rsi), %r15
movq %r15, (%r14)
testq %r15, %r15
je 0x27c61
movl 0x4(%r15), %eax
cmpl $0x6, %eax
ja 0x27c44
movl $0x43, %ecx
btl %eax, %ecx
jb 0x27c61
xorl %edi, %edi
callq 0x12264
movq %r14, 0x8(%rax)
movq %rbx, (%rax)
addq $0x8, %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x227b4
movl 0x4(%r12), %eax
movl $0x1, %ebp
cmpl $0x6, %eax
ja 0x27c7a
movl $0x43, %ecx
btl %eax, %ecx
jb 0x27cbb
leaq 0x8(%r12), %rdi
movq %r14, %rsi
callq 0x2806f
cmpq $0x0, 0x8(%r12)
jne 0x27cbb
movl 0x4(%r12), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x27cbb
movq 0x18(%r12), %rdi
xorl %esi, %esi
callq 0x24a3f
jmp 0x27cbb
movq 0x38(%rsi), %rdx
movq %rbx, %rdi
callq 0x29e83
movl $0x1, %ebp
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %rcx, %rsi
jmp 0x27c0c
testq %rdx, %rdx
je 0x27cde
movq %rcx, 0x38(%rbx)
movq %rax, 0x40(%rbx)
movq 0x30(%rsi), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x28562
jmp 0x27cb6