// File: luooofan[P]hblzbd_compiler/src/Pass/simplify_cfg.cpp
// Function: SimplifyCFG::Run4IRFunc(IRFunction*)
void SimplifyCFG::Run4IRFunc(IRFunction* func) {
#ifdef DEBUG_SIMPLIFY_CFG_PROCESS
  std::cout << "========Before Simplyfy:========" << std::endl;
  func->EmitCode(std::cout);
#endif
  std::unordered_set<IRBasicBlock*> worklist;
  std::unordered_set<IRBasicBlock*> wait;
  for (auto bb : func->bb_list_) {
    if (bb->pred_.size() == 0) worklist.insert(bb);
  }
  if (func->bb_list_.size() > 0) worklist.erase(func->bb_list_[0]);
  while (!worklist.empty()) {
    auto bb = *worklist.begin();
    worklist.erase(bb);
    wait.insert(bb);
    for (auto succ : bb->succ_) {
      succ->pred_.erase(std::find(succ->pred_.begin(), succ->pred_.end(), bb));
      if (succ->pred_.size() == 0) worklist.insert(succ);
    }
  }
  for (auto it = func->bb_list_.begin(); it != func->bb_list_.end();) {
    if (wait.count(*it))
      it = func->bb_list_.erase(it);
    else
      ++it;
  }
}

// Assembly:
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdi, 0x1c0(%rsp)
movq %rsi, 0x1b8(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x18db0
leaq 0x148(%rsp), %rdi
callq 0x18db0
movq 0x1b8(%rsp), %rax
addq $0x30, %rax
movq %rax, 0x140(%rsp)
movq 0x140(%rsp), %rdi
callq 0x1cc40
movq %rax, 0x138(%rsp)
movq 0x140(%rsp), %rdi
callq 0x1cac0
movq %rax, 0x130(%rsp)
leaq 0x138(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x492e0
testb $0x1, %al
jne 0xf750d
jmp 0xf75bd
leaq 0x138(%rsp), %rdi
callq 0x49320
movq (%rax), %rax
movq %rax, 0x128(%rsp)
movq 0x128(%rsp), %rdi
addq $0x28, %rdi
callq 0x1cd80
cmpq $0x0, %rax
jne 0xf75a9
leaq 0x180(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x8f780
movb %dl, 0x67(%rsp)
movq %rax, 0x68(%rsp)
jmp 0xf755c
movb 0x67(%rsp), %al
movq 0x68(%rsp), %rcx
movq %rcx, 0x108(%rsp)
movb %al, 0x110(%rsp)
jmp 0xf75a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x49480
leaq 0x180(%rsp), %rdi
callq 0x49480
jmp 0xf7919
jmp 0xf75ab
leaq 0x138(%rsp), %rdi
callq 0x49330
jmp 0xf74ef
movq 0x1b8(%rsp), %rdi
addq $0x30, %rdi
callq 0x1cd80
cmpq $0x0, %rax
jbe 0xf75fd
movq 0x1b8(%rsp), %rdi
addq $0x30, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8ee50
movq %rax, %rsi
leaq 0x180(%rsp), %rdi
callq 0xf7940
jmp 0xf75fb
jmp 0xf75fd
jmp 0xf75ff
leaq 0x180(%rsp), %rdi
callq 0x8f8c0
xorb $-0x1, %al
testb $0x1, %al
jne 0xf7617
jmp 0xf7814
leaq 0x180(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x8d590
movq %rax, 0xf8(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x8d610
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq %rax, 0x100(%rsp)
leaq 0x100(%rsp), %rsi
callq 0xf7940
jmp 0xf765d
leaq 0x148(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x8f780
movb %dl, 0x4f(%rsp)
movq %rax, 0x50(%rsp)
jmp 0xf767d
movb 0x4f(%rsp), %al
movq 0x50(%rsp), %rcx
movq %rcx, 0xe8(%rsp)
movb %al, 0xf0(%rsp)
movq 0x100(%rsp), %rax
addq $0x40, %rax
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rdi
callq 0x1cc40
movq %rax, 0xd8(%rsp)
movq 0xe0(%rsp), %rdi
callq 0x1cac0
movq %rax, 0xd0(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x492e0
testb $0x1, %al
jne 0xf76f1
jmp 0xf780f
leaq 0xd8(%rsp), %rdi
callq 0x49320
movq (%rax), %rax
movq %rax, 0xc8(%rsp)
movq 0xc8(%rsp), %rdi
addq $0x28, %rdi
movq %rdi, 0x38(%rsp)
callq 0x1cc40
movq %rax, 0xb0(%rsp)
movq 0xc8(%rsp), %rdi
addq $0x28, %rdi
callq 0x1cac0
movq %rax, 0xa8(%rsp)
movq 0xb0(%rsp), %rdi
movq 0xa8(%rsp), %rsi
leaq 0x100(%rsp), %rdx
callq 0x49560
movq %rax, 0x40(%rsp)
jmp 0xf7764
movq 0x40(%rsp), %rax
movq %rax, 0xb8(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0xd6210
movq 0x38(%rsp), %rdi
movq 0xc0(%rsp), %rsi
callq 0xd6300
movq %rax, 0x30(%rsp)
jmp 0xf779f
movq 0x30(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xc8(%rsp), %rdi
addq $0x28, %rdi
callq 0x1cd80
cmpq $0x0, %rax
jne 0xf77fb
leaq 0x180(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x8f780
movb %dl, 0x27(%rsp)
movq %rax, 0x28(%rsp)
jmp 0xf77e3
movb 0x27(%rsp), %al
movq 0x28(%rsp), %rcx
movq %rcx, 0x90(%rsp)
movb %al, 0x98(%rsp)
jmp 0xf77fd
leaq 0xd8(%rsp), %rdi
callq 0x49330
jmp 0xf76d3
jmp 0xf75ff
movq 0x1b8(%rsp), %rdi
addq $0x30, %rdi
callq 0x1cc40
movq %rax, 0x88(%rsp)
movq 0x1b8(%rsp), %rdi
addq $0x30, %rdi
callq 0x1cac0
movq %rax, 0x80(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x492e0
testb $0x1, %al
jne 0xf7864
jmp 0xf78f7
leaq 0x88(%rsp), %rdi
callq 0x49320
movq %rax, %rsi
leaq 0x148(%rsp), %rdi
callq 0xf7970
movq %rax, 0x18(%rsp)
jmp 0xf7888
movq 0x18(%rsp), %rax
cmpq $0x0, %rax
je 0xf78e5
movq 0x1b8(%rsp), %rax
addq $0x30, %rax
movq %rax, 0x8(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0xd6210
movq 0x8(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0xd6300
movq %rax, 0x10(%rsp)
jmp 0xf78cc
movq 0x10(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x88(%rsp)
jmp 0xf78f2
leaq 0x88(%rsp), %rdi
callq 0x49330
jmp 0xf782d
leaq 0x148(%rsp), %rdi
callq 0x49480
leaq 0x180(%rsp), %rdi
callq 0x49480
addq $0x1c8, %rsp            # imm = 0x1C8
retq
movq 0x120(%rsp), %rdi
callq 0x8670
nopw %cs:(%rax,%rax)