// File: Chrom3D[P]Chrom3D/src/Model.cpp
// Function: Model::isClashing(Move&, bool)
bool Model::isClashing(Move &mov, bool onlyIntra /*=false*/) { //

  vector<Chromosome>::iterator chriter;  
  boost::container::static_vector<Bead,MAXSIZE>::iterator beaditer;

  uint movSize = (mov.stop-mov.start)+1;
  for(uint i=0; i!=movSize; i++) {
    double moveX=mov.mat(i,0);
    double moveY=mov.mat(i,1);
    double moveZ=mov.mat(i,2);
    double moveRadius=mov.chr[mov.start+i].getRadius();

    // INTRACHROMOSOMAL
    // "left" part:
    for(beaditer = mov.chr.begin(); beaditer != mov.begin(); beaditer++) {
      if(util::coordClash(beaditer->getX(),beaditer->getY(), beaditer->getZ(), moveX, moveY, moveZ, beaditer->getRadius(), moveRadius)) {
        return true;
      }
    }
    // "Right" part:
    for(beaditer = mov.end()+1; beaditer != mov.chr.end(); beaditer++) {
      if(util::coordClash(beaditer->getX(),beaditer->getY(), beaditer->getZ(), moveX, moveY, moveZ, beaditer->getRadius(), moveRadius)) {
        return true;
      }
    }
  }
    
  if(onlyIntra) {
    return false;
  }

  // INTERCHROMOSOMAL
  for(uint i=0; i!=movSize; i++) {
    double moveX=mov.mat(i,0);
    double moveY=mov.mat(i,1);
    double moveZ=mov.mat(i,2);
    double moveRadius=mov.chr[mov.start+i].getRadius();
    for(chriter = chromosomes.begin(); chriter != chromosomes.end(); chriter++) {
      if(*chriter != mov.chr) { 
        for(beaditer = chriter->begin(); beaditer != chriter->end(); beaditer++) {
          if(util::coordClash(beaditer->getX(),beaditer->getY(), beaditer->getZ(), moveX, moveY, moveZ, beaditer->getRadius()-0.00000001, moveRadius)) {
            return true;
          }
        }
      }
    }
  }
  return false;
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movb %dl, %al
movq %rdi, 0x178(%rsp)
movq %rsi, 0x170(%rsp)
andb $0x1, %al
movb %al, 0x16f(%rsp)
movq 0x178(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x27c50
leaq 0x158(%rsp), %rdi
callq 0x16890
movq 0x170(%rsp), %rax
movl 0xc(%rax), %eax
movq 0x170(%rsp), %rcx
subl 0x8(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x154(%rsp)
movl $0x0, 0x150(%rsp)
movl 0x150(%rsp), %eax
cmpl 0x154(%rsp), %eax
je 0x1e8a7
movq 0x170(%rsp), %rdi
addq $0x10, %rdi
movl 0x150(%rsp), %eax
movl %eax, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0xb2a0
movsd (%rax), %xmm0
movsd %xmm0, 0x148(%rsp)
movq 0x170(%rsp), %rdi
addq $0x10, %rdi
movl 0x150(%rsp), %eax
movl %eax, %esi
movl $0x1, %edx
callq 0xb2a0
movsd (%rax), %xmm0
movsd %xmm0, 0x140(%rsp)
movq 0x170(%rsp), %rdi
addq $0x10, %rdi
movl 0x150(%rsp), %eax
movl %eax, %esi
movl $0x2, %edx
callq 0xb2a0
movsd (%rax), %xmm0
movsd %xmm0, 0x138(%rsp)
movq 0x170(%rsp), %rax
movq (%rax), %rdi
movq 0x170(%rsp), %rax
movl 0x8(%rax), %esi
addl 0x150(%rsp), %esi
callq 0x16820
movq %rax, %rdi
callq 0x14e60
movsd %xmm0, 0x130(%rsp)
movq 0x170(%rsp), %rax
movq (%rax), %rsi
leaq 0x128(%rsp), %rdi
callq 0x15540
leaq 0x158(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x16a00
movq 0x170(%rsp), %rsi
leaq 0x120(%rsp), %rdi
callq 0x19320
leaq 0x158(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x16b40
testb $0x1, %al
jne 0x1e611
jmp 0x1e71c
leaq 0x158(%rsp), %rdi
callq 0x16ca0
movq %rax, %rdi
callq 0x14e30
movsd %xmm0, 0x90(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x16ca0
movq %rax, %rdi
callq 0x14e40
movsd %xmm0, 0x68(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x16ca0
movq %rax, %rdi
callq 0x14e50
movsd %xmm0, 0x70(%rsp)
movsd 0x148(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x140(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x138(%rsp), %xmm0
movsd %xmm0, 0x88(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x16ca0
movq %rax, %rdi
callq 0x14e60
movsd 0x68(%rsp), %xmm1
movsd 0x70(%rsp), %xmm2
movsd 0x78(%rsp), %xmm3
movsd 0x80(%rsp), %xmm4
movsd 0x88(%rsp), %xmm5
movaps %xmm0, %xmm6
movsd 0x90(%rsp), %xmm0
movsd 0x130(%rsp), %xmm7
callq 0x99c0
testb $0x1, %al
jne 0x1e6f1
jmp 0x1e6fe
movb $0x1, 0x187(%rsp)
jmp 0x1ebd1
jmp 0x1e700
leaq 0x118(%rsp), %rdi
leaq 0x158(%rsp), %rsi
xorl %edx, %edx
callq 0x16b60
jmp 0x1e5de
movq 0x170(%rsp), %rsi
leaq 0x108(%rsp), %rdi
callq 0x19380
leaq 0x110(%rsp), %rdi
leaq 0x108(%rsp), %rsi
movl $0x1, %edx
callq 0x16c10
leaq 0x158(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x16a00
movq 0x170(%rsp), %rax
movq (%rax), %rsi
leaq 0x100(%rsp), %rdi
callq 0x15570
leaq 0x158(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x16b40
testb $0x1, %al
jne 0x1e796
jmp 0x1e88f
leaq 0x158(%rsp), %rdi
callq 0x16ca0
movq %rax, %rdi
callq 0x14e30
movsd %xmm0, 0x60(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x16ca0
movq %rax, %rdi
callq 0x14e40
movsd %xmm0, 0x38(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x16ca0
movq %rax, %rdi
callq 0x14e50
movsd %xmm0, 0x40(%rsp)
movsd 0x148(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x140(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x138(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x16ca0
movq %rax, %rdi
callq 0x14e60
movsd 0x38(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
movsd 0x48(%rsp), %xmm3
movsd 0x50(%rsp), %xmm4
movsd 0x58(%rsp), %xmm5
movaps %xmm0, %xmm6
movsd 0x60(%rsp), %xmm0
movsd 0x130(%rsp), %xmm7
callq 0x99c0
testb $0x1, %al
jne 0x1e864
jmp 0x1e871
movb $0x1, 0x187(%rsp)
jmp 0x1ebd1
jmp 0x1e873
leaq 0xf8(%rsp), %rdi
leaq 0x158(%rsp), %rsi
xorl %edx, %edx
callq 0x16b60
jmp 0x1e760
jmp 0x1e891
movl 0x150(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x150(%rsp)
jmp 0x1e4e7
testb $0x1, 0x16f(%rsp)
je 0x1e8be
movb $0x0, 0x187(%rsp)
jmp 0x1ebd1
movl $0x0, 0xf4(%rsp)
movl 0xf4(%rsp), %eax
cmpl 0x154(%rsp), %eax
je 0x1ebc9
movq 0x170(%rsp), %rdi
addq $0x10, %rdi
movl 0xf4(%rsp), %eax
movl %eax, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0xb2a0
movsd (%rax), %xmm0
movsd %xmm0, 0xe8(%rsp)
movq 0x170(%rsp), %rdi
addq $0x10, %rdi
movl 0xf4(%rsp), %eax
movl %eax, %esi
movl $0x1, %edx
callq 0xb2a0
movsd (%rax), %xmm0
movsd %xmm0, 0xe0(%rsp)
movq 0x170(%rsp), %rdi
addq $0x10, %rdi
movl 0xf4(%rsp), %eax
movl %eax, %esi
movl $0x2, %edx
callq 0xb2a0
movsd (%rax), %xmm0
movsd %xmm0, 0xd8(%rsp)
movq 0x170(%rsp), %rax
movq (%rax), %rdi
movq 0x170(%rsp), %rax
movl 0x8(%rax), %esi
addl 0xf4(%rsp), %esi
callq 0x16820
movq %rax, %rdi
callq 0x14e60
movq 0x98(%rsp), %rdi
movsd %xmm0, 0xd0(%rsp)
addq $0xa78, %rdi            # imm = 0xA78
callq 0x27be0
movq %rax, 0xc8(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x160(%rsp)
movq 0x98(%rsp), %rdi
addq $0xa78, %rdi            # imm = 0xA78
callq 0x27c10
movq %rax, 0xc0(%rsp)
leaq 0x160(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x27c70
testb $0x1, %al
jne 0x1e9f9
jmp 0x1ebb1
leaq 0x160(%rsp), %rdi
callq 0x28980
movq %rax, %rdi
movq 0x170(%rsp), %rax
movq (%rax), %rsi
callq 0x167f0
testb $0x1, %al
jne 0x1ea22
jmp 0x1eb93
leaq 0x160(%rsp), %rdi
callq 0x27cb0
movq %rax, %rsi
leaq 0xb8(%rsp), %rdi
callq 0x15540
leaq 0x158(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x16a00
leaq 0x160(%rsp), %rdi
callq 0x27cb0
movq %rax, %rsi
leaq 0xb0(%rsp), %rdi
callq 0x15570
leaq 0x158(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x16b40
testb $0x1, %al
jne 0x1ea8f
jmp 0x1eb91
leaq 0x158(%rsp), %rdi
callq 0x16ca0
movq %rax, %rdi
callq 0x14e30
movsd %xmm0, 0x30(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x16ca0
movq %rax, %rdi
callq 0x14e40
movsd %xmm0, 0x8(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x16ca0
movq %rax, %rdi
callq 0x14e50
movsd %xmm0, 0x10(%rsp)
movsd 0xe8(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x16ca0
movq %rax, %rdi
callq 0x14e60
movsd 0x8(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
movsd 0x20(%rsp), %xmm4
movsd 0x28(%rsp), %xmm5
movaps %xmm0, %xmm6
movsd 0x30(%rsp), %xmm0
movsd 0x31a6f(%rip), %xmm7    # 0x505c0
subsd %xmm7, %xmm6
movsd 0xd0(%rsp), %xmm7
callq 0x99c0
testb $0x1, %al
jne 0x1eb69
jmp 0x1eb73
movb $0x1, 0x187(%rsp)
jmp 0x1ebd1
jmp 0x1eb75
leaq 0xa8(%rsp), %rdi
leaq 0x158(%rsp), %rsi
xorl %edx, %edx
callq 0x16b60
jmp 0x1ea54
jmp 0x1eb93
jmp 0x1eb95
leaq 0x160(%rsp), %rdi
xorl %esi, %esi
callq 0x27db0
movq %rax, 0xa0(%rsp)
jmp 0x1e9bf
jmp 0x1ebb3
movl 0xf4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf4(%rsp)
jmp 0x1e8c9
movb $0x0, 0x187(%rsp)
movb 0x187(%rsp), %al
andb $0x1, %al
addq $0x188, %rsp            # imm = 0x188
retq
nopw %cs:(%rax,%rax)