// File: matallui[P]nibble-curses/src/CSingle.cpp
// Function: CSingle::Move()
bool CSingle::Move ( void )
{
  if ( !m_lives ) return true;
  
  int next_head = (m_head + 1) % m_max_size;
  
  int key = getch();
  switch ( key )
  {
    case KEY_UP:
      if ( m_direction != 'D' ) m_direction = 'U';
      break;
    case KEY_DOWN:
      if ( m_direction != 'U' ) m_direction = 'D';
      break;
    case KEY_LEFT:
      if ( m_direction != 'R' ) m_direction = 'L';
      break;
    case KEY_RIGHT:
      if ( m_direction != 'L' ) m_direction = 'R';
      break;
  }
  
  // snake has to increase
  if ( m_delay > 0 )
  {
    m_delay --;
    m_size ++;
  }
  else
  {
    attrset ( COLOR_PAIR(m_cp_erase) );
    m_body[m_tail].Draw( ' ' );
    m_tail = (m_tail + 1) % m_max_size;
  }
  
  // update new head coordinates
  m_body[next_head] = m_body[m_head];
  m_head = next_head;
  
  switch ( m_direction )
  {
    case 'U':
      m_body[m_head].decX(1);
      break;
    case 'D':
      m_body[m_head].incX(1);
      break;
    case 'L':
      m_body[m_head].decY(1);
      break;
    case 'R':
      m_body[m_head].incY(1);
      break;
  }
  
  attrset ( COLOR_PAIR(m_cp_draw) );
  m_body[m_head].Draw ( '@' );
  refresh();
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, 0x24(%rax)
jne 0x4bc3
movb $0x1, -0x1(%rbp)
jmp 0x4e0b
movq -0x38(%rbp), %rax
movl 0x10(%rax), %ecx
movl 0x18(%rax), %eax
incl %eax
cltd
idivl %ecx
movl %edx, -0x14(%rbp)
movq 0xb3f4(%rip), %rax      # 0xffd0
movq (%rax), %rdi
callq 0x3130
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
addl $0xfffffefe, %eax       # imm = 0xFFFFFEFE
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x3, %eax
ja 0x4c6a
movq -0x40(%rbp), %rax
leaq 0x74f3(%rip), %rcx      # 0xc0f8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x38(%rbp), %rax
movsbl 0x28(%rax), %eax
cmpl $0x44, %eax
je 0x4c23
movq -0x38(%rbp), %rax
movb $0x55, 0x28(%rax)
jmp 0x4c6a
movq -0x38(%rbp), %rax
movsbl 0x28(%rax), %eax
cmpl $0x55, %eax
je 0x4c3a
movq -0x38(%rbp), %rax
movb $0x44, 0x28(%rax)
jmp 0x4c6a
movq -0x38(%rbp), %rax
movsbl 0x28(%rax), %eax
cmpl $0x52, %eax
je 0x4c51
movq -0x38(%rbp), %rax
movb $0x4c, 0x28(%rax)
jmp 0x4c6a
movq -0x38(%rbp), %rax
movsbl 0x28(%rax), %eax
cmpl $0x4c, %eax
je 0x4c68
movq -0x38(%rbp), %rax
movb $0x52, 0x28(%rax)
jmp 0x4c6a
movq -0x38(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jle 0x4c8c
movq -0x38(%rbp), %rax
movl 0x2c(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x2c(%rax)
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
jmp 0x4ce0
movq -0x38(%rbp), %rax
movq 0xb339(%rip), %rcx      # 0xffd0
movq (%rcx), %rdi
movl 0x34(%rax), %esi
shll $0x8, %esi
andl $0xff00, %esi           # imm = 0xFF00
callq 0x3330
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movslq 0x1c(%rax), %rax
shlq $0x3, %rax
addq %rax, %rdi
movb $0x20, -0x19(%rbp)
leaq -0x19(%rbp), %rsi
callq 0x3e20
movq -0x38(%rbp), %rcx
movl 0x1c(%rcx), %eax
addl $0x1, %eax
cltd
idivl 0x10(%rcx)
movq -0x38(%rbp), %rax
movl %edx, 0x1c(%rax)
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rax
movslq 0x18(%rcx), %rcx
leaq (%rax,%rcx,8), %rsi
movslq -0x14(%rbp), %rcx
leaq (%rax,%rcx,8), %rdi
callq 0x3c80
movq -0x38(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, 0x18(%rax)
movsbl 0x28(%rax), %eax
addl $-0x44, %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x11, %eax
ja 0x4dc3
movq -0x48(%rbp), %rax
leaq 0x73e0(%rip), %rcx      # 0xc108
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movslq 0x18(%rax), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl $0x1, -0x20(%rbp)
leaq -0x20(%rbp), %rsi
callq 0x3d60
jmp 0x4dc3
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movslq 0x18(%rax), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl $0x1, -0x24(%rbp)
leaq -0x24(%rbp), %rsi
callq 0x3d20
jmp 0x4dc3
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movslq 0x18(%rax), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl $0x1, -0x28(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x3d80
jmp 0x4dc3
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movslq 0x18(%rax), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl $0x1, -0x2c(%rbp)
leaq -0x2c(%rbp), %rsi
callq 0x3d40
movq -0x38(%rbp), %rax
movq 0xb202(%rip), %rcx      # 0xffd0
movq (%rcx), %rdi
movl 0x30(%rax), %esi
shll $0x8, %esi
andl $0xff00, %esi           # imm = 0xFF00
callq 0x3330
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movslq 0x18(%rax), %rax
shlq $0x3, %rax
addq %rax, %rdi
movb $0x40, -0x2d(%rbp)
leaq -0x2d(%rbp), %rsi
callq 0x3e20
callq 0x34c0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)