// File: luooofan[P]hblzbd_compiler/src/construct_ir_module.cpp
// Function: ConstructModule(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<ir::IR*, std::allocator<ir::IR*>>&)
IRModule* ConstructModule(const std::string& module_name, std::vector<ir::IR*>& gIRList) {
  // Construct BasicBlocks Functions and Module from gIRList

  // 基本块的首指令
  //  由于IR中使用了label 所有跳转语句都跳到某个label
  //  并且每个出现在四元式中的label都有跳转到该label的指令(不一定)
  //  所以首指令为每个label和每个跳转语句(call,ret,goto,jxx)的下一句
  //  (即便不一定为真正的首指令也可以接受)

  // 先遍历一遍IR 把所有func和有label的BB创建完成 创建两个map
  std::unordered_map<std::string, IRBasicBlock*> label2bb;
  std::unordered_map<std::string, IRFunction*> label2func;

  // add library function to label2func
  // not add them to module
  label2func.insert({"getint", new IRFunction("getint", 0)});
  label2func.insert({"getch", new IRFunction("getch", 0)});
  label2func.insert({"getarray", new IRFunction("getarray", 0)});
  label2func.insert({"putint", new IRFunction("putint", 1)});
  label2func.insert({"putch", new IRFunction("putch", 1)});
  label2func.insert({"putarray", new IRFunction("putarray", 1)});
  label2func.insert({"_sysy_starttime", new IRFunction("_sysy_starttime", 1)});
  label2func.insert({"_sysy_stoptime", new IRFunction("_sysy_stoptime", 1)});
  label2func.insert({"memset", new IRFunction("memset", 3)});

  IRModule* module = new IRModule(module_name, gScopes[0]);

  // fill label2bb label2func. every bb has its first ir. every func has it first bb. module has all funs.
  for (int i = 0; i < gIRList.size(); ++i) {
    auto& ir = *gIRList[i];
    if (ir.op_ == IR::OpKind::LABEL) {
      auto& label_name = ir.opn1_.name_;
      IRBasicBlock* bb = new IRBasicBlock();
      bb->ir_list_.push_back(&ir);
      label2bb.insert({label_name, bb});
      if (ir.opn1_.type_ == Opn::Type::Func) {  // is a function begin
        auto& func_item = (*ir::gFuncTable.find(label_name)).second;
        IRFunction* func = new IRFunction(label_name, func_item.shape_list_.size());
        func->bb_list_.push_back(bb);
        bb->func_ = func;
        label2func.insert({label_name, func});
        module->func_list_.push_back(func);
      }
    }
  }

  bool is_leader = false;
  bool is_succ = true;
  IRFunction* curr_func = nullptr;
  IRBasicBlock* pre_bb = nullptr;
  IRBasicBlock* curr_bb = nullptr;
  // for every ir
  for (int i = 0; i < gIRList.size(); ++i) {
    auto& ir = *gIRList[i];
    if (ir.op_ == IR::OpKind::LABEL) {
      is_leader = true;  // 表示这条一定是首指令
    }
    if (is_leader) {  // 一定已经或者将要把该ir放入到基本块中
      pre_bb = curr_bb;
      // 更新curr_bb curr_func
      if (ir.op_ == IR::OpKind::LABEL) {
        curr_bb = label2bb[ir.opn1_.name_];
        if (ir.opn1_.type_ == Opn::Type::Func) {
          curr_func = label2func[ir.opn1_.name_];
          is_leader = false;  // 下一条语句非首指令
          continue;
        }
      } else {
        // new BB
        curr_bb = new IRBasicBlock();
        curr_bb->ir_list_.push_back(&ir);
      }
      curr_func->bb_list_.push_back(curr_bb);
      curr_bb->func_ = curr_func;
      // 维护两个基本块之间的关系
      if (nullptr != pre_bb && is_succ) {
        pre_bb->succ_.push_back(curr_bb);
        curr_bb->pred_.push_back(pre_bb);
      }
    } else {
      curr_bb->ir_list_.push_back(&ir);
    }
    is_succ = true;
    // 维护当前基本块和跳转目标基本块之间的关系 维护is_leader 之后is_leader表示下一条ir是否为首指令
    switch (ir.op_) {
      case IR::OpKind::RET:
        is_leader = true;
        is_succ = false;
        break;
      case IR::OpKind::CALL:  // NOTE: 此时不维护调用双方两个基本块之间的关系 TODO: call语句的下一条语句是首指令吗
        curr_func->call_func_list_.push_back(label2func[ir.opn1_.name_]);
        is_leader = false;
        break;
      case IR::OpKind::GOTO: {
        auto succ_bb = label2bb[ir.opn1_.name_];
        curr_bb->succ_.push_back(succ_bb);
        succ_bb->pred_.push_back(curr_bb);
        is_leader = true;
        is_succ = false;
        break;
      }
      case IR::OpKind::JEQ:
      case IR::OpKind::JNE:
      case IR::OpKind::JLT:
      case IR::OpKind::JLE:
      case IR::OpKind::JGT:
      case IR::OpKind::JGE: {
        auto succ_bb = label2bb[ir.res_.name_];
        curr_bb->succ_.push_back(succ_bb);
        succ_bb->pred_.push_back(curr_bb);
        is_leader = true;
        break;
      }
      default:
        is_leader = false;
        break;
    }
  }

  return module;
}

// Assembly:
subq $0x708, %rsp            # imm = 0x708
movq %rdi, 0x700(%rsp)
movq %rsi, 0x6f8(%rsp)
leaq 0x6c0(%rsp), %rdi
callq 0x18000
leaq 0x688(%rsp), %rdi
callq 0x18010
movl $0x98, %edi
callq 0x8340
movq %rax, 0x1c0(%rsp)
jmp 0x16965
movb $0x1, 0x626(%rsp)
leaq 0x627(%rsp), %rdi
movq %rdi, 0x1b8(%rsp)
callq 0x8680
movq 0x1b8(%rsp), %rdx
leaq 0xe3f4f(%rip), %rsi     # 0xfa8e0
leaq 0x628(%rsp), %rdi
callq 0xc570
jmp 0x169a0
movq 0x1c0(%rsp), %rdi
leaq 0x628(%rsp), %rsi
xorl %edx, %edx
callq 0x18070
jmp 0x169b9
movq 0x1c0(%rsp), %rax
movb $0x0, 0x626(%rsp)
movq %rax, 0x658(%rsp)
leaq 0xe3f08(%rip), %rsi     # 0xfa8e0
leaq 0x660(%rsp), %rdi
leaq 0x658(%rsp), %rdx
callq 0x180e0
jmp 0x169ef
leaq 0x688(%rsp), %rdi
leaq 0x660(%rsp), %rsi
callq 0x18020
movb %dl, 0x1af(%rsp)
movq %rax, 0x1b0(%rsp)
jmp 0x16a15
movb 0x1af(%rsp), %al
movq 0x1b0(%rsp), %rcx
movq %rcx, 0x610(%rsp)
movb %al, 0x618(%rsp)
leaq 0x660(%rsp), %rdi
callq 0x18170
leaq 0x628(%rsp), %rdi
callq 0x8728
leaq 0x627(%rsp), %rdi
callq 0x83c0
movl $0x98, %edi
callq 0x8340
movq %rax, 0x1a0(%rsp)
jmp 0x16a6e
movb $0x1, 0x5be(%rsp)
leaq 0x5bf(%rsp), %rdi
movq %rdi, 0x198(%rsp)
callq 0x8680
movq 0x198(%rsp), %rdx
leaq 0xe3e4d(%rip), %rsi     # 0xfa8e7
leaq 0x5c0(%rsp), %rdi
callq 0xc570
jmp 0x16aa9
movq 0x1a0(%rsp), %rdi
leaq 0x5c0(%rsp), %rsi
xorl %edx, %edx
callq 0x18070
jmp 0x16ac2
movq 0x1a0(%rsp), %rax
movb $0x0, 0x5be(%rsp)
movq %rax, 0x5e0(%rsp)
leaq 0xe3e06(%rip), %rsi     # 0xfa8e7
leaq 0x5e8(%rsp), %rdi
leaq 0x5e0(%rsp), %rdx
callq 0x18180
jmp 0x16af8
leaq 0x688(%rsp), %rdi
leaq 0x5e8(%rsp), %rsi
callq 0x18020
movb %dl, 0x18f(%rsp)
movq %rax, 0x190(%rsp)
jmp 0x16b1e
movb 0x18f(%rsp), %al
movq 0x190(%rsp), %rcx
movq %rcx, 0x5a8(%rsp)
movb %al, 0x5b0(%rsp)
leaq 0x5e8(%rsp), %rdi
callq 0x18170
leaq 0x5c0(%rsp), %rdi
callq 0x8728
leaq 0x5bf(%rsp), %rdi
callq 0x83c0
movl $0x98, %edi
callq 0x8340
movq %rax, 0x180(%rsp)
jmp 0x16b77
movb $0x1, 0x556(%rsp)
leaq 0x557(%rsp), %rdi
movq %rdi, 0x178(%rsp)
callq 0x8680
movq 0x178(%rsp), %rdx
leaq 0xe3d4a(%rip), %rsi     # 0xfa8ed
leaq 0x558(%rsp), %rdi
callq 0xc570
jmp 0x16bb2
movq 0x180(%rsp), %rdi
leaq 0x558(%rsp), %rsi
xorl %edx, %edx
callq 0x18070
jmp 0x16bcb
movq 0x180(%rsp), %rax
movb $0x0, 0x556(%rsp)
movq %rax, 0x578(%rsp)
leaq 0xe3d03(%rip), %rsi     # 0xfa8ed
leaq 0x580(%rsp), %rdi
leaq 0x578(%rsp), %rdx
callq 0x18210
jmp 0x16c01
leaq 0x688(%rsp), %rdi
leaq 0x580(%rsp), %rsi
callq 0x18020
movb %dl, 0x16f(%rsp)
movq %rax, 0x170(%rsp)
jmp 0x16c27
movb 0x16f(%rsp), %al
movq 0x170(%rsp), %rcx
movq %rcx, 0x540(%rsp)
movb %al, 0x548(%rsp)
leaq 0x580(%rsp), %rdi
callq 0x18170
leaq 0x558(%rsp), %rdi
callq 0x8728
leaq 0x557(%rsp), %rdi
callq 0x83c0
movl $0x98, %edi
callq 0x8340
movq %rax, 0x160(%rsp)
jmp 0x16c80
movb $0x1, 0x4ee(%rsp)
leaq 0x4ef(%rsp), %rdi
movq %rdi, 0x158(%rsp)
callq 0x8680
movq 0x158(%rsp), %rdx
leaq 0xe3c4a(%rip), %rsi     # 0xfa8f6
leaq 0x4f0(%rsp), %rdi
callq 0xc570
jmp 0x16cbb
movq 0x160(%rsp), %rdi
leaq 0x4f0(%rsp), %rsi
movl $0x1, %edx
callq 0x18070
jmp 0x16cd7
movq 0x160(%rsp), %rax
movb $0x0, 0x4ee(%rsp)
movq %rax, 0x510(%rsp)
leaq 0xe3c00(%rip), %rsi     # 0xfa8f6
leaq 0x518(%rsp), %rdi
leaq 0x510(%rsp), %rdx
callq 0x180e0
jmp 0x16d0d
leaq 0x688(%rsp), %rdi
leaq 0x518(%rsp), %rsi
callq 0x18020
movb %dl, 0x14f(%rsp)
movq %rax, 0x150(%rsp)
jmp 0x16d33
movb 0x14f(%rsp), %al
movq 0x150(%rsp), %rcx
movq %rcx, 0x4d8(%rsp)
movb %al, 0x4e0(%rsp)
leaq 0x518(%rsp), %rdi
callq 0x18170
leaq 0x4f0(%rsp), %rdi
callq 0x8728
leaq 0x4ef(%rsp), %rdi
callq 0x83c0
movl $0x98, %edi
callq 0x8340
movq %rax, 0x140(%rsp)
jmp 0x16d8c
movb $0x1, 0x486(%rsp)
leaq 0x487(%rsp), %rdi
movq %rdi, 0x138(%rsp)
callq 0x8680
movq 0x138(%rsp), %rdx
leaq 0xe3b45(%rip), %rsi     # 0xfa8fd
leaq 0x488(%rsp), %rdi
callq 0xc570
jmp 0x16dc7
movq 0x140(%rsp), %rdi
leaq 0x488(%rsp), %rsi
movl $0x1, %edx
callq 0x18070
jmp 0x16de3
movq 0x140(%rsp), %rax
movb $0x0, 0x486(%rsp)
movq %rax, 0x4a8(%rsp)
leaq 0xe3afb(%rip), %rsi     # 0xfa8fd
leaq 0x4b0(%rsp), %rdi
leaq 0x4a8(%rsp), %rdx
callq 0x18180
jmp 0x16e19
leaq 0x688(%rsp), %rdi
leaq 0x4b0(%rsp), %rsi
callq 0x18020
movb %dl, 0x12f(%rsp)
movq %rax, 0x130(%rsp)
jmp 0x16e3f
movb 0x12f(%rsp), %al
movq 0x130(%rsp), %rcx
movq %rcx, 0x470(%rsp)
movb %al, 0x478(%rsp)
leaq 0x4b0(%rsp), %rdi
callq 0x18170
leaq 0x488(%rsp), %rdi
callq 0x8728
leaq 0x487(%rsp), %rdi
callq 0x83c0
movl $0x98, %edi
callq 0x8340
movq %rax, 0x120(%rsp)
jmp 0x16e98
movb $0x1, 0x41e(%rsp)
leaq 0x41f(%rsp), %rdi
movq %rdi, 0x118(%rsp)
callq 0x8680
movq 0x118(%rsp), %rdx
leaq 0xe3a3f(%rip), %rsi     # 0xfa903
leaq 0x420(%rsp), %rdi
callq 0xc570
jmp 0x16ed3
movq 0x120(%rsp), %rdi
leaq 0x420(%rsp), %rsi
movl $0x1, %edx
callq 0x18070
jmp 0x16eef
movq 0x120(%rsp), %rax
movb $0x0, 0x41e(%rsp)
movq %rax, 0x440(%rsp)
leaq 0xe39f5(%rip), %rsi     # 0xfa903
leaq 0x448(%rsp), %rdi
leaq 0x440(%rsp), %rdx
callq 0x18210
jmp 0x16f25
leaq 0x688(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0x18020
movb %dl, 0x10f(%rsp)
movq %rax, 0x110(%rsp)
jmp 0x16f4b
movb 0x10f(%rsp), %al
movq 0x110(%rsp), %rcx
movq %rcx, 0x408(%rsp)
movb %al, 0x410(%rsp)
leaq 0x448(%rsp), %rdi
callq 0x18170
leaq 0x420(%rsp), %rdi
callq 0x8728
leaq 0x41f(%rsp), %rdi
callq 0x83c0
movl $0x98, %edi
callq 0x8340
movq %rax, 0x100(%rsp)
jmp 0x16fa4
movb $0x1, 0x3b6(%rsp)
leaq 0x3b7(%rsp), %rdi
movq %rdi, 0xf8(%rsp)
callq 0x8680
movq 0xf8(%rsp), %rdx
leaq 0xe393c(%rip), %rsi     # 0xfa90c
leaq 0x3b8(%rsp), %rdi
callq 0xc570
jmp 0x16fdf
movq 0x100(%rsp), %rdi
leaq 0x3b8(%rsp), %rsi
movl $0x1, %edx
callq 0x18070
jmp 0x16ffb
movq 0x100(%rsp), %rax
movb $0x0, 0x3b6(%rsp)
movq %rax, 0x3d8(%rsp)
leaq 0xe38f2(%rip), %rsi     # 0xfa90c
leaq 0x3e0(%rsp), %rdi
leaq 0x3d8(%rsp), %rdx
callq 0x182a0
jmp 0x17031
leaq 0x688(%rsp), %rdi
leaq 0x3e0(%rsp), %rsi
callq 0x18020
movb %dl, 0xef(%rsp)
movq %rax, 0xf0(%rsp)
jmp 0x17057
movb 0xef(%rsp), %al
movq 0xf0(%rsp), %rcx
movq %rcx, 0x3a0(%rsp)
movb %al, 0x3a8(%rsp)
leaq 0x3e0(%rsp), %rdi
callq 0x18170
leaq 0x3b8(%rsp), %rdi
callq 0x8728
leaq 0x3b7(%rsp), %rdi
callq 0x83c0
movl $0x98, %edi
callq 0x8340
movq %rax, 0xe0(%rsp)
jmp 0x170b0
movb $0x1, 0x34e(%rsp)
leaq 0x34f(%rsp), %rdi
movq %rdi, 0xd8(%rsp)
callq 0x8680
movq 0xd8(%rsp), %rdx
leaq 0xe3840(%rip), %rsi     # 0xfa91c
leaq 0x350(%rsp), %rdi
callq 0xc570
jmp 0x170eb
movq 0xe0(%rsp), %rdi
leaq 0x350(%rsp), %rsi
movl $0x1, %edx
callq 0x18070
jmp 0x17107
movq 0xe0(%rsp), %rax
movb $0x0, 0x34e(%rsp)
movq %rax, 0x370(%rsp)
leaq 0xe37f6(%rip), %rsi     # 0xfa91c
leaq 0x378(%rsp), %rdi
leaq 0x370(%rsp), %rdx
callq 0x18330
jmp 0x1713d
leaq 0x688(%rsp), %rdi
leaq 0x378(%rsp), %rsi
callq 0x18020
movb %dl, 0xcf(%rsp)
movq %rax, 0xd0(%rsp)
jmp 0x17163
movb 0xcf(%rsp), %al
movq 0xd0(%rsp), %rcx
movq %rcx, 0x338(%rsp)
movb %al, 0x340(%rsp)
leaq 0x378(%rsp), %rdi
callq 0x18170
leaq 0x350(%rsp), %rdi
callq 0x8728
leaq 0x34f(%rsp), %rdi
callq 0x83c0
movl $0x98, %edi
callq 0x8340
movq %rax, 0xc0(%rsp)
jmp 0x171bc
movb $0x1, 0x2e6(%rsp)
leaq 0x2e7(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x8680
movq 0xb8(%rsp), %rdx
leaq 0xe3743(%rip), %rsi     # 0xfa92b
leaq 0x2e8(%rsp), %rdi
callq 0xc570
jmp 0x171f7
movq 0xc0(%rsp), %rdi
leaq 0x2e8(%rsp), %rsi
movl $0x3, %edx
callq 0x18070
jmp 0x17213
movq 0xc0(%rsp), %rax
movb $0x0, 0x2e6(%rsp)
movq %rax, 0x308(%rsp)
leaq 0xe36f9(%rip), %rsi     # 0xfa92b
leaq 0x310(%rsp), %rdi
leaq 0x308(%rsp), %rdx
callq 0x180e0
jmp 0x17249
leaq 0x688(%rsp), %rdi
leaq 0x310(%rsp), %rsi
callq 0x18020
movb %dl, 0xaf(%rsp)
movq %rax, 0xb0(%rsp)
jmp 0x1726f
movb 0xaf(%rsp), %al
movq 0xb0(%rsp), %rcx
movq %rcx, 0x2d0(%rsp)
movb %al, 0x2d8(%rsp)
leaq 0x310(%rsp), %rdi
callq 0x18170
leaq 0x2e8(%rsp), %rdi
callq 0x8728
leaq 0x2e7(%rsp), %rdi
callq 0x83c0
movl $0x48, %edi
callq 0x8340
movq %rax, 0xa0(%rsp)
jmp 0x172c8
movq 0x700(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0x135349(%rip), %rdi    # 0x14c628
xorl %eax, %eax
movl %eax, %esi
callq 0x183c0
movq 0xa0(%rsp), %rdi
movq 0x98(%rsp), %rsi
movq %rax, %rdx
callq 0x183e0
jmp 0x17302
movq 0xa0(%rsp), %rax
movq %rax, 0x2c8(%rsp)
movl $0x0, 0x2c4(%rsp)
movslq 0x2c4(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x6f8(%rsp), %rdi
callq 0x18440
movq %rax, %rcx
movq 0x90(%rsp), %rax
cmpq %rcx, %rax
jae 0x17b87
movq 0x6f8(%rsp), %rdi
movslq 0x2c4(%rsp), %rsi
callq 0x18460
movq (%rax), %rax
movq %rax, 0x2b8(%rsp)
movq 0x2b8(%rsp), %rax
cmpl $0x7, (%rax)
jne 0x17b6f
movq 0x2b8(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x2b0(%rsp)
movl $0x2a8, %edi            # imm = 0x2A8
callq 0x8340
movq %rax, 0x88(%rsp)
jmp 0x173a7
movq 0x88(%rsp), %rdi
callq 0x18480
jmp 0x173b6
movq 0x88(%rsp), %rax
movq %rax, 0x2a8(%rsp)
movq 0x2a8(%rsp), %rdi
addq $0x8, %rdi
movq 0x2b8(%rsp), %rax
movq %rax, 0x2a0(%rsp)
leaq 0x2a0(%rsp), %rsi
callq 0x185b0
jmp 0x173f1
movq 0x2b0(%rsp), %rsi
leaq 0x278(%rsp), %rdi
leaq 0x2a8(%rsp), %rdx
callq 0x18630
jmp 0x17410
leaq 0x6c0(%rsp), %rdi
leaq 0x278(%rsp), %rsi
callq 0x185e0
movb %dl, 0x7f(%rsp)
movq %rax, 0x80(%rsp)
jmp 0x17433
movb 0x7f(%rsp), %al
movq 0x80(%rsp), %rcx
movq %rcx, 0x268(%rsp)
movb %al, 0x270(%rsp)
leaq 0x278(%rsp), %rdi
callq 0x18670
movq 0x2b8(%rsp), %rax
cmpl $0x3, 0x8(%rax)
jne 0x17b6d
movq 0x2b0(%rsp), %rsi
leaq 0x1351c4(%rip), %rdi    # 0x14c640
callq 0x18680
movq %rax, 0x70(%rsp)
jmp 0x17488
movq 0x70(%rsp), %rax
movq %rax, 0x258(%rsp)
leaq 0x258(%rsp), %rdi
callq 0x186b0
addq $0x20, %rax
movq %rax, 0x260(%rsp)
movl $0x98, %edi
callq 0x8340
movq %rax, 0x68(%rsp)
jmp 0x174bf
movq 0x2b0(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x260(%rsp), %rdi
addq $0x8, %rdi
callq 0x186d0
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl %eax, %edx
callq 0x18070
jmp 0x174f0
movq 0x68(%rsp), %rax
movq %rax, 0x250(%rsp)
movq 0x250(%rsp), %rdi
addq $0x30, %rdi
leaq 0x2a8(%rsp), %rsi
callq 0x186f0
jmp 0x17518
movq 0x250(%rsp), %rcx
movq 0x2a8(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x2b0(%rsp), %rsi
leaq 0x228(%rsp), %rdi
leaq 0x250(%rsp), %rdx
callq 0x18760
jmp 0x1754b
leaq 0x688(%rsp), %rdi
leaq 0x228(%rsp), %rsi
callq 0x18020
movb %dl, 0x57(%rsp)
movq %rax, 0x58(%rsp)
jmp 0x1756b
movb 0x57(%rsp), %al
movq 0x58(%rsp), %rcx
movq %rcx, 0x218(%rsp)
movb %al, 0x220(%rsp)
leaq 0x228(%rsp), %rdi
callq 0x18170
movq 0x2c8(%rsp), %rdi
addq $0x28, %rdi
leaq 0x250(%rsp), %rsi
callq 0x187a0
jmp 0x175ab
jmp 0x17b6d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x17fd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x17623
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x17616
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
leaq 0x660(%rsp), %rdi
callq 0x18170
leaq 0x628(%rsp), %rdi
callq 0x8728
leaq 0x627(%rsp), %rdi
callq 0x83c0
testb $0x1, 0x626(%rsp)
jne 0x1763c
jmp 0x1764e
movq 0x1c0(%rsp), %rdi
movl $0x98, %esi
callq 0x8350
jmp 0x17fd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x176ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x176a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
leaq 0x5e8(%rsp), %rdi
callq 0x18170
leaq 0x5c0(%rsp), %rdi
callq 0x8728
leaq 0x5bf(%rsp), %rdi
callq 0x83c0
testb $0x1, 0x5be(%rsp)
jne 0x176c6
jmp 0x176d8
movq 0x1a0(%rsp), %rdi
movl $0x98, %esi
callq 0x8350
jmp 0x17fd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x17737
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x1772a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
leaq 0x580(%rsp), %rdi
callq 0x18170
leaq 0x558(%rsp), %rdi
callq 0x8728
leaq 0x557(%rsp), %rdi
callq 0x83c0
testb $0x1, 0x556(%rsp)
jne 0x17750
jmp 0x17762
movq 0x180(%rsp), %rdi
movl $0x98, %esi
callq 0x8350
jmp 0x17fd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x177c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x177b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
leaq 0x518(%rsp), %rdi
callq 0x18170
leaq 0x4f0(%rsp), %rdi
callq 0x8728
leaq 0x4ef(%rsp), %rdi
callq 0x83c0
testb $0x1, 0x4ee(%rsp)
jne 0x177da
jmp 0x177ec
movq 0x160(%rsp), %rdi
movl $0x98, %esi
callq 0x8350
jmp 0x17fd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x1784b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x1783e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
leaq 0x4b0(%rsp), %rdi
callq 0x18170
leaq 0x488(%rsp), %rdi
callq 0x8728
leaq 0x487(%rsp), %rdi
callq 0x83c0
testb $0x1, 0x486(%rsp)
jne 0x17864
jmp 0x17876
movq 0x140(%rsp), %rdi
movl $0x98, %esi
callq 0x8350
jmp 0x17fd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x178d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x178c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
leaq 0x448(%rsp), %rdi
callq 0x18170
leaq 0x420(%rsp), %rdi
callq 0x8728
leaq 0x41f(%rsp), %rdi
callq 0x83c0
testb $0x1, 0x41e(%rsp)
jne 0x178ee
jmp 0x17900
movq 0x120(%rsp), %rdi
movl $0x98, %esi
callq 0x8350
jmp 0x17fd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x1795f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x17952
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
leaq 0x3e0(%rsp), %rdi
callq 0x18170
leaq 0x3b8(%rsp), %rdi
callq 0x8728
leaq 0x3b7(%rsp), %rdi
callq 0x83c0
testb $0x1, 0x3b6(%rsp)
jne 0x17978
jmp 0x1798a
movq 0x100(%rsp), %rdi
movl $0x98, %esi
callq 0x8350
jmp 0x17fd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x179e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x179dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
leaq 0x378(%rsp), %rdi
callq 0x18170
leaq 0x350(%rsp), %rdi
callq 0x8728
leaq 0x34f(%rsp), %rdi
callq 0x83c0
testb $0x1, 0x34e(%rsp)
jne 0x17a02
jmp 0x17a14
movq 0xe0(%rsp), %rdi
movl $0x98, %esi
callq 0x8350
jmp 0x17fd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x17a73
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
jmp 0x17a66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
leaq 0x310(%rsp), %rdi
callq 0x18170
leaq 0x2e8(%rsp), %rdi
callq 0x8728
leaq 0x2e7(%rsp), %rdi
callq 0x83c0
testb $0x1, 0x2e6(%rsp)
jne 0x17a8c
jmp 0x17a9e
movq 0xc0(%rsp), %rdi
movl $0x98, %esi
callq 0x8350
jmp 0x17fd4
movq 0xa0(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
movl $0x48, %esi
callq 0x8350
jmp 0x17fd4
movq 0x88(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
movl $0x2a8, %esi            # imm = 0x2A8
callq 0x8350
jmp 0x17fd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
leaq 0x278(%rsp), %rdi
callq 0x18670
jmp 0x17fd4
movq 0x68(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
movl $0x98, %esi
callq 0x8350
jmp 0x17fd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
leaq 0x228(%rsp), %rdi
callq 0x18170
jmp 0x17fd4
jmp 0x17b6f
jmp 0x17b71
movl 0x2c4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c4(%rsp)
jmp 0x1731d
movb $0x0, 0x217(%rsp)
movb $0x1, 0x216(%rsp)
movq $0x0, 0x208(%rsp)
movq $0x0, 0x200(%rsp)
movq $0x0, 0x1f8(%rsp)
movl $0x0, 0x1f4(%rsp)
movslq 0x1f4(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x6f8(%rsp), %rdi
callq 0x18440
movq %rax, %rcx
movq 0x48(%rsp), %rax
cmpq %rcx, %rax
jae 0x17fa2
movq 0x6f8(%rsp), %rdi
movslq 0x1f4(%rsp), %rsi
callq 0x18460
movq (%rax), %rax
movq %rax, 0x1e8(%rsp)
movq 0x1e8(%rsp), %rax
cmpl $0x7, (%rax)
jne 0x17c26
movb $0x1, 0x217(%rsp)
testb $0x1, 0x217(%rsp)
je 0x17dcc
movq 0x1f8(%rsp), %rax
movq %rax, 0x200(%rsp)
movq 0x1e8(%rsp), %rax
cmpl $0x7, (%rax)
jne 0x17cce
movq 0x1e8(%rsp), %rsi
addq $0x10, %rsi
leaq 0x6c0(%rsp), %rdi
callq 0x18810
movq %rax, 0x40(%rsp)
jmp 0x17c71
movq 0x40(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x1f8(%rsp)
movq 0x1e8(%rsp), %rax
cmpl $0x3, 0x8(%rax)
jne 0x17ccc
movq 0x1e8(%rsp), %rsi
addq $0x10, %rsi
leaq 0x688(%rsp), %rdi
callq 0x18840
movq %rax, 0x38(%rsp)
jmp 0x17caf
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x208(%rsp)
movb $0x0, 0x217(%rsp)
jmp 0x17f8c
jmp 0x17d4d
movl $0x2a8, %edi            # imm = 0x2A8
callq 0x8340
movq %rax, 0x30(%rsp)
jmp 0x17cdf
movq 0x30(%rsp), %rdi
callq 0x18480
jmp 0x17ceb
movq 0x30(%rsp), %rax
movq %rax, 0x1f8(%rsp)
movq 0x1f8(%rsp), %rdi
addq $0x8, %rdi
movq 0x1e8(%rsp), %rax
movq %rax, 0x1e0(%rsp)
leaq 0x1e0(%rsp), %rsi
callq 0x185b0
jmp 0x17d23
jmp 0x17d4d
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x650(%rsp)
movl %eax, 0x64c(%rsp)
movl $0x2a8, %esi            # imm = 0x2A8
callq 0x8350
jmp 0x17fd4
movq 0x208(%rsp), %rdi
addq $0x30, %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x186f0
jmp 0x17d68
movq 0x208(%rsp), %rcx
movq 0x1f8(%rsp), %rax
movq %rcx, 0x20(%rax)
xorl %eax, %eax
cmpq 0x200(%rsp), %rax
je 0x17dca
testb $0x1, 0x216(%rsp)
je 0x17dca
movq 0x200(%rsp), %rdi
addq $0x40, %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x186f0
jmp 0x17dad
movq 0x1f8(%rsp), %rdi
addq $0x28, %rdi
leaq 0x200(%rsp), %rsi
callq 0x186f0
jmp 0x17dc8
jmp 0x17dca
jmp 0x17df9
movq 0x1f8(%rsp), %rdi
addq $0x8, %rdi
movq 0x1e8(%rsp), %rax
movq %rax, 0x1d8(%rsp)
leaq 0x1d8(%rsp), %rsi
callq 0x185b0
jmp 0x17df7
jmp 0x17df9
movb $0x1, 0x216(%rsp)
movq 0x1e8(%rsp), %rax
movl (%rax), %eax
addl $-0x9, %eax
movl %eax, %ecx
movq %rcx, 0x28(%rsp)
subl $0x9, %eax
ja 0x17f82
movq 0x28(%rsp), %rax
leaq 0xe2a8a(%rip), %rcx     # 0xfa8b4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x1, 0x217(%rsp)
movb $0x0, 0x216(%rsp)
jmp 0x17f8a
movq 0x208(%rsp), %rax
addq $0x48, %rax
movq %rax, 0x18(%rsp)
movq 0x1e8(%rsp), %rsi
addq $0x10, %rsi
leaq 0x688(%rsp), %rdi
callq 0x18840
movq %rax, 0x20(%rsp)
jmp 0x17e79
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdi
callq 0x187a0
jmp 0x17e8a
movb $0x0, 0x217(%rsp)
jmp 0x17f8a
movq 0x1e8(%rsp), %rsi
addq $0x10, %rsi
leaq 0x6c0(%rsp), %rdi
callq 0x18810
movq %rax, 0x10(%rsp)
jmp 0x17eb7
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x1d0(%rsp)
movq 0x1f8(%rsp), %rdi
addq $0x40, %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x186f0
jmp 0x17ee2
movq 0x1d0(%rsp), %rdi
addq $0x28, %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x186f0
jmp 0x17efd
movb $0x1, 0x217(%rsp)
movb $0x0, 0x216(%rsp)
jmp 0x17f8a
movq 0x1e8(%rsp), %rsi
addq $0x90, %rsi
leaq 0x6c0(%rsp), %rdi
callq 0x18810
movq %rax, 0x8(%rsp)
jmp 0x17f32
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x1c8(%rsp)
movq 0x1f8(%rsp), %rdi
addq $0x40, %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x186f0
jmp 0x17f5d
movq 0x1c8(%rsp), %rdi
addq $0x28, %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x186f0
jmp 0x17f78
movb $0x1, 0x217(%rsp)
jmp 0x17f8a
movb $0x0, 0x217(%rsp)
jmp 0x17f8c
movl 0x1f4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1f4(%rsp)
jmp 0x17bc6
movq 0x2c8(%rsp), %rax
movq %rax, (%rsp)
leaq 0x688(%rsp), %rdi
callq 0x18870
leaq 0x6c0(%rsp), %rdi
callq 0x18880
movq (%rsp), %rax
addq $0x708, %rsp            # imm = 0x708
retq
leaq 0x688(%rsp), %rdi
callq 0x18870
leaq 0x6c0(%rsp), %rdi
callq 0x18880
movq 0x650(%rsp), %rdi
callq 0x8670
nopl (%rax,%rax)