// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movq %rdi, 0x50(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
xorl %edi, %edi
movq %rdi, 0x20(%rsp)
movq %rdi, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq (%rsi), %rax
movq 0x8(%rsi), %rcx
movl $0x0, 0xc(%rsp)
cmpq %rax, %rcx
je 0x2da59
movq %rsi, %r15
xorl %edi, %edi
movl $0x1, %r12d
movabsq $-0x5555555555555555, %r14 # imm = 0xAAAAAAAAAAAAAAAB
leaq 0x30(%rsp), %r13
xorl %ebx, %ebx
movl $0x0, 0xc(%rsp)
leaq 0x1(%rbx), %rsi
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r14, %rdx
movq %rsi, 0x58(%rsp)
cmpq %rsi, %rdx
movq %r12, 0x60(%rsp)
jbe 0x2da43
leaq (%rbx,%rbx,2), %rbp
movq 0x8(%rax,%rbp,8), %rdx
subq (%rax,%rbp,8), %rdx
leaq (%r12,%r12,2), %rcx
movq 0x8(%rax,%rcx,8), %rsi
subq (%rax,%rcx,8), %rsi
cmpq %rsi, %rdx
jae 0x2d98b
leaq (%rax,%rcx,8), %rsi
leaq 0x10(%rsp), %rdi
callq 0x1b2e0
movq %rbx, %rax
jmp 0x2d99c
leaq (%rax,%rbp,8), %rsi
leaq 0x10(%rsp), %rdi
callq 0x1b2e0
movq %r12, %rax
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq (%r15), %rsi
movq %r13, %rdi
callq 0x1b2e0
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x2da22
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rdx
subq %rcx, %rdx
je 0x2da22
sarq $0x3, %rdx
subq %rdi, %rax
movq %rax, %rsi
sarq $0x3, %rsi
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %r8d, %r8d
movq (%rcx,%r8,8), %r9
cmpq %r8, %rsi
jbe 0x2da0d
movq (%rdi,%r8,8), %r10
cmpq %r10, %r9
je 0x2da1e
testq %r8, %r8
je 0x2da14
cmpq %r10, -0x8(%rcx,%r8,8)
jne 0x2da14
cmpq -0x8(%rdi,%r8,8), %r9
jne 0x2da14
jmp 0x2da1e
cmpq -0x8(%rdi,%rax), %r9
je 0x2da1e
incq %r8
cmpq %r8, %rdx
jne 0x2d9e6
jmp 0x2da22
incl 0xc(%rsp)
incq %r12
movq (%r15), %rax
movq 0x8(%r15), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r14, %rdx
cmpq %r12, %rdx
ja 0x2d95d
movq 0x60(%rsp), %r12
incq %r12
movq 0x58(%rsp), %rbx
cmpq %rbx, %rdx
ja 0x2d934
movl 0xc(%rsp), %ebx
movslq %ebx, %rax
movq 0x50(%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 0x2dabb
testq %rdi, %rdi
je 0x2da93
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2daaa
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x344e6(%rip), %rdi     # 0x61fa8
leaq 0x1ca12(%rip), %rsi     # 0x4a4db
movl $0x1f, %edx
callq 0x63f0
movq 0x344ce(%rip), %rdi     # 0x61fa8
movl 0xc(%rsp), %esi
callq 0x6610
leaq 0x1aa79(%rip), %rsi     # 0x48563
movq %rax, %rdi
callq 0x6360
movl $0x1, %edi
callq 0x6440
jmp 0x2dafe
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2db18
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2db2f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq %rbx, %rdi
callq 0x6620
nop