// File: /workspace/github_c_makefile_star2_O0/lucvoo[P]sparse-dev/simplify.c
// Function: simplify_add_one_side
static int simplify_add_one_side(struct instruction *insn, pseudo_t *p1, pseudo_t *p2)
{
	struct instruction *defr = NULL;
	struct instruction *def;
	pseudo_t src1 = *p1;
	pseudo_t src2 = *p2;

	switch (DEF_OPCODE(def, src1)) {
	case OP_MUL:
		if (DEF_OPCODE(defr, *p2) == OP_MUL) {
			if (defr->src2 == def->src2 && can_move_to(def->src2, defr)) {
				// ((x * z) + (y * z)) into ((x + y) * z)
				swap_insn(insn, defr, def->src1, defr->src1, def->src2);
				return REPEAT_CSE;
			}
			if (defr->src1 == def->src1 && can_move_to(def->src1, defr)) {
				// ((z * x) + (z * y)) into ((x + y) * z)
				swap_insn(insn, defr, def->src2, defr->src2, def->src1);
				return REPEAT_CSE;
			}
			if (defr->src1 == def->src2 && can_move_to(def->src1, defr)) {
				// ((x * z) + (z * y)) into ((x + y) * z)
				swap_insn(insn, defr, def->src1, defr->src2, def->src2);
				return REPEAT_CSE;
			}
		}
		break;

	case OP_NEG:				// (-x + y) --> (y - x)
		return replace_binop(insn, OP_SUB, &insn->src1, src2, &insn->src2, def->src);

	case OP_SUB:
		if (def->src2 == src2)		// (x - y) + y --> x
			return replace_with_pseudo(insn, def->src1);
		break;
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x3, 0x4(%rax)
jne 0x3b7ac
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x3b7ac
movq -0x30(%rbp), %rax
movl (%rax), %eax
andl $0x7f, %eax
movl %eax, -0x44(%rbp)
jmp 0x3b7b3
xorl %eax, %eax
movl %eax, -0x44(%rbp)
jmp 0x3b7b3
movl -0x44(%rbp), %eax
movl %eax, -0x48(%rbp)
subl $0x9, %eax
je 0x3b7df
jmp 0x3b7c0
movl -0x48(%rbp), %eax
subl $0xa, %eax
je 0x3b964
jmp 0x3b7ce
movl -0x48(%rbp), %eax
subl $0x32, %eax
je 0x3b931
jmp 0x3b98a
movq -0x20(%rbp), %rax
movq (%rax), %rax
cmpl $0x3, 0x4(%rax)
jne 0x3b80f
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x3b80f
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x7f, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3b816
xorl %eax, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3b816
movl -0x4c(%rbp), %eax
cmpl $0x9, %eax
jne 0x3b92f
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jne 0x3b87c
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x3b4b0
testb $0x1, %al
jne 0x3b84b
jmp 0x3b87c
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdx
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x30(%rbp), %rax
movq 0x38(%rax), %r8
callq 0x3b9a0
movl $0x1, -0x4(%rbp)
jmp 0x3b991
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jne 0x3b8d6
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x3b4b0
testb $0x1, %al
jne 0x3b8a5
jmp 0x3b8d6
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rdx
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x30(%rbp), %rax
movq 0x30(%rax), %r8
callq 0x3b9a0
movl $0x1, -0x4(%rbp)
jmp 0x3b991
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jne 0x3b92d
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x3b4b0
testb $0x1, %al
jne 0x3b8ff
jmp 0x3b92d
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdx
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x30(%rbp), %rax
movq 0x38(%rax), %r8
callq 0x3b9a0
movl $0x1, -0x4(%rbp)
jmp 0x3b991
jmp 0x3b92f
jmp 0x3b98a
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rdx
addq $0x30, %rdx
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %r8
addq $0x30, %r8
addq $0x8, %r8
movq -0x30(%rbp), %rax
movq 0x30(%rax), %r9
movl $0xa, %esi
callq 0x3ba00
movl %eax, -0x4(%rbp)
jmp 0x3b991
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
cmpq -0x40(%rbp), %rax
jne 0x3b988
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rsi
callq 0x357e0
movl %eax, -0x4(%rbp)
jmp 0x3b991
jmp 0x3b98a
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)