// File: cdalitz[P]kdtree-cpp/kdtree.cpp
// Function: Kdtree::KdTree::KdTree(std::vector<Kdtree::KdNode, std::allocator<Kdtree::KdNode>> const*, int)
KdTree::KdTree(const KdNodeVector* nodes, int distance_type /*=2*/) {
  size_t i, j;
  double val;
  // copy over input data
  if (!nodes || nodes->empty())
    throw std::invalid_argument(
        "kdtree::KdTree(): argument nodes must not be empty");
  dimension = nodes->begin()->point.size();
  allnodes = *nodes;
  // initialize distance values
  distance = NULL;
  this->distance_type = -1;
  set_distance(distance_type);
  // compute global bounding box
  lobound = nodes->begin()->point;
  upbound = nodes->begin()->point;
  for (i = 1; i < nodes->size(); i++) {
    for (j = 0; j < dimension; j++) {
      val = allnodes[i].point[j];
      if (lobound[j] > val) lobound[j] = val;
      if (upbound[j] < val) upbound[j] = val;
    }
  }
  // build tree recursively
  root = build_tree(0, 0, allnodes.size());
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x68(%rbp)
callq 0x3d50
movq -0x68(%rbp), %rdi
addq $0x18, %rdi
movq %rdi, -0x70(%rbp)
callq 0x3d50
movq -0x68(%rbp), %rdi
addq $0x48, %rdi
movq %rdi, -0x60(%rbp)
callq 0x3810
cmpq $0x0, -0x10(%rbp)
je 0x6a2b
movq -0x10(%rbp), %rdi
callq 0x8190
testb $0x1, %al
jne 0x6a2b
jmp 0x6a94
movl $0x10, %edi
callq 0x2080
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x78(%rbp)
leaq 0x78ca(%rip), %rsi      # 0xe310
callq 0x21a0
jmp 0x6a4d
movq -0x78(%rbp), %rdi
movq 0xe588(%rip), %rsi      # 0x14fe0
movq 0xe571(%rip), %rdx      # 0x14fd0
callq 0x2180
jmp 0x6cb2
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x20c0
jmp 0x6c8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x6c8e
movq -0x10(%rbp), %rdi
callq 0x81d0
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x8200
movq %rax, %rdi
callq 0x37d0
movq -0x68(%rbp), %rdi
movq %rax, 0x60(%rdi)
movq -0x10(%rbp), %rsi
addq $0x48, %rdi
callq 0x8220
jmp 0x6ac9
movq -0x68(%rbp), %rdi
movq $0x0, 0x38(%rdi)
movl $0xffffffff, 0x30(%rdi) # imm = 0xFFFFFFFF
movl -0x14(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x6cc0
jmp 0x6aea
movq -0x10(%rbp), %rdi
callq 0x81d0
movq %rax, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x8200
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x3d70
jmp 0x6b0e
movq -0x10(%rbp), %rdi
callq 0x81d0
movq %rax, -0x58(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x8200
movq -0x68(%rbp), %rdi
movq %rax, %rsi
addq $0x18, %rdi
callq 0x3d70
jmp 0x6b36
movq $0x1, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3780
movq %rax, %rcx
movq -0x80(%rbp), %rax
cmpq %rcx, %rax
jae 0x6c4d
movq $0x0, -0x28(%rbp)
movq -0x68(%rbp), %rcx
movq -0x28(%rbp), %rax
cmpq 0x60(%rcx), %rax
jae 0x6c3a
movq -0x68(%rbp), %rdi
addq $0x48, %rdi
movq -0x20(%rbp), %rsi
callq 0x3b30
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x38e0
movq -0x68(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x28(%rbp), %rsi
callq 0x38e0
movsd (%rax), %xmm0
ucomisd -0x30(%rbp), %xmm0
jbe 0x6bdd
movq -0x68(%rbp), %rdi
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x28(%rbp), %rsi
callq 0x38e0
movsd -0x88(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x68(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rsi
callq 0x38e0
movsd (%rax), %xmm1
movsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6c27
movq -0x68(%rbp), %rdi
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
addq $0x18, %rdi
movq -0x28(%rbp), %rsi
callq 0x38e0
movsd -0x90(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x6c29
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x6b67
jmp 0x6c3c
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x6b3e
movq -0x68(%rbp), %rdi
addq $0x48, %rdi
callq 0x3780
movq -0x68(%rbp), %rdi
movq %rax, %rcx
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x6e70
movq %rax, -0x98(%rbp)
jmp 0x6c76
movq -0x68(%rbp), %rax
movq -0x98(%rbp), %rcx
movq %rcx, 0x68(%rax)
addq $0xa0, %rsp
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x3c40
movq -0x70(%rbp), %rdi
callq 0x39c0
movq -0x68(%rbp), %rdi
callq 0x39c0
movq -0x38(%rbp), %rdi
callq 0x2190
nopw %cs:(%rax,%rax)