// File: /workspace/github_c_makefile_star2_O2/baskerville[P]bspwm/src/tree.c
// Function: find_closest_node
bool find_closest_node(coordinates_t *ref, coordinates_t *dst, cycle_dir_t dir, node_select_t *sel)
{
	monitor_t *m = ref->monitor;
	desktop_t *d = ref->desktop;
	node_t *n = ref->node;
	n = (dir == CYCLE_PREV ? prev_node(n) : next_node(n));

#define HANDLE_BOUNDARIES(m, d, n)  \
	while (n == NULL) { \
		d = (dir == CYCLE_PREV ? d->prev : d->next); \
		if (d == NULL) { \
			m = (dir == CYCLE_PREV ? m->prev : m->next); \
			if (m == NULL) { \
				m = (dir == CYCLE_PREV ? mon_tail : mon_head); \
			} \
			d = (dir == CYCLE_PREV ? m->desk_tail : m->desk_head); \
		} \
		n = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root)); \
		if (ref->node == NULL && d == ref->desktop) { \
			break; \
		} \
	}
	HANDLE_BOUNDARIES(m, d, n);

	while (n != ref->node) {
		coordinates_t loc = {m, d, n};
		if (node_matches(&loc, ref, sel)) {
			*dst = loc;
			return true;
		}
		n = (dir == CYCLE_PREV ? prev_node(n) : next_node(n));
		HANDLE_BOUNDARIES(m, d, n);
		if (ref->node == NULL && d == ref->desktop) {
			break;
		}
	}
#undef HANDLE_BOUNDARIES
	return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, 0x30(%rsp)
movq %rsi, %r14
movq %rdi, %r15
movq (%rdi), %rbx
movq 0x8(%rdi), %rax
movq %rax, 0x18(%rsp)
movq 0x10(%rdi), %rbp
movl %edx, 0xc(%rsp)
movq %rbp, %rdi
cmpl $0x1, %edx
jne 0xb803
callq 0xa51c
movq %rax, %r12
pushq $0x40
popq %r13
pushq $0x70
popq %rax
movq %rax, 0x10(%rsp)
pushq $0x68
jmp 0xb819
callq 0xa4e4
movq %rax, %r12
pushq $0x48
popq %r13
pushq $0x78
popq %rax
movq %rax, 0x10(%rsp)
pushq $0x60
popq %rax
movq %rax, 0x20(%rsp)
cmpl $0x1, 0xc(%rsp)
movq %r14, 0x28(%rsp)
jne 0xb834
leaq 0x1cece(%rip), %rax     # 0x28700
jmp 0xb83b
leaq 0x1cecd(%rip), %rax     # 0x28708
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x18(%rsp), %r14
testq %r12, %r12
jne 0xb897
movq (%r14,%r13), %r14
testq %r14, %r14
jne 0xb871
movq 0x10(%rsp), %rax
movq (%rbx,%rax), %rbx
testq %rbx, %rbx
cmoveq 0x38(%rsp), %rbx
movq 0x20(%rsp), %rax
movq (%rbx,%rax), %r14
movq 0x30(%r14), %rdi
cmpl $0x1, 0xc(%rsp)
jne 0xb883
callq 0xa4d2
jmp 0xb888
callq 0x8e72
movq %rax, %r12
testq %rbp, %rbp
jne 0xb848
cmpq 0x18(%rsp), %r14
jne 0xb848
xorl %eax, %eax
xorl %ecx, %ecx
cmpl $0x1, 0xc(%rsp)
sete %al
setne %cl
shll $0x3, %ecx
leaq 0x40(%rcx), %r13
orq $0x70, %rcx
movq %rcx, 0x18(%rsp)
leaq 0x60(,%rax,8), %rax
movq %rax, 0x10(%rsp)
cmpq %rbp, %r12
je 0xb990
movq %rbx, 0x40(%rsp)
movq %r14, 0x48(%rsp)
movq %r12, 0x50(%rsp)
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
movq 0x30(%rsp), %rdx
callq 0x17e76
testb %al, %al
jne 0xb9a1
cmpl $0x1, 0xc(%rsp)
jne 0xb906
movq %r12, %rdi
callq 0xa51c
jmp 0xb90e
movq %r12, %rdi
callq 0xa4e4
movq %rax, %r12
leaq 0x1cdf0(%rip), %rax     # 0x28708
cmpl $0x1, 0xc(%rsp)
jne 0xb926
leaq 0x1cdda(%rip), %rax     # 0x28700
movq (%rax), %rbp
testq %r12, %r12
jne 0xb979
movq (%r14,%r13), %r14
testq %r14, %r14
jne 0xb950
movq 0x18(%rsp), %rax
movq (%rbx,%rax), %rbx
testq %rbx, %rbx
cmoveq %rbp, %rbx
movq 0x10(%rsp), %rax
movq (%rbx,%rax), %r14
movq 0x30(%r14), %rdi
cmpl $0x1, 0xc(%rsp)
jne 0xb962
callq 0xa4d2
jmp 0xb967
callq 0x8e72
movq %rax, %r12
cmpq $0x0, 0x10(%r15)
jne 0xb929
cmpq 0x8(%r15), %r14
jne 0xb929
jmp 0xb990
movq 0x10(%r15), %rbp
testq %rbp, %rbp
jne 0xb8c3
cmpq 0x8(%r15), %r14
jne 0xb8c3
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x50(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rax, 0x10(%rcx)
movups 0x40(%rsp), %xmm0
movups %xmm0, (%rcx)
movb $0x1, %al
jmp 0xb992