// File: /workspace/github_cpp_makefile_star2_O2/matallui[P]nibble-curses/src/CNibbles.cpp
// Function: CNibbles::Step()
bool CNibbles::Step ( void )
{
  if ( m_nplayers == 1)
  {
    // move snake
    m_snakes[0]->Move();
    // check collisions
    if ( m_snakes[0]->Collision ( m_obstacles, m_num_obstacles, NULL ) )
    {
      m_score -= 1000;
      UpdateScores();
      if ( m_snakes[0]->getLives() > 0 ) 	
      {
	m_state = 1;	// restart level
	PlayerDies(1);
      }
      else					m_state = 3;	// game over
      return false;
    }
    // check if eats food
    if ( m_snakes[0]->Eat ( m_xyfood, m_nfood, m_level ) )
    {
      m_score += (100*m_level + 100*m_nfood);
      m_nfood ++;
      UpdateScores();
      if ( m_nfood == 10 )
      {
	m_state = 2;	// Next Level
	return false;
      }
      PutFood();
    }
  }
  else
  {
    // move snakes
    if ( ! m_snakes[0]->Move() )	throw CException( "Problems with communication." );
    if ( ! m_snakes[1]->Move() )	throw CException( "Problems with communication." );
    
    // check for collisions
    if ( m_snakes[0]->Collision ( m_obstacles, m_num_obstacles, m_snakes[1] ) )
    {
      m_score -= 1000;
      UpdateScores();
      if ( m_snakes[0]->getLives() > 0 || m_snakes[1]->getLives() > 0 )
      {
	m_state = 1;
	PlayerDies(1);
      }
      else	m_state = 3;
      return false;
    }
    else if ( m_snakes[1]->Collision ( m_obstacles, m_num_obstacles, m_snakes[0] ) )
    {
      m_score -= 1000;
      UpdateScores();
      if ( m_snakes[0]->getLives() > 0 || m_snakes[1]->getLives() > 0 )
      {
	m_state = 1;
	PlayerDies(2);
      }
      else	m_state = 3;
      return false;
    }
    // check if someone eats food
    if ( m_snakes[0]->Eat ( m_xyfood, m_nfood, m_level ) || m_snakes[1]->Eat ( m_xyfood, m_nfood, m_level ) )
    {
      m_score += (100*m_level + 100*m_nfood);
      m_nfood ++;
      UpdateScores();
      if ( m_nfood == 10 )
      {
	m_state = 2;
	return false;
      }
      PutFood();
    } 
  }

  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rdi, %rbx
movl 0x10(%rdi), %r14d
movq 0x30(%rdi), %rax
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
cmpl $0x1, %r14d
jne 0x62dc
movq 0x28(%rbx), %rsi
movq 0x30(%rbx), %rax
movq (%rax), %rdi
leaq 0xc(%rbx), %rdx
movq (%rdi), %rax
xorl %ecx, %ecx
callq *0x20(%rax)
testb %al, %al
je 0x6363
addl $0xfffffc18, 0x20(%rbx) # imm = 0xFFFFFC18
movq %rbx, %rdi
callq 0x79ec
movq 0x30(%rbx), %rax
movq (%rax), %rdi
jmp 0x6345
testb %al, %al
je 0x64b5
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
testb %al, %al
je 0x64fe
movq 0x28(%rbx), %rsi
movq 0x30(%rbx), %rax
leaq 0xc(%rbx), %r14
movq (%rax), %rdi
movq 0x8(%rax), %rcx
movq (%rdi), %rax
movq %r14, %rdx
callq *0x20(%rax)
testb %al, %al
je 0x63b9
addl $0xfffffc18, 0x20(%rbx) # imm = 0xFFFFFC18
movq %rbx, %rdi
callq 0x79ec
movq 0x30(%rbx), %rax
movq (%rax), %rdi
callq 0x3d02
testl %eax, %eax
jg 0x6352
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rdi
callq 0x3d02
testl %eax, %eax
jle 0x6420
pushq $0x1
popq %rax
movl %eax, 0x24(%rbx)
leaq -0x48(%rbp), %rsi
movl %eax, (%rsi)
jmp 0x6416
movq 0x30(%rbx), %rax
movq (%rax), %rdi
leaq 0x38(%rbx), %rsi
leaq 0x40(%rbx), %rdx
leaq 0x8(%rbx), %rcx
movq (%rdi), %rax
callq *0x28(%rax)
movb $0x1, %r14b
testb %al, %al
je 0x6498
movl 0x40(%rbx), %eax
movl 0x8(%rbx), %ecx
addl %eax, %ecx
imull $0x64, %ecx, %ecx
addl %ecx, 0x20(%rbx)
incl %eax
movl %eax, 0x40(%rbx)
movq %rbx, %rdi
callq 0x79ec
cmpl $0xa, 0x40(%rbx)
je 0x648e
movq %rbx, %rdi
callq 0x7ab8
jmp 0x6498
movq 0x28(%rbx), %rsi
movq 0x30(%rbx), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rdi
movq (%rdi), %rax
movq %r14, %rdx
callq *0x20(%rax)
testb %al, %al
je 0x6429
addl $0xfffffc18, 0x20(%rbx) # imm = 0xFFFFFC18
movq %rbx, %rdi
callq 0x79ec
movq 0x30(%rbx), %rax
movq (%rax), %rdi
callq 0x3d02
testl %eax, %eax
jg 0x6405
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rdi
callq 0x3d02
testl %eax, %eax
jle 0x6420
movl $0x1, 0x24(%rbx)
leaq -0x48(%rbp), %rsi
movl $0x2, (%rsi)
movq %rbx, %rdi
callq 0x7652
jmp 0x6495
movl $0x3, 0x24(%rbx)
jmp 0x6495
movq 0x30(%rbx), %rax
movq (%rax), %rdi
leaq 0x38(%rbx), %r14
leaq 0x40(%rbx), %r15
leaq 0x8(%rbx), %r12
movq (%rdi), %rax
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq *0x28(%rax)
testb %al, %al
jne 0x646d
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq *0x28(%rax)
movb $0x1, %r14b
testb %al, %al
je 0x6498
movl 0x40(%rbx), %eax
movl 0x8(%rbx), %ecx
addl %eax, %ecx
imull $0x64, %ecx, %ecx
addl %ecx, 0x20(%rbx)
incl %eax
movl %eax, 0x40(%rbx)
movq %rbx, %rdi
callq 0x79ec
cmpl $0xa, 0x40(%rbx)
jne 0x64a8
movl $0x2, 0x24(%rbx)
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x7ab8
movb $0x1, %r14b
jmp 0x6498
pushq $0x20
popq %rdi
callq 0x3180
movq %rax, %rbx
leaq 0x1f14(%rip), %rsi      # 0x83db
leaq -0x48(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x369c
movb $0x1, %r15b
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x361a
xorl %r15d, %r15d
leaq 0x588b(%rip), %rsi      # 0xbd78
leaq 0x185a(%rip), %rdx      # 0x7d4e
movq %rbx, %rdi
callq 0x3410
jmp 0x6545
pushq $0x20
popq %rdi
callq 0x3180
movq %rax, %rbx
leaq 0x1ecb(%rip), %rsi      # 0x83db
leaq -0x48(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x369c
movb $0x1, %r15b
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x361a
xorl %r15d, %r15d
leaq 0x5842(%rip), %rsi      # 0xbd78
leaq 0x1811(%rip), %rdx      # 0x7d4e
movq %rbx, %rdi
callq 0x3410
jmp 0x6549
jmp 0x655c
movq %rax, %r14
leaq -0x48(%rbp), %rdi
callq 0x3150
testb %r15b, %r15b
jne 0x655f
jmp 0x6567
movq %rax, %r14
movq %rbx, %rdi
callq 0x31f0
movq %r14, %rdi
callq 0x3420
nop