// File: /workspace/github_c_makefile_star2_O0/lucvoo[P]sparse-dev/simplify.c
// Function: simplify_seteq_setne
static int simplify_seteq_setne(struct instruction *insn, long long value)
{
	pseudo_t old = insn->src1;
	struct instruction *def;
	unsigned osize;
	int inverse;
	int opcode;

	if (value != 0 && value != 1)
		return 0;

	if (old->type != PSEUDO_REG)
		return 0;
	def = old->def;
	if (!def)
		return 0;

	inverse = (insn->opcode == OP_SET_NE) == value;
	if (!inverse && def->size == 1 && insn->size == 1) {
		// Replace:
		//	setne   %r <- %s, $0
		// or:
		//	seteq   %r <- %s, $1
		// by %s when boolean
		return replace_with_pseudo(insn, old);
	}
	opcode = def->opcode;
	switch (opcode) {
	case OP_AND:
		if (inverse)
			break;
		if (def->size != insn->size)
			break;
		if (def->src2->type != PSEUDO_VAL)
			break;
		if (def->src2->value != 1)
			break;
		return replace_with_pseudo(insn, old);
	case OP_FPCMP ... OP_BINCMP_END:
		// Convert:
		//	setcc.n	%t <- %a, %b
		//	setne.m %r <- %t, $0
		// into:
		//	setcc.n	%t <- %a, %b
		//	setcc.m %r <- %a, $b
		// and similar for setne/eq ... 0/1
		insn->opcode = inverse ? opcode_table[opcode].negate : opcode;
		insn->itype = def->itype;
		use_pseudo(insn, def->src1, &insn->src1);
		use_pseudo(insn, def->src2, &insn->src2);
		remove_usage(old, &insn->src1);
		return REPEAT_CSE;

	case OP_SEXT:
		if (value && (def->orig_type->bit_size == 1))
			break;
		/* Fall through */
	case OP_ZEXT:
		// Convert:
		//	*ext.m	%s <- (1) %a
		//	setne.1 %r <- %s, $0
		// into:
		//	setne.1 %s <- %a, $0
		// and same for setne/eq ... 0/1
		insn->itype = def->orig_type;
		return replace_pseudo(insn, &insn->src1, def->src);
	case OP_TRUNC:
		if (!one_use(old))
			break;
		// convert
		//	trunc.n	%s <- (o) %a
		//	setne.m %r <- %s, $0
		// into:
		//	and.o	%s <- %a, $((1 << o) - 1)
		//	setne.m %r <- %s, $0
		// and same for setne/eq ... 0/1
		osize = def->size;
		def->opcode = OP_AND;
		def->type = def->orig_type;
		def->size = def->type->bit_size;
		def->src2 = value_pseudo(bits_mask(osize));
		return REPEAT_CSE;
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x39716
cmpq $0x1, -0x18(%rbp)
je 0x39716
movl $0x0, -0x4(%rbp)
jmp 0x399b1
movq -0x20(%rbp), %rax
cmpl $0x3, 0x4(%rax)
je 0x3972c
movl $0x0, -0x4(%rbp)
jmp 0x399b1
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x3974b
movl $0x0, -0x4(%rbp)
jmp 0x399b1
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x7f, %eax
cmpl $0x30, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq -0x18(%rbp), %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x397a7
movq -0x28(%rbp), %rax
movl (%rax), %eax
shrl $0x8, %eax
cmpl $0x1, %eax
jne 0x397a7
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x8, %eax
cmpl $0x1, %eax
jne 0x397a7
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x357e0
movl %eax, -0x4(%rbp)
jmp 0x399b1
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x7f, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
addl $-0x16, %eax
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x20, %eax
ja 0x399aa
movq -0x40(%rbp), %rax
leaq 0x2f681(%rip), %rcx     # 0x68e54
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, -0x30(%rbp)
je 0x397e7
jmp 0x399aa
movq -0x28(%rbp), %rax
movl (%rax), %eax
shrl $0x8, %eax
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
shrl $0x8, %ecx
cmpl %ecx, %eax
je 0x39802
jmp 0x399aa
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
cmpl $0x6, 0x4(%rax)
je 0x39815
jmp 0x399aa
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
cmpq $0x1, 0x18(%rax)
je 0x39829
jmp 0x399aa
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x357e0
movl %eax, -0x4(%rbp)
jmp 0x399b1
cmpl $0x0, -0x30(%rbp)
je 0x39860
movslq -0x34(%rbp), %rcx
leaq 0x2a301(%rip), %rax     # 0x63b50
movq (%rax,%rcx,8), %rax
shlq $0x38, %rax
sarq $0x38, %rax
movl %eax, -0x44(%rbp)
jmp 0x39866
movl -0x34(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %edx
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $0x7f, %edx
andl $-0x80, %ecx
orl %edx, %ecx
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x10(%rbp), %rdx
addq $0x30, %rdx
callq 0x381b0
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x10(%rbp), %rdx
addq $0x30, %rdx
addq $0x8, %rdx
callq 0x381b0
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x30, %rsi
callq 0x38200
movl $0x1, -0x4(%rbp)
jmp 0x399b1
cmpq $0x0, -0x18(%rbp)
je 0x398f6
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
cmpl $0x1, 0x50(%rax)
jne 0x398f6
jmp 0x399aa
jmp 0x398f8
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x30, %rsi
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rdx
callq 0x38d50
movl %eax, -0x4(%rbp)
jmp 0x399b1
movq -0x20(%rbp), %rdi
callq 0x3ad20
testb $0x1, %al
jne 0x39938
jmp 0x399aa
movq -0x28(%rbp), %rax
movl (%rax), %eax
shrl $0x8, %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %ecx
andl $-0x80, %ecx
orl $0x16, %ecx
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x50(%rax), %edx
movq -0x28(%rbp), %rax
movl (%rax), %ecx
andl $0xffffff, %edx         # imm = 0xFFFFFF
shll $0x8, %edx
andl $0xff, %ecx
orl %edx, %ecx
movl %ecx, (%rax)
movl -0x2c(%rbp), %edi
callq 0x3acf0
movq %rax, %rdi
callq 0x1a390
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x38(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x399b1
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)