// File: /workspace/github_c_makefile_star2_O2/lucvoo[P]sparse-dev/flow.c
// Function: convert_to_jump
int convert_to_jump(struct instruction *insn, struct basic_block *target)
{
	struct basic_block *bb = insn->bb;
	struct basic_block *child;
	int changed = REPEAT_CSE;

	switch (insn->opcode) {
	case OP_CBR:
		changed |= remove_phisources(insn->bb, insn->bb_true == target ? insn->bb_false : insn->bb_true);
		break;
	case OP_SWITCH:
		changed |= remove_other_phisources(insn->bb, insn->multijmp_list, target);
		break;
	}
	kill_use(&insn->cond);
	insn->bb_true = target;
	insn->bb_false = NULL;
	insn->cond = NULL;
	insn->size = 0;
	insn->opcode = OP_BR;

	FOR_EACH_PTR(bb->children, child) {
		if (child == target) {
			target = NULL;	// leave first occurence
			continue;
		}
		DELETE_CURRENT_PTR(child);
		remove_bb_from_list(&child->parents, bb, 1);
		changed |= REPEAT_CFG_CLEANUP;
	} END_FOR_EACH_PTR(child);
	PACK_PTR_LIST(&bb->children);
	repeat_phase |= changed;
	return changed;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %r12
movq 0x8(%rdi), %rax
movq %rax, (%rsp)
movl (%rdi), %eax
andl $0x7f, %eax
pushq $0x1
popq %r15
cmpl $0x5, %eax
je 0x35355
cmpl $0x4, %eax
jne 0x353bc
movq 0x38(%r12), %rsi
cmpq %r14, %rsi
jne 0x35343
movq 0x40(%r12), %rsi
movq (%rsp), %rdi
callq 0x3454f
movl %eax, %r15d
orl $0x1, %r15d
jmp 0x353bc
movq 0x38(%r12), %rbx
testq %rbx, %rbx
je 0x353bc
movq %r12, 0x8(%rsp)
xorl %r15d, %r15d
movq %rbx, %r13
movq %r14, %rbp
xorl %r12d, %r12d
movl (%r13), %eax
movsbq %al, %rcx
cmpq %rcx, %r12
jge 0x353aa
movq 0x18(%r13,%r12,8), %rcx
cmpw $0x100, %ax             # imm = 0x100
jb 0x3538d
testq %rcx, %rcx
je 0x353a5
movq (%rcx), %rsi
cmpq %rbp, %rsi
je 0x353a3
movq (%rsp), %rdi
callq 0x3454f
orl %eax, %r15d
jmp 0x353a5
xorl %ebp, %ebp
incq %r12
jmp 0x35370
movq 0x10(%r13), %r13
cmpq %rbx, %r13
jne 0x3536d
orl $0x1, %r15d
movq 0x8(%rsp), %r12
leaq 0x30(%r12), %rdi
callq 0x21c58
movq %r14, 0x38(%r12)
andq $0x0, 0x40(%r12)
andq $0x0, 0x30(%r12)
movl $0x80, %eax
andl (%r12), %eax
orl $0x3, %eax
movl %eax, (%r12)
movq (%rsp), %rax
leaq 0x20(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x3549b
movq %rax, %r13
movq %rax, 0x8(%rsp)
leaq 0x18(%r13), %rbp
leaq 0x10(%r13), %r12
xorl %ebx, %ebx
movl (%r13), %eax
movsbl %al, %ecx
cmpl %ecx, %ebx
jge 0x35489
movslq %ebx, %rcx
movq (%rbp,%rcx,8), %rdi
cmpw $0x100, %ax             # imm = 0x100
jb 0x35431
testq %rdi, %rdi
je 0x35485
cmpq %r14, %rdi
je 0x35482
movsbl %al, %edx
leaq (,%rcx,8), %rax
addq %rbp, %rax
movswq %dx, %rcx
leaq (%r12,%rcx,8), %rcx
cmpq %rcx, %rax
jae 0x3545e
movq 0x8(%rax), %rdx
movq %rdx, (%rax)
addq $0x8, %rax
jmp 0x3544c
movl $0xf0f0f0f0, %ecx       # imm = 0xF0F0F0F0
movq %rcx, (%rax)
decb (%r13)
decl %ebx
addq $0x18, %rdi
movq (%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x1fbfd
orl $0x4, %r15d
jmp 0x35485
xorl %r14d, %r14d
incl %ebx
jmp 0x35413
movq (%r12), %r13
movq 0x8(%rsp), %rax
cmpq %rax, %r13
jne 0x35409
movq 0x10(%rsp), %rdi
callq 0x1fa10
leaq 0x2b8c8(%rip), %rax     # 0x60d74
orl %r15d, (%rax)
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq