// File: /workspace/github_c_makefile_star2_O0/tudurom[P]windowchef/wm.c
// Function: setup
static int
setup(void)
{
	/* init xcb and grab events */
	unsigned int values[1];
	int mask;

	conn = xcb_connect(NULL, &scrno);
	if (xcb_connection_has_error(conn)) {
		return -1;
	}

	/* get the first screen. hope it's the last one too */
	scr = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
	focused_win = NULL;

	mask = XCB_CW_EVENT_MASK;
	values[0] = XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY
		| XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT;
	xcb_generic_error_t *e = xcb_request_check(conn,
			xcb_change_window_attributes_checked(conn, scr->root,
				mask, values));
	if (e != NULL) {
		free(e);
		errx(EXIT_FAILURE, "Another window manager is already running.");
	}

	/* initialize ewmh variables */
	ewmh = calloc(1, sizeof(xcb_ewmh_connection_t));
	if (!ewmh)
		warnx("couldn't set up ewmh connection");
	xcb_intern_atom_cookie_t *cookie = xcb_ewmh_init_atoms(conn, ewmh);
	xcb_ewmh_init_atoms_replies(ewmh, cookie, (void *)0);
	xcb_ewmh_set_wm_pid(ewmh, scr->root, getpid());
	xcb_ewmh_set_wm_name(ewmh, scr->root, strlen(__NAME__), __NAME__);
	xcb_ewmh_set_current_desktop(ewmh, 0, 0);
	xcb_ewmh_set_number_of_desktops(ewmh, 0, GROUPS);
	update_desktop_viewport();

	xcb_atom_t supported_atoms[] = {
		ewmh->_NET_SUPPORTED               , ewmh->_NET_WM_DESKTOP              ,
		ewmh->_NET_NUMBER_OF_DESKTOPS      , ewmh->_NET_CURRENT_DESKTOP         ,
		ewmh->_NET_ACTIVE_WINDOW           , ewmh->_NET_WM_STATE                ,
		ewmh->_NET_WM_STATE_FULLSCREEN     , ewmh->_NET_WM_STATE_MAXIMIZED_VERT ,
		ewmh->_NET_WM_STATE_MAXIMIZED_HORZ , ewmh->_NET_WM_NAME                 ,
		ewmh->_NET_WM_ICON_NAME            , ewmh->_NET_WM_WINDOW_TYPE          ,
		ewmh->_NET_WM_WINDOW_TYPE_DOCK     , ewmh->_NET_WM_PID                  ,
		ewmh->_NET_WM_WINDOW_TYPE_TOOLBAR  , ewmh->_NET_WM_WINDOW_TYPE_DESKTOP  ,
		ewmh->_NET_SUPPORTING_WM_CHECK     , ewmh->_NET_DESKTOP_VIEWPORT        ,
	};
	xcb_ewmh_set_supported(ewmh, scrno, sizeof(supported_atoms) / sizeof(xcb_atom_t), supported_atoms);

	xcb_ewmh_set_supporting_wm_check(ewmh, scr->root, scr->root);

	pointer_init();

	/* send requests */
	xcb_flush(conn);

	/* get various atoms for icccm and ewmh */
	for (int i = 0; i < NR_ATOMS; i++)
		ATOMS[i] = get_atom(atom_names[i]);

	randr_base = setup_randr();

	group_in_use = malloc(conf.groups * sizeof(bool));
	for (uint32_t i = 0; i < conf.groups; i++)
		group_in_use[i] = false;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
xorl %eax, %eax
movl %eax, %edi
leaq 0xba9e(%rip), %rsi      # 0xf934
callq 0x3260
movq %rax, 0xb536(%rip)      # 0xf3d8
movq 0xb52f(%rip), %rdi      # 0xf3d8
callq 0x30a0
cmpl $0x0, %eax
je 0x3ebf
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4262
movq 0xb512(%rip), %rdi      # 0xf3d8
callq 0x3330
movq %rax, %rdi
callq 0x3290
movq %rax, -0x20(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x20(%rbp), %rax
movq %rax, 0xb912(%rip)      # 0xf7f8
movq $0x0, 0xb90f(%rip) # 0xf800
movl $0x800, -0xc(%rbp)      # imm = 0x800
movl $0x180000, -0x8(%rbp)   # imm = 0x180000
movq 0xb4d2(%rip), %rax      # 0xf3d8
movq %rax, -0xa8(%rbp)
movq 0xb4c4(%rip), %rdi      # 0xf3d8
movq 0xb8dd(%rip), %rax      # 0xf7f8
movl (%rax), %esi
movl -0xc(%rbp), %edx
leaq -0x8(%rbp), %rcx
callq 0x33f0
movq -0xa8(%rbp), %rdi
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %esi
callq 0x35e0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x3f62
movq -0x28(%rbp), %rdi
callq 0x32d0
movl $0x1, %edi
leaq 0x83c9(%rip), %rsi      # 0xc324
movb $0x0, %al
callq 0x35d0
movl $0x1, %edi
movl $0x168, %esi            # imm = 0x168
callq 0x3570
movq %rax, 0xb468(%rip)      # 0xf3e0
cmpq $0x0, 0xb460(%rip)      # 0xf3e0
jne 0x3f90
leaq 0x83c6(%rip), %rdi      # 0xc34f
movb $0x0, %al
callq 0x3120
movq 0xb441(%rip), %rdi      # 0xf3d8
movq 0xb442(%rip), %rsi      # 0xf3e0
callq 0x3250
movq %rax, -0x38(%rbp)
movq 0xb432(%rip), %rdi      # 0xf3e0
movq -0x38(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x3310
movq 0xb41e(%rip), %rax      # 0xf3e0
movq %rax, -0xb8(%rbp)
movq 0xb828(%rip), %rax      # 0xf7f8
movl (%rax), %eax
movl %eax, -0xac(%rbp)
callq 0x3240
movq -0xb8(%rbp), %rdi
movl -0xac(%rbp), %esi
movl %eax, %edx
callq 0x3650
movl %eax, -0x3c(%rbp)
movq 0xb3e5(%rip), %rdi      # 0xf3e0
movq 0xb7f6(%rip), %rax      # 0xf7f8
movl (%rax), %esi
movl $0x2, %edx
leaq 0x817b(%rip), %rcx      # 0xc18b
callq 0x3470
movl %eax, -0x40(%rbp)
movq 0xb3c1(%rip), %rdi      # 0xf3e0
xorl %edx, %edx
movl %edx, %esi
callq 0x35c0
movl %eax, -0x44(%rbp)
movq 0xb3ae(%rip), %rdi      # 0xf3e0
xorl %esi, %esi
movl $0xa, %edx
callq 0x3060
movl %eax, -0x48(%rbp)
callq 0xb210
movq 0xb393(%rip), %rax      # 0xf3e0
movl 0x20(%rax), %eax
movl %eax, -0x90(%rbp)
movq 0xb383(%rip), %rax      # 0xf3e0
movl 0x7c(%rax), %eax
movl %eax, -0x8c(%rbp)
movq 0xb373(%rip), %rax      # 0xf3e0
movl 0x2c(%rax), %eax
movl %eax, -0x88(%rbp)
movq 0xb363(%rip), %rax      # 0xf3e0
movl 0x38(%rax), %eax
movl %eax, -0x84(%rbp)
movq 0xb353(%rip), %rax      # 0xf3e0
movl 0x40(%rax), %eax
movl %eax, -0x80(%rbp)
movq 0xb346(%rip), %rax      # 0xf3e0
movl 0x84(%rax), %eax
movl %eax, -0x7c(%rbp)
movq 0xb336(%rip), %rax      # 0xf3e0
movl 0x128(%rax), %eax
movl %eax, -0x78(%rbp)
movq 0xb326(%rip), %rax      # 0xf3e0
movl 0x110(%rax), %eax
movl %eax, -0x74(%rbp)
movq 0xb316(%rip), %rax      # 0xf3e0
movl 0x114(%rax), %eax
movl %eax, -0x70(%rbp)
movq 0xb306(%rip), %rax      # 0xf3e0
movl 0x6c(%rax), %eax
movl %eax, -0x6c(%rbp)
movq 0xb2f9(%rip), %rax      # 0xf3e0
movl 0x74(%rax), %eax
movl %eax, -0x68(%rbp)
movq 0xb2ec(%rip), %rax      # 0xf3e0
movl 0x80(%rax), %eax
movl %eax, -0x64(%rbp)
movq 0xb2dc(%rip), %rax      # 0xf3e0
movl 0xd4(%rax), %eax
movl %eax, -0x60(%rbp)
movq 0xb2cc(%rip), %rax      # 0xf3e0
movl 0x9c(%rax), %eax
movl %eax, -0x5c(%rbp)
movq 0xb2bc(%rip), %rax      # 0xf3e0
movl 0xd8(%rax), %eax
movl %eax, -0x58(%rbp)
movq 0xb2ac(%rip), %rax      # 0xf3e0
movl 0xd0(%rax), %eax
movl %eax, -0x54(%rbp)
movq 0xb29c(%rip), %rax      # 0xf3e0
movl 0x48(%rax), %eax
movl %eax, -0x50(%rbp)
movq 0xb28f(%rip), %rax      # 0xf3e0
movl 0x34(%rax), %eax
movl %eax, -0x4c(%rbp)
movq 0xb282(%rip), %rdi      # 0xf3e0
movl 0xb7d0(%rip), %esi      # 0xf934
leaq -0x90(%rbp), %rcx
movl $0x12, %edx
callq 0x3550
movl %eax, -0x94(%rbp)
movq 0xb25e(%rip), %rdi      # 0xf3e0
movq 0xb66f(%rip), %rax      # 0xf7f8
movl (%rax), %esi
movq 0xb666(%rip), %rax      # 0xf7f8
movl (%rax), %edx
callq 0x32c0
movl %eax, -0x98(%rbp)
callq 0xb250
movq 0xb22d(%rip), %rdi      # 0xf3d8
callq 0x3400
movl $0x0, -0x9c(%rbp)
cmpl $0x4, -0x9c(%rbp)
jge 0x41fe
movslq -0x9c(%rbp), %rcx
leaq 0xb1cf(%rip), %rax      # 0xf3a0
movq (%rax,%rcx,8), %rdi
callq 0xb2a0
movl %eax, %edx
movslq -0x9c(%rbp), %rcx
leaq 0xb626(%rip), %rax      # 0xf810
movl %edx, (%rax,%rcx,4)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x41ba
callq 0xb310
movl %eax, 0xb623(%rip)      # 0xf82c
movl 0xb5cd(%rip), %eax      # 0xf7dc
movl %eax, %edi
shlq $0x0, %rdi
callq 0x31b0
movq %rax, 0xb5ff(%rip)      # 0xf820
movl $0x0, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
cmpl 0xb5a5(%rip), %eax      # 0xf7dc
jae 0x425b
movq 0xb5e0(%rip), %rax      # 0xf820
movl -0xa0(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x422b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nop