// File: /workspace/github_cpp_makefile_star2_O2/jakubsvehla[P]hex/src/normal_mode.cpp
// Function: NormalMode::Run()
void NormalMode::Run ()
{
  int c;
  int offset = 1;
  int jmp = 1;
  int i;
  int whence = SEEK_CUR;
  bool clear = true;
  std::stringstream buffer;

  m_Editor -> m_File -> Seek(0, whence);

  while (true) {

    m_Editor -> m_FileView -> Get(c);

    if (clear) {
      m_Editor -> m_CmdLineView -> Erase();
      m_Editor -> m_CmdLineView -> Refresh();
      m_Editor -> m_FileView -> Refresh();

      clear = false;
    }

    if (isdigit(c)) {
      buffer << (char) c;
      continue;
    }

    buffer >> jmp;

    switch (c) {

      case 'x':
        offset = 0;
        for (i = 0; i < jmp; i ++) {
          m_Editor -> m_File -> Del();
        }
        break;

      case 'r':
        offset = 0;

        try {
          if (m_Editor -> m_FileView -> GetHex(c)) {
            m_Editor -> m_File -> Put(c);
          }
        }
        catch (NotHexadecimalValue) {
          m_Editor -> m_FileView -> Beep();
        }
        break;

      case KEY_LEFT:
      case 'h':
        offset = -1;
        offset *= jmp;
        break;

      case KEY_RIGHT:
      case 'l':
        offset = 1;
        offset *= jmp;
        break;

      case KEY_DOWN:
      case 'j':
        offset = m_Editor -> m_FileView -> BytesPerLine();
        offset *= jmp;
        break;

      case KEY_UP:
      case 'k':
        offset = m_Editor -> m_FileView -> BytesPerLine();
        offset = -offset;
        offset *= jmp;
        break;

      case 'i':
        m_Editor -> m_Mode = m_Editor -> m_InsertMode;
        return;

      case ':':
        m_Editor -> m_Mode = m_Editor -> m_CmdMode;
        return;

      case ESC:
        jmp = 1;
        buffer.clear();
        buffer.str("");
        return;

      default:
        continue;
    }

    jmp = 1;
    buffer.clear();
    buffer.str("");

    if (!m_Editor -> m_File -> Seek(offset, whence)) {
      m_Editor -> m_FileView -> Beep();
    }

  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdi, %r15
movl $0x1, 0x4(%rsp)
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x3190
movq 0x8(%r15), %rax
movq 0x10(%rax), %rdi
pushq $0x1
popq %rdx
xorl %esi, %esi
callq 0x3af8
movb $0x1, %r12b
leaq 0x40(%rsp), %r13
leaq 0xc(%rsp), %rbx
movq 0x8(%r15), %rax
movq 0x18(%rax), %rdi
movq %rbx, %rsi
callq 0x3e5e
testb $0x1, %r12b
je 0x44eb
movq 0x8(%r15), %rax
movq 0x20(%rax), %rdi
callq 0x3f7c
movq 0x8(%r15), %rax
movq 0x20(%rax), %rdi
callq 0x3f72
movq 0x8(%r15), %rax
movq 0x18(%rax), %rdi
callq 0x3f72
movl 0xc(%rsp), %eax
leal -0x30(%rax), %ecx
cmpl $0x9, %ecx
ja 0x4507
xorl %r12d, %r12d
movsbl %al, %esi
movq %r13, %rdi
callq 0x32e0
jmp 0x44ae
movq %r14, %rdi
leaq 0x4(%rsp), %rsi
callq 0x3180
xorl %r12d, %r12d
movl 0xc(%rsp), %eax
leal -0x68(%rax), %ecx
cmpl $0x10, %ecx
ja 0x4565
leaq 0x1cae(%rip), %rdx      # 0x61d8
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x8(%r15), %rax
movq 0x18(%rax), %rdi
movq %rbx, %rsi
callq 0x3e76
xorl %r12d, %r12d
testb %al, %al
je 0x45e9
movq 0x8(%r15), %rax
movq 0x10(%rax), %rdi
movzbl 0xc(%rsp), %esi
callq 0x3ce2
jmp 0x45e9
leal -0x102(%rax), %ecx
cmpl $0x3, %ecx
ja 0x4665
leaq 0x1ca1(%rip), %rdx      # 0x621c
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x8(%r15), %rax
movq 0x18(%rax), %rdi
callq 0x437c
movl %eax, %r12d
imull 0x4(%rsp), %r12d
jmp 0x45e9
xorl %r12d, %r12d
subl 0x4(%rsp), %r12d
jmp 0x45e9
movl 0x4(%rsp), %r12d
jmp 0x45e9
movq 0x8(%r15), %rax
movq 0x18(%rax), %rdi
callq 0x437c
movl %eax, %r12d
imull 0x4(%rsp), %r12d
negl %r12d
jmp 0x45e9
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpl 0x4(%rsp), %ebp
jge 0x45e4
movq 0x8(%r15), %rax
movq 0x10(%rax), %rdi
callq 0x3c44
incl %ebp
jmp 0x45cd
leaq 0xc(%rsp), %rbx
movl $0x1, 0x4(%rsp)
movq 0x30(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
xorl %esi, %esi
callq 0x3400
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
leaq 0x1b5f(%rip), %rsi      # 0x6172
leaq 0xb(%rsp), %rdx
callq 0x4766
leaq 0x48(%rsp), %rdi
movq %rbp, %rsi
callq 0x3390
movq %rbp, %rdi
callq 0x3140
movq 0x8(%r15), %rax
movq 0x10(%rax), %rdi
movl %r12d, %esi
pushq $0x1
popq %rdx
callq 0x3af8
xorl %r12d, %r12d
testb %al, %al
jne 0x44ae
movq 0x8(%r15), %rax
movq 0x18(%rax), %rdi
xorl %r12d, %r12d
callq 0x3f86
jmp 0x44ae
cmpl $0x1b, %eax
je 0x46b0
cmpl $0x3a, %eax
jne 0x44ae
jmp 0x46fc
movq %rax, %r12
cmpl $0x1, %edx
jne 0x4754
movq %r12, %rdi
callq 0x3120
movq 0x8(%r15), %rax
movq 0x18(%rax), %rdi
callq 0x3f86
xorl %r12d, %r12d
callq 0x33f0
jmp 0x45e9
movq 0x8(%r15), %rax
movq 0x40(%rax), %rcx
jmp 0x4704
movl $0x1, 0x4(%rsp)
movq 0x30(%rsp), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x3400
leaq 0x1aa0(%rip), %rsi      # 0x6172
leaq 0x10(%rsp), %rdi
leaq 0xb(%rsp), %rdx
callq 0x4766
leaq 0x10(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0x3390
leaq 0x10(%rsp), %rdi
callq 0x3140
jmp 0x4708
movq 0x8(%r15), %rax
movq 0x38(%rax), %rcx
movq %rcx, 0x28(%rax)
leaq 0x30(%rsp), %rdi
callq 0x31b0
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4751
movq %rax, %r12
callq 0x33f0
jmp 0x4754
movq %rax, %rdi
callq 0x37d6
jmp 0x473e
jmp 0x4751
jmp 0x4751
movq %rax, %r12
leaq 0x10(%rsp), %rdi
callq 0x3140
jmp 0x4754
jmp 0x4751
jmp 0x4751
movq %rax, %r12
leaq 0x30(%rsp), %rdi
callq 0x31b0
movq %r12, %rdi
callq 0x3420