// File: /workspace/github_c_makefile_star2_O1/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 0x28dc4
movq 0x38(%rbx), %rcx
cmpl $0x6, 0x4(%rcx)
jne 0x28dc4
movq %rsi, %r14
movq %rdi, %r13
movq 0x18(%rcx), %rax
leaq 0x30(%rdi), %rsi
movq %rax, %rbp
andq %r14, %rbp
je 0x28c56
movq %rdx, %r12
movq %rax, %r13
movq %rsi, %r15
movq (%rsi), %rax
movq 0x8(%rax), %rdi
callq 0x22603
testb %al, %al
je 0x28ce7
xorl %eax, %eax
jmp 0x28dc4
movq (%rsi), %rbx
movq %r15, (%rsi)
testq %r15, %r15
je 0x28c97
movl 0x4(%r15), %eax
cmpl $0x6, %eax
ja 0x28c74
movl $0x43, %ecx
btl %eax, %ecx
jb 0x28c97
xorl %edi, %edi
movq %rsi, %r14
callq 0x12220
movq %r14, 0x8(%rax)
movq %r13, (%rax)
addq $0x8, %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x2285b
movq %r14, %rsi
movl $0x1, %eax
testq %rbx, %rbx
je 0x28dc4
movl 0x4(%rbx), %edx
cmpl $0x6, %edx
ja 0x28cbb
movl $0x43, %ecx
btl %edx, %ecx
jb 0x28dc4
leaq 0x8(%rbx), %rdi
callq 0x2830b
cmpq $0x0, 0x8(%rbx)
jne 0x28dbf
movl 0x4(%rbx), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x28dbf
movq 0x18(%rbx), %rdi
jmp 0x28d8e
cmpq %r14, %rbp
jne 0x28d97
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 0x28d4e
movl 0x4(%rbx), %eax
cmpl $0x6, %eax
ja 0x28d31
movl $0x43, %ecx
btl %eax, %ecx
jb 0x28d4e
xorl %edi, %edi
callq 0x12220
movq %r14, 0x8(%rax)
movq %r13, (%rax)
addq $0x8, %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2285b
movl $0x1, %eax
testq %r15, %r15
je 0x28dc4
movl 0x4(%r15), %edx
cmpl $0x6, %edx
ja 0x28d6b
movl $0x43, %ecx
btl %edx, %ecx
jb 0x28dc4
leaq 0x8(%r15), %rdi
movq %r14, %rsi
callq 0x2830b
cmpq $0x0, 0x8(%r15)
jne 0x28dbf
movl 0x4(%r15), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x28dbf
movq 0x18(%r15), %rdi
xorl %esi, %esi
callq 0x24adf
jmp 0x28dbf
cmpq %r13, %rbp
je 0x28c4f
movq 0x8(%r12), %rdi
callq 0x22603
testb %al, %al
movl $0x0, %eax
jne 0x28dc4
movq %rbp, %rdi
callq 0x136d3
movq %rax, 0x38(%rbx)
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq