// File: /workspace/github_cpp_makefile_star2_O3/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, 0x8(%rsp)
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x31a0
movq 0x8(%r15), %rax
movq 0x10(%rax), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x3be0
movb $0x1, %bl
leaq 0xc(%rsp), %r13
leaq 0x10(%rsp), %rbp
leaq 0x1ae8(%rip), %r12      # 0x6172
movq 0x8(%r15), %rax
movq 0x18(%rax), %rdi
movq %r13, %rsi
callq 0x3f7a
testb $0x1, %bl
je 0x46c6
movq 0x8(%r15), %rax
movq 0x20(%rax), %rdi
callq 0x40cc
movq 0x8(%r15), %rax
movq 0x20(%rax), %rdi
callq 0x40c2
movq 0x8(%r15), %rax
movq 0x18(%rax), %rdi
callq 0x40c2
movl 0xc(%rsp), %eax
leal -0x30(%rax), %ecx
cmpl $0x9, %ecx
ja 0x46ec
movb %al, 0x10(%rsp)
movl $0x1, %edx
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0x32e0
xorl %ebx, %ebx
jmp 0x468a
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3180
xorl %ebx, %ebx
movl 0xc(%rsp), %eax
cmpl $0x101, %eax            # imm = 0x101
jg 0x4750
leal -0x68(%rax), %ecx
cmpl $0x10, %ecx
ja 0x4858
leaq 0x1adf(%rip), %rdx      # 0x61f8
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x8(%r15), %rax
movq 0x18(%rax), %rdi
movq %r13, %rsi
callq 0x3f92
xorl %ebx, %ebx
testb %al, %al
je 0x47ca
movq 0x8(%r15), %rax
movq 0x10(%rax), %rdi
movzbl 0xc(%rsp), %esi
callq 0x3dfa
jmp 0x47ca
addl $0xfffffefe, %eax       # imm = 0xFFFFFEFE
cmpl $0x3, %eax
ja 0x468a
leaq 0x1ad7(%rip), %rcx      # 0x623c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%r15), %rax
movq 0x18(%rax), %rdi
callq 0x4578
movl %eax, %ebx
imull 0x8(%rsp), %ebx
jmp 0x47ca
movl 0x8(%rsp), %ebx
jmp 0x47ca
xorl %ebx, %ebx
subl 0x8(%rsp), %ebx
jmp 0x47ca
movq 0x8(%r15), %rax
movq 0x18(%rax), %rdi
callq 0x4578
movl %eax, %ebx
imull 0x8(%rsp), %ebx
negl %ebx
jmp 0x47ca
cmpl $0x0, 0x8(%rsp)
jle 0x47c8
xorl %ebx, %ebx
movq 0x8(%r15), %rax
movq 0x10(%rax), %rdi
callq 0x3d5c
incl %ebx
cmpl 0x8(%rsp), %ebx
jl 0x47b3
xorl %ebx, %ebx
movl $0x1, 0x8(%rsp)
movq 0x30(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
xorl %esi, %esi
callq 0x3410
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0x49c0
leaq 0x48(%rsp), %rdi
movq %rbp, %rsi
callq 0x3390
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4826
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3270
movq 0x8(%r15), %rax
movq 0x10(%rax), %rdi
movl %ebx, %esi
movl $0x1, %edx
callq 0x3be0
xorl %ebx, %ebx
testb %al, %al
jne 0x468a
movq 0x8(%r15), %rax
movq 0x18(%rax), %rdi
xorl %ebx, %ebx
callq 0x40d6
jmp 0x468a
cmpl $0x1b, %eax
je 0x48a0
cmpl $0x3a, %eax
jne 0x468a
jmp 0x4904
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x4982
movq %rbx, %rdi
callq 0x3130
movq 0x8(%r15), %rax
movq 0x18(%rax), %rdi
callq 0x40d6
callq 0x3400
jmp 0x47c8
movq 0x8(%r15), %rax
movq 0x40(%rax), %rcx
jmp 0x490c
movl $0x1, 0x8(%rsp)
movq 0x30(%rsp), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x3410
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
movq %rax, (%rdi)
leaq 0x18a3(%rip), %rdx      # 0x6172
movq %rdx, %rsi
callq 0x49c0
leaq 0x10(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0x3390
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4910
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3270
jmp 0x4910
movq 0x8(%r15), %rax
movq 0x38(%rax), %rcx
movq %rcx, 0x28(%rax)
movq 0x46a9(%rip), %rsi      # 0x8fc0
leaq 0x30(%rsp), %rdi
callq 0x31c0
leaq 0xb0(%rsp), %rdi
callq 0x30f0
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x497f
movq %rax, %rbx
callq 0x3400
jmp 0x4982
movq %rax, %rdi
callq 0x380e
jmp 0x495c
jmp 0x497f
jmp 0x497f
jmp 0x497f
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4982
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3270
jmp 0x4982
jmp 0x497f
movq %rax, %rbx
movq 0x4637(%rip), %rsi      # 0x8fc0
leaq 0x30(%rsp), %rdi
callq 0x31c0
leaq 0xb0(%rsp), %rdi
callq 0x30f0
movq %rbx, %rdi
callq 0x3440