// File: /workspace/github_cpp_makefile_star2_O2/Kei18[P]pibt/./src/solver/ecbs.cpp
// Function: ECBS::h3(std::vector<std::vector<Node*, std::allocator<Node*>>, std::allocator<std::vector<Node*, std::allocator<Node*>>>>&)
int ECBS::h3(Paths &paths) {

  int collision = 0;
  Nodes p1, p2;

  for (int i = 0; i < paths.size(); ++i) {
    for (int j = i + 1; j < paths.size(); ++j) {
      if (paths[i].size() >= paths[j].size()) {
        p1 = paths[i];
        p2 = paths[j];
      } else {
        p1 = paths[j];
        p2 = paths[i];
      }

      if (p2.empty()) continue;

      for (int t = 0; t < p1.size(); ++t) {
        if (t >= p2.size()) {
          // goal pos
          if (p1[t] == p2[p2.size() - 1]) {
            ++collision;
            break;
          }
          continue;
        }
        if (p1[t] == p2[t]) {  // collision
          ++collision;
          break;
        }
        // intersection
        if (t > 0 && p1[t-1] == p2[t] && p1[t] == p2[t-1]) {
          ++collision;
          break;
        }
      }
    }
  }

  // error check
  if (collision > A.size() * (A.size() - 1) / 2) {
    std::cout << "error@ECBS::h3, invalid value, " << collision << "\n";
    std::exit(1);
  }

  return collision;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r15
movq %rdi, 0x40(%rsp)
xorps %xmm0, %xmm0
movq %rsp, %rax
andq $0x0, 0x10(%rax)
leaq 0x20(%rsp), %rcx
andq $0x0, 0x10(%rcx)
movaps %xmm0, (%rax)
movaps %xmm0, (%rcx)
movq (%rsi), %rsi
movq 0x8(%r15), %rcx
xorl %ebp, %ebp
pushq $0x1
popq %r13
pushq $0x18
popq %r14
xorl %ebx, %ebx
movq %rcx, %rax
subq %rsi, %rax
cqto
idivq %r14
cmpq %rbp, %rax
jbe 0x2561d
leaq 0x1(%rbp), %rax
movq %rax, 0x48(%rsp)
imulq $0x18, %rbp, %r12
movq %r13, 0x50(%rsp)
movq %rcx, %rax
subq %rsi, %rax
cqto
idivq %r14
cmpq %r13, %rax
jbe 0x2560b
movq 0x8(%rsi,%r12), %rcx
subq (%rsi,%r12), %rcx
imulq $0x18, %r13, %rax
movq 0x8(%rsi,%rax), %rdx
subq (%rsi,%rax), %rdx
cmpq %rdx, %rcx
jae 0x25577
addq %rax, %rsi
movq %rsp, %rdi
callq 0x16f90
movq %rbp, %rax
jmp 0x25585
addq %r12, %rsi
movq %rsp, %rdi
callq 0x16f90
movq %r13, %rax
imulq $0x18, %rax, %rsi
addq (%r15), %rsi
leaq 0x20(%rsp), %rdi
callq 0x16f90
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
cmpq %rcx, %rax
je 0x255fc
movq (%rsp), %rdx
movq 0x8(%rsp), %rsi
subq %rdx, %rsi
sarq $0x3, %rsi
subq %rax, %rcx
movq %rcx, %rdi
sarq $0x3, %rdi
xorl %r8d, %r8d
cmpq %r8, %rsi
je 0x255fc
movq (%rdx,%r8,8), %r9
cmpq %r8, %rdi
jbe 0x255ee
movq (%rax,%r8,8), %r10
cmpq %r10, %r9
je 0x255fa
testq %r8, %r8
je 0x255f5
cmpq %r10, -0x8(%rdx,%r8,8)
jne 0x255f5
cmpq -0x8(%rax,%r8,8), %r9
jne 0x255f5
jmp 0x255fa
cmpq -0x8(%rax,%rcx), %r9
je 0x255fa
incq %r8
jmp 0x255c2
incl %ebx
incq %r13
movq (%r15), %rsi
movq 0x8(%r15), %rcx
jmp 0x25538
movq 0x50(%rsp), %r13
incq %r13
movq 0x48(%rsp), %rbp
jmp 0x25512
movslq %ebx, %rax
movq 0x40(%rsp), %rdx
movq 0x28(%rdx), %rcx
subq 0x20(%rdx), %rcx
sarq $0x3, %rcx
leaq -0x1(%rcx), %rdx
imulq %rcx, %rdx
shrq %rdx
cmpq %rax, %rdx
jb 0x25664
leaq 0x20(%rsp), %rdi
callq 0x990e
movq %rsp, %rdi
callq 0x990e
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3492d(%rip), %rdi     # 0x59f98
leaq 0x16f19(%rip), %rsi     # 0x3c58b
callq 0x63a0
movq %rax, %rdi
movl %ebx, %esi
callq 0x6630
leaq 0x14edb(%rip), %rsi     # 0x3a563
movq %rax, %rdi
callq 0x63a0
pushq $0x1
popq %rdi
callq 0x6450
jmp 0x2569a
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x990e
movq %rsp, %rdi
callq 0x990e
movq %rbx, %rdi
callq 0x6650
nop