// File: /workspace/github_c_makefile_star2_O3/mati75[P]evilwm/display.c
// Function: display_open
void display_open(void) {
	LOG_ENTER("display_open()");

	display.dpy = XOpenDisplay(option.display);
	if (!display.dpy) {
		LOG_ERROR("can't open display %s\n", option.display);
		exit(1);
	}
	display.info_window = None;

	XSetErrorHandler(handle_xerror);

	// While debugging, synchronous behaviour may be desirable:
	//XSynchronize(display.dpy, True);

	// Sanity check that there's a name for each atom in the enum:
	assert(NUM_ATOMS == (sizeof(atom_list)/sizeof(atom_list[0])));

	// Get or create all required atom IDs
	for (int i = 0; i < NUM_ATOMS; i++) {
		display.atom[i] = XInternAtom(display.dpy, atom_list[i], False);
	}

	// Get the font used for window info
	display.font = XLoadQueryFont(display.dpy, option.font);
	if (!display.font) {
		LOG_DEBUG("failed to load specified font, trying default: %s\n", DEF_FONT);
		display.font = XLoadQueryFont(display.dpy, DEF_FONT);
	}
	if (!display.font) {
		LOG_ERROR("couldn't find a font to use: try starting with -fn fontname\n");
		exit(1);
	}

	// Cursors used for different actions
	display.move_curs = XCreateFontCursor(display.dpy, XC_fleur);
	display.resize_curs = XCreateFontCursor(display.dpy, XC_plus);

	// Find out which modifier is NumLock - for every grab, we need to also
	// grab the combination where this is set.
	numlockmask = 0;
	XModifierKeymap *modmap = XGetModifierMapping(display.dpy);
	for (unsigned i = 0; i < 8; i++) {
		for (unsigned j = 0; j < (unsigned)modmap->max_keypermod; j++) {
			if (modmap->modifiermap[i*modmap->max_keypermod+j] == XKeysymToKeycode(display.dpy, XK_Num_Lock)) {
				numlockmask = (1<<i);
				LOG_DEBUG("XK_Num_Lock is (1<<0x%02x)\n", i);
			}
		}
	}
	XFreeModifiermap(modmap);

	// SHAPE extension?
#ifdef SHAPE
	{
		int e_dummy;
		display.have_shape = XShapeQueryExtension(display.dpy, &display.shape_event, &e_dummy);
	}
#endif
	// XRandR extension?
#ifdef RANDR
	{
		int e_dummy;
		display.have_randr = XRRQueryExtension(display.dpy, &display.randr_event_base, &e_dummy);
		if (!display.have_randr) {
			LOG_DEBUG("XRandR is not supported on this display.\n");
		}
	}
#endif

	// Initialise screens
	display.nscreens = ScreenCount(display.dpy);
	if (display.nscreens < 0) {
		LOG_ERROR("Can't count screens\n");
		exit(1);
	}
	display.screens = xmalloc(display.nscreens * sizeof(struct screen));
	for (int i = 0; i < display.nscreens; i++) {
		display.screens[i].screen = i;
		screen_init(&display.screens[i]);
	}

	LOG_LEAVE();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x8802(%rip), %rbx      # 0xf8f0
movq (%rbx), %rdi
callq 0x42b0
movq %rax, 0x862b(%rip)      # 0xf728
testq %rax, %rax
je 0x72e6
movq $0x0, 0x87af(%rip) # 0xf8c0
leaq 0x257a(%rip), %rdi      # 0x9692
callq 0x4670
xorl %r14d, %r14d
leaq 0x8601(%rip), %r15      # 0xf728
leaq 0x3732(%rip), %r12      # 0xa860
movq 0x85f3(%rip), %rdi      # 0xf728
movslq (%r14,%r12), %rsi
addq %r12, %rsi
xorl %edx, %edx
callq 0x45d0
movq %rax, 0x8(%r15,%r14,2)
addq $0x4, %r14
cmpq $0xac, %r14
jne 0x712e
movq 0x85cc(%rip), %rdi      # 0xf728
movq 0x8(%rbx), %rsi
callq 0x4560
movq %rax, 0x871c(%rip)      # 0xf888
testq %rax, %rax
jne 0x7194
movq 0x85b0(%rip), %rdi      # 0xf728
leaq 0x38f9(%rip), %rsi      # 0xaa78
callq 0x4560
movq %rax, 0x86fd(%rip)      # 0xf888
testq %rax, %rax
je 0x72f0
movq 0x858d(%rip), %rdi      # 0xf728
movl $0x34, %esi
callq 0x4040
movq %rax, 0x86e4(%rip)      # 0xf890
movq 0x8575(%rip), %rdi      # 0xf728
movl $0x5a, %esi
callq 0x4040
movq %rax, 0x86d4(%rip)      # 0xf898
leaq 0x870d(%rip), %r14      # 0xf8d8
movl $0x0, (%r14)
movq 0x854f(%rip), %rdi      # 0xf728
callq 0x45c0
movq %rax, %rbx
movl (%rax), %edx
xorl %ebp, %ebp
movl $0x0, %eax
testl %edx, %edx
je 0x722f
movl $0x1, %r15d
movl %ebp, %ecx
shll %cl, %r15d
xorl %r12d, %r12d
movl %edx, %eax
movq 0x8(%rbx), %rcx
imull %ebp, %eax
addl %r12d, %eax
movb (%rcx,%rax), %r13b
movq 0x8515(%rip), %rdi      # 0xf728
movl $0xff7f, %esi           # imm = 0xFF7F
callq 0x4610
cmpb %al, %r13b
jne 0x7225
movl %r15d, (%r14)
incl %r12d
movl (%rbx), %eax
cmpl %eax, %r12d
jb 0x71fe
incl %ebp
movl %eax, %edx
cmpl $0x8, %ebp
jne 0x71e5
movq %rbx, %rdi
callq 0x41d0
movq 0x84e1(%rip), %rdi      # 0xf728
leaq 0x8656(%rip), %rsi      # 0xf8a4
leaq 0x4(%rsp), %rdx
callq 0x41a0
movl %eax, 0x8642(%rip)      # 0xf8a0
movq 0x84c3(%rip), %rdi      # 0xf728
leaq 0x8640(%rip), %rsi      # 0xf8ac
movq %rsp, %rdx
callq 0x4210
movl %eax, 0x862e(%rip)      # 0xf8a8
movq 0x84a7(%rip), %rax      # 0xf728
movslq 0xe4(%rax), %rax
movl %eax, 0x8622(%rip)      # 0xf8b0
testq %rax, %rax
js 0x72eb
imulq $0x78, %rax, %rdi
callq 0x9eb8
movq %rax, 0x8615(%rip)      # 0xf8b8
cmpl $0x0, 0x8606(%rip)      # 0xf8b0
jle 0x72d7
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x8600(%rip), %rdi      # 0xf8b8
movl %r14d, (%rdi,%rbx)
addq %rbx, %rdi
callq 0x8c40
incq %r14
movslq 0x85e2(%rip), %rax      # 0xf8b0
addq $0x78, %rbx
cmpq %rax, %r14
jl 0x72b1
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x483f
callq 0x47f5
callq 0x481a