// File: /workspace/github_c_makefile_star2_O0/baskerville[P]bspwm/src/tree.c
// Function: find_nearest_neighbor
void find_nearest_neighbor(coordinates_t *ref, coordinates_t *dst, direction_t dir, node_select_t *sel)
{
	xcb_rectangle_t rect = get_rectangle(ref->monitor, ref->desktop, ref->node);
	uint32_t md = UINT32_MAX, mr = UINT32_MAX;

	for (monitor_t *m = mon_head; m != NULL; m = m->next) {
		desktop_t *d = m->desk;
		for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f, d->root)) {
			coordinates_t loc = {m, d, f};
			xcb_rectangle_t r = get_rectangle(m, d, f);
			if (f == ref->node ||
			    f->client == NULL ||
			    f->hidden ||
			    is_descendant(f, ref->node) ||
			    !node_matches(&loc, ref, sel) ||
			    !on_dir_side(rect, r, dir)) {
				continue;
			}
			uint32_t fd = boundary_distance(rect, r, dir);
			uint32_t fr = history_rank(f);
			if (fd < md || (fd == md && fr < mr)) {
				md = fd;
				mr = fr;
				*dst = loc;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0xc7f0
movq %rax, -0x28(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
leaq 0x2682c(%rip), %rax     # 0x356f8
movq (%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0xf025
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0xbe70
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0xf012
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0xc7f0
movq %rax, -0x68(%rbp)
movq -0x48(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x10(%rcx), %rax
je 0xef96
movq -0x48(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0xef96
movq -0x48(%rbp), %rax
testb $0x1, 0x25(%rax)
jne 0xef96
movq -0x48(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0xd040
testb $0x1, %al
jne 0xef96
movq -0x8(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x60(%rbp), %rdi
callq 0x23df0
testb $0x1, %al
jne 0xef82
jmp 0xef96
movl -0x14(%rbp), %edx
movq -0x28(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x6e50
testb $0x1, %al
jne 0xef98
jmp 0xeff8
movl -0x14(%rbp), %edx
movq -0x28(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x6cf0
movl %eax, -0x6c(%rbp)
movq -0x48(%rbp), %rdi
callq 0x13020
movl %eax, -0x70(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jb 0xefcf
movl -0x6c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0xeff6
movl -0x70(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0xeff6
movl -0x6c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, (%rax)
movq -0x58(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0xeff8
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rsi
callq 0xbf80
movq %rax, -0x48(%rbp)
jmp 0xeefb
jmp 0xf014
movq -0x38(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0xeed3
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)