// File: /workspace/github_c_makefile_star2_O1/baskerville[P]bspwm/src/tree.c
// Function: focus_node
bool focus_node(monitor_t *m, desktop_t *d, node_t *n)
{
	if (m == NULL) {
		m = mon;
		if (m == NULL) {
			m = history_last_monitor(NULL);
		}
		if (m == NULL) {
			m = mon_head;
		}
	}

	if (m == NULL) {
		return false;
	}

	if (d == NULL) {
		d = m->desk;
		if (d == NULL) {
			d = history_last_desktop(m, NULL);
		}
		if (d == NULL) {
			d = m->desk_head;
		}
	}

	if (d == NULL) {
		return false;
	}

	bool guess = (n == NULL);

	if (n == NULL && d->root != NULL) {
		n = d->focus;
		if (n == NULL) {
			n = history_last_node(d, NULL);
		}
		if (n == NULL) {
			n = first_focusable_leaf(d->root);
		}
	}

	if (n != NULL && !is_focusable(n)) {
		return false;
	}

	if ((mon != NULL && mon->desk != d) || n == NULL || n->client == NULL) {
		clear_input_focus();
	}

	if (m->sticky_count > 0 && m->desk != NULL && d != m->desk) {
		if (guess && m->desk->focus != NULL && m->desk->focus->sticky) {
			n = m->desk->focus;
		}

		transfer_sticky_nodes(m, m->desk, m, d, m->desk->root);

		if (n == NULL && d->focus != NULL) {
			n = d->focus;
		}
	}

	if (d->focus != NULL && n != d->focus) {
		neutralize_occluding_windows(m, d, n);
	}

	if (n != NULL && n->client != NULL && n->client->urgent) {
		set_urgent(m, d, n, false);
	}

	if (mon != m) {
		if (mon != NULL) {
			for (desktop_t *e = mon->desk_head; e != NULL; e = e->next) {
				draw_border(e->focus, true, false);
			}
		}
		for (desktop_t *e = m->desk_head; e != NULL; e = e->next) {
			if (e == d) {
				continue;
			}
			draw_border(e->focus, true, true);
		}
	}

	if (d->focus != n) {
		for (node_t *f = first_extrema(d->focus); f != NULL; f = next_leaf(f, d->focus)) {
			if (f->client != NULL && !is_descendant(f, n)) {
				window_draw_border(f->id, get_border_color(false, true));
			}
		}
	}

	draw_border(n, true, true);

	bool desk_changed = (m != mon || m->desk != d);
	bool has_input_focus = false;

	if (mon != m) {
		mon = m;

		if (pointer_follows_monitor) {
			center_pointer(m->rectangle);
		}

		put_status(SBSC_MASK_MONITOR_FOCUS, "monitor_focus 0x%08X\n", m->id);
	}

	if (m->desk != d) {
		show_desktop(d);
		set_input_focus(n);
		has_input_focus = true;
		hide_desktop(m->desk);
		m->desk = d;
	}

	if (desk_changed) {
		ewmh_update_current_desktop();
		put_status(SBSC_MASK_DESKTOP_FOCUS, "desktop_focus 0x%08X 0x%08X\n", m->id, d->id);
	}

	d->focus = n;
	if (!has_input_focus) {
		set_input_focus(n);
	}
	ewmh_update_active_window();
	history_add(m, d, n, true);

	put_status(SBSC_MASK_REPORT);

	if (n == NULL) {
		if (focus_follows_pointer) {
			update_motion_recorder();
		}
		return true;
	}

	put_status(SBSC_MASK_NODE_FOCUS, "node_focus 0x%08X 0x%08X 0x%08X\n", m->id, d->id, n->id);

	stack(d, n, true);

	if (pointer_follows_focus) {
		center_pointer(get_rectangle(m, d, n));
	} else if (focus_follows_pointer) {
		update_motion_recorder();
	}

	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r14
testq %rdi, %rdi
jne 0xa30e
leaq 0x1f423(%rip), %rax     # 0x29710
movq (%rax), %r14
testq %r14, %r14
jne 0xa2ff
xorl %edi, %edi
callq 0xd831
movq %rax, %r14
testq %r14, %r14
jne 0xa30e
leaq 0x1f3fd(%rip), %rax     # 0x29708
movq (%rax), %r14
testq %r14, %r14
je 0xa372
testq %rbx, %rbx
jne 0xa337
movq 0x58(%r14), %rbx
testq %rbx, %rbx
jne 0xa32e
movq %r14, %rdi
xorl %esi, %esi
callq 0xd805
movq %rax, %rbx
testq %rbx, %rbx
jne 0xa337
movq 0x60(%r14), %rbx
testq %rbx, %rbx
je 0xa372
movq %r12, %r15
testq %r12, %r12
je 0xa385
testq %r15, %r15
je 0xa355
movq %r15, %rdi
callq 0x9a26
testb %al, %al
je 0xa372
leaq 0x1f3b4(%rip), %r13     # 0x29710
movq (%r13), %rax
testq %rax, %rax
je 0xa3b9
testq %r15, %r15
je 0xa3c5
cmpq %rbx, 0x58(%rax)
je 0xa3be
jmp 0xa3c5
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0x30(%rbx)
je 0xa670
movq 0x38(%rbx), %r15
testq %r15, %r15
jne 0xa3a6
movq %rbx, %rdi
xorl %esi, %esi
callq 0xd797
movq %rax, %r15
testq %r15, %r15
jne 0xa344
movq 0x30(%rbx), %rdi
callq 0x9cae
movq %rax, %r15
jmp 0xa344
testq %r15, %r15
je 0xa3c5
cmpq $0x0, 0x48(%r15)
jne 0xa3ca
callq 0x11504
cmpl $0x0, 0x40(%r14)
je 0xa416
movq 0x58(%r14), %rsi
testq %rsi, %rsi
sete %al
cmpq %rsi, %rbx
sete %cl
orb %al, %cl
jne 0xa416
testq %r12, %r12
jne 0xa3fb
movq 0x38(%rsi), %rax
testq %rax, %rax
je 0xa3fb
cmpb $0x0, 0x26(%rax)
cmovneq %rax, %r15
movq 0x30(%rsi), %r8
movq %r14, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x9dd4
testq %r15, %r15
jne 0xa416
movq 0x38(%rbx), %r15
movq 0x38(%rbx), %rax
testq %rax, %rax
je 0xa432
cmpq %rax, %r15
je 0xa432
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x9cd8
testq %r15, %r15
je 0xa459
movq 0x48(%r15), %rax
testq %rax, %rax
je 0xa459
cmpb $0x1, 0x304(%rax)
jne 0xa459
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xa678
movq (%r13), %rax
cmpq %r14, %rax
je 0xa4b1
testq %rax, %rax
je 0xa488
movq 0x60(%rax), %r12
testq %r12, %r12
je 0xa488
movq 0x38(%r12), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0xff0c
movq 0x48(%r12), %r12
jmp 0xa46b
movq 0x60(%r14), %r12
testq %r12, %r12
je 0xa4b1
cmpq %rbx, %r12
je 0xa4aa
movq 0x38(%r12), %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xff0c
movq 0x48(%r12), %r12
jmp 0xa48c
movq 0x38(%rbx), %rdi
cmpq %r15, %rdi
je 0xa51f
callq 0x92fd
testq %rax, %rax
je 0xa51f
movq %rax, %r12
cmpq $0x0, 0x48(%r12)
je 0xa50b
testq %r15, %r15
je 0xa4f2
movq %r12, %rax
cmpq %r15, %r12
je 0xa4ed
movq %r12, %rax
movq 0x40(%rax), %rax
cmpq %r15, %rax
je 0xa4ed
testq %rax, %rax
jne 0xa4df
cmpq %r15, %rax
je 0xa50b
movl (%r12), %ebp
xorl %edi, %edi
movl $0x1, %esi
callq 0x1056b
movl %ebp, %edi
movl %eax, %esi
callq 0x10595
movq 0x38(%rbx), %rsi
movq %r12, %rdi
callq 0x9363
movq %rax, %r12
testq %rax, %rax
jne 0xa4c7
movq %r15, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xff0c
movq (%r13), %rax
movb $0x1, %bpl
cmpq %rax, %r14
jne 0xa545
cmpq %rbx, 0x58(%r14)
setne %bpl
cmpq %rax, %r14
je 0xa57a
movq %r14, (%r13)
leaq 0x1f8a7(%rip), %rax     # 0x29dfc
cmpb $0x1, (%rax)
jne 0xa563
movq 0x4c(%r14), %rdi
callq 0x1158c
movl 0x20(%r14), %edx
leaq 0x151bb(%rip), %rsi     # 0x1f729
movl $0x20, %edi
xorl %eax, %eax
callq 0x1eb0b
movq 0x58(%r14), %r12
cmpq %rbx, %r12
je 0xa5a0
movq %rbx, %rdi
callq 0x7cbf
movq %r15, %rdi
callq 0x1148e
movq 0x58(%r14), %rdi
callq 0x7cce
movq %rbx, 0x58(%r14)
testb %bpl, %bpl
je 0xa5c4
callq 0x1df11
movl 0x20(%r14), %edx
movl 0x20(%rbx), %ecx
leaq 0x15187(%rip), %rsi     # 0x1f73f
movl $0x1000, %edi           # imm = 0x1000
xorl %eax, %eax
callq 0x1eb0b
movq %r15, 0x38(%rbx)
cmpq %rbx, %r12
jne 0xa5d5
movq %r15, %rdi
callq 0x1148e
callq 0x1ddf2
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl $0x1, %ecx
callq 0xd40d
movl $0x1, %edi
xorl %eax, %eax
callq 0x1eb0b
testq %r15, %r15
je 0xa654
movl 0x20(%r14), %edx
movl 0x20(%rbx), %ecx
movl (%r15), %r8d
leaq 0x1514d(%rip), %rsi     # 0x1f75c
movl $0x80000, %edi          # imm = 0x80000
xorl %eax, %eax
callq 0x1eb0b
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xd20e
leaq 0x1f7c9(%rip), %rax     # 0x29dfb
cmpb $0x1, (%rax)
jne 0xa654
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x982d
movq %rax, %rdi
callq 0x1158c
movb $0x1, %bl
jmp 0xa374
leaq 0x1f79f(%rip), %rax     # 0x29dfa
movb $0x1, %bl
cmpb $0x1, (%rax)
jne 0xa374
callq 0x1112d
jmp 0xa374
xorl %r15d, %r15d
jmp 0xa344