// File: /workspace/github_c_makefile_star2_O0/baskerville[P]bspwm/src/bspwm.c
// Function: setup
void setup(void)
{
	init();
	ewmh_init();
	pointer_init();

	screen = xcb_setup_roots_iterator(xcb_get_setup(dpy)).data;

	if (screen == NULL) {
		err("Can't acquire the default screen.\n");
	}

	root = screen->root;
	register_events();

	screen_width = screen->width_in_pixels;
	screen_height = screen->height_in_pixels;

	meta_window = xcb_generate_id(dpy);
	xcb_create_window(dpy, XCB_COPY_FROM_PARENT, meta_window, root, -1, -1, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_ONLY, XCB_COPY_FROM_PARENT, XCB_NONE, NULL);
	xcb_icccm_set_wm_class(dpy, meta_window, sizeof(META_WINDOW_IC), META_WINDOW_IC);

	motion_recorder.id = xcb_generate_id(dpy);
	motion_recorder.sequence = 0;
	motion_recorder.enabled = false;
	uint32_t values[] = {XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_POINTER_MOTION};
	xcb_create_window(dpy, XCB_COPY_FROM_PARENT, motion_recorder.id, root, 0, 0, 1, 1, 0,
	                  XCB_WINDOW_CLASS_INPUT_ONLY, XCB_COPY_FROM_PARENT, XCB_CW_EVENT_MASK, values);
	xcb_icccm_set_wm_class(dpy, motion_recorder.id, sizeof(MOTION_RECORDER_IC), MOTION_RECORDER_IC);

	xcb_atom_t net_atoms[] = {ewmh->_NET_SUPPORTED,
	                          ewmh->_NET_SUPPORTING_WM_CHECK,
	                          ewmh->_NET_DESKTOP_NAMES,
	                          ewmh->_NET_DESKTOP_VIEWPORT,
	                          ewmh->_NET_NUMBER_OF_DESKTOPS,
	                          ewmh->_NET_CURRENT_DESKTOP,
	                          ewmh->_NET_CLIENT_LIST,
	                          ewmh->_NET_ACTIVE_WINDOW,
	                          ewmh->_NET_CLOSE_WINDOW,
	                          ewmh->_NET_WM_STRUT_PARTIAL,
	                          ewmh->_NET_WM_DESKTOP,
	                          ewmh->_NET_WM_STATE,
	                          ewmh->_NET_WM_STATE_HIDDEN,
	                          ewmh->_NET_WM_STATE_FULLSCREEN,
	                          ewmh->_NET_WM_STATE_BELOW,
	                          ewmh->_NET_WM_STATE_ABOVE,
	                          ewmh->_NET_WM_STATE_STICKY,
	                          ewmh->_NET_WM_STATE_DEMANDS_ATTENTION,
	                          ewmh->_NET_WM_WINDOW_TYPE,
	                          ewmh->_NET_WM_WINDOW_TYPE_DOCK,
	                          ewmh->_NET_WM_WINDOW_TYPE_DESKTOP,
	                          ewmh->_NET_WM_WINDOW_TYPE_NOTIFICATION,
	                          ewmh->_NET_WM_WINDOW_TYPE_DIALOG,
	                          ewmh->_NET_WM_WINDOW_TYPE_UTILITY,
	                          ewmh->_NET_WM_WINDOW_TYPE_TOOLBAR};

	xcb_ewmh_set_supported(ewmh, default_screen, LENGTH(net_atoms), net_atoms);
	ewmh_set_supporting(meta_window);

#define GETATOM(a) \
	get_atom(#a, &a);
	GETATOM(WM_STATE)
	GETATOM(WM_DELETE_WINDOW)
	GETATOM(WM_TAKE_FOCUS)
#undef GETATOM

	const xcb_query_extension_reply_t *qep = xcb_get_extension_data(dpy, &xcb_randr_id);
	if (qep->present && update_monitors()) {
		randr = true;
		randr_base = qep->first_event;
		xcb_randr_select_input(dpy, root, XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE);
	} else {
		randr = false;
		warn("Couldn't retrieve monitors via RandR.\n");
		bool xinerama_is_active = false;

		if (xcb_get_extension_data(dpy, &xcb_xinerama_id)->present) {
			xcb_xinerama_is_active_reply_t *xia = xcb_xinerama_is_active_reply(dpy, xcb_xinerama_is_active(dpy), NULL);
			if (xia != NULL) {
				xinerama_is_active = xia->state;
				free(xia);
			}
		}

		if (xinerama_is_active) {
			xcb_xinerama_query_screens_reply_t *xsq = xcb_xinerama_query_screens_reply(dpy, xcb_xinerama_query_screens(dpy), NULL);
			xcb_xinerama_screen_info_t *xsi = xcb_xinerama_query_screens_screen_info(xsq);
			int n = xcb_xinerama_query_screens_screen_info_length(xsq);
			for (int i = 0; i < n; i++) {
				xcb_xinerama_screen_info_t info = xsi[i];
				xcb_rectangle_t rect = (xcb_rectangle_t) {info.x_org, info.y_org, info.width, info.height};
				monitor_t *m = make_monitor(NULL, &rect, XCB_NONE);
				add_monitor(m);
				add_desktop(m, make_desktop(NULL, XCB_NONE));
			}
			free(xsq);
		} else {
			warn("Xinerama is inactive.\n");
			xcb_rectangle_t rect = (xcb_rectangle_t) {0, 0, screen_width, screen_height};
			monitor_t *m = make_monitor(NULL, &rect, XCB_NONE);
			add_monitor(m);
			add_desktop(m, make_desktop(NULL, XCB_NONE));
		}
	}

	ewmh_update_number_of_desktops();
	ewmh_update_desktop_names();
	ewmh_update_desktop_viewport();
	ewmh_update_current_desktop();
	xcb_get_input_focus_reply_t *ifo = xcb_get_input_focus_reply(dpy, xcb_get_input_focus(dpy), NULL);
	if (ifo != NULL && (ifo->focus == XCB_INPUT_FOCUS_POINTER_ROOT || ifo->focus == XCB_NONE)) {
		clear_input_focus();
	}
	free(ifo);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
callq 0x6210
callq 0x2abd0
callq 0x14ac0
movq 0x2fd17(%rip), %rdi     # 0x356b8
callq 0x4510
movq %rax, %rdi
callq 0x4400
movq %rax, -0x10(%rbp)
movq %rdx, -0x8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, 0x2fd9f(%rip)     # 0x35760
cmpq $0x0, 0x2fd97(%rip)     # 0x35760
jne 0x59d9
leaq 0x27816(%rip), %rdi     # 0x2d1e8
movb $0x0, %al
callq 0x64b0
movq 0x2fd80(%rip), %rax     # 0x35760
movl (%rax), %eax
movl %eax, 0x2fd80(%rip)     # 0x35768
callq 0x6300
movq 0x2fd6c(%rip), %rax     # 0x35760
movzwl 0x14(%rax), %eax
movl %eax, 0x2fd6e(%rip)     # 0x3576c
movq 0x2fd5b(%rip), %rax     # 0x35760
movzwl 0x16(%rax), %eax
movl %eax, 0x2fd61(%rip)     # 0x35770
movq 0x2fca2(%rip), %rdi     # 0x356b8
callq 0x4900
movl %eax, 0x2fcb3(%rip)     # 0x356d4
movq 0x2fc90(%rip), %rdi     # 0x356b8
movl 0x2fca6(%rip), %edx     # 0x356d4
movl 0x2fd34(%rip), %ecx     # 0x35768
xorl %esi, %esi
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %r9d, %r8d
movl $0x1, (%rsp)
movl $0x1, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x2, 0x18(%rsp)
movl $0x0, 0x20(%rsp)
movl $0x0, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
callq 0x4030
movl %eax, -0x14(%rbp)
movq 0x2fc30(%rip), %rdi     # 0x356b8
movl 0x2fc46(%rip), %esi     # 0x356d4
movl $0x9, %edx
leaq 0x275d6(%rip), %rcx     # 0x2d070
callq 0x46f0
movl %eax, -0x18(%rbp)
movq 0x2fc0f(%rip), %rdi     # 0x356b8
callq 0x4900
movl %eax, 0x2fc24(%rip)     # 0x356d8
movw $0x0, 0x2fc1f(%rip)     # 0x356dc
movb $0x0, 0x2fc1a(%rip)     # 0x356de
movl 0x278ba(%rip), %eax     # 0x2d384
movl %eax, -0x1c(%rbp)
movq 0x2fbe4(%rip), %rdi     # 0x356b8
movl 0x2fbfe(%rip), %edx     # 0x356d8
movl 0x2fc88(%rip), %ecx     # 0x35768
leaq -0x1c(%rbp), %rax
xorl %r9d, %r9d
movl %r9d, %esi
movl %r9d, %r8d
movl $0x1, (%rsp)
movl $0x1, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x2, 0x18(%rsp)
movl $0x0, 0x20(%rsp)
movl $0x800, 0x28(%rsp)      # imm = 0x800
movq %rax, 0x30(%rsp)
callq 0x4030
movl %eax, -0x20(%rbp)
movq 0x2fb88(%rip), %rdi     # 0x356b8
movl 0x2fba2(%rip), %esi     # 0x356d8
movl $0x16, %edx
leaq 0x27537(%rip), %rcx     # 0x2d079
callq 0x46f0
movl %eax, -0x24(%rbp)
leaq 0x302cf(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x20(%rax), %eax
movl %eax, -0x90(%rbp)
leaq 0x302bc(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x48(%rax), %eax
movl %eax, -0x8c(%rbp)
leaq 0x302a9(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x3c(%rax), %eax
movl %eax, -0x88(%rbp)
leaq 0x30296(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x34(%rax), %eax
movl %eax, -0x84(%rbp)
leaq 0x30283(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x80(%rbp)
leaq 0x30273(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x38(%rax), %eax
movl %eax, -0x7c(%rbp)
leaq 0x30263(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x24(%rax), %eax
movl %eax, -0x78(%rbp)
leaq 0x30253(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x40(%rax), %eax
movl %eax, -0x74(%rbp)
leaq 0x30243(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x58(%rax), %eax
movl %eax, -0x70(%rbp)
leaq 0x30233(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x90(%rax), %eax
movl %eax, -0x6c(%rbp)
leaq 0x30220(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x7c(%rax), %eax
movl %eax, -0x68(%rbp)
leaq 0x30210(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x84(%rax), %eax
movl %eax, -0x64(%rbp)
leaq 0x301fd(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x124(%rax), %eax
movl %eax, -0x60(%rbp)
leaq 0x301ea(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x128(%rax), %eax
movl %eax, -0x5c(%rbp)
leaq 0x301d7(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x130(%rax), %eax
movl %eax, -0x58(%rbp)
leaq 0x301c4(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x12c(%rax), %eax
movl %eax, -0x54(%rbp)
leaq 0x301b1(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x10c(%rax), %eax
movl %eax, -0x50(%rbp)
leaq 0x3019e(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x134(%rax), %eax
movl %eax, -0x4c(%rbp)
leaq 0x3018b(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0x80(%rax), %eax
movl %eax, -0x48(%rbp)
leaq 0x30178(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0xd4(%rax), %eax
movl %eax, -0x44(%rbp)
leaq 0x30165(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0xd0(%rax), %eax
movl %eax, -0x40(%rbp)
leaq 0x30152(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0xf8(%rax), %eax
movl %eax, -0x3c(%rbp)
leaq 0x3013f(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0xe8(%rax), %eax
movl %eax, -0x38(%rbp)
leaq 0x3012c(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0xe0(%rax), %eax
movl %eax, -0x34(%rbp)
leaq 0x30119(%rip), %rax     # 0x35e20
movq (%rax), %rax
movl 0xd8(%rax), %eax
movl %eax, -0x30(%rbp)
leaq 0x30106(%rip), %rax     # 0x35e20
movq (%rax), %rdi
movl 0x2f98d(%rip), %esi     # 0x356b0
leaq -0x90(%rbp), %rcx
movl $0x19, %edx
callq 0x4870
movl %eax, -0x94(%rbp)
movl 0x2f994(%rip), %edi     # 0x356d4
callq 0x2bac0
leaq 0x274bf(%rip), %rdi     # 0x2d20b
leaq 0x2fa21(%rip), %rsi     # 0x35774
callq 0x18ac0
leaq 0x274b5(%rip), %rdi     # 0x2d214
leaq 0x2fa12(%rip), %rsi     # 0x35778
callq 0x18ac0
leaq 0x274b3(%rip), %rdi     # 0x2d225
leaq 0x2fa03(%rip), %rsi     # 0x3577c
callq 0x18ac0
movq 0x2f933(%rip), %rdi     # 0x356b8
movq 0x2f244(%rip), %rsi     # 0x34fd0
callq 0x42c0
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x0, %eax
je 0x5def
callq 0x93b0
testb $0x1, %al
jne 0x5db3
jmp 0x5def
movb $0x1, 0x2f9c6(%rip)     # 0x35780
movq -0xa0(%rbp), %rax
movb 0xa(%rax), %cl
leaq 0x30035(%rip), %rax     # 0x35e00
movb %cl, (%rax)
movq 0x2f8e4(%rip), %rdi     # 0x356b8
movl 0x2f98e(%rip), %esi     # 0x35768
movl $0x1, %edx
callq 0x4230
movl %eax, -0xa4(%rbp)
jmp 0x6066
movb $0x0, 0x2f98a(%rip)     # 0x35780
leaq 0x27436(%rip), %rdi     # 0x2d233
movb $0x0, %al
callq 0x6410
movb $0x0, -0xa5(%rbp)
movq 0x2f8a6(%rip), %rdi     # 0x356b8
movq 0x2f1df(%rip), %rsi     # 0x34ff8
callq 0x42c0
cmpb $0x0, 0x8(%rax)
je 0x5e8f
movq 0x2f88d(%rip), %rax     # 0x356b8
movq %rax, -0x118(%rbp)
movq 0x2f87f(%rip), %rdi     # 0x356b8
callq 0x46b0
movq -0x118(%rbp), %rdi
movl %eax, -0xb4(%rbp)
movl -0xb4(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x4500
movq %rax, -0xb0(%rbp)
cmpq $0x0, -0xb0(%rbp)
je 0x5e8d
movq -0xb0(%rbp), %rax
cmpl $0x0, 0x8(%rax)
setne %al
andb $0x1, %al
movb %al, -0xa5(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x4450
jmp 0x5e8f
testb $0x1, -0xa5(%rbp)
je 0x5fdd
movq 0x2f815(%rip), %rax     # 0x356b8
movq %rax, -0x120(%rbp)
movq 0x2f807(%rip), %rdi     # 0x356b8
callq 0x47a0
movq -0x120(%rbp), %rdi
movl %eax, -0xc4(%rbp)
movl -0xc4(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x4250
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x4a60
movq %rax, -0xd0(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x43d0
movl %eax, -0xd4(%rbp)
movl $0x0, -0xd8(%rbp)
movl -0xd8(%rbp), %eax
cmpl -0xd4(%rbp), %eax
jge 0x5fcc
movq -0xd0(%rbp), %rax
movslq -0xd8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xe0(%rbp)
movw -0xe0(%rbp), %ax
movw %ax, -0xe8(%rbp)
movw -0xde(%rbp), %ax
movw %ax, -0xe6(%rbp)
movw -0xdc(%rbp), %ax
movw %ax, -0xe4(%rbp)
movw -0xda(%rbp), %ax
movw %ax, -0xe2(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq -0xe8(%rbp), %rsi
xorl %edx, %edx
callq 0x7ec0
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rdi
callq 0x8bc0
movq -0xf0(%rbp), %rax
movq %rax, -0x128(%rbp)
xorl %eax, %eax
movl %eax, %edi
xorl %esi, %esi
callq 0xa460
movq -0x128(%rbp), %rdi
movq %rax, %rsi
callq 0xa610
movl -0xd8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd8(%rbp)
jmp 0x5f08
movq -0xc0(%rbp), %rdi
callq 0x4450
jmp 0x6064
leaq 0x27276(%rip), %rdi     # 0x2d25a
movb $0x0, %al
callq 0x6410
movw $0x0, -0xf8(%rbp)
movw $0x0, -0xf6(%rbp)
movl 0x2f769(%rip), %eax     # 0x3576c
movw %ax, -0xf4(%rbp)
movl 0x2f760(%rip), %eax     # 0x35770
movw %ax, -0xf2(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq -0xf8(%rbp), %rsi
xorl %edx, %edx
callq 0x7ec0
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rdi
callq 0x8bc0
movq -0x100(%rbp), %rax
movq %rax, -0x130(%rbp)
xorl %eax, %eax
movl %eax, %edi
xorl %esi, %esi
callq 0xa460
movq -0x130(%rbp), %rdi
movq %rax, %rsi
callq 0xa610
jmp 0x6066
callq 0x2acc0
callq 0x2afe0
callq 0x2b1a0
callq 0x2ae60
movq 0x2f637(%rip), %rax     # 0x356b8
movq %rax, -0x138(%rbp)
movq 0x2f629(%rip), %rdi     # 0x356b8
callq 0x4930
movq -0x138(%rbp), %rdi
movl %eax, -0x10c(%rbp)
movl -0x10c(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x4ae0
movq %rax, -0x108(%rbp)
cmpq $0x0, -0x108(%rbp)
je 0x60e3
movq -0x108(%rbp), %rax
cmpl $0x1, 0x8(%rax)
je 0x60de
movq -0x108(%rbp), %rax
movl 0x8(%rax), %eax
cmpq $0x0, %rax
jne 0x60e3
callq 0x18950
movq -0x108(%rbp), %rdi
callq 0x4450
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopl (%rax,%rax)