// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
leaq 0xa5e9(%rip), %rax      # 0x12f48
movq (%rax), %rdi
callq 0x42c0
movq %rax, 0xa412(%rip)      # 0x12d80
cmpq $0x0, 0xa40a(%rip)      # 0x12d80
jne 0x89a4
movq 0x9671(%rip), %rax      # 0x11ff0
movq (%rax), %rdi
leaq 0xa5bf(%rip), %rax      # 0x12f48
movq (%rax), %rdx
leaq 0x5ab6(%rip), %rsi      # 0xe449
movb $0x0, %al
callq 0x4700
movl $0x1, %edi
callq 0x4170
movq $0x0, 0xa569(%rip) # 0x12f18
leaq 0x41ca(%rip), %rdi      # 0xcb80
callq 0x4680
movl $0x0, -0x4(%rbp)
cmpl $0x2b, -0x4(%rbp)
jge 0x8a03
movq 0xa3b1(%rip), %rdi      # 0x12d80
movslq -0x4(%rbp), %rcx
leaq 0x9f76(%rip), %rax      # 0x12950
movq (%rax,%rcx,8), %rsi
xorl %edx, %edx
callq 0x45e0
movq %rax, %rdx
movslq -0x4(%rbp), %rcx
leaq 0xa38d(%rip), %rax      # 0x12d80
movq %rdx, 0x8(%rax,%rcx,8)
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x89c2
movq 0xa376(%rip), %rdi      # 0x12d80
leaq 0xa537(%rip), %rax      # 0x12f48
movq 0x8(%rax), %rsi
callq 0x4570
movq %rax, 0xa4bf(%rip)      # 0x12ee0
cmpq $0x0, 0xa4b7(%rip)      # 0x12ee0
jne 0x8a45
movq 0xa34e(%rip), %rdi      # 0x12d80
leaq 0x5fbb(%rip), %rsi      # 0xe9f4
callq 0x4570
movq %rax, 0xa49b(%rip)      # 0x12ee0
cmpq $0x0, 0xa493(%rip)      # 0x12ee0
jne 0x8a71
movq 0x959a(%rip), %rax      # 0x11ff0
movq (%rax), %rdi
leaq 0x5a00(%rip), %rsi      # 0xe460
movb $0x0, %al
callq 0x4700
movl $0x1, %edi
callq 0x4170
movq 0xa308(%rip), %rdi      # 0x12d80
movl $0x34, %esi
callq 0x4040
movq %rax, 0xa45f(%rip)      # 0x12ee8
movq 0xa2f0(%rip), %rdi      # 0x12d80
movl $0x5a, %esi
callq 0x4040
movq %rax, 0xa44f(%rip)      # 0x12ef0
leaq 0xa488(%rip), %rax      # 0x12f30
movl $0x0, (%rax)
movq 0xa2cb(%rip), %rdi      # 0x12d80
callq 0x45d0
movq %rax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x8, -0x14(%rbp)
jae 0x8b4a
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x8b3a
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull (%rdx), %ecx
addl -0x18(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movl %eax, -0x28(%rbp)
movq 0xa27e(%rip), %rdi      # 0x12d80
movl $0xff7f, %esi           # imm = 0xFF7F
callq 0x4620
movb %al, %cl
movl -0x28(%rbp), %eax
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x8b2d
movl -0x14(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
leaq 0xa405(%rip), %rax      # 0x12f30
movl %ecx, (%rax)
jmp 0x8b2f
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x8ad2
jmp 0x8b3c
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x8ac5
movq -0x10(%rbp), %rdi
callq 0x41e0
movq 0xa226(%rip), %rdi      # 0x12d80
leaq 0xa21f(%rip), %rsi      # 0x12d80
addq $0x17c, %rsi            # imm = 0x17C
leaq -0x1c(%rbp), %rdx
callq 0x41b0
movl %eax, 0xa381(%rip)      # 0x12ef8
movq 0xa202(%rip), %rdi      # 0x12d80
leaq 0xa1fb(%rip), %rsi      # 0x12d80
addq $0x184, %rsi            # imm = 0x184
leaq -0x20(%rbp), %rdx
callq 0x4220
movl %eax, 0xa365(%rip)      # 0x12f00
cmpl $0x0, 0xa35e(%rip)      # 0x12f00
jne 0x8ba6
jmp 0x8ba6
movq 0xa1d3(%rip), %rax      # 0x12d80
movl 0xe4(%rax), %eax
movl %eax, 0xa34f(%rip)      # 0x12f08
cmpl $0x0, 0xa348(%rip)      # 0x12f08
jge 0x8be4
movq 0x9427(%rip), %rax      # 0x11ff0
movq (%rax), %rdi
leaq 0x58ca(%rip), %rsi      # 0xe49d
movb $0x0, %al
callq 0x4700
movl $0x1, %edi
callq 0x4170
movslq 0xa31d(%rip), %rax      # 0x12f08
imulq $0x78, %rax, %rdi
callq 0xd890
movq %rax, 0xa315(%rip)      # 0x12f10
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl 0xa2fd(%rip), %eax      # 0x12f08
jge 0x8c46
movl -0x24(%rbp), %ecx
movq 0xa2f9(%rip), %rax      # 0x12f10
movslq -0x24(%rbp), %rdx
imulq $0x78, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq 0xa2e5(%rip), %rdi      # 0x12f10
movslq -0x24(%rbp), %rax
imulq $0x78, %rax, %rax
addq %rax, %rdi
callq 0xb900
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x8c02
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)