// File: /workspace/github_c_makefile_star2_O3/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 0x97a3
cmpl $0x2, %eax
jl 0xc4bc
movq 0x38(%rbx), %rax
movq 0x40(%rax), %rdx
testq %rdx, %rdx
je 0xc309
xorl %ecx, %ecx
cmpq %rax, 0x30(%rdx)
setne %cl
leaq 0x30(,%rcx,8), %rax
jmp 0xc30e
movl $0x38, %eax
movq %rax, 0x10(%rsp)
movq %r15, %rax
testl %ebp, %ebp
je 0xc32d
testq %rax, %rax
je 0xc395
movq %rax, %r12
movq 0x30(%rax), %rax
testq %rax, %rax
jne 0xc31a
jmp 0xc360
testq %rax, %rax
je 0xc443
movq %rax, %r12
movq 0x38(%rax), %rax
testq %rax, %rax
jne 0xc32d
jmp 0xc40e
movq 0x38(%r12), %rax
testq %rax, %rax
je 0xc395
movq %rax, %r12
movq 0x30(%rax), %rcx
movq %rcx, %rax
testq %rcx, %rcx
jne 0xc34c
movq 0x48(%r12), %rax
testq %rax, %rax
je 0xc377
cmpl $0x2, 0x308(%rax)
jb 0xc50d
movq %r12, %rax
movq 0x40(%r12), %r12
testq %r12, %r12
je 0xc390
cmpq %r15, %rax
je 0xc390
cmpq %rax, 0x38(%r12)
je 0xc377
cmpq %r15, %rax
jne 0xc347
movq %rdx, %rbp
xorl %r12d, %r12d
xorl %edi, %edi
movq %r15, %rsi
callq 0xac20
movq %rax, %r13
testq %rax, %rax
je 0xc49a
movl $0x0, (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r14, %rcx
movq %rbx, %r8
movq %r13, %r9
callq 0xbad5
movq %r13, %rdi
movq %r15, %rsi
callq 0xac20
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
callq 0xac20
movq %rax, %r13
testq %rax, %rax
jne 0xc3b1
jmp 0xc49a
movq 0x30(%r12), %rax
testq %rax, %rax
je 0xc443
movq %rax, %r12
movq 0x38(%rax), %rcx
movq %rcx, %rax
testq %rcx, %rcx
jne 0xc3fa
movq 0x48(%r12), %rax
testq %rax, %rax
je 0xc425
cmpl $0x2, 0x308(%rax)
jb 0xc518
movq %r12, %rax
movq 0x40(%r12), %r12
testq %r12, %r12
je 0xc43e
cmpq %r15, %rax
je 0xc43e
cmpq %rax, 0x30(%r12)
je 0xc425
cmpq %r15, %rax
jne 0xc3f5
movq %rdx, %rbp
xorl %r12d, %r12d
xorl %edi, %edi
movq %r15, %rsi
callq 0xac47
movq %rax, %r13
testq %rax, %rax
je 0xc49a
movl $0x0, (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rbx, %r8
movq %r12, %r9
callq 0xbad5
movq %r13, %rdi
movq %r15, %rsi
callq 0xac47
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
callq 0xac47
movq %rax, %r13
testq %rax, %rax
jne 0xc45b
testq %rbp, %rbp
je 0xc4bc
movq 0x10(%rsp), %rax
movq (%rbp,%rax), %rdx
testq %rdx, %rdx
je 0xc4bc
cmpq $0x0, 0x30(%rdx)
jne 0xc4bc
cmpq $0x0, 0x38(%rdx)
je 0xc4cb
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1d23e(%rip), %rax     # 0x29710
movq (%rax), %rax
cmpq %rbx, 0x58(%rax)
je 0xc4f4
movq %r14, %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9a3d
movq %r14, %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa308
movq %rdx, %rbp
movq %r12, %rdi
jmp 0xc39d
movq %rdx, %rbp
movq %r12, %rdi
jmp 0xc44b