// File: /workspace/github_c_makefile_star2_O3/lucvoo[P]sparse-dev/simplify.c
// Function: simplify_mask_or_and
static int simplify_mask_or_and(struct instruction *insn, unsigned long long mask,
	pseudo_t ora, pseudo_t orb)
{
	unsigned long long omask, nmask;
	struct instruction *and = ora->def;
	pseudo_t src2 = and->src2;

	if (and->opcode != OP_AND)
		return 0;
	if (!constant(src2))
		return 0;
	omask = src2->value;
	nmask = omask & mask;
	if (nmask == 0) {
		// if (M' & M) == 0: ((a & M') | b) -> b
		return replace_pseudo(insn, &insn->src1, orb);
	}
	if (!one_use(insn->src1))
		return 0;	// can't modify anything inside the OR
	if (nmask == mask) {
		struct instruction *or = insn->src1->def;
		pseudo_t *arg = (ora == or->src1) ? &or->src1 : &or->src2;
		// if (M' & M) == M: ((a & M') | b) -> (a | b)
		return replace_pseudo(or, arg, and->src1);
	}
	if (nmask != omask && one_use(ora)) {
		// if (M' & M) != M': AND(a, M') -> AND(a, (M' & M))
		and->src2 = value_pseudo(nmask);
		return REPEAT_CSE;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r15
movq 0x18(%rdx), %rbx
movl (%rbx), %ecx
andl $0x7f, %ecx
xorl %eax, %eax
cmpl $0x16, %ecx
jne 0x28ae2
movq 0x38(%rbx), %rcx
cmpl $0x6, 0x4(%rcx)
jne 0x28ae2
movq %rsi, %r14
movq %rdi, %r13
movq 0x18(%rcx), %rax
leaq 0x30(%rdi), %rsi
movq %rax, %rbp
andq %r14, %rbp
je 0x28974
movq %rdx, %r12
movq %rax, %r13
movq %rsi, %r15
movq (%rsi), %rax
movq 0x8(%rax), %rdi
callq 0x2257f
testb %al, %al
je 0x28a05
xorl %eax, %eax
jmp 0x28ae2
movq (%rsi), %rbx
movq %r15, (%rsi)
testq %r15, %r15
je 0x289b5
movl 0x4(%r15), %eax
cmpl $0x6, %eax
ja 0x28992
movl $0x43, %ecx
btl %eax, %ecx
jb 0x289b5
xorl %edi, %edi
movq %rsi, %r14
callq 0x12264
movq %r14, 0x8(%rax)
movq %r13, (%rax)
addq $0x8, %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x227b4
movq %r14, %rsi
movl $0x1, %eax
testq %rbx, %rbx
je 0x28ae2
movl 0x4(%rbx), %edx
cmpl $0x6, %edx
ja 0x289d9
movl $0x43, %ecx
btl %edx, %ecx
jb 0x28ae2
leaq 0x8(%rbx), %rdi
callq 0x2806f
cmpq $0x0, 0x8(%rbx)
jne 0x28add
movl 0x4(%rbx), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x28add
movq 0x18(%rbx), %rdi
jmp 0x28aac
cmpq %r14, %rbp
jne 0x28ab5
movq (%r15), %rax
movq 0x18(%rax), %r13
leaq 0x30(%r13), %rax
xorl %ecx, %ecx
cmpq %r12, 0x30(%r13)
leaq 0x38(%r13), %r14
setne %cl
cmoveq %rax, %r14
movq 0x30(%rbx), %rbx
movq 0x30(%r13,%rcx,8), %r15
movq %rbx, 0x30(%r13,%rcx,8)
testq %rbx, %rbx
je 0x28a6c
movl 0x4(%rbx), %eax
cmpl $0x6, %eax
ja 0x28a4f
movl $0x43, %ecx
btl %eax, %ecx
jb 0x28a6c
xorl %edi, %edi
callq 0x12264
movq %r14, 0x8(%rax)
movq %r13, (%rax)
addq $0x8, %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x227b4
movl $0x1, %eax
testq %r15, %r15
je 0x28ae2
movl 0x4(%r15), %edx
cmpl $0x6, %edx
ja 0x28a89
movl $0x43, %ecx
btl %edx, %ecx
jb 0x28ae2
leaq 0x8(%r15), %rdi
movq %r14, %rsi
callq 0x2806f
cmpq $0x0, 0x8(%r15)
jne 0x28add
movl 0x4(%r15), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x28add
movq 0x18(%r15), %rdi
xorl %esi, %esi
callq 0x24a3f
jmp 0x28add
cmpq %r13, %rbp
je 0x2896d
movq 0x8(%r12), %rdi
callq 0x2257f
testb %al, %al
movl $0x0, %eax
jne 0x28ae2
movq %rbp, %rdi
callq 0x13745
movq %rax, 0x38(%rbx)
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq