// File: /workspace/github_c_makefile_star2_O0/lucvoo[P]sparse-dev/simplify.c
// Function: if_convert_phi
static int if_convert_phi(struct instruction *insn)
{
	struct instruction *array[2];
	struct basic_block *parents[2];
	struct basic_block *bb, *bb1, *bb2, *source;
	struct instruction *br;
	pseudo_t p1, p2;

	bb = insn->bb;
	if (get_phisources(array, 2, insn))
		return 0;
	if (ptr_list_to_array(bb->parents, parents, 2) != 2)
		return 0;
	p1 = array[0]->phi_src;
	bb1 = array[0]->bb;
	p2 = array[1]->phi_src;
	bb2 = array[1]->bb;

	/* Only try the simple "direct parents" case */
	if ((bb1 != parents[0] || bb2 != parents[1]) &&
	    (bb1 != parents[1] || bb2 != parents[0]))
		return 0;

	/*
	 * See if we can find a common source for this..
	 */
	source = phi_parent(bb1, p1);
	if (source != phi_parent(bb2, p2))
		return 0;

	/*
	 * Cool. We now know that 'source' is the exclusive
	 * parent of both phi-nodes, so the exit at the
	 * end of it fully determines which one it is, and
	 * we can turn it into a select.
	 *
	 * HOWEVER, right now we only handle regular
	 * conditional branches. No multijumps or computed
	 * stuff. Verify that here.
	 */
	br = last_instruction(source->insns);
	if (!br || br->opcode != OP_CBR)
		return 0;

	assert(br->cond);
	assert(br->bb_false);

	/*
	 * We're in business. Match up true/false with p1/p2.
	 */
	if (br->bb_true == bb2 || br->bb_false == bb1) {
		pseudo_t p = p1;
		p1 = p2;
		p2 = p;
	}

	/*
	 * OK, we can now replace that last
	 *
	 *	br cond, a, b
	 *
	 * with the sequence
	 *
	 *	setcc cond
	 *	select pseudo, p1, p2
	 *	br cond, a, b
	 *
	 * and remove the phi-node. If it then
	 * turns out that 'a' or 'b' is entirely
	 * empty (common case), and now no longer
	 * a phi-source, we'll be able to simplify
	 * the conditional branch too.
	 */
	insert_select(source, br, insn, p1, p2);
	kill_instruction(insn);
	return REPEAT_CSE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
leaq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl $0x2, %esi
callq 0x3ce10
cmpl $0x0, %eax
je 0x3cbfe
movl $0x0, -0x4(%rbp)
jmp 0x3cdc0
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x2, %edx
callq 0x310b0
movl %eax, -0x74(%rbp)
cmpl $0x2, -0x74(%rbp)
je 0x3cc31
movl $0x0, -0x4(%rbp)
jmp 0x3cdc0
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x30(%rbp), %rax
jne 0x3cc75
movq -0x48(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0x3cc95
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x3cc89
movq -0x48(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0x3cc95
movl $0x0, -0x4(%rbp)
jmp 0x3cdc0
movq -0x40(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x3cf90
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x48(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x3cf90
movq %rax, %rcx
movq -0x88(%rbp), %rax
cmpq %rcx, %rax
je 0x3ccd9
movl $0x0, -0x4(%rbp)
jmp 0x3cdc0
movq -0x50(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x3d020
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x3ccff
movq -0x58(%rbp), %rax
movl (%rax), %eax
andl $0x7f, %eax
cmpl $0x4, %eax
je 0x3cd0b
movl $0x0, -0x4(%rbp)
jmp 0x3cdc0
movq -0x58(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x3cd18
jmp 0x3cd37
leaq 0x26a14(%rip), %rdi     # 0x63733
leaq 0x2c4a2(%rip), %rsi     # 0x691c8
movl $0x98, %edx
leaq 0x2c554(%rip), %rcx     # 0x69286
callq 0x11120
movq -0x58(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x3cd44
jmp 0x3cd63
leaq 0x2c564(%rip), %rdi     # 0x692af
leaq 0x2c476(%rip), %rsi     # 0x691c8
movl $0x99, %edx
leaq 0x2c528(%rip), %rcx     # 0x69286
callq 0x11120
movq -0x58(%rbp), %rax
movq 0x38(%rax), %rax
cmpq -0x48(%rbp), %rax
je 0x3cd7f
movq -0x58(%rbp), %rax
movq 0x40(%rax), %rax
cmpq -0x40(%rbp), %rax
jne 0x3cd97
movq -0x60(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %r8
callq 0x1a130
movq -0x10(%rbp), %rdi
callq 0x357c0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)