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

	switch (DEF_OPCODE(def, src1)) {
	case OP_AND:
		if (DEF_OPCODE(defr, *p2) == OP_AND) {
			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_NOT:
		if (def->src == *p2)
			return replace_with_value(insn, bits_mask(insn->size));
		break;
	case OP_BINCMP ... OP_BINCMP_END:
		if (DEF_OPCODE(defr, *p2) == opcode_negate(def->opcode)) {
			if (def->src1 == defr->src1 && def->src2 == defr->src2)
				return replace_with_value(insn, 1);
		}
		break;
	case OP_SHL: case OP_LSR: case OP_ASR:
		if (DEF_OPCODE(defr, *p2) == def->opcode && defr->src2 == def->src2) {
			if (can_move_to(def->src1, defr)) {
				// SHIFT(x, s) | SHIFT(y, s) --> SHIFT((x | y), s)
				swap_insn(insn, defr, def->src1, defr->src1, def->src2);
				return REPEAT_CSE;
			}
		}
		break;
	}
	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq (%rsi), %rax
xorl %ebx, %ebx
cmpl $0x3, 0x4(%rax)
jne 0x253b6
movq 0x18(%rax), %r12
testq %r12, %r12
je 0x253b6
movl (%r12), %eax
andl $0x7f, %eax
leal -0xf(%rax), %ecx
cmpl $0x22, %ecx
ja 0x253b6
movq %rdi, %r14
leaq 0x1b2b8(%rip), %rsi     # 0x404e4
movslq (%rsi,%rcx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
movq (%rdx), %rcx
xorl %ebx, %ebx
cmpl $0x3, 0x4(%rcx)
jne 0x25250
movq 0x18(%rcx), %rcx
testq %rcx, %rcx
je 0x25250
movl (%rcx), %edx
andl $0x7f, %edx
jmp 0x25254
xorl %ecx, %ecx
xorl %edx, %edx
leaq 0x15a25(%rip), %rsi     # 0x3ac80
movsbl (%rsi,%rax,8), %eax
cmpl %eax, %edx
jne 0x253b6
movq 0x30(%r12), %rax
cmpq 0x30(%rcx), %rax
jne 0x253b6
movq 0x38(%r12), %rax
cmpq 0x38(%rcx), %rax
jne 0x253b6
pushq $0x1
popq %rsi
jmp 0x25315
movq (%rdx), %rcx
xorl %ebx, %ebx
cmpl $0x3, 0x4(%rcx)
jne 0x252a9
movq 0x18(%rcx), %r15
testq %r15, %r15
je 0x252a9
movl (%r15), %ecx
andl $0x7f, %ecx
jmp 0x252ae
xorl %r15d, %r15d
xorl %ecx, %ecx
cmpl %eax, %ecx
jne 0x253b6
movq 0x38(%r15), %rax
cmpq 0x38(%r12), %rax
jne 0x253b6
movq 0x30(%r12), %rdi
movq %r15, %rsi
callq 0x24c0b
testb %al, %al
je 0x253b6
movq 0x30(%r15), %rcx
movq 0x30(%r12), %rdx
movq 0x38(%r12), %r8
movq %r14, %rdi
movq %r15, %rsi
callq 0x24e3b
pushq $0x1
popq %rbx
jmp 0x253b6
movq 0x30(%r12), %rax
cmpq (%rdx), %rax
jne 0x253b6
xorl %ecx, %ecx
subb 0x1(%r14), %cl
pushq $-0x1
popq %rsi
shrq %cl, %rsi
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x2495f
movq (%rdx), %rax
cmpl $0x3, 0x4(%rax)
jne 0x253b6
movq 0x18(%rax), %r15
testq %r15, %r15
je 0x253b6
movl (%r15), %eax
andl $0x7f, %eax
cmpl $0x16, %eax
jne 0x253b6
movq 0x38(%r12), %rdi
cmpq %rdi, 0x38(%r15)
jne 0x25364
movq %r15, %rsi
callq 0x24c0b
testb %al, %al
jne 0x252da
movq 0x30(%r15), %rax
movq 0x30(%r12), %rdi
cmpq %rdi, %rax
jne 0x25395
movq %r15, %rsi
callq 0x24c0b
testb %al, %al
je 0x25391
movq 0x30(%r12), %r8
movq 0x38(%r12), %rdx
movq 0x38(%r15), %rcx
jmp 0x252e8
movq 0x30(%r15), %rax
cmpq 0x38(%r12), %rax
jne 0x253b6
movq 0x30(%r12), %rdi
movq %r15, %rsi
callq 0x24c0b
testb %al, %al
je 0x253b6
movq 0x38(%r15), %rcx
jmp 0x252de
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq