// File: /workspace/github_c_makefile_star2_O1/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 0x21ed5(%rip), %r12     # 0x296c8
movq (%r12), %r14
leaq 0x21f7a(%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 0x7bd5
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
movl %ebx, %ecx
movq %rsp, %rbx
leaq 0xf(,%r13,4), %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
movl %ecx, -0x30(%rbp)
testl %ecx, %ecx
jle 0x787e
xorl %r14d, %r14d
movq (%r12), %rdi
movl (%r15,%r14,4), %esi
xorl %edx, %edx
callq 0x46e0
movl %eax, (%rbx,%r14,4)
incq %r14
cmpq %r14, %r13
jne 0x7863
movq %rbx, -0x40(%rbp)
leaq 0x21e7f(%rip), %rax     # 0x29708
movq (%rax), %rax
testq %rax, %rax
je 0x789b
movb $0x0, 0x2c(%rax)
movq 0x78(%rax), %rax
jmp 0x788c
cmpl $0x0, -0x30(%rbp)
jle 0x7a2b
movq %r15, -0x30(%rbp)
xorl %r15d, %r15d
xorl %r14d, %r14d
movq -0x40(%rbp), %rbx
movq %r13, -0x58(%rbp)
movq (%r12), %rdi
movl (%rbx,%r15,4), %esi
xorl %edx, %edx
callq 0x4340
movq %rax, %r13
testq %rax, %rax
je 0x7a11
movl 0xc(%r13), %esi
testl %esi, %esi
je 0x7965
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 0x7a05
movzwl 0xc(%rbx), %eax
movw %ax, -0x38(%rbp)
movzwl 0xe(%rbx), %eax
movw %ax, -0x36(%rbp)
movzwl 0x10(%rbx), %eax
movw %ax, -0x34(%rbp)
movzwl 0x12(%rbx), %eax
movw %ax, -0x32(%rbp)
leaq 0x21ddd(%rip), %rax     # 0x29708
movq (%rax), %r14
testq %r14, %r14
je 0x794a
movq -0x30(%rbp), %rax
movl (%rax,%r15,4), %eax
cmpl %eax, 0x24(%r14)
je 0x794a
movq 0x78(%r14), %r14
testq %r14, %r14
jne 0x793b
testq %r14, %r14
je 0x79b0
movq %r14, %rdi
leaq -0x38(%rbp), %rsi
callq 0x6c4e
movb $0x1, 0x2c(%r14)
jmp 0x7a05
leaq 0x224a0(%rip), %rax     # 0x29e0c
cmpb $0x0, (%rax)
jne 0x7a11
cmpb $0x1, 0x18(%r13)
je 0x7a11
leaq 0x21d81(%rip), %rax     # 0x29708
movq (%rax), %rax
testq %rax, %rax
je 0x79a5
movq -0x30(%rbp), %rcx
movl (%rcx,%r15,4), %ecx
cmpl %ecx, 0x24(%rax)
je 0x79a5
movq 0x78(%rax), %rax
testq %rax, %rax
jne 0x7997
testq %rax, %rax
je 0x7a11
movb $0x1, 0x2c(%rax)
jmp 0x7a11
movq %r13, %rdi
callq 0x4630
movq %rax, %r14
movq %r13, %rdi
callq 0x4500
movslq %eax, %rsi
movq %r14, %rdi
callq 0x5e6e
movq %rax, %r12
movq %rax, %rdi
leaq -0x38(%rbp), %rsi
xorl %edx, %edx
callq 0x6b68
movq %rax, %r14
movq %r12, %rdi
leaq 0x21cdc(%rip), %r12     # 0x296c8
callq 0x4460
movq -0x30(%rbp), %rax
movl (%rax,%r15,4), %eax
movl %eax, 0x24(%r14)
movq %r14, %rdi
callq 0x7261
movq %rbx, %rdi
callq 0x4460
movq -0x40(%rbp), %rbx
movq %r13, %rdi
callq 0x4460
incq %r15
movq -0x58(%rbp), %r13
cmpq %r13, %r15
jne 0x78b7
jmp 0x7a2e
xorl %r14d, %r14d
movq (%r12), %rbx
leaq 0x21d3f(%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 0x7a7e
leaq 0x21cad(%rip), %rcx     # 0x29708
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x7a74
movl 0x8(%rax), %edx
cmpl %edx, 0x24(%rcx)
je 0x7a74
movq 0x78(%rcx), %rcx
testq %rcx, %rcx
jne 0x7a66
leaq 0x21c7d(%rip), %rdx     # 0x296f8
movq %rcx, (%rdx)
movq %rax, %rdi
callq 0x4460
leaq 0x22381(%rip), %rax     # 0x29e0e
leaq 0x21c74(%rip), %rcx     # 0x29708
movq (%rcx), %rbx
testq %rbx, %rbx
setne %cl
andb (%rax), %cl
cmpb $0x1, %cl
jne 0x7b0c
movq 0x78(%rbx), %r12
cmpb $0x1, 0x2c(%rbx)
jne 0x7b04
leaq 0x21c53(%rip), %rax     # 0x29708
movq (%rax), %r13
testq %r13, %r13
je 0x7b04
movq %r13, %r15
movq 0x78(%r13), %r13
cmpq %r15, %rbx
je 0x7ab8
cmpb $0x1, 0x2c(%r15)
jne 0x7ab8
movq 0x4c(%rbx), %rdi
movq 0x4c(%r15), %rsi
callq 0x616b
testb %al, %al
je 0x7ab8
cmpq %r15, %r14
cmoveq %rbx, %r14
cmpq %r15, %r12
cmoveq %r13, %r12
movq %r15, %rdi
movq %rbx, %rsi
callq 0x742b
movq %r15, %rdi
callq 0x73ad
jmp 0x7ab8
movq %r12, %rbx
testq %r12, %r12
jne 0x7aa4
leaq 0x222fa(%rip), %rax     # 0x29e0d
leaq 0x21bee(%rip), %rcx     # 0x29708
movq (%rcx), %rbx
testq %rbx, %rbx
setne %cl
andb (%rax), %cl
cmpb $0x1, %cl
jne 0x7b4f
movq 0x78(%rbx), %r15
cmpb $0x0, 0x2c(%rbx)
jne 0x7b47
movq %rbx, %rdi
movq %r14, %rsi
callq 0x742b
movq %rbx, %rdi
callq 0x73ad
movq %r15, %rbx
testq %r15, %r15
jne 0x7b2a
leaq 0x21bb2(%rip), %rax     # 0x29708
movq (%rax), %rbx
testq %rbx, %rbx
movq -0x50(%rbp), %r14
je 0x7b86
cmpq $0x0, 0x58(%rbx)
jne 0x7b7d
xorl %edi, %edi
xorl %esi, %esi
callq 0x8297
movq %rbx, %rdi
movq %rax, %rsi
callq 0x8389
movq 0x78(%rbx), %rbx
testq %rbx, %rbx
jne 0x7b62
leaq 0x21b43(%rip), %rax     # 0x296d0
leaq 0x21b7c(%rip), %rbx     # 0x29710
cmpb $0x0, (%rax)
jne 0x7bc2
cmpq $0x0, (%rbx)
je 0x7bc2
leaq 0x21b52(%rip), %rax     # 0x296f8
movq (%rax), %rax
testq %rax, %rax
je 0x7bb1
movq %rax, (%rbx)
movq (%rbx), %rax
movq 0x4c(%rax), %rdi
callq 0x1158c
callq 0x1df11
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
nop