// File: /workspace/github_cpp_makefile_star2_O1/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 0x67d6
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 0x685f
addl $0xfffffc18, 0x20(%rbx) # imm = 0xFFFFFC18
movq %rbx, %rdi
callq 0x8180
movq 0x30(%rbx), %rax
movq (%rax), %rdi
jmp 0x683f
testb %al, %al
je 0x69b1
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
testb %al, %al
je 0x6a08
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 0x68b5
addl $0xfffffc18, 0x20(%rbx) # imm = 0xFFFFFC18
movq %rbx, %rdi
callq 0x8180
movq 0x30(%rbx), %rax
movq (%rax), %rdi
callq 0x3dc2
testl %eax, %eax
jg 0x684c
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rdi
callq 0x3dc2
testl %eax, %eax
jle 0x691c
movl $0x1, %eax
movl %eax, 0x24(%rbx)
leaq -0x40(%rbp), %rsi
movl %eax, (%rsi)
jmp 0x6912
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 0x6994
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 0x8180
cmpl $0xa, 0x40(%rbx)
je 0x698a
movq %rbx, %rdi
callq 0x8258
jmp 0x6994
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 0x6925
addl $0xfffffc18, 0x20(%rbx) # imm = 0xFFFFFC18
movq %rbx, %rdi
callq 0x8180
movq 0x30(%rbx), %rax
movq (%rax), %rdi
callq 0x3dc2
testl %eax, %eax
jg 0x6901
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rdi
callq 0x3dc2
testl %eax, %eax
jle 0x691c
movl $0x1, 0x24(%rbx)
leaq -0x40(%rbp), %rsi
movl $0x2, (%rsi)
movq %rbx, %rdi
callq 0x7d74
jmp 0x6991
movl $0x3, 0x24(%rbx)
jmp 0x6991
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 0x6969
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 0x6994
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 0x8180
cmpl $0xa, 0x40(%rbx)
jne 0x69a4
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 0x8258
movb $0x1, %r14b
jmp 0x6994
movl $0x20, %edi
callq 0x3160
movq %rax, %rbx
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x2a0d(%rip), %rsi      # 0x93db
leaq 0x2a22(%rip), %rdx      # 0x93f7
leaq -0x40(%rbp), %rdi
callq 0x376a
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x35f8
xorl %r15d, %r15d
leaq 0x6381(%rip), %rsi      # 0xcd78
leaq 0x1b3e(%rip), %rdx      # 0x853c
movq %rbx, %rdi
callq 0x33f0
jmp 0x6a5d
movl $0x20, %edi
callq 0x3160
movq %rax, %rbx
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x29b6(%rip), %rsi      # 0x93db
leaq 0x29cb(%rip), %rdx      # 0x93f7
leaq -0x40(%rbp), %rdi
callq 0x376a
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x35f8
xorl %r15d, %r15d
leaq 0x632a(%rip), %rsi      # 0xcd78
leaq 0x1ae7(%rip), %rdx      # 0x853c
movq %rbx, %rdi
callq 0x33f0
jmp 0x6a61
jmp 0x6a7b
movq %rax, %r14
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x6a81
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x3280
jmp 0x6a81
movq %rax, %r14
movb $0x1, %r15b
testb %r15b, %r15b
je 0x6a8e
movq %rbx, %rdi
callq 0x31e0
movq %r14, %rdi
callq 0x3400