// File: /workspace/github_c_makefile_star2_O1/baskerville[P]bspwm/src/tree.c
// Function: circulate_leaves
void circulate_leaves(monitor_t *m, desktop_t *d, node_t *n, circulate_dir_t dir)
{
	if (tiled_count(n, false) < 2) {
		return;
	}
	node_t *p = d->focus->parent;
	bool focus_first_child = is_first_child(d->focus);
	if (dir == CIRCULATE_FORWARD) {
		node_t *e = second_extrema(n);
		while (e != NULL && (e->client == NULL || !IS_TILED(e->client))) {
			e = prev_leaf(e, n);
		}
		for (node_t *s = e, *f = prev_tiled_leaf(s, n); f != NULL; s = prev_tiled_leaf(f, n), f = prev_tiled_leaf(s, n)) {
			swap_nodes(m, d, f, m, d, s, false);
		}
	} else {
		node_t *e = first_extrema(n);
		while (e != NULL && (e->client == NULL || !IS_TILED(e->client))) {
			e = next_leaf(e, n);
		}
		for (node_t *f = e, *s = next_tiled_leaf(f, n); s != NULL; f = next_tiled_leaf(s, n), s = next_tiled_leaf(f, n)) {
			swap_nodes(m, d, f, m, d, s, false);
		}
	}
	if (p != NULL) {
		node_t *f = focus_first_child ? p->first_child : p->second_child;
		if (is_leaf(f)) {
			if (d == mon->desk) {
				focus_node(m, d, f);
			} else {
				activate_node(m, d, f);
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movq %rdx, %rdi
xorl %esi, %esi
callq 0x98c5
cmpl $0x2, %eax
jl 0xc42b
movq 0x38(%rbx), %rax
movq 0x40(%rax), %rsi
testq %rax, %rax
sete %cl
testq %rsi, %rsi
sete %dl
orb %cl, %dl
movl $0x38, %ecx
jne 0xc2ec
xorl %ecx, %ecx
cmpq %rax, 0x30(%rsi)
setne %cl
leaq 0x30(,%rcx,8), %rcx
movq %rcx, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movq %r15, %rdi
testl %ebp, %ebp
je 0xc386
callq 0x92fd
movq %rax, %r12
testq %rax, %rax
je 0xc32e
movq 0x48(%r12), %rax
testq %rax, %rax
je 0xc321
cmpl $0x2, 0x308(%rax)
jb 0xc32e
movq %r12, %rdi
movq %r15, %rsi
callq 0x9363
jmp 0xc306
movq %r12, %rdi
movq %r15, %rsi
callq 0xac2b
testq %rax, %rax
je 0xc405
movq %rax, %r13
movl $0x0, (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r14, %rcx
movq %rbx, %r8
movq %r13, %r9
callq 0xba8a
movq %r13, %rdi
movq %r15, %rsi
callq 0xac2b
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
callq 0xac2b
movq %rax, %r13
testq %rax, %rax
jne 0xc345
jmp 0xc405
callq 0xab18
movq %rax, %r12
testq %rax, %rax
je 0xc3b3
movq 0x48(%r12), %rax
testq %rax, %rax
je 0xc3a6
cmpl $0x2, 0x308(%rax)
jb 0xc3b3
movq %r12, %rdi
movq %r15, %rsi
callq 0xabe9
jmp 0xc38b
movq %r12, %rdi
movq %r15, %rsi
callq 0xac51
testq %rax, %rax
je 0xc405
movq %rax, %r13
movl $0x0, (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rbx, %r8
movq %r12, %r9
callq 0xba8a
movq %r13, %rdi
movq %r15, %rsi
callq 0xac51
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
callq 0xac51
movq %rax, %r13
testq %rax, %rax
jne 0xc3c6
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0xc42b
movq 0x8(%rsp), %rcx
movq (%rax,%rcx), %rdx
testq %rdx, %rdx
je 0xc42b
cmpq $0x0, 0x30(%rdx)
jne 0xc42b
cmpq $0x0, 0x38(%rdx)
je 0xc43a
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1d2cf(%rip), %rax     # 0x29710
movq (%rax), %rax
cmpq %rbx, 0x58(%rax)
je 0xc463
movq %r14, %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9af5
movq %r14, %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa2cd