// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x382a0
cmpl $0x0, %eax
je 0x37788
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x37767
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x37773
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x59f90
movl %eax, -0x4(%rbp)
jmp 0x379a5
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jne 0x377b3
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x59f90
movl %eax, -0x4(%rbp)
jmp 0x379a5
movq -0x18(%rbp), %rax
cmpl $0x3, 0x4(%rax)
jne 0x3799e
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl $0x7f, %eax
cmpl $0x30, %eax
je 0x377e9
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl $0x7f, %eax
cmpl $0x27, %eax
jne 0x37867
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x382a0
cmpl $0x0, %eax
je 0x37827
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
cmpq $0x0, 0x18(%rax)
jne 0x37827
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdx
callq 0x3d1d0
movl %eax, -0x4(%rbp)
jmp 0x379a5
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x382a0
cmpl $0x0, %eax
je 0x37865
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
cmpq $0x0, 0x18(%rax)
jne 0x37865
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdx
callq 0x3d1d0
movl %eax, -0x4(%rbp)
jmp 0x379a5
jmp 0x37867
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl $0x7f, %eax
cmpl $0x41, %eax
jne 0x37962
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x382a0
cmpl $0x0, %eax
je 0x37960
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x382a0
cmpl $0x0, %eax
je 0x37960
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x378ec
cmpq $0x0, -0x30(%rbp)
jne 0x378ec
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
callq 0x59f90
movl %eax, -0x4(%rbp)
jmp 0x379a5
cmpq $0x0, -0x28(%rbp)
je 0x37913
cmpq $0x0, -0x30(%rbp)
je 0x37913
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x59f90
movl %eax, -0x4(%rbp)
jmp 0x379a5
cmpq $0x0, -0x30(%rbp)
je 0x37942
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x30, %rsi
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdx
callq 0x38d50
movl %eax, -0x4(%rbp)
jmp 0x379a5
jmp 0x37962
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl $0x7f, %eax
cmpl $0x36, %eax
je 0x3797e
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl $0x7f, %eax
cmpl $0x35, %eax
jne 0x3799c
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x30, %rsi
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdx
callq 0x38d50
movl %eax, -0x4(%rbp)
jmp 0x379a5
jmp 0x3799e
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop