// File: /workspace/github_c_makefile_star2_O1/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, 0x50(%rsp)
movq %rsi, 0x40(%rsp)
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 0xc0b9
callq 0xab8b
movq %rax, %r12
movl $0x40, %r13d
movl $0x70, %eax
movq %rax, 0x10(%rsp)
movl $0x68, %eax
jmp 0xc0d6
callq 0xab2d
movq %rax, %r12
movl $0x48, %r13d
movl $0x78, %eax
movq %rax, 0x10(%rsp)
movl $0x60, %eax
movq %rax, 0x20(%rsp)
cmpl $0x1, 0xc(%rsp)
jne 0xc0eb
leaq 0x1d617(%rip), %rax     # 0x29700
jmp 0xc0f2
leaq 0x1d616(%rip), %rax     # 0x29708
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x18(%rsp), %r14
testq %r12, %r12
jne 0xc14e
movq (%r14,%r13), %r14
testq %r14, %r14
jne 0xc128
movq 0x10(%rsp), %rax
movq (%rbx,%rax), %rbx
testq %rbx, %rbx
cmoveq 0x48(%rsp), %rbx
movq 0x20(%rsp), %rax
movq (%rbx,%rax), %r14
movq 0x30(%r14), %rdi
cmpl $0x1, 0xc(%rsp)
jne 0xc13a
callq 0xab18
jmp 0xc13f
callq 0x92fd
movq %rax, %r12
testq %rbp, %rbp
jne 0xc0ff
cmpq 0x18(%rsp), %r14
jne 0xc0ff
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)
leaq 0x28(%rsp), %rbp
cmpq 0x10(%r15), %r12
je 0xc27d
movq %rbx, 0x28(%rsp)
movq %r14, 0x30(%rsp)
movq %r12, 0x38(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
movq 0x50(%rsp), %rdx
callq 0x192cf
testb %al, %al
je 0xc1cc
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rax, 0x10(%rcx)
movups 0x28(%rsp), %xmm0
movups %xmm0, (%rcx)
movl $0x1, %eax
jmp 0xc267
cmpl $0x1, 0xc(%rsp)
jne 0xc1dd
movq %r12, %rdi
callq 0xab8b
jmp 0xc1e5
movq %r12, %rdi
callq 0xab2d
movq %rax, %r12
testq %rax, %rax
jne 0xc253
leaq 0x1d514(%rip), %rax     # 0x29708
cmpl $0x1, 0xc(%rsp)
jne 0xc202
leaq 0x1d4fe(%rip), %rax     # 0x29700
movq (%rax), %rbp
movq (%r14,%r13), %r14
testq %r14, %r14
jne 0xc227
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 0xc239
callq 0xab18
jmp 0xc23e
callq 0x92fd
movq %rax, %r12
cmpq $0x0, 0x10(%r15)
jne 0xc24e
cmpq 0x8(%r15), %r14
je 0xc253
testq %r12, %r12
je 0xc205
cmpq $0x0, 0x10(%r15)
jne 0xc260
cmpq 0x8(%r15), %r14
je 0xc271
xorl %eax, %eax
leaq 0x28(%rsp), %rbp
testl %eax, %eax
je 0xc17f
jmp 0xc278
movl $0x5, %eax
jmp 0xc262
cmpl $0x5, %eax
jne 0xc281
xorl %eax, %eax
jmp 0xc283
movb $0x1, %al
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq