// File: /workspace/github_c_makefile_star2_O3/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 0xa34e
leaq 0x1f3e8(%rip), %rax     # 0x29710
movq (%rax), %r14
testq %r14, %r14
jne 0xa33a
xorl %edi, %edi
callq 0xd8de
movq %rax, %r14
testq %r14, %r14
jne 0xa349
leaq 0x1f3c2(%rip), %rax     # 0x29708
movq (%rax), %r14
testq %r14, %r14
je 0xa3a9
testq %rbx, %rbx
jne 0xa377
movq 0x58(%r14), %rbx
testq %rbx, %rbx
jne 0xa377
movq %r14, %rdi
xorl %esi, %esi
callq 0xd8b2
movq %rax, %rbx
testq %rax, %rax
jne 0xa377
movq 0x60(%r14), %rbx
testq %rbx, %rbx
je 0xa3a9
movq %r12, %r15
testq %r12, %r12
je 0xa3b0
movq %r15, %rdi
callq 0x9943
testb %al, %al
je 0xa3a9
leaq 0x1f37e(%rip), %rax     # 0x29710
movq (%rax), %rax
testq %rax, %rax
je 0xa3a0
cmpq %rbx, 0x58(%rax)
jne 0xa3e5
cmpq $0x0, 0x48(%r15)
jne 0xa3ea
jmp 0xa3e5
xorl %ebx, %ebx
jmp 0xa6c9
cmpq $0x0, 0x30(%rbx)
je 0xa3e2
movq 0x38(%rbx), %r15
testq %r15, %r15
jne 0xa37f
movq %rbx, %rdi
xorl %esi, %esi
callq 0xd844
testq %rax, %rax
jne 0xa3dd
movq 0x30(%rbx), %rdi
callq 0x9c33
testq %rax, %rax
je 0xa3e2
movq %rax, %r15
jmp 0xa37f
xorl %r15d, %r15d
callq 0x11510
cmpl $0x0, 0x40(%r14)
je 0xa44d
movq 0x58(%r14), %rsi
testq %rsi, %rsi
sete %al
cmpq %rsi, %rbx
sete %cl
orb %al, %cl
jne 0xa44d
testq %r12, %r12
je 0xa427
movq 0x30(%rsi), %r8
movq %r14, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x9de8
testq %r15, %r15
jne 0xa44d
movq 0x38(%rbx), %r15
jmp 0xa44d
movq 0x38(%rsi), %r12
testq %r12, %r12
je 0xa40a
cmpb $0x1, 0x26(%r12)
jne 0xa40a
movq 0x30(%rsi), %r8
movq %r14, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x9de8
movq %r12, %r15
movq 0x38(%rbx), %rax
testq %rax, %rax
je 0xa469
cmpq %rax, %r15
je 0xa469
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x9c8d
testq %r15, %r15
je 0xa490
movq 0x48(%r15), %rax
testq %rax, %rax
je 0xa490
cmpb $0x1, 0x304(%rax)
jne 0xa490
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xa6da
leaq 0x1f279(%rip), %r12     # 0x29710
movq (%r12), %rax
cmpq %r14, %rax
je 0xa4eb
testq %rax, %rax
je 0xa4c4
movq 0x60(%rax), %r13
testq %r13, %r13
je 0xa4c4
movq 0x38(%r13), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0xff61
movq 0x48(%r13), %r13
jmp 0xa4a9
movq 0x60(%r14), %r13
testq %r13, %r13
je 0xa4eb
cmpq %rbx, %r13
je 0xa4e5
movq 0x38(%r13), %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xff61
movq 0x48(%r13), %r13
jmp 0xa4c8
movq 0x38(%rbx), %rax
cmpq %r15, %rax
je 0xa587
movq %rax, %rcx
testq %rcx, %rcx
je 0xa587
movq %rcx, %r13
movq 0x30(%rcx), %rcx
testq %rcx, %rcx
jne 0xa4fb
jmp 0xa527
movq 0x38(%r13), %rcx
testq %rcx, %rcx
je 0xa587
movq %rcx, %r13
movq 0x30(%rcx), %rcx
testq %rcx, %rcx
jne 0xa516
cmpq $0x0, 0x48(%r13)
je 0xa56b
testq %r15, %r15
je 0xa54e
cmpq %r15, %r13
je 0xa56b
movq %r13, %rcx
movq 0x40(%rcx), %rcx
cmpq %r15, %rcx
je 0xa549
testq %rcx, %rcx
jne 0xa53b
cmpq %r15, %rcx
je 0xa56b
movl (%r13), %ebp
xorl %edi, %edi
movl $0x1, %esi
callq 0x105ef
movl %ebp, %edi
movl %eax, %esi
callq 0x10619
movq 0x38(%rbx), %rax
movq %r13, %rcx
movq 0x40(%r13), %r13
testq %r13, %r13
je 0xa582
cmpq %rax, %rcx
je 0xa582
cmpq %rcx, 0x38(%r13)
je 0xa56b
cmpq %rax, %rcx
jne 0xa512
movq %r15, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xff61
cmpq (%r12), %r14
je 0xa5d8
movq %r14, (%r12)
leaq 0x1f852(%rip), %rax     # 0x29dfc
cmpb $0x1, (%rax)
jne 0xa5b8
movq 0x4c(%r14), %rdi
callq 0x11591
movl 0x20(%r14), %edx
leaq 0x15156(%rip), %rsi     # 0x1f719
movl $0x20, %edi
xorl %eax, %eax
callq 0x1e6b8
movq 0x58(%r14), %r12
movb $0x1, %bpl
jmp 0xa5e3
movq 0x58(%r14), %r12
cmpq %rbx, %r12
setne %bpl
cmpq %rbx, %r12
je 0xa605
movq %rbx, %rdi
callq 0x7b8b
movq %r15, %rdi
callq 0x1149a
movq 0x58(%r14), %rdi
callq 0x7b9a
movq %rbx, 0x58(%r14)
testb %bpl, %bpl
je 0xa629
callq 0x1db67
movl 0x20(%r14), %edx
movl 0x20(%rbx), %ecx
leaq 0x15112(%rip), %rsi     # 0x1f72f
movl $0x1000, %edi           # imm = 0x1000
xorl %eax, %eax
callq 0x1e6b8
movq %r15, 0x38(%rbx)
cmpq %rbx, %r12
jne 0xa63a
movq %r15, %rdi
callq 0x1149a
callq 0x1da82
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl $0x1, %ecx
callq 0xd4f6
movl $0x1, %edi
xorl %eax, %eax
callq 0x1e6b8
testq %r15, %r15
je 0xa6b6
movl 0x20(%r14), %edx
movl 0x20(%rbx), %ecx
movl (%r15), %r8d
leaq 0x150d8(%rip), %rsi     # 0x1f74c
movl $0x80000, %edi          # imm = 0x80000
xorl %eax, %eax
callq 0x1e6b8
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xd303
leaq 0x1f764(%rip), %rax     # 0x29dfb
cmpb $0x1, (%rax)
jne 0xa6b6
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x970b
movq %rax, %rdi
callq 0x11591
movb $0x1, %bl
jmp 0xa6c9
leaq 0x1f73d(%rip), %rax     # 0x29dfa
movb $0x1, %bl
cmpb $0x1, (%rax)
jne 0xa6c9
callq 0x1113f
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq