// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movq %rcx, 0x18(%rsp)
movl %edx, %ebp
movq %rsi, %r14
movq (%rdi), %rbx
movq 0x8(%rdi), %r15
movq %rdi, (%rsp)
movq 0x10(%rdi), %r13
movq %r13, %rdi
cmpl $0x1, %edx
jne 0xc0fa
callq 0xaba9
movq %rax, %r12
movl $0x40, %eax
movl $0x70, %ecx
movl $0x68, %edx
jmp 0xc111
callq 0xab6c
movq %rax, %r12
movl $0x48, %eax
movl $0x78, %ecx
movl $0x60, %edx
cmpl $0x1, %ebp
movq %r14, 0x8(%rsp)
jne 0xc124
leaq 0x1d5de(%rip), %rsi     # 0x29700
jmp 0xc12b
leaq 0x1d5dd(%rip), %rsi     # 0x29708
movq (%rsi), %rsi
movq %r15, %r14
testq %r12, %r12
jne 0xc18a
movq (%r14,%rax), %r14
testq %r14, %r14
jne 0xc14e
movq (%rbx,%rcx), %rbx
testq %rbx, %rbx
cmoveq %rsi, %rbx
movq (%rbx,%rdx), %r14
movq 0x30(%r14), %rdi
cmpl $0x1, %ebp
jne 0xc16a
testq %rdi, %rdi
je 0xc17d
movq %rdi, %r12
movq 0x38(%rdi), %rdi
testq %rdi, %rdi
jne 0xc157
jmp 0xc180
testq %rdi, %rdi
je 0xc17d
movq %rdi, %r12
movq 0x30(%rdi), %rdi
testq %rdi, %rdi
jne 0xc16a
jmp 0xc180
xorl %r12d, %r12d
testq %r13, %r13
jne 0xc131
cmpq %r15, %r14
jne 0xc131
cmpq %r13, %r12
je 0xc292
xorl %eax, %eax
xorl %r15d, %r15d
cmpl $0x1, %ebp
sete %al
setne %r15b
shll $0x3, %r15d
leaq 0x40(%r15), %r9
orq $0x70, %r15
leaq 0x60(,%rax,8), %r13
movq (%rsp), %rsi
movq %r9, 0x10(%rsp)
movq %rbx, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %r12, 0x30(%rsp)
leaq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rdx
callq 0x191e4
testb %al, %al
jne 0xc2a3
movq %r12, %rdi
cmpl $0x1, %ebp
jne 0xc1f4
callq 0xaba9
jmp 0xc1f9
callq 0xab6c
movq %rax, %r12
movq (%rsp), %rsi
movq 0x10(%rsi), %rax
testq %r12, %r12
movq 0x10(%rsp), %r9
jne 0xc27e
leaq 0x1d4f3(%rip), %rcx     # 0x29708
cmpl $0x1, %ebp
jne 0xc221
leaq 0x1d4df(%rip), %rcx     # 0x29700
movq (%rcx), %rcx
movq (%r14,%r9), %r14
testq %r14, %r14
jne 0xc23c
movq (%rbx,%r15), %rbx
testq %rbx, %rbx
cmoveq %rcx, %rbx
movq (%rbx,%r13), %r14
movq 0x30(%r14), %rdx
cmpl $0x1, %ebp
jne 0xc258
testq %rdx, %rdx
je 0xc26b
movq %rdx, %r12
movq 0x38(%rdx), %rdx
testq %rdx, %rdx
jne 0xc245
jmp 0xc26e
testq %rdx, %rdx
je 0xc26b
movq %rdx, %r12
movq 0x30(%rdx), %rdx
testq %rdx, %rdx
jne 0xc258
jmp 0xc26e
xorl %r12d, %r12d
testq %rax, %rax
jne 0xc279
cmpq 0x8(%rsi), %r14
je 0xc292
testq %r12, %r12
je 0xc224
testq %rax, %rax
jne 0xc289
cmpq 0x8(%rsi), %r14
je 0xc292
cmpq %rax, %r12
jne 0xc1bf
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rax, 0x10(%rcx)
movups 0x20(%rsp), %xmm0
movups %xmm0, (%rcx)
movb $0x1, %al
jmp 0xc294