// File: /workspace/github_cpp_makefile_star2_O3/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 $0x20, %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 0x6714
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 0x679d
addl $0xfffffc18, 0x20(%rbx) # imm = 0xFFFFFC18
movq %rbx, %rdi
callq 0x8064
movq 0x30(%rbx), %rax
movq (%rax), %rdi
jmp 0x677d
testb %al, %al
je 0x68ef
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
testb %al, %al
je 0x6945
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 0x67f3
addl $0xfffffc18, 0x20(%rbx) # imm = 0xFFFFFC18
movq %rbx, %rdi
callq 0x8064
movq 0x30(%rbx), %rax
movq (%rax), %rdi
callq 0x3dca
testl %eax, %eax
jg 0x678a
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rdi
callq 0x3dca
testl %eax, %eax
jle 0x685a
movl $0x1, %eax
movl %eax, 0x24(%rbx)
leaq -0x40(%rbp), %rsi
movl %eax, (%rsi)
jmp 0x6850
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 0x68d2
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 0x8064
cmpl $0xa, 0x40(%rbx)
je 0x68c8
movq %rbx, %rdi
callq 0x813c
jmp 0x68d2
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 0x6863
addl $0xfffffc18, 0x20(%rbx) # imm = 0xFFFFFC18
movq %rbx, %rdi
callq 0x8064
movq 0x30(%rbx), %rax
movq (%rax), %rdi
callq 0x3dca
testl %eax, %eax
jg 0x683f
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rdi
callq 0x3dca
testl %eax, %eax
jle 0x685a
movl $0x1, 0x24(%rbx)
leaq -0x40(%rbp), %rsi
movl $0x2, (%rsi)
movq %rbx, %rdi
callq 0x7c62
jmp 0x68cf
movl $0x3, 0x24(%rbx)
jmp 0x68cf
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 0x68a7
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 0x68d2
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 0x8064
cmpl $0xa, 0x40(%rbx)
jne 0x68e2
movl $0x2, 0x24(%rbx)
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x813c
movb $0x1, %r14b
jmp 0x68d2
movl $0x20, %edi
callq 0x3160
movq %rax, %rbx
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x2ad0(%rip), %rsi      # 0x93db
leaq 0x2ae5(%rip), %rdx      # 0x93f7
leaq -0x40(%rbp), %rdi
callq 0x376e
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x35f8
xorl %r12d, %r12d
leaq 0x6444(%rip), %rsi      # 0xcd78
leaq 0x1acd(%rip), %rdx      # 0x8408
movq %rbx, %rdi
callq 0x33f0
jmp 0x6999
movl $0x20, %edi
callq 0x3160
movq %rax, %rbx
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x2a7a(%rip), %rsi      # 0x93db
leaq 0x2a8f(%rip), %rdx      # 0x93f7
leaq -0x40(%rbp), %rdi
callq 0x376e
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x35f8
xorl %r12d, %r12d
leaq 0x63ee(%rip), %rsi      # 0xcd78
leaq 0x1a77(%rip), %rdx      # 0x8408
movq %rbx, %rdi
callq 0x33f0
jmp 0x699d
jmp 0x69bc
movq %rax, %r14
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0x69b5
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x3280
testb %r12b, %r12b
jne 0x69bf
jmp 0x69c7
movq %rax, %r14
movq %rbx, %rdi
callq 0x31e0
movq %r14, %rdi
callq 0x3400
nop