// File: /workspace/github_c_makefile_star2_O2/AtifChy[P]st/x.c
// Function: xinit
void
xinit(int w, int h)
{
	XGCValues gcvalues;
	Cursor cursor;
	Window parent;
	pid_t thispid = getpid();
	XColor xmousefg, xmousebg;

	xw.scr = XDefaultScreen(xw.dpy);
	xw.vis = XDefaultVisual(xw.dpy, xw.scr);

	/* font */
	if (!FcInit())
		die("could not init fontconfig.\n");

	usedfont = (opt_font == NULL)? font : opt_font;
	xloadfonts(usedfont, 0);

	/* spare fonts */
	xloadsparefonts();

	/* colors */
	xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
	xloadcols();

	/* adjust fixed window geometry */
	switch (geometry) {
	case CellGeometry:
		win.w = 2 * win.hborderpx + w * win.cw;
		win.h = 2 * win.vborderpx + h * win.ch;
		break;
	case PixelGeometry:
		win.w = w;
		win.h = h;
		break;
	}
	if (xw.gm & XNegative)
		xw.l += DisplayWidth(xw.dpy, xw.scr) - win.w - 2;
	if (xw.gm & YNegative)
		xw.t += DisplayHeight(xw.dpy, xw.scr) - win.h - 2;

	/* Events */
	xw.attrs.background_pixel = dc.col[defaultbg].pixel;
	xw.attrs.border_pixel = dc.col[defaultbg].pixel;
	xw.attrs.bit_gravity = NorthWestGravity;
	xw.attrs.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask
		| ExposureMask | VisibilityChangeMask | StructureNotifyMask
		| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
	xw.attrs.colormap = xw.cmap;

	if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
		parent = XRootWindow(xw.dpy, xw.scr);
	xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
			win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
			xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
			| CWEventMask | CWColormap, &xw.attrs);

	memset(&gcvalues, 0, sizeof(gcvalues));
	gcvalues.graphics_exposures = False;
	dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
			&gcvalues);
	xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
			DefaultDepth(xw.dpy, xw.scr));
	XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
	XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);

	/* font spec buffer */
	xw.specbuf = xmalloc(cols * sizeof(GlyphFontSpec));

	/* Xft rendering context */
	xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);

	/* input methods */
	if (!ximopen(xw.dpy)) {
		XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
	                                       ximinstantiate, NULL);
	}

	/* white cursor, black outline */
	cursor = XCreateFontCursor(xw.dpy, mouseshape);
	XDefineCursor(xw.dpy, xw.win, cursor);

	if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) {
		xmousefg.red   = 0xffff;
		xmousefg.green = 0xffff;
		xmousefg.blue  = 0xffff;
	}

	if (XParseColor(xw.dpy, xw.cmap, colorname[mousebg], &xmousebg) == 0) {
		xmousebg.red   = 0x0000;
		xmousebg.green = 0x0000;
		xmousebg.blue  = 0x0000;
	}

	XRecolorCursor(xw.dpy, cursor, &xmousefg, &xmousebg);

	xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
	xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
	xw.netwmname = XInternAtom(xw.dpy, "_NET_WM_NAME", False);
	XSetWMProtocols(xw.dpy, xw.win, &xw.wmdeletewin, 1);

	xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False);
	XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32,
			PropModeReplace, (uchar *)&thispid, 1);

	win.mode = MODE_NUMLOCK;
	resettitle();
	xhints();
	XMapWindow(xw.dpy, xw.win);
	XSync(xw.dpy, False);

	clock_gettime(CLOCK_MONOTONIC, &xsel.tclick1);
	clock_gettime(CLOCK_MONOTONIC, &xsel.tclick2);
	xsel.primary = NULL;
	xsel.clipboard = NULL;
	xsel.xtarget = XInternAtom(xw.dpy, "UTF8_STRING", 0);
	if (xsel.xtarget == None)
		xsel.xtarget = XA_STRING;

	boxdraw_xinit(xw.dpy, xw.cmap, xw.draw, xw.vis);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %esi, %ebx
