// File: /workspace/github_c_makefile_star2_O0/lucvoo[P]sparse-dev/simplify.c
// Function: simplify_cgoto
static int simplify_cgoto(struct instruction *insn)
{
	struct basic_block *target, *bb = insn->bb;
	struct basic_block *bbt, *bbf;
	struct instruction *def;
	struct multijmp *jmp;

	switch (DEF_OPCODE(def, insn->src)) {
	case OP_SEL:	// CGOTO(SEL(x, L1, L2)) --> CBR x, L1, L2
		if ((bbt = is_label(def->src2)) && (bbf = is_label(def->src3))) {
			insn->opcode = OP_CBR;
			insn->bb_true = bbt;
			insn->bb_false = bbf;
			return replace_pseudo(insn, &insn->src1, def->cond);
		}
		break;
	case OP_LABEL:
		target = def->bb_true;
		if (!target->ep)
			return 0;
		FOR_EACH_PTR(insn->multijmp_list, jmp) {
			if (jmp->target == target)
				continue;
			remove_bb_from_list(&jmp->target->parents, bb, 1);
			remove_bb_from_list(&bb->children, jmp->target, 1);
			DELETE_CURRENT_PTR(jmp);
		} END_FOR_EACH_PTR(jmp);
		kill_use(&insn->src);
		insn->opcode = OP_BR;
		insn->bb_true = target;
		return REPEAT_CSE|REPEAT_CFG_CLEANUP;
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
cmpl $0x3, 0x4(%rax)
jne 0x37b4d
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x37b4d
movq -0x38(%rbp), %rax
movl (%rax), %eax
andl $0x7f, %eax
movl %eax, -0x74(%rbp)
jmp 0x37b54
xorl %eax, %eax
movl %eax, -0x74(%rbp)
jmp 0x37b54
movl -0x74(%rbp), %eax
movl %eax, -0x78(%rbp)
subl $0x41, %eax
je 0x37b6e
jmp 0x37b61
movl -0x78(%rbp), %eax
subl $0x47, %eax
je 0x37be8
jmp 0x37dcf
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x3d240
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x37be3
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x3d240
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x37be3
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $-0x80, %ecx
orl $0x4, %ecx
movl %ecx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x30, %rsi
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rdx
callq 0x38d50
movl %eax, -0x4(%rbp)
jmp 0x37dd6
jmp 0x37dcf
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x37c0b
movl $0x0, -0x4(%rbp)
jmp 0x37dd6
jmp 0x37c0d
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x37c35
jmp 0x37d9f
jmp 0x37c37
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x50(%rbp), %rcx
movw (%rcx), %cx
shlw $0x8, %cx
sarw $0x8, %cx
movswl %cx, %ecx
cmpl %ecx, %eax
jge 0x37d87
movq -0x50(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movq 0x18(%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rax
movw (%rax), %ax
sarw $0x8, %ax
cwtl
cmpl $0x0, %eax
je 0x37c89
cmpq $0x0, -0x40(%rbp)
jne 0x37c89
jmp 0x37d79
movq -0x40(%rbp), %rax
movq (%rax), %rax
cmpq -0x18(%rbp), %rax
jne 0x37c9b
jmp 0x37d79
movq -0x40(%rbp), %rax
movq (%rax), %rdi
addq $0x18, %rdi
movq -0x20(%rbp), %rsi
movl $0x1, %edx
callq 0x3d2a0
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
movq -0x40(%rbp), %rax
movq (%rax), %rsi
movl $0x1, %edx
callq 0x3d2a0
movq -0x50(%rbp), %rax
addq $0x18, %rax
movslq -0x5c(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
addq $0x18, %rax
movq -0x50(%rbp), %rcx
movw (%rcx), %cx
shlw $0x8, %cx
sarw $0x8, %cx
movswl %cx, %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
addq $-0x8, %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x70(%rbp), %rax
jae 0x37d37
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x68(%rbp), %rax
movq %rcx, (%rax)
movq -0x68(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x68(%rbp)
jmp 0x37d10
movq -0x68(%rbp), %rax
movl $0xf0f0f0f0, %ecx       # imm = 0xF0F0F0F0
movq %rcx, (%rax)
movq -0x50(%rbp), %rax
movw (%rax), %cx
shlw $0x8, %cx
sarw $0x8, %cx
movswl %cx, %ecx
addl $-0x1, %ecx
movw %cx, %dx
movw (%rax), %cx
andw $0xff, %dx
andw $0xff00, %cx            # imm = 0xFF00
orw %dx, %cx
movw %cx, (%rax)
movl -0x5c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x37d79
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x37c3e
jmp 0x37d89
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq -0x48(%rbp), %rax
jne 0x37c37
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
callq 0x35160
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $-0x80, %ecx
orl $0x3, %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movl $0x5, -0x4(%rbp)
jmp 0x37dd6
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)