// File: /workspace/github_c_makefile_star2_O3/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
movl $0x1, %r15d
cmpl $0x5, %eax
je 0x3bdcb
cmpl $0x4, %eax
jne 0x3be42
movq 0x38(%r12), %rsi
cmpq %r14, %rsi
jne 0x3bdb9
movq 0x40(%r12), %rsi
movq (%rsp), %rdi
callq 0x3ae80
movl %eax, %r15d
orl $0x1, %r15d
jmp 0x3be42
movq 0x38(%r12), %rbx
testq %rbx, %rbx
je 0x3be42
movq %r12, 0x8(%rsp)
xorl %r15d, %r15d
movq %rbx, %r13
movq %r14, %rbp
movzwl (%r13), %eax
testb %al, %al
jle 0x3be30
xorl %r12d, %r12d
movq 0x18(%r13,%r12,8), %rcx
movzwl %ax, %edx
cmpl $0x100, %edx            # imm = 0x100
jb 0x3be04
testq %rcx, %rcx
je 0x3be21
movq (%rcx), %rsi
cmpq %rbp, %rsi
je 0x3be1f
movq (%rsp), %rdi
callq 0x3ae80
orl %eax, %r15d
movzwl (%r13), %eax
jmp 0x3be21
xorl %ebp, %ebp
incq %r12
movzwl %ax, %ecx
movsbq %cl, %rcx
cmpq %rcx, %r12
jl 0x3bdef
movq 0x10(%r13), %r13
cmpq %rbx, %r13
jne 0x3bde3
orl $0x1, %r15d
movq 0x8(%rsp), %r12
leaq 0x30(%r12), %rdi
callq 0x249b8
movq %r14, 0x38(%r12)
xorl %eax, %eax
movq %rax, 0x40(%r12)
movq %rax, 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 0x3bf46
movq %rax, %r13
movq %rax, 0x8(%rsp)
movzwl (%r13), %eax
movsbl %al, %ecx
testw %cx, %cx
jle 0x3bf34
leaq 0x18(%r13), %r12
leaq 0x10(%r13), %rbp
xorl %ebx, %ebx
movslq %ebx, %rdx
movq (%r12,%rdx,8), %rdi
movzwl %ax, %esi
cmpl $0x100, %esi            # imm = 0x100
jb 0x3bec1
testq %rdi, %rdi
je 0x3bf24
cmpq %r14, %rdi
je 0x3bef3
leaq (%r12,%rdx,8), %rax
movswq %cx, %rcx
leaq (,%rcx,8), %rcx
addq %rbp, %rcx
cmpq %rcx, %rax
jae 0x3bef8
leaq 0x8(%rax), %rdx
movq 0x8(%rax), %rsi
movq %rsi, (%rax)
movq %rdx, %rax
cmpq %rcx, %rdx
jb 0x3bede
jmp 0x3befb
xorl %r14d, %r14d
jmp 0x3bf24
movq %rax, %rdx
movl $0xf0f0f0f0, %eax       # imm = 0xF0F0F0F0
movq %rax, (%rdx)
decb (%r13)
decl %ebx
addq $0x18, %rdi
movq (%rsp), %rsi
movl $0x1, %edx
callq 0x228ce
orl $0x4, %r15d
movzwl (%r13), %eax
incl %ebx
movsbl %al, %ecx
movsbl %al, %edx
cmpl %edx, %ebx
jl 0x3beaa
movq 0x10(%r13), %r13
movq 0x8(%rsp), %rax
cmpq %rax, %r13
jne 0x3be8f
movq 0x10(%rsp), %rdi
callq 0x226a7
leaq 0x2ae1d(%rip), %rax     # 0x66d74
orl %r15d, (%rax)
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq