// File: cdalitz[P]kdtree-cpp/kdtree.cpp
// Function: Kdtree::KdTree::bounds_overlap_ball(std::vector<double, std::allocator<double>> const&, double, Kdtree::kdtree_node*)
bool KdTree::bounds_overlap_ball(const CoordPoint& point, double dist,
                                 kdtree_node* node) {
  if (distance_type != 0) {
    double distsum = 0.0;
    size_t i;
    for (i = 0; i < dimension; i++) {
      if (point[i] < node->lobound[i]) {  // lower than low boundary
        distsum += distance->coordinate_distance(point[i], node->lobound[i], i);
        if (distsum > dist) return false;
      } else if (point[i] > node->upbound[i]) {  // higher than high boundary
        distsum += distance->coordinate_distance(point[i], node->upbound[i], i);
        if (distsum > dist) return false;
      }
    }
    return true;
  } else { // maximum distance needs different treatment
    double max_dist = 0.0;
    double curr_dist = 0.0;
    size_t i;
    for (i = 0; i < dimension; i++) {
      if (point[i] < node->lobound[i]) {  // lower than low boundary
        curr_dist = distance->coordinate_distance(point[i], node->lobound[i], i);
      } else if (point[i] > node->upbound[i]) {  // higher than high boundary
        curr_dist = distance->coordinate_distance(point[i], node->upbound[i], i);
      }
      if(curr_dist > max_dist) {
        max_dist = curr_dist;
      }
      if (max_dist > dist) return false;
    }
    return true;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpl $0x0, 0x30(%rax)
je 0x7e15
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x58(%rbp), %rcx
movq -0x38(%rbp), %rax
cmpq 0x60(%rcx), %rax
jae 0x7e0c
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x37f0
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
movq -0x38(%rbp), %rsi
callq 0x38e0
movsd -0x60(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x7d54
movq -0x58(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x37f0
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
movq -0x38(%rbp), %rsi
callq 0x38e0
movq -0x70(%rbp), %rdi
movsd -0x68(%rbp), %xmm0
movsd (%rax), %xmm1
movq -0x38(%rbp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
ucomisd -0x20(%rbp), %xmm0
jbe 0x7d4f
movb $0x0, -0x1(%rbp)
jmp 0x7faf
jmp 0x7df9
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x37f0
movsd (%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x28(%rbp), %rdi
addq $0x50, %rdi
movq -0x38(%rbp), %rsi
callq 0x38e0
movsd -0x78(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x7df7
movq -0x58(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x37f0
movsd (%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
movq -0x28(%rbp), %rdi
addq $0x50, %rdi
movq -0x38(%rbp), %rsi
callq 0x38e0
movq -0x88(%rbp), %rdi
movsd -0x80(%rbp), %xmm0
movsd (%rax), %xmm1
movq -0x38(%rbp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
ucomisd -0x20(%rbp), %xmm0
jbe 0x7df5
movb $0x0, -0x1(%rbp)
jmp 0x7faf
jmp 0x7df7
jmp 0x7df9
jmp 0x7dfb
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x7c9e
movb $0x1, -0x1(%rbp)
jmp 0x7faf
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %rax
cmpq 0x60(%rcx), %rax
jae 0x7fab
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x37f0
movsd (%rax), %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
movq -0x50(%rbp), %rsi
callq 0x38e0
movsd -0x90(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x7edb
movq -0x58(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x37f0
movsd (%rax), %xmm0
movsd %xmm0, -0x98(%rbp)
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
movq -0x50(%rbp), %rsi
callq 0x38e0
movq -0xa0(%rbp), %rdi
movsd -0x98(%rbp), %xmm0
movsd (%rax), %xmm1
movq -0x50(%rbp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movsd %xmm0, -0x48(%rbp)
jmp 0x7f70
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x37f0
movsd (%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
movq -0x28(%rbp), %rdi
addq $0x50, %rdi
movq -0x50(%rbp), %rsi
callq 0x38e0
movsd -0xa8(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x7f6e
movq -0x58(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x37f0
movsd (%rax), %xmm0
movsd %xmm0, -0xb0(%rbp)
movq -0x28(%rbp), %rdi
addq $0x50, %rdi
movq -0x50(%rbp), %rsi
callq 0x38e0
movq -0xb8(%rbp), %rdi
movsd -0xb0(%rbp), %xmm0
movsd (%rax), %xmm1
movq -0x50(%rbp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movsd %xmm0, -0x48(%rbp)
jmp 0x7f70
movsd -0x48(%rbp), %xmm0
ucomisd -0x40(%rbp), %xmm0
jbe 0x7f86
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
ucomisd -0x20(%rbp), %xmm0
jbe 0x7f98
movb $0x0, -0x1(%rbp)
jmp 0x7faf
jmp 0x7f9a
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x7e2d
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)