movl %edi, %r14d
callq 0x62c0
movl %eax, 0xc(%rsp)
movq 0x1146e(%rip), %rdi     # 0x1e890
callq 0x64e0
movl %eax, 0x1154b(%rip)     # 0x1e978
movq 0x1145c(%rip), %rdi     # 0x1e890
movl %eax, %esi
callq 0x62e0
movq %rax, 0x114be(%rip)     # 0x1e900
callq 0x6a20
testl %eax, %eax
jne 0xd459
leaq 0x3b5b(%rip), %rdi      # 0x10fad
xorl %eax, %eax
callq 0x6bb6
movq 0x11578(%rip), %rdi     # 0x1e9d8
testq %rdi, %rdi
jne 0xd46c
movq 0xa19c(%rip), %rdi      # 0x17608
movq %rdi, 0x1156d(%rip)     # 0x1e9e0
xorps %xmm0, %xmm0
callq 0xc70f
callq 0xdcc9
movq 0x11409(%rip), %rdi     # 0x1e890
movl 0x114eb(%rip), %esi     # 0x1e978
callq 0x6610
movq %rax, 0x113ff(%rip)     # 0x1e898
callq 0xb104
cmpb $0x0, 0x1154b(%rip)     # 0x1e9f0
jne 0xd4c9
movl 0x114f3(%rip), %eax     # 0x1e9a0
imull 0x114f7(%rip), %r14d    # 0x1e9ac
leal (%r14,%rax,2), %r14d
movl 0x114e5(%rip), %eax     # 0x1e9a4
imull 0x114e2(%rip), %ebx     # 0x1e9a8
leal (%rbx,%rax,2), %ebx
movl %r14d, 0x114c8(%rip)    # 0x1e998
movl %ebx, 0x114c6(%rip)     # 0x1e99c
movl 0x114ac(%rip), %eax     # 0x1e988
testb $0x10, %al
je 0xd511
movq 0x113a9(%rip), %rcx     # 0x1e890
movq 0xe8(%rcx), %rcx
movslq 0x11483(%rip), %rdx     # 0x1e978
shlq $0x7, %rdx
movl 0x18(%rcx,%rdx), %ecx
movl 0x1147d(%rip), %edx     # 0x1e980
subl %r14d, %ecx
addl %edx, %ecx
addl $-0x2, %ecx
movl %ecx, 0x1146f(%rip)     # 0x1e980
testb $0x20, %al
je 0xd545
movq 0x11374(%rip), %rax     # 0x1e890
movq 0xe8(%rax), %rax
movslq 0x1144e(%rip), %rcx     # 0x1e978
shlq $0x7, %rcx
movl 0x1c(%rax,%rcx), %eax
movl 0x1144c(%rip), %ecx     # 0x1e984
subl %ebx, %eax
addl %ecx, %eax
addl $-0x2, %eax
movl %eax, 0x1143f(%rip)     # 0x1e984
movq 0x1124c(%rip), %rax     # 0x1e798
movl 0xa0ae(%rip), %ecx      # 0x17600
shlq $0x4, %rcx
movq (%rax,%rcx), %rax
movq %rax, 0x113af(%rip)     # 0x1e910
movq %rax, 0x113b8(%rip)     # 0x1e920
movl $0x1, 0x113b6(%rip)     # 0x1e928
movq $0x23a00f, 0x113d3(%rip) # imm = 0x23A00F
movq 0x11314(%rip), %rax     # 0x1e898
movq %rax, 0x113dd(%rip)     # 0x1e968
movq 0x11476(%rip), %rdi     # 0x1ea08
testq %rdi, %rdi
je 0xd5a8
xorl %esi, %esi
xorl %edx, %edx
callq 0x6520
movq %rax, %rbx
testq %rax, %rax
jne 0xd5bd
movq 0x112e1(%rip), %rdi     # 0x1e890
movl 0x113c3(%rip), %esi     # 0x1e978
callq 0x62f0
movq %rax, %rbx
movq 0x112cc(%rip), %r14     # 0x1e890
movl 0x113b6(%rip), %ebp     # 0x1e980
movl 0x113b3(%rip), %r15d    # 0x1e984
movl 0x113c0(%rip), %r12d    # 0x1e998
movl 0x113bd(%rip), %r13d    # 0x1e99c
movl 0x11393(%rip), %esi     # 0x1e978
movq %r14, %rdi
callq 0x68a0
leaq 0x11314(%rip), %r10     # 0x1e908
movq %r14, %rdi
movq %rbx, %rsi
movl %ebp, %edx
movl %r15d, %ecx
movl %r12d, %r8d
movl %r13d, %r9d
pushq %r10
pushq $0x281a                 # imm = 0x281A
pushq 0x112ee(%rip)           # 0x1e900
pushq $0x1
pushq %rax
pushq $0x0
callq 0x6280
addq $0x30, %rsp
movq %rax, 0x11279(%rip)     # 0x1e8a0
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rcx
movaps %xmm0, (%rcx)
movaps %xmm0, 0x10(%rcx)
movaps %xmm0, 0x20(%rcx)
movaps %xmm0, 0x30(%rcx)
movaps %xmm0, 0x40(%rcx)
movaps %xmm0, 0x50(%rcx)
movaps %xmm0, 0x60(%rcx)
movaps %xmm0, 0x70(%rcx)
movq 0x1123b(%rip), %rdi     # 0x1e890
movl $0x10000, %edx          # imm = 0x10000
movq %rbx, %rsi
callq 0x65d0
movq %rax, 0x1121f(%rip)     # 0x1e888
movq 0x11220(%rip), %rdi     # 0x1e890
movq 0x11229(%rip), %rsi     # 0x1e8a0
movl 0x1131b(%rip), %edx     # 0x1e998
movl 0x11319(%rip), %ecx     # 0x1e99c
movq 0xe8(%rdi), %rax
movslq 0x112e7(%rip), %r8      # 0x1e978
shlq $0x7, %r8
movl 0x38(%rax,%r8), %r8d
callq 0x6980
movq %rax, 0x11202(%rip)     # 0x1e8a8
movq 0x111e3(%rip), %rdi     # 0x1e890
movq 0x111d4(%rip), %rsi     # 0x1e888
movq 0x110dd(%rip), %rax     # 0x1e798
movl 0x9f3f(%rip), %ecx      # 0x17600
shlq $0x4, %rcx
movq (%rax,%rcx), %rdx
callq 0x63f0
movq 0x111bb(%rip), %rdi     # 0x1e890
movq 0x111cc(%rip), %rsi     # 0x1e8a8
movq 0x111a5(%rip), %rdx     # 0x1e888
movl 0x112ae(%rip), %r9d     # 0x1e998
movl 0x112ac(%rip), %eax     # 0x1e99c
subq $0x8, %rsp
xorl %ecx, %ecx
xorl %r8d, %r8d
pushq %rax
callq 0x6400
popq %rcx
popq %rdx
movl 0xaa41(%rip), %edi      # 0x18148
shlq $0x4, %rdi
callq 0x6b8c
movq %rax, 0x11199(%rip)     # 0x1e8b0
movq 0x11172(%rip), %rdi     # 0x1e890
movq 0x11183(%rip), %rsi     # 0x1e8a8
movq 0x111d4(%rip), %rdx     # 0x1e900
movq 0x11165(%rip), %rcx     # 0x1e898
callq 0x69b0
movq %rax, 0x111b9(%rip)     # 0x1e8f8
callq 0xdf1f
testl %eax, %eax
jne 0xd764
movq 0x11141(%rip), %rdi     # 0x1e890
leaq 0x8e5(%rip), %r8        # 0xe03b
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x6350
movq 0x11125(%rip), %rdi     # 0x1e890
movl $0x98, %esi
callq 0x6090
movq %rax, %rbx
movq 0x11111(%rip), %rdi     # 0x1e890
movq 0x1111a(%rip), %rsi     # 0x1e8a0
movq %rax, %rdx
callq 0x6800
movq 0x110fb(%rip), %rdi     # 0x1e890
movq 0x110fc(%rip), %rsi     # 0x1e898
movq 0x9ea5(%rip), %rdx      # 0x17648
leaq 0x20(%rsp), %rcx
callq 0x67a0
testl %eax, %eax
jne 0xd7bc
orl $-0x1, 0x28(%rsp)
orw $-0x1, 0x2c(%rsp)
movq 0x110cd(%rip), %rdi     # 0x1e890
movq 0x110ce(%rip), %rsi     # 0x1e898
movq 0x9e3f(%rip), %rdx      # 0x17610
leaq 0x10(%rsp), %rcx
callq 0x67a0
testl %eax, %eax
jne 0xd7ea
andl $0x0, 0x18(%rsp)
andw $0x0, 0x1c(%rsp)
movq 0x1109f(%rip), %rdi     # 0x1e890
leaq 0x20(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rsi
callq 0x6300
movq 0x11086(%rip), %rdi     # 0x1e890
leaq 0x37b8(%rip), %rsi      # 0x10fc9
xorl %edx, %edx
callq 0x6840
movq %rax, 0x11099(%rip)     # 0x1e8b8
movq 0x1106a(%rip), %rdi     # 0x1e890
leaq 0x37a4(%rip), %rsi      # 0x10fd1
xorl %edx, %edx
callq 0x6840
movq %rax, 0x11085(%rip)     # 0x1e8c0
leaq 0x1107e(%rip), %r14     # 0x1e8c0
movq 0x11047(%rip), %rdi     # 0x1e890
leaq 0x3792(%rip), %rsi      # 0x10fe2
xorl %edx, %edx
callq 0x6840
movq %rax, 0x1106a(%rip)     # 0x1e8c8
movq 0x1102b(%rip), %rdi     # 0x1e890
movq 0x11034(%rip), %rsi     # 0x1e8a0
pushq $0x1
popq %rbx
movq %r14, %rdx
movl %ebx, %ecx
callq 0x6480
movq 0x11010(%rip), %rdi     # 0x1e890
leaq 0x3768(%rip), %rsi      # 0x10fef
xorl %edx, %edx
callq 0x6840
movq %rax, 0x1103b(%rip)     # 0x1e8d0
movq 0x10ff4(%rip), %rdi     # 0x1e890
movq 0x10ffd(%rip), %rsi     # 0x1e8a0
leaq 0xc(%rsp), %r10
pushq $0x6
popq %rcx
pushq $0x20
popq %r8
movq %rax, %rdx
xorl %r9d, %r9d
pushq $0x1
pushq %r10
callq 0x68d0
popq %rcx
popq %rdx
movl $0x20000, 0x110e6(%rip) # imm = 0x20000
callq 0x8745
callq 0xe064
movq 0x10fb5(%rip), %rdi     # 0x1e890
movq 0x10fbe(%rip), %rsi     # 0x1e8a0
callq 0x6540
movq 0x10fa2(%rip), %rdi     # 0x1e890
xorl %esi, %esi
callq 0x66a0
leaq 0x11134(%rip), %rsi     # 0x1ea30
movl %ebx, %edi
callq 0x6140
leaq 0x11136(%rip), %rsi     # 0x1ea40
movl %ebx, %edi
callq 0x6140
xorps %xmm0, %xmm0
movups %xmm0, 0x11105(%rip)    # 0x1ea20
movq 0x10f6e(%rip), %rdi     # 0x1e890
leaq 0x36d2(%rip), %rsi      # 0x10ffb
xorl %edx, %edx
callq 0x6840
testq %rax, %rax
pushq $0x1f
popq %rcx
cmovneq %rax, %rcx
movq %rcx, 0x110d7(%rip)     # 0x1ea18
movq 0x10f48(%rip), %rdi     # 0x1e890
movq 0x10f49(%rip), %rsi     # 0x1e898
movq 0x10fa2(%rip), %rdx     # 0x1e8f8
movq 0x10fa3(%rip), %rcx     # 0x1e900
callq 0xeedc
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq