// File: /workspace/github_c_makefile_star2_O1/baskerville[P]bspwm/src/history.c
// Function: history_add
void history_add(monitor_t *m, desktop_t *d, node_t *n, bool focused)
{
	if (!record_history) {
		return;
	}

	if (focused) {
		history_needle = NULL;
	}

	history_t *h = make_history(m, d, n);

	if (history_head == NULL) {
		history_head = history_tail = h;
	} else if ((n != NULL && history_tail->loc.node != n) || (n == NULL && d != history_tail->loc.desktop)) {
		history_t *ip = focused ? history_tail : NULL;

		for (history_t *hh = history_tail; hh != NULL; hh = hh->prev) {
			if ((n != NULL && hh->loc.node == n) || (n == NULL && d == hh->loc.desktop)) {
				hh->latest = false;
			}
			if (ip == NULL && ((n != NULL && hh->loc.desktop == d) || (n == NULL && hh->loc.monitor == m))) {
				ip = hh;
			}
		}

		if (ip != NULL) {
			history_insert_after(h, ip);
		} else {
			ip = history_head;
			if (n != NULL) {
				for (history_t *hh = history_head; hh != NULL; hh = hh->next) {
					if (hh->latest && hh->loc.monitor == m) {
						ip = hh;
						break;
					}
				}
			}
			history_insert_before(h, ip);
		}
	} else {
		free(h);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
leaq 0x1c34d(%rip), %rax     # 0x29768
cmpb $0x1, (%rax)
jne 0xd547
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
testb %bpl, %bpl
je 0xd442
leaq 0x1c2dd(%rip), %rax     # 0x29718
movq $0x0, (%rax)
movl $0x1, %edi
movl $0x30, %esi
callq 0x48b0
movq %rbx, (%rax)
movq %r15, 0x8(%rax)
movq %r14, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movb $0x1, 0x18(%rax)
leaq 0x1c2ba(%rip), %rcx     # 0x29728
movq (%rcx), %rdx
testq %rdx, %rdx
je 0xd53a
testq %r14, %r14
je 0xd498
leaq 0x1c29a(%rip), %rsi     # 0x29720
movq (%rsi), %rsi
cmpq %r14, 0x10(%rsi)
jne 0xd4ac
testq %r14, %r14
jne 0xd552
leaq 0x1c281(%rip), %rsi     # 0x29720
movq (%rsi), %rsi
cmpq %r15, 0x8(%rsi)
je 0xd552
leaq 0x1c26d(%rip), %rsi     # 0x29720
movq (%rsi), %rdi
xorl %r8d, %r8d
testb %bpl, %bpl
cmovneq %rdi, %r8
testq %rdi, %rdi
je 0xd50e
movq %rdi, %r9
testq %r14, %r14
je 0xd4d8
cmpq %r14, 0x10(%r9)
je 0xd4de
testq %r14, %r14
jne 0xd4e3
cmpq %r15, 0x8(%r9)
jne 0xd4e3
movb $0x0, 0x18(%r9)
testq %r8, %r8
jne 0xd505
testq %r14, %r14
je 0xd4f8
cmpq %r15, 0x8(%r9)
je 0xd502
testq %r14, %r14
jne 0xd4fd
cmpq %rbx, (%r9)
je 0xd502
xorl %r8d, %r8d
jmp 0xd505
movq %r9, %r8
movq 0x20(%r9), %r9
testq %r9, %r9
jne 0xd4c8
testq %r8, %r8
je 0xd564
movq 0x28(%r8), %rcx
movq %rcx, 0x28(%rax)
movq 0x28(%r8), %rcx
testq %rcx, %rcx
je 0xd528
movq %rax, 0x20(%rcx)
movq %rax, 0x28(%r8)
movq %r8, 0x20(%rax)
cmpq %r8, %rdi
jne 0xd547
movq %rax, (%rsi)
jmp 0xd547
leaq 0x1c1df(%rip), %rdx     # 0x29720
movq %rax, (%rdx)
movq %rax, (%rcx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4460
movq %rax, %rdi
addq $0x20, %rdi
movq %rdx, %rsi
testq %r14, %r14
je 0xd58d
movq %rdx, %rsi
cmpb $0x1, 0x18(%rsi)
jne 0xd581
cmpq %rbx, (%rsi)
je 0xd58d
movq 0x28(%rsi), %rsi
testq %rsi, %rsi
jne 0xd576
movq %rdx, %rsi
movq 0x20(%rsi), %r8
movq %r8, (%rdi)
movq 0x20(%rsi), %rdi
testq %rdi, %rdi
je 0xd5a1
movq %rax, 0x28(%rdi)
movq %rax, 0x20(%rsi)
movq %rsi, 0x28(%rax)
cmpq %rsi, %rdx
jne 0xd547
jmp 0xd544