// File: /workspace/github_cpp_makefile_star2_O2/wrighteagle2d[P]wrighteaglebase/Debug/../src/DynamicDebug.cpp
// Function: DynamicDebug::Run(char*)
MessageType DynamicDebug::Run(char *msg) {
  std::cerr << std::endl << mpObserver->CurrentTime(); // 输出当前周期

  if (mRunning == true) {
    if (mRuntoCycle >= Time(0, 0)) {
      if (mRuntoCycle <= mpObserver->CurrentTime()) {
        mRunning = false;
        mRuntoCycle = 0;
      }
    }

    if (mRunning) {
      return GetMessage(msg);
    }
  }

  std::string read_msg;
  while (std::cin) {
    if (std::cin.eof()) {
      std::cin.rdbuf(mpStreamBuffer);
    }

    std::cerr << std::endl << ">>> ";
    std::cin >> read_msg;

    if (*read_msg.c_str() == '\0') {
      std::cin.rdbuf(mpStreamBuffer); // 到达文件末尾会读入'\0'，这里重定向
      continue;
    }

    if (read_msg == "load") {
      std::string file_name;
      std::cin >> file_name;
      mpFile = fopen(file_name.c_str(), "rb");
      if (mpFile == 0) {
        std::cerr << "Can't open dynamicdebug file, exit..." << std::endl;
        continue;
      }

      char ch1(0), ch2(0);

      if (fread(&ch1, sizeof(char), 1, mpFile) < 1) {
        Assert(0);
      }

      if (fread(&ch2, sizeof(char), 1, mpFile) < 1) {
        Assert(0);
      }

      if (ch1 != 'D' || ch2 != 'D') {
        std::cerr << "Not a dynamicdebug logfile!" << std::endl;
        return MT_Null;
      }

      if (fread(&mFileHead, sizeof(mFileHead), 1, mpFile) < 1) {
        Assert(0);
      }

      long long size;

      size = mFileHead.mIndexTableSize;
      mpIndex = new MessageIndexTableUnit[size];
      fseek(mpFile, mFileHead.mIndexTableOffset, SEEK_SET);
      if (size > 0 &&
          fread(mpIndex, size * sizeof(MessageIndexTableUnit), 1, mpFile) < 1) {
        Assert(0);
      }

      size = mFileHead.mParserTableSize;
      mpParserTime = new timeval[size];
      fseek(mpFile, mFileHead.mParserTableOffset, SEEK_SET);
      if (size > 0 &&
          fread(mpParserTime, size * sizeof(timeval), 1, mpFile) < 1) {
        Assert(0);
      }

      size = mFileHead.mDecisionTableSize;
      mpDecisionTime = new timeval[size];
      fseek(mpFile, mFileHead.mDecisionTableOffset, SEEK_SET);
      if (size > 0 &&
          fread(mpDecisionTime, size * sizeof(timeval), 1, mpFile) < 1) {
        Assert(0);
      }

      size = mFileHead.mCommandSendTableSize;
      mpCommandSendTime = new timeval[size];
      fseek(mpFile, mFileHead.mCommandSendTableOffset, SEEK_SET);
      if (size > 0 &&
          fread(mpCommandSendTime, size * sizeof(timeval), 1, mpFile) < 1) {
        Assert(0);
      }

      fseek(mpFile, sizeof(mFileHead) + 2 * sizeof(char), SEEK_SET);
      mpCurrentIndex = mpIndex; // load后，第一个为初始化信息，先进行初始化

      std::cerr << "Load finished." << std::endl;
      fseek(mpFile, mpCurrentIndex->mDataOffset, SEEK_SET);
      if (fread(msg, 1, 1, mpFile) < 1) {
        Assert(0);
      }
      if (mpCurrentIndex->mDataSize > 0 &&
          fread(msg, mpCurrentIndex->mDataSize, 1, mpFile) < 1) {
        Assert(0);
      }
      msg[mpCurrentIndex->mDataSize] = '\0';
      return MT_Parse;
    } else if (read_msg == "step" || read_msg == "s") {
      if (mpCurrentIndex == 0) {
        std::cerr << "no file loaded!";
        continue;
      }
      return GetMessage(msg);
    } else if (read_msg == "goto" || read_msg == "g") {
      if (mpCurrentIndex == 0) {
        std::cerr << "no file loaded!";
        continue;
      }

      int cycle;
      std::cin >> cycle;
      if (FindCycle(cycle) == true) {
        std::cerr << "goto finished ..." << std::endl;
      } else {
        std::cerr << "no such cycle ..." << std::endl;
      }
      continue;
    } else if (read_msg == "runto" || read_msg == "rt") {
      if (mpCurrentIndex == 0) {
        std::cerr << "no file loaded!";
        continue;
      }

      std::string str;
      std::cin >> str;

      char a;
      int t; // time
      int s; // stop time
      if (sscanf(str.c_str(), "%d%c%d", &t, &a, &s) != 3) {
        s = 0;
      }

      mRuntoCycle = Time(t, s);

      if (mRuntoCycle == mpObserver->CurrentTime()) {
        std::cerr << "already here ...";
        continue;
      } else if (mRuntoCycle < mpObserver->CurrentTime()) {
        std::cerr << "can not run to previous cycle";
        continue;
      } else {
        mRunning = true;
        return GetMessage(msg);
      }
    } else if (read_msg == "run" || read_msg == "r") {
      mRuntoCycle = -1;
      mRunning = true;
      return GetMessage(msg);
    } else if (read_msg == "msg" || read_msg == "m") {
      mShowMessage = !mShowMessage;
      std::cerr << "Set ShowMessage: " << mShowMessage << std::endl;
      continue;
    } else if (read_msg == "quit" || read_msg == "q") {
      std::cerr << "Bye ..." << std::endl;
      return MT_Null;
    } else {
      std::cerr << "Error command, only the following commands are aviliable: "
                << std::endl;
      std::cerr << "\tload" << std::endl;
      std::cerr << "\tstep(s)" << std::endl;
      std::cerr << "\trunto(rt)" << std::endl;
      std::cerr << "\tgoto(g)" << std::endl;
      std::cerr << "\trun(r)" << std::endl;
      std::cerr << "\tmsg(m)" << std::endl;
      std::cerr << "\ttype(t)" << std::endl;
      std::cerr << "\tquit(q)" << std::endl;
      continue;
    }
  }

  return MT_Null;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, -0x48(%rbp)
movq %rdi, %r14
movq 0x59384(%rip), %rdi     # 0x76ff0
callq 0x99e8
movq (%r14), %rsi
addq $0xc, %rsi
movq %rax, %rdi
callq 0xd465
movb 0x138(%r14), %al
cmpb $0x1, %al
jne 0x1dcf2
cmpl $0x0, 0x13c(%r14)
jg 0x1dca1
jne 0x1dcd1
cmpl $0x0, 0x140(%r14)
js 0x1dcd1
leaq 0x13c(%r14), %rdi
movq (%r14), %rsi
addq $0xc, %rsi
callq 0x1e928
testb %al, %al
je 0x1dcca
movb $0x0, 0x138(%r14)
andq $0x0, 0x13c(%r14)
jmp 0x1dcf2
movb 0x138(%r14), %al
testb $0x1, %al
je 0x1dcf2
movq %r14, %rdi
movq -0x48(%rbp), %rsi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1e50c
leaq -0x98(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x13c(%r14), %rax
movq %rax, -0x80(%rbp)
leaq 0x10(%r14), %rax
movq %rax, -0x88(%rbp)
movq 0x592b6(%rip), %r13     # 0x76fd8
movq 0x592c7(%rip), %r15     # 0x76ff0
leaq -0xa8(%rbp), %rbx
leaq -0x2c(%rbp), %r12
movq (%r13), %rax
movq -0x18(%rax), %rdi
movl 0x20(%r13,%rdi), %eax
testb $0x5, %al
jne 0x1e46a
testb $0x2, %al
je 0x1dd5c
addq %r13, %rdi
movq 0x130(%r14), %rsi
callq 0x9950
movq %r15, %rdi
callq 0x99e8
movq %rax, %rdi
leaq 0x3a611(%rip), %rsi     # 0x5837f
callq 0x94b0
movq %r13, %rdi
movq %rbx, %rsi
callq 0x9620
movq -0xa8(%rbp), %rax
cmpb $0x0, (%rax)
je 0x1dde9
movq %rbx, %rdi
leaq 0x3a716(%rip), %rsi     # 0x584aa
callq 0x1e947
testb %al, %al
jne 0x1def8
movq %rbx, %rdi
leaq 0x3c80b(%rip), %rsi     # 0x5a5b6
callq 0x1e947
testb %al, %al
jne 0x1ddc7
movq %rbx, %rdi
leaq 0x3d22f(%rip), %rsi     # 0x5afed
callq 0x1e947
testb %al, %al
je 0x1de05
cmpq $0x0, 0xf0(%r14)
jne 0x1e487
movq %r15, %rdi
leaq 0x3a5f9(%rip), %rsi     # 0x583d8
callq 0x94b0
jmp 0x1dd34
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movq 0x130(%r14), %rsi
callq 0x9950
jmp 0x1dd34
movq %rbx, %rdi
leaq 0x3a5d9(%rip), %rsi     # 0x583e8
callq 0x1e947
testb %al, %al
jne 0x1de2b
movq %rbx, %rdi
leaq 0x3aa51(%rip), %rsi     # 0x58873
callq 0x1e947
testb %al, %al
je 0x1de75
cmpq $0x0, 0xf0(%r14)
je 0x1ddd5
movq %r13, %rdi
leaq -0x68(%rbp), %rsi
callq 0x92f0
movl -0x68(%rbp), %esi
movq %r14, %rdi
callq 0x1e5ea
testb %al, %al
leaq 0x3a5aa(%rip), %rsi     # 0x583ff
leaq 0x3a591(%rip), %rax     # 0x583ed
cmovneq %rax, %rsi
movq %r15, %rdi
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
jmp 0x1dd34
movq %rbx, %rdi
leaq 0x3a592(%rip), %rsi     # 0x58411
callq 0x1e947
testb %al, %al
jne 0x1de9f
movq %rbx, %rdi
leaq 0x3a206(%rip), %rsi     # 0x58098
callq 0x1e947
testb %al, %al
je 0x1e201
cmpq $0x0, 0xf0(%r14)
je 0x1ddd5
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
andq $0x0, -0x60(%rbp)
movb $0x0, -0x58(%rbp)
movq %r13, %rdi
leaq -0x68(%rbp), %rsi
callq 0x9620
movq -0x68(%rbp), %rdi
leaq 0x3a542(%rip), %rsi     # 0x58417
leaq -0x3c(%rbp), %rdx
leaq -0x3d(%rbp), %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x94a0
cmpl $0x3, %eax
jne 0x1e3e2
movl -0x2c(%rbp), %eax
jmp 0x1e3e8
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
andq $0x0, -0x60(%rbp)
movb $0x0, -0x58(%rbp)
movq %r13, %rdi
leaq -0x68(%rbp), %rsi
callq 0x9620
movq -0x68(%rbp), %rdi
leaq 0x3a464(%rip), %rsi     # 0x58384
callq 0x95a0
movq %rax, 0x120(%r14)
testq %rax, %rax
movq %rax, -0x78(%rbp)
je 0x1e285
movq %rax, %rcx
xorl %eax, %eax
movb %al, -0x3c(%rbp)
movb %al, -0x2c(%rbp)
leaq -0x3c(%rbp), %rdi
movq %r12, %r15
pushq $0x1
popq %r12
movq %r12, %rsi
movq %r12, %rdx
callq 0x9740
movq 0x120(%r14), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0x9740
cmpb $0x44, -0x3c(%rbp)
jne 0x1e29e
cmpb $0x44, -0x2c(%rbp)
jne 0x1e29e
movq 0x120(%r14), %rcx
movq -0x88(%rbp), %rdi
pushq $0x48
popq %rsi
pushq $0x1
popq %rdx
callq 0x9740
movq 0x18(%r14), %r12
movq %r12, %rax
shrq $0x3b, %rax
movq %r12, %rcx
shlq $0x5, %rcx
negq %rax
movl $0x0, %edi
sbbq %rdi, %rdi
movq %rcx, -0x38(%rbp)
orq %rcx, %rdi
callq 0x9050
movq 0x59024(%rip), %r15     # 0x76ff0
movq %r12, -0x70(%rbp)
testq %r12, %r12
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
movq -0x38(%rbp), %r12
je 0x1dff3
movq %rax, %rcx
addq %r12, %rcx
movq %rax, %rdx
movq %rsi, (%rdx)
addq $0x20, %rdx
cmpq %rcx, %rdx
jne 0x1dfe7
movq %rax, 0xd0(%r14)
movq 0x20(%r14), %rsi
movq 0x120(%r14), %rdi
xorl %edx, %edx
callq 0x9530
cmpq $0x0, -0x70(%rbp)
jle 0x1e02c
movq 0xd0(%r14), %rdi
movq 0x120(%r14), %rcx
movq %r12, %rsi
pushq $0x1
popq %rdx
callq 0x9740
movq 0x28(%r14), %r12
movq %r12, %rax
shrq $0x3c, %rax
movq %r12, -0x38(%rbp)
shlq $0x4, %r12
negq %rax
movl $0x0, %edi
sbbq %rdi, %rdi
orq %r12, %rdi
callq 0x9050
movq %rax, 0xd8(%r14)
movq 0x30(%r14), %rsi
movq 0x120(%r14), %rdi
xorl %edx, %edx
callq 0x9530
cmpq $0x0, -0x38(%rbp)
jle 0x1e08b
movq 0xd8(%r14), %rdi
movq 0x120(%r14), %rcx
movq %r12, %rsi
pushq $0x1
popq %rdx
callq 0x9740
movq 0x38(%r14), %rcx
movq %rcx, %r12
shlq $0x4, %r12
movabsq $0xfffffffffffffff, %rax # imm = 0xFFFFFFFFFFFFFFF
movq %rcx, -0x38(%rbp)
cmpq %rax, %rcx
movq %r12, %rdi
pushq $-0x1
popq %rax
cmovaq %rax, %rdi
callq 0x9050
movq %rax, 0xe0(%r14)
movq 0x40(%r14), %rsi
movq 0x120(%r14), %rdi
xorl %edx, %edx
callq 0x9530
cmpq $0x0, -0x38(%rbp)
jle 0x1e0ef
movq 0xe0(%r14), %rdi
movq 0x120(%r14), %rcx
movq %r12, %rsi
pushq $0x1
popq %rdx
callq 0x9740
movq 0x48(%r14), %rcx
movq %rcx, %r12
shlq $0x4, %r12
movabsq $0xfffffffffffffff, %rax # imm = 0xFFFFFFFFFFFFFFF
movq %rcx, -0x38(%rbp)
cmpq %rax, %rcx
movq %r12, %rdi
pushq $-0x1
popq %rax
cmovaq %rax, %rdi
callq 0x9050
movq %rax, 0xe8(%r14)
movq 0x50(%r14), %rsi
movq 0x120(%r14), %rdi
xorl %edx, %edx
callq 0x9530
cmpq $0x0, -0x38(%rbp)
jle 0x1e153
movq 0xe8(%r14), %rdi
movq 0x120(%r14), %rcx
movq %r12, %rsi
pushq $0x1
popq %rdx
callq 0x9740
movq 0x120(%r14), %rdi
pushq $0x4a
popq %rsi
xorl %edx, %edx
callq 0x9530
movq 0xd0(%r14), %rax
movq %rax, 0xf0(%r14)
movq %r15, %rdi
leaq 0x3a24d(%rip), %rsi     # 0x583c9
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
movq 0xf0(%r14), %rax
movq 0x120(%r14), %rdi
movq 0x10(%rax), %rsi
xorl %edx, %edx
callq 0x9530
movq 0x120(%r14), %rcx
movq -0x48(%rbp), %rdi
pushq $0x1
popq %r12
movq %r12, %rsi
movq %r12, %rdx
callq 0x9740
movq 0xf0(%r14), %rax
movq 0x8(%rax), %rsi
testq %rsi, %rsi
jle 0x1e1ea
movq 0x120(%r14), %rcx
movq -0x48(%rbp), %rdi
movq %r12, %rdx
callq 0x9740
movq 0xf0(%r14), %rax
movq 0x8(%rax), %rsi
leaq -0x2c(%rbp), %r12
movq -0x48(%rbp), %rax
movb $0x0, (%rax,%rsi)
pushq $0x1
popq %rax
movl %eax, -0x38(%rbp)
jmp 0x1e2c7
movq %rbx, %rdi
leaq 0x3a242(%rip), %rsi     # 0x5844d
callq 0x1e947
testb %al, %al
jne 0x1e473
movq %rbx, %rdi
leaq 0x3d31e(%rip), %rsi     # 0x5b540
callq 0x1e947
testb %al, %al
jne 0x1e473
movq %rbx, %rdi
leaq 0x3a218(%rip), %rsi     # 0x58451
callq 0x1e947
testb %al, %al
jne 0x1e259
movq %rbx, %rdi
leaq 0x3c2fe(%rip), %rsi     # 0x5a54a
callq 0x1e947
testb %al, %al
je 0x1e2e0
xorb $0x1, 0x139(%r14)
movq %r15, %rdi
leaq 0x3a1ea(%rip), %rsi     # 0x58455
callq 0x94b0
movzbl 0x139(%r14), %esi
movq %rax, %rdi
callq 0x9830
jmp 0x1e3d5
movq %r15, %rdi
leaq 0x3a0f8(%rip), %rsi     # 0x58387
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
jmp 0x1e2c7
movq 0x58d4b(%rip), %r15     # 0x76ff0
movq %r15, %rdi
leaq 0x3a0fe(%rip), %rsi     # 0x583ad
callq 0x94b0
leaq -0x2c(%rbp), %r12
movl $0x0, -0x38(%rbp)
movq %rax, %rdi
callq 0x99e8
leaq -0x68(%rbp), %rdi
callq 0x9240
cmpq $0x0, -0x78(%rbp)
je 0x1dd34
jmp 0x1e496
movq %rbx, %rdi
leaq 0x3a17d(%rip), %rsi     # 0x58467
callq 0x1e947
testb %al, %al
jne 0x1e4b7
movq %rbx, %rdi
leaq 0x3a16b(%rip), %rsi     # 0x5846c
callq 0x1e947
testb %al, %al
jne 0x1e4b7
movq %r15, %rdi
leaq 0x3a156(%rip), %rsi     # 0x5846e
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
movq %r15, %rdi
leaq 0x3a17a(%rip), %rsi     # 0x584a9
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
movq %r15, %rdi
leaq 0x3a169(%rip), %rsi     # 0x584af
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
movq %r15, %rdi
leaq 0x3a15b(%rip), %rsi     # 0x584b8
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
movq %r15, %rdi
leaq 0x3a14f(%rip), %rsi     # 0x584c3
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
movq %r15, %rdi
leaq 0x3a141(%rip), %rsi     # 0x584cc
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
movq %r15, %rdi
leaq 0x3a132(%rip), %rsi     # 0x584d4
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
movq %r15, %rdi
leaq 0x3a123(%rip), %rsi     # 0x584dc
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
movq %r15, %rdi
leaq 0x3a115(%rip), %rsi     # 0x584e5
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
jmp 0x1dd34
andl $0x0, -0x2c(%rbp)
xorl %eax, %eax
movl -0x3c(%rbp), %edx
movq %rax, %rcx
shlq $0x20, %rcx
orq %rdx, %rcx
movq %rcx, 0x13c(%r14)
movq (%r14), %rsi
cmpl 0x10(%rsi), %eax
jne 0x1e410
leaq 0x3a013(%rip), %rcx     # 0x5841e
cmpl 0xc(%rsi), %edx
je 0x1e428
addq $0xc, %rsi
movq -0x80(%rbp), %rdi
callq 0x1e958
leaq 0x3a00b(%rip), %rcx     # 0x5842f
testb %al, %al
je 0x1e438
movb $0x1, %r12b
movq %r15, %rdi
movq %rcx, %rsi
callq 0x94b0
jmp 0x1e452
movb $0x1, 0x138(%r14)
movq %r14, %rdi
movq -0x48(%rbp), %rsi
callq 0x1e50c
movl %eax, -0x38(%rbp)
xorl %r12d, %r12d
leaq -0x68(%rbp), %rdi
callq 0x9240
testb %r12b, %r12b
leaq -0x2c(%rbp), %r12
jne 0x1dd34
jmp 0x1e496
movl $0x0, -0x38(%rbp)
jmp 0x1e496
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x13c(%r14)
movb $0x1, 0x138(%r14)
movq %r14, %rdi
movq -0x48(%rbp), %rsi
callq 0x1e50c
movl %eax, -0x38(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x9240
movl -0x38(%rbp), %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x58b32(%rip), %rdi     # 0x76ff0
leaq 0x39b09(%rip), %rsi     # 0x57fce
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
movl $0x0, -0x38(%rbp)
jmp 0x1e496
jmp 0x1e4e5
jmp 0x1e4e5
jmp 0x1e4e5
jmp 0x1e4f5
jmp 0x1e4e5
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x9240
jmp 0x1e4f8
jmp 0x1e4f5
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x9240
movq %rbx, %rdi
callq 0x98b0