// File: /workspace/github_c_makefile_star2_O0/lucvoo[P]sparse-dev/unssa.c
// Function: replace_phi_node
static void replace_phi_node(struct instruction *phi)
{
	pseudo_t tmp;
	pseudo_t p;

	tmp = alloc_pseudo(NULL);
	tmp->type = phi->target->type;
	tmp->ident = phi->target->ident;
	tmp->def = NULL;		// defined by all the phisrc

	// can we avoid to make of copy?
	simplify_phi_node(phi, tmp);

	// rewrite all it's phi_src to copy to a new tmp
	FOR_EACH_PTR(phi->phi_list, p) {
		struct instruction *def = p->def;
		pseudo_t src;

		if (p == VOID)
			continue;

		assert(def->opcode == OP_PHISOURCE);

		def->opcode = OP_COPY;
		def->target = tmp;

		// can we eliminate the copy?
		src = def->phi_src;
		if (src->type != PSEUDO_REG)
			continue;
		switch (nbr_users(src)) {
			struct instruction *insn;
		case 1:
			insn = src->def;
			if (!insn)
				break;
			insn->target = tmp;
		case 0:
			kill_instruction(def);
			def->bb = NULL;
		}
	} END_FOR_EACH_PTR(p);

	if (!phi->bb)
		return;

	// rewrite the phi node:
	//	phi	%rt, ...
	// to:
	//	copy	%rt, %tmp
	phi->opcode = OP_COPY;
	use_pseudo(phi, tmp, &phi->src);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x1de30
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4a540
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x4a3b0
jmp 0x4a4ff
jmp 0x4a3b2
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x28(%rbp), %rcx
movw (%rcx), %cx
shlw $0x8, %cx
sarw $0x8, %cx
movswl %cx, %ecx
cmpl %ecx, %eax
jge 0x4a4e7
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq 0x18(%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rax
movw (%rax), %ax
sarw $0x8, %ax
cwtl
cmpl $0x0, %eax
je 0x4a404
cmpq $0x0, -0x18(%rbp)
jne 0x4a404
jmp 0x4a4d9
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
leaq 0x429a9(%rip), %rax     # 0x8cdc0
cmpq %rax, -0x18(%rbp)
jne 0x4a422
jmp 0x4a4d9
movq -0x40(%rbp), %rax
movl (%rax), %eax
andl $0x7f, %eax
cmpl $0x45, %eax
jne 0x4a432
jmp 0x4a451
leaq 0x1f1af(%rip), %rdi     # 0x695e8
leaq 0x201f3(%rip), %rsi     # 0x6a633
movl $0x54, %edx
leaq 0x201ef(%rip), %rcx     # 0x6a63b
callq 0x11120
movq -0x40(%rbp), %rax
movl (%rax), %ecx
andl $-0x80, %ecx
orl $0x51, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpl $0x3, 0x4(%rax)
je 0x4a483
jmp 0x4a4d9
movq -0x48(%rbp), %rdi
callq 0x4a700
movl %eax, %ecx
movl %ecx, -0x54(%rbp)
testl %eax, %eax
je 0x4a4c2
jmp 0x4a497
movl -0x54(%rbp), %eax
subl $0x1, %eax
jne 0x4a4d7
jmp 0x4a4a1
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x4a4b6
jmp 0x4a4d7
movq -0x10(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x40(%rbp), %rdi
callq 0x4a720
movq -0x40(%rbp), %rax
movq $0x0, 0x8(%rax)
jmp 0x4a4d9
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4a3b9
jmp 0x4a4e9
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq -0x20(%rbp), %rax
jne 0x4a3b2
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x4a50c
jmp 0x4a52f
movq -0x8(%rbp), %rax
movl (%rax), %ecx
andl $-0x80, %ecx
orl $0x51, %ecx
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x8(%rbp), %rdx
addq $0x30, %rdx
callq 0x4a740
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)