// File: matallui[P]nibble-curses/src/CMultPC.cpp
// Function: CMultPC::Collision(CObstacle*, int const&, CSnake*)
bool CMultPC::Collision ( CObstacle * const obstacles, int const & num_obstacles, CSnake * sfriend )
{
  if ( !m_lives ) return false;
  
  // collision with obstacles
  for ( int i = 0; i < num_obstacles; i++ )
    if ( obstacles[i].Intersection ( m_body[m_head] ) )
    {
      Die ( dynamic_cast <CMultPC*> (sfriend) );
      m_score -= 1000;
      return true;
    }
  
  // collision with itself
  int i = m_tail;
  for ( int k = 0; k < m_size-3; k++ )
  {
    if ( m_body[m_head] == m_body[i] )
    {
      Die ( dynamic_cast <CMultPC*> (sfriend) );
      m_score -= 1000;
      return true;
    }
    i = (i + 1) % m_max_size;
  }
  
  // collision with friend
  if ( sfriend ) 
    if ( sfriend->hasPoint ( m_body[m_head] ) )
    {
      Die ( dynamic_cast <CMultPC*> (sfriend) );
      m_score -= 1000;
      return true;
    }
  
  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, 0x24(%rax)
jne 0x533f
movb $0x0, -0x1(%rbp)
jmp 0x5547
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x53ef
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rdi
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rdi
movq 0x8(%rax), %rsi
movslq 0x18(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x4150
testb $0x1, %al
jne 0x5382
jmp 0x53df
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x53b1
movq -0x48(%rbp), %rdi
leaq 0xa7a5(%rip), %rsi      # 0xfb40
leaq 0xa856(%rip), %rdx      # 0xfbf8
xorl %eax, %eax
movl %eax, %ecx
callq 0x3380
movq %rax, -0x50(%rbp)
jmp 0x53b9
xorl %eax, %eax
movq %rax, -0x50(%rbp)
jmp 0x53b9
movq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x5560
movq -0x40(%rbp), %rax
movl 0x20(%rax), %ecx
subl $0x3e8, %ecx            # imm = 0x3E8
movl %ecx, 0x20(%rax)
movb $0x1, -0x1(%rbp)
jmp 0x5547
jmp 0x53e1
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x5346
movq -0x40(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x40(%rbp), %rcx
movl -0x34(%rbp), %eax
movl 0x14(%rcx), %ecx
subl $0x3, %ecx
cmpl %ecx, %eax
jge 0x54be
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
movslq 0x18(%rax), %rcx
shlq $0x3, %rcx
addq %rcx, %rdi
movq 0x8(%rax), %rsi
movslq -0x30(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x3de0
testb $0x1, %al
jne 0x5442
jmp 0x549f
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x5471
movq -0x58(%rbp), %rdi
leaq 0xa6e5(%rip), %rsi      # 0xfb40
leaq 0xa796(%rip), %rdx      # 0xfbf8
xorl %eax, %eax
movl %eax, %ecx
callq 0x3380
movq %rax, -0x60(%rbp)
jmp 0x5479
xorl %eax, %eax
movq %rax, -0x60(%rbp)
jmp 0x5479
movq -0x40(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x5560
movq -0x40(%rbp), %rax
movl 0x20(%rax), %ecx
subl $0x3e8, %ecx            # imm = 0x3E8
movl %ecx, 0x20(%rax)
movb $0x1, -0x1(%rbp)
jmp 0x5547
movq -0x40(%rbp), %rcx
movl -0x30(%rbp), %eax
addl $0x1, %eax
cltd
idivl 0x10(%rcx)
movl %edx, -0x30(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x5400
cmpq $0x0, -0x28(%rbp)
je 0x5543
movq -0x40(%rbp), %rax
movq -0x28(%rbp), %rdi
movq 0x8(%rax), %rsi
movslq 0x18(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x4470
testb $0x1, %al
jne 0x54e7
jmp 0x5541
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x5516
movq -0x68(%rbp), %rdi
leaq 0xa640(%rip), %rsi      # 0xfb40
leaq 0xa6f1(%rip), %rdx      # 0xfbf8
xorl %eax, %eax
movl %eax, %ecx
callq 0x3380
movq %rax, -0x70(%rbp)
jmp 0x551e
xorl %eax, %eax
movq %rax, -0x70(%rbp)
jmp 0x551e
movq -0x40(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x5560
movq -0x40(%rbp), %rax
movl 0x20(%rax), %ecx
subl $0x3e8, %ecx            # imm = 0x3E8
movl %ecx, 0x20(%rax)
movb $0x1, -0x1(%rbp)
jmp 0x5547
jmp 0x5543
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)