// File: /workspace/github_c_makefile_star2_O0/lucvoo[P]sparse-dev/simplify.c
// Function: simplify_constant_rightside
static int simplify_constant_rightside(struct instruction *insn)
{
	long long value = insn->src2->value;
	long long sbit = 1ULL << (insn->size - 1);
	long long bits = sbit | (sbit - 1);
	int changed = 0;

	switch (insn->opcode) {
	case OP_OR:
		if ((value & bits) == bits)
			return replace_with_pseudo(insn, insn->src2);
		goto case_neutral_zero;

	case OP_XOR:
		if ((value & bits) == bits) {
			insn->opcode = OP_NOT;
			return REPEAT_CSE;
		}
		/* fallthrough */
	case_neutral_zero:
		if (!value)
			return replace_with_pseudo(insn, insn->src1);
		return 0;

	case OP_SUB:
		insn->opcode = OP_ADD;
		insn->src2 = eval_unop(OP_NEG, insn->size, insn->src2);
		changed = REPEAT_CSE;
		/* fallthrough */
	case OP_ADD:
		if (!value)
			return replace_with_pseudo(insn, insn->src1);
		if (insn->src1->type == PSEUDO_REG)	// (x # y) + z
			changed |= simplify_const_rightadd(insn->src1->def, insn);
		return changed;
	case OP_ASR:
	case OP_SHL:
	case OP_LSR:
		return simplify_shift(insn, insn->src1, value);

	case OP_MODU: case OP_MODS:
		if (value == 1)
			return replace_with_value(insn, 0);
		return 0;

	case OP_DIVU: case OP_DIVS:
	case OP_MUL:
		return simplify_mul_div(insn, value);

	case OP_AND:
		if (!value)
			return replace_with_pseudo(insn, insn->src2);
		if ((value & bits) == bits)
			return replace_with_pseudo(insn, insn->src1);
		return simplify_constant_mask(insn, value);

	case OP_SET_NE:
	case OP_SET_EQ:
		if ((changed = simplify_seteq_setne(insn, value)))
			return changed;
		/* fallthrough */
	case OP_SET_LT: case OP_SET_LE: case OP_SET_GE: case OP_SET_GT:
	case OP_SET_B:  case OP_SET_BE: case OP_SET_AE: case OP_SET_A:
		return simplify_compare_constant(insn, value);
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movb 0x1(%rax), %cl
decb %cl
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, %rcx
decq %rcx
orq %rcx, %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x7f, %eax
addl $-0x8, %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x28, %eax
ja 0x38694
movq -0x38(%rbp), %rax
leaq 0x306e5(%rip), %rcx     # 0x68b84
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
andq -0x28(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x384cf
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x357e0
movl %eax, -0x4(%rbp)
jmp 0x3869b
jmp 0x384fb
movq -0x18(%rbp), %rax
andq -0x28(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x384f9
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $-0x80, %ecx
orl $0x31, %ecx
movl %ecx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x3869b
jmp 0x384fb
cmpq $0x0, -0x18(%rbp)
jne 0x3851b
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
callq 0x357e0
movl %eax, -0x4(%rbp)
jmp 0x3869b
movl $0x0, -0x4(%rbp)
jmp 0x3869b
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $-0x80, %ecx
orl $0x8, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl (%rax), %esi
shrl $0x8, %esi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdx
movl $0x32, %edi
callq 0x38da0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movl $0x1, -0x2c(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x38582
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
callq 0x357e0
movl %eax, -0x4(%rbp)
jmp 0x3869b
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
cmpl $0x3, 0x4(%rax)
jne 0x385ab
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x38dd0
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3869b
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x18(%rbp), %rdx
callq 0x38e90
movl %eax, -0x4(%rbp)
jmp 0x3869b
cmpq $0x1, -0x18(%rbp)
jne 0x385ef
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x39480
movl %eax, -0x4(%rbp)
jmp 0x3869b
movl $0x0, -0x4(%rbp)
jmp 0x3869b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x394c0
movl %eax, -0x4(%rbp)
jmp 0x3869b
cmpq $0x0, -0x18(%rbp)
jne 0x3862d
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x357e0
movl %eax, -0x4(%rbp)
jmp 0x3869b
movq -0x18(%rbp), %rax
andq -0x28(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x38651
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
callq 0x357e0
movl %eax, -0x4(%rbp)
jmp 0x3869b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x395b0
movl %eax, -0x4(%rbp)
jmp 0x3869b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x396e0
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
je 0x38680
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3869b
jmp 0x38682
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x399c0
movl %eax, -0x4(%rbp)
jmp 0x3869b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)