// File: /workspace/github_c_makefile_star2_O2/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 0x2118f(%rip), %r15     # 0x286c8
movq (%r15), %r14
leaq 0x21235(%rip), %rax     # 0x28778
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 0x78a2
movq %rax, %r14
movq %rax, %rdi
callq 0x45d0
movl %eax, %r13d
movq %r14, %rdi
callq 0x4170
movq %rax, -0x38(%rbp)
movq %rsp, -0x48(%rbp)
movl %r13d, %eax
movq %rsp, %r12
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
testl %r13d, %r13d
cmovlel %ebx, %r13d
cmpq %rbx, %r13
je 0x75c0
movq (%r15), %rdi
movq -0x38(%rbp), %rax
movl (%rax,%rbx,4), %esi
xorl %edx, %edx
callq 0x46e0
movl %eax, (%r12,%rbx,4)
incq %rbx
jmp 0x75a1
leaq 0x21141(%rip), %rax     # 0x28708
movq (%rax), %rax
testq %rax, %rax
je 0x75d9
movb $0x0, 0x2c(%rax)
addq $0x78, %rax
jmp 0x75c7
movq %r14, -0x50(%rbp)
xorl %r14d, %r14d
movq $0x0, -0x30(%rbp)
movq %r13, -0x60(%rbp)
movq %r12, -0x58(%rbp)
movq (%r15), %rbx
cmpq %r14, %r13
je 0x771b
movl (%r12,%r14,4), %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x4340
movq %rax, %rbx
testq %rax, %rax
je 0x770b
movl 0xc(%rbx), %esi
testl %esi, %esi
je 0x7676
movq (%r15), %r13
movq %r13, %rdi
xorl %edx, %edx
callq 0x4430
movq %r13, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x45e0
movq %rax, %r13
testq %rax, %rax
je 0x76ff
movq 0xc(%r13), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %r12
movl (%r12,%r14,4), %edi
callq 0x6fd4
testq %rax, %rax
je 0x76a4
movq %rax, %r15
movq %rax, %rdi
leaq -0x40(%rbp), %rsi
callq 0x6a5d
movq %r15, -0x30(%rbp)
movb $0x1, 0x2c(%r15)
jmp 0x76f4
leaq 0x2178f(%rip), %rax     # 0x28e0c
cmpb $0x0, (%rax)
jne 0x770b
cmpb $0x1, 0x18(%rbx)
je 0x770b
movq -0x38(%rbp), %rax
movl (%rax,%r14,4), %edi
callq 0x6fd4
testq %rax, %rax
je 0x770b
movb $0x1, 0x2c(%rax)
jmp 0x770b
movq %rbx, %rdi
callq 0x4630
movq %rax, %r15
movq %rbx, %rdi
callq 0x4500
movslq %eax, %rsi
movq %r15, %rdi
callq 0x5d82
movq %rax, -0x30(%rbp)
movq %rax, %rdi
leaq -0x40(%rbp), %rsi
xorl %edx, %edx
callq 0x6984
movq %rax, %r15
movq -0x30(%rbp), %rdi
callq 0x4460
movl (%r12,%r14,4), %eax
movl %eax, 0x24(%r15)
movq %r15, -0x30(%rbp)
movq %r15, %rdi
callq 0x7056
leaq 0x20fcd(%rip), %r15     # 0x286c8
movq -0x58(%rbp), %r12
movq %r13, %rdi
callq 0x4460
movq -0x60(%rbp), %r13
movq %rbx, %rdi
callq 0x4460
incq %r14
jmp 0x75f0
leaq 0x21056(%rip), %rax     # 0x28778
movl (%rax), %esi
movq %rbx, %rdi
callq 0x4650
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x4210
movq %rax, %rbx
testq %rax, %rax
je 0x7752
movl 0x8(%rbx), %edi
callq 0x6fd4
leaq 0x20fa9(%rip), %rcx     # 0x286f8
movq %rax, (%rcx)
movq %rbx, %rdi
callq 0x4460
leaq 0x216ad(%rip), %rax     # 0x28e0e
cmpb $0x1, (%rax)
jne 0x77da
leaq 0x20f9b(%rip), %r14     # 0x28708
movq (%r14), %r12
testq %r12, %r12
je 0x77da
movq %r12, %rbx
movq 0x78(%r12), %r12
cmpb $0x1, 0x2c(%rbx)
jne 0x7770
movq (%r14), %r13
testq %r13, %r13
je 0x7770
movq %r13, %r15
movq 0x78(%r13), %r13
cmpq %r15, %rbx
je 0x7786
cmpb $0x1, 0x2c(%r15)
jne 0x7786
movq 0x4c(%rbx), %rdi
movq 0x4c(%r15), %rsi
callq 0x6057
testb %al, %al
je 0x7786
movq -0x30(%rbp), %rax
cmpq %r15, %rax
cmoveq %rbx, %rax
movq %rax, -0x30(%rbp)
cmpq %r15, %r12
cmoveq %r13, %r12
movq %r15, %rdi
movq %rbx, %rsi
callq 0x720e
movq %r15, %rdi
callq 0x7194
jmp 0x7786
movq -0x30(%rbp), %r15
leaq 0x21628(%rip), %rax     # 0x28e0d
cmpb $0x0, (%rax)
je 0x781b
leaq 0x20f17(%rip), %rax     # 0x28708
movq (%rax), %r14
testq %r14, %r14
je 0x781b
movq %r14, %rbx
movq 0x78(%r14), %r14
cmpb $0x0, 0x2c(%rbx)
jne 0x77f4
movq %rbx, %rdi
movq %r15, %rsi
callq 0x720e
movq %rbx, %rdi
callq 0x7194
jmp 0x77f4
leaq 0x20ee6(%rip), %rbx     # 0x28708
movq -0x50(%rbp), %r14
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x784f
cmpq $0x0, 0x58(%rbx)
jne 0x7849
xorl %edi, %edi
xorl %esi, %esi
callq 0x7efd
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7fe2
addq $0x78, %rbx
jmp 0x7826
leaq 0x20e7a(%rip), %rcx     # 0x286d0
leaq 0x20eb3(%rip), %rbx     # 0x28710
movq (%rbx), %rax
testq %rax, %rax
sete %dl
orb (%rcx), %dl
jne 0x788f
leaq 0x20e87(%rip), %rcx     # 0x286f8
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x787e
movq %rcx, (%rbx)
jmp 0x7881
movq %rax, %rcx
movq 0x4c(%rcx), %rdi
callq 0x10648
callq 0x1c5f3
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