// File: /workspace/github_c_makefile_star2_O3/baskerville[P]bspwm/src/monitor.c
// Function: update_monitors
bool update_monitors(void)
{
	xcb_randr_get_screen_resources_reply_t *sres = xcb_randr_get_screen_resources_reply(dpy, xcb_randr_get_screen_resources(dpy, root), NULL);
	if (sres == NULL) {
		return false;
	}

	monitor_t *last_wired = NULL;

	int len = xcb_randr_get_screen_resources_outputs_length(sres);
	xcb_randr_output_t *outputs = xcb_randr_get_screen_resources_outputs(sres);

	xcb_randr_get_output_info_cookie_t cookies[len];
	for (int i = 0; i < len; i++) {
		cookies[i] = xcb_randr_get_output_info(dpy, outputs[i], XCB_CURRENT_TIME);
	}

	for (monitor_t *m = mon_head; m != NULL; m = m->next) {
		m->wired = false;
	}

	for (int i = 0; i < len; i++) {
		xcb_randr_get_output_info_reply_t *info = xcb_randr_get_output_info_reply(dpy, cookies[i], NULL);
		if (info != NULL) {
			if (info->crtc != XCB_NONE) {
				xcb_randr_get_crtc_info_reply_t *cir = xcb_randr_get_crtc_info_reply(dpy, xcb_randr_get_crtc_info(dpy, info->crtc, XCB_CURRENT_TIME), NULL);
				if (cir != NULL) {
					xcb_rectangle_t rect = (xcb_rectangle_t) {cir->x, cir->y, cir->width, cir->height};
					last_wired = get_monitor_by_randr_id(outputs[i]);
					if (last_wired != NULL) {
						update_root(last_wired, &rect);
						last_wired->wired = true;
					} else {
						char *name = (char *) xcb_randr_get_output_info_name(info);
						size_t len = (size_t) xcb_randr_get_output_info_name_length(info);
						char *name_copy = copy_string(name, len);
						last_wired = make_monitor(name_copy, &rect, XCB_NONE);
						free(name_copy);
						last_wired->randr_id = outputs[i];
						add_monitor(last_wired);
					}
				}
				free(cir);
			} else if (!remove_disabled_monitors && info->connection != XCB_RANDR_CONNECTION_DISCONNECTED) {
				monitor_t *m = get_monitor_by_randr_id(outputs[i]);
				if (m != NULL) {
					m->wired = true;
				}
			}
		}
		free(info);
	}

	xcb_randr_get_output_primary_reply_t *gpo = xcb_randr_get_output_primary_reply(dpy, xcb_randr_get_output_primary(dpy, root), NULL);
	if (gpo != NULL) {
		pri_mon = get_monitor_by_randr_id(gpo->output);
	}
	free(gpo);

	/* handle overlapping monitors */
	if (merge_overlapping_monitors) {
		monitor_t *m = mon_head;
		while (m != NULL) {
			monitor_t *next = m->next;
			if (m->wired) {
				monitor_t *mb = mon_head;
				while (mb != NULL) {
					monitor_t *mb_next = mb->next;
					if (m != mb && mb->wired && contains(m->rectangle, mb->rectangle)) {
						if (last_wired == mb) {
							last_wired = m;
						}
						if (next == mb) {
							next = mb_next;
						}
						merge_monitors(mb, m);
						remove_monitor(mb);
					}
					mb = mb_next;
				}
			}
			m = next;
		}
	}

	/* merge and remove disconnected monitors */
	if (remove_unplugged_monitors) {
		monitor_t *m = mon_head;
		while (m != NULL) {
			monitor_t *next = m->next;
			if (!m->wired) {
				merge_monitors(m, last_wired);
				remove_monitor(m);
			}
			m = next;
		}
	}

	/* add one desktop to each new monitor */
	for (monitor_t *m = mon_head; m != NULL; m = m->next) {
		if (m->desk == NULL) {
			add_desktop(m, make_desktop(NULL, XCB_NONE));
		}
	}

	if (!running && mon != NULL) {
		if (pri_mon != NULL) {
			mon = pri_mon;
		}
		center_pointer(mon->rectangle);
		ewmh_update_current_desktop();
	}

	free(sres);

	return (mon != NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
leaq 0x21fe0(%rip), %r12     # 0x296c8
movq (%r12), %r14
leaq 0x22085(%rip), %rax     # 0x29778
movl (%rax), %esi
movq %r14, %rdi
callq 0x42f0
xorl %ebx, %ebx
movq %r14, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x4330
testq %rax, %rax
je 0x7aa3
movq %rax, %r14
movq %rax, %rdi
callq 0x45d0
movl %eax, %ebx
movq %r14, -0x50(%rbp)
movq %r14, %rdi
callq 0x4170
movq %rax, %r15
movq %rsp, -0x48(%rbp)
movl %ebx, %r13d
movq %rsp, %r14
leaq 0xf(,%r13,4), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
testl %ebx, %ebx
jle 0x776d
xorl %ebx, %ebx
movq (%r12), %rdi
movl (%r15,%rbx,4), %esi
xorl %edx, %edx
callq 0x46e0
movl %eax, (%r14,%rbx,4)
incq %rbx
cmpq %rbx, %r13
jne 0x7752
movq %r14, -0x38(%rbp)
leaq 0x21f90(%rip), %rax     # 0x29708
movq (%rax), %rax
testq %rax, %rax
je 0x778a
movb $0x0, 0x2c(%rax)
movq 0x78(%rax), %rax
jmp 0x777b
testl %r13d, %r13d
movq -0x38(%rbp), %rbx
jle 0x78f2
movq %r15, -0x30(%rbp)
xorl %r15d, %r15d
xorl %r14d, %r14d
movq %r13, -0x58(%rbp)
movq (%r12), %rdi
movl (%rbx,%r15,4), %esi
xorl %edx, %edx
callq 0x4340
movq %rax, %r13
testq %rax, %rax
je 0x78d2
movl 0xc(%r13), %esi
testl %esi, %esi
je 0x787b
movq (%r12), %rbx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x4430
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x45e0
movq %rax, %rbx
testq %rax, %rax
je 0x78c6
movq 0xc(%rbx), %rax
movq %rax, -0x40(%rbp)
leaq 0x21f07(%rip), %rax     # 0x29708
movq (%rax), %r14
testq %r14, %r14
je 0x7824
movq -0x30(%rbp), %rax
movl (%rax,%r15,4), %eax
cmpl %eax, 0x24(%r14)
je 0x78b5
movq 0x78(%r14), %r14
testq %r14, %r14
jne 0x7811
movq %r13, %rdi
callq 0x4630
movq %rax, %r14
movq %r13, %rdi
callq 0x4500
movslq %eax, %rsi
movq %r14, %rdi
callq 0x5e2f
movq %rax, %r12
movq %rax, %rdi
leaq -0x40(%rbp), %rsi
xorl %edx, %edx
callq 0x6a8c
movq %rax, %r14
movq %r12, %rdi
leaq 0x21e68(%rip), %r12     # 0x296c8
callq 0x4460
movq -0x30(%rbp), %rax
movl (%rax,%r15,4), %eax
movl %eax, 0x24(%r14)
movq %r14, %rdi
callq 0x7186
jmp 0x78c6
leaq 0x2258a(%rip), %rax     # 0x29e0c
cmpb $0x0, (%rax)
jne 0x78d2
cmpb $0x1, 0x18(%r13)
je 0x78d2
leaq 0x21e73(%rip), %rax     # 0x29708
movq (%rax), %rax
testq %rax, %rax
je 0x78d2
movq -0x30(%rbp), %rcx
movl (%rcx,%r15,4), %ecx
cmpl %ecx, 0x24(%rax)
je 0x78ec
movq 0x78(%rax), %rax
testq %rax, %rax
jne 0x78a5
jmp 0x78d2
movq %r14, %rdi
leaq -0x40(%rbp), %rsi
callq 0x6b6f
movb $0x1, 0x2c(%r14)
movq %rbx, %rdi
callq 0x4460
movq -0x38(%rbp), %rbx
movq %r13, %rdi
callq 0x4460
incq %r15
movq -0x58(%rbp), %r13
cmpq %r13, %r15
jne 0x77a5
jmp 0x78f5
movb $0x1, 0x2c(%rax)
jmp 0x78d2
xorl %r14d, %r14d
movq (%r12), %rbx
leaq 0x21e78(%rip), %rax     # 0x29778
movl (%rax), %esi
movq %rbx, %rdi
callq 0x4650
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x4210
testq %rax, %rax
je 0x7947
leaq 0x21de6(%rip), %rcx     # 0x29708
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x793b
movl 0x8(%rax), %edx
cmpl %edx, 0x24(%rcx)
je 0x793d
movq 0x78(%rcx), %rcx
testq %rcx, %rcx
jne 0x792d
xorl %ecx, %ecx
leaq 0x21db4(%rip), %rdx     # 0x296f8
movq %rcx, (%rdx)
movq %rax, %rdi
callq 0x4460
leaq 0x224b8(%rip), %rax     # 0x29e0e
leaq 0x21dab(%rip), %rcx     # 0x29708
movq (%rcx), %r15
testq %r15, %r15
setne %cl
andb (%rax), %cl
cmpb $0x1, %cl
jne 0x79df
movq 0x78(%r15), %r12
cmpb $0x1, 0x2c(%r15)
jne 0x79cd
leaq 0x21d89(%rip), %rax     # 0x29708
movq (%rax), %r13
testq %r13, %r13
je 0x79cd
movq %r13, %rbx
movq 0x78(%r13), %r13
cmpq %rbx, %r15
je 0x7982
cmpb $0x1, 0x2c(%rbx)
jne 0x7982
movq 0x4c(%r15), %rdi
movq 0x4c(%rbx), %rsi
callq 0x610b
testb %al, %al
je 0x7982
cmpq %rbx, %r14
cmoveq %r15, %r14
cmpq %rbx, %r12
cmoveq %r13, %r12
movq %rbx, %rdi
movq %r15, %rsi
callq 0x7350
movq %rbx, %rdi
callq 0x72d2
jmp 0x7982
movq %r12, %r15
testq %r12, %r12
jne 0x796d
leaq 0x21d2c(%rip), %rax     # 0x29708
movq (%rax), %r15
leaq 0x22427(%rip), %rax     # 0x29e0d
testq %r15, %r15
setne %cl
andb (%rax), %cl
cmpb $0x1, %cl
jne 0x7a23
movq 0x78(%r15), %rbx
cmpb $0x0, 0x2c(%r15)
jne 0x7a11
movq %r15, %rdi
movq %r14, %rsi
callq 0x7350
movq %r15, %rdi
callq 0x72d2
movq %rbx, %r15
testq %rbx, %rbx
jne 0x79f3
leaq 0x21ce8(%rip), %rax     # 0x29708
movq (%rax), %r15
testq %r15, %r15
movq -0x50(%rbp), %r14
je 0x7a50
cmpq $0x0, 0x58(%r15)
jne 0x7a47
xorl %edi, %edi
xorl %esi, %esi
callq 0x813c
movq %r15, %rdi
movq %rax, %rsi
callq 0x822e
movq 0x78(%r15), %r15
testq %r15, %r15
jne 0x7a2c
leaq 0x21c79(%rip), %rcx     # 0x296d0
leaq 0x21cb2(%rip), %rbx     # 0x29710
movq (%rbx), %rax
testq %rax, %rax
sete %dl
orb (%rcx), %dl
jne 0x7a90
leaq 0x21c86(%rip), %rcx     # 0x296f8
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x7a7f
movq %rcx, (%rbx)
jmp 0x7a82
movq %rax, %rcx
movq 0x4c(%rcx), %rdi
callq 0x11591
callq 0x1db67
movq %r14, %rdi
callq 0x4460
cmpq $0x0, (%rbx)
setne %bl
movq -0x48(%rbp), %rsp
movl %ebx, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq