// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movl $0x1, 0x8(%rsp)
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x31a0
movq 0x8(%r14), %rax
movq 0x10(%rax), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x3bd4
movb $0x1, %r12b
leaq 0xc(%rsp), %r13
leaq 0x10(%rsp), %rbp
movq 0x8(%r14), %rax
movq 0x18(%rax), %rdi
movq %r13, %rsi
callq 0x3f70
testb $0x1, %r12b
je 0x46b8
movq 0x8(%r14), %rax
movq 0x20(%rax), %rdi
callq 0x40c6
movq 0x8(%r14), %rax
movq 0x20(%rax), %rdi
callq 0x40bc
movq 0x8(%r14), %rax
movq 0x18(%rax), %rdi
callq 0x40bc
xorl %r12d, %r12d
movl 0xc(%rsp), %eax
leal -0x30(%rax), %ecx
cmpl $0x9, %ecx
ja 0x46dc
movb %al, 0x10(%rsp)
movl $0x1, %edx
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0x32e0
jmp 0x4678
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3180
movl 0xc(%rsp), %eax
cmpl $0x101, %eax            # imm = 0x101
jg 0x4742
leal -0x68(%rax), %ecx
cmpl $0x10, %ecx
ja 0x4857
leaq 0x1af1(%rip), %rdx      # 0x61f8
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x8(%r14), %rax
movq 0x18(%rax), %rdi
movq %r13, %rsi
callq 0x3f88
xorl %r15d, %r15d
testb %al, %al
je 0x47c8
movq 0x8(%r14), %rax
movq 0x10(%rax), %rdi
movzbl 0xc(%rsp), %esi
callq 0x3df4
jmp 0x47c8
addl $0xfffffefe, %eax       # imm = 0xFFFFFEFE
cmpl $0x3, %eax
ja 0x4678
leaq 0x1ae5(%rip), %rcx      # 0x623c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%r14), %rax
movq 0x18(%rax), %rdi
callq 0x456e
movl %eax, %r15d
imull 0x8(%rsp), %r15d
jmp 0x47c8
movl 0x8(%rsp), %r15d
jmp 0x47c8
xorl %r15d, %r15d
subl 0x8(%rsp), %r15d
jmp 0x47c8
movq 0x8(%r14), %rax
movq 0x18(%rax), %rdi
callq 0x456e
movl %eax, %r15d
imull 0x8(%rsp), %r15d
negl %r15d
jmp 0x47c8
cmpl $0x0, 0x8(%rsp)
jle 0x47c5
xorl %r15d, %r15d
movq 0x8(%r14), %rax
movq 0x10(%rax), %rdi
callq 0x3d4c
incl %r15d
cmpl 0x8(%rsp), %r15d
jl 0x47ae
xorl %r15d, %r15d
movl $0x1, 0x8(%rsp)
movq 0x30(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x3410
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rbp, %rdi
leaq 0x1981(%rip), %rdx      # 0x6178
movq %rdx, %rsi
callq 0x49c0
leaq 0x48(%rsp), %rdi
movq %rbp, %rsi
callq 0x3390
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4828
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3270
movq 0x8(%r14), %rax
movq 0x10(%rax), %rdi
movl %r15d, %esi
movl $0x1, %edx
callq 0x3bd4
testb %al, %al
jne 0x4678
movq 0x8(%r14), %rax
movq 0x18(%rax), %rdi
callq 0x40d0
jmp 0x4678
cmpl $0x1b, %eax
je 0x489f
cmpl $0x3a, %eax
jne 0x4678
jmp 0x4903
movq %rax, %r15
cmpl $0x1, %edx
jne 0x4981
movq %r15, %rdi
callq 0x3130
movq 0x8(%r14), %rax
movq 0x18(%rax), %rdi
callq 0x40d0
callq 0x3400
jmp 0x47c5
movq 0x8(%r14), %rax
movq 0x40(%rax), %rcx
jmp 0x490b
movl $0x1, 0x8(%rsp)
movq 0x30(%rsp), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3410
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
movq %rax, (%rdi)
leaq 0x18aa(%rip), %rdx      # 0x6178
movq %rdx, %rsi
callq 0x49c0
leaq 0x48(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3390
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x490f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3270
jmp 0x490f
movq 0x8(%r14), %rax
movq 0x38(%rax), %rcx
movq %rcx, 0x28(%rax)
movq 0x46aa(%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 0x497e
movq %rax, %r15
callq 0x3400
jmp 0x4981
movq %rax, %rdi
callq 0x3812
jmp 0x495b
jmp 0x497e
jmp 0x497e
jmp 0x497e
movq %rax, %r15
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4981
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3270
jmp 0x4981
jmp 0x497e
movq %rax, %r15
movq 0x4638(%rip), %rsi      # 0x8fc0
leaq 0x30(%rsp), %rdi
callq 0x31c0
leaq 0xb0(%rsp), %rdi
callq 0x30f0
movq %r15, %rdi
callq 0x3440
nop