// File: /workspace/github_c_makefile_star2_O1/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), %eax
cmpl $0x6, %eax
jne 0x27d9a
xorl %eax, %eax
cmpq $0x0, 0x18(%r12)
sete %al
movq 0x38(%rbx,%rax,8), %rsi
jmp 0x27e51
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rcx
cmpq %rcx, %rsi
je 0x27e51
cmpl $0x3, %eax
jne 0x27f28
leaq 0x30(%rbx), %r14
movq 0x18(%r12), %rax
movl (%rax), %edi
andl $0x7f, %edi
cmpl $0x27, %edi
je 0x27dd5
cmpl $0x41, %edi
je 0x27e05
cmpl $0x30, %edi
jne 0x27e61
movq 0x30(%rax), %rdx
cmpl $0x6, 0x4(%rdx)
jne 0x27dea
cmpq $0x0, 0x18(%rdx)
je 0x27efe
movq 0x38(%rax), %r8
cmpl $0x6, 0x4(%r8)
jne 0x27e00
cmpq $0x0, 0x18(%r8)
je 0x27f02
cmpl $0x41, %edi
jne 0x27e61
movq 0x38(%rax), %rdx
cmpl $0x6, 0x4(%rdx)
jne 0x27e61
movq 0x40(%rax), %r8
cmpl $0x6, 0x4(%r8)
jne 0x27e61
movq 0x18(%rdx), %rdi
movq 0x18(%r8), %rdx
movq %rdi, %r8
orq %rdx, %r8
je 0x27f14
testq %rdx, %rdx
setne %r8b
testq %rdi, %rdi
setne %dil
andb %r8b, %dil
cmpb $0x1, %dil
jne 0x27f35
movq %rbx, %rdi
jmp 0x27f1a
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x3cc50
addl $-0x35, %edi
cmpl $0x1, %edi
ja 0x27ef9
movq 0x30(%rax), %r15
movq %r15, (%r14)
testq %r15, %r15
je 0x27ea9
movl 0x4(%r15), %eax
cmpl $0x6, %eax
ja 0x27e8c
movl $0x43, %ecx
btl %eax, %ecx
jb 0x27ea9
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, %ebx
testq %r12, %r12
je 0x27f21
movl 0x4(%r12), %eax
cmpl $0x6, %eax
ja 0x27ec7
movl $0x43, %ecx
btl %eax, %ecx
jb 0x27f21
leaq 0x8(%r12), %rdi
movq %r14, %rsi
callq 0x2830b
cmpq $0x0, 0x8(%r12)
jne 0x27f21
movl 0x4(%r12), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x27f21
movq 0x18(%r12), %rdi
xorl %ebp, %ebp
xorl %esi, %esi
callq 0x24adf
jmp 0x27f23
movb $0x1, %bpl
jmp 0x27f23
movq 0x38(%rax), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2a2c8
movl $0x1, %ebx
jmp 0x27f21
movq %rbx, %rdi
movq %rcx, %rsi
callq 0x3cc50
movl %eax, %ebx
xorl %ebp, %ebp
testb %bpl, %bpl
je 0x27f2a
xorl %ebx, %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
testq %rdx, %rdx
je 0x27f42
movq %rcx, 0x38(%rbx)
movq %rsi, 0x40(%rbx)
movq 0x30(%rax), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x28833
jmp 0x27f0d