// File: /workspace/github_c_makefile_star2_O1/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 0x1195e(%rip), %rdi     # 0x1f880
callq 0x64e0
movl %eax, 0x11a3b(%rip)     # 0x1f968
movq 0x1194c(%rip), %rdi     # 0x1f880
movl %eax, %esi
callq 0x62e0
movq %rax, 0x119ae(%rip)     # 0x1f8f0
callq 0x6a20
testl %eax, %eax
jne 0xdf59
leaq 0x406b(%rip), %rdi      # 0x11fbd
xorl %eax, %eax
callq 0x6ff6
movq 0x11a68(%rip), %rdi     # 0x1f9c8
testq %rdi, %rdi
jne 0xdf6c
movq 0xa69c(%rip), %rdi      # 0x18608
movq %rdi, 0x11a5d(%rip)     # 0x1f9d0
xorps %xmm0, %xmm0
callq 0xd169
callq 0xe763
movq 0x118f9(%rip), %rdi     # 0x1f880
movl 0x119db(%rip), %esi     # 0x1f968
callq 0x6610
movq %rax, 0x118ef(%rip)     # 0x1f888
callq 0xb99b
cmpb $0x0, 0x11a3b(%rip)     # 0x1f9e0
je 0xdfb0
movl %r14d, 0x119da(%rip)    # 0x1f988
jmp 0xdfd8
movl 0x119da(%rip), %eax     # 0x1f990
imull 0x119de(%rip), %r14d    # 0x1f99c
leal (%r14,%rax,2), %eax
movl %eax, 0x119c0(%rip)     # 0x1f988
movl 0x119c6(%rip), %eax     # 0x1f994
imull 0x119c3(%rip), %ebx     # 0x1f998
leal (%rbx,%rax,2), %ebx
movl %ebx, 0x119ae(%rip)     # 0x1f98c
movl 0x11994(%rip), %eax     # 0x1f978
testb $0x10, %al
je 0xe01c
movq 0x11891(%rip), %rcx     # 0x1f880
movq 0xe8(%rcx), %rcx
movslq 0x1196b(%rip), %rdx     # 0x1f968
shlq $0x7, %rdx
movl 0x18(%rcx,%rdx), %ecx
movl 0x11965(%rip), %edx     # 0x1f970
subl 0x11977(%rip), %ecx     # 0x1f988
addl %edx, %ecx
addl $-0x2, %ecx
movl %ecx, 0x11954(%rip)     # 0x1f970
testb $0x20, %al
je 0xe050
movq 0x11859(%rip), %rax     # 0x1f880
movq 0xe8(%rax), %rax
movslq 0x11933(%rip), %rcx     # 0x1f968
shlq $0x7, %rcx
movl 0x1c(%rax,%rcx), %eax
movl 0x11931(%rip), %ecx     # 0x1f974
subl %ebx, %eax
addl %ecx, %eax
addl $-0x2, %eax
movl %eax, 0x11924(%rip)     # 0x1f974
movq 0x11731(%rip), %rax     # 0x1f788
movl 0xa5a3(%rip), %ecx      # 0x18600
shlq $0x4, %rcx
movq (%rax,%rcx), %rax
movq %rax, 0x11894(%rip)     # 0x1f900
movq %rax, 0x1189d(%rip)     # 0x1f910
movl $0x1, 0x1189b(%rip)     # 0x1f918
movq $0x23a00f, 0x118b8(%rip) # imm = 0x23A00F
movq 0x117f9(%rip), %rax     # 0x1f888
movq %rax, 0x118c2(%rip)     # 0x1f958
movq 0x1195b(%rip), %rdi     # 0x1f9f8
testq %rdi, %rdi
je 0xe0b3
xorl %esi, %esi
xorl %edx, %edx
callq 0x6520
movq %rax, %rbx
testq %rax, %rax
jne 0xe0c8
movq 0x117c6(%rip), %rdi     # 0x1f880
movl 0x118a8(%rip), %esi     # 0x1f968
callq 0x62f0
movq %rax, %rbx
movq 0x117b1(%rip), %r14     # 0x1f880
movl 0x1189b(%rip), %ebp     # 0x1f970
movl 0x11898(%rip), %r15d    # 0x1f974
movl 0x118a5(%rip), %r12d    # 0x1f988
movl 0x118a2(%rip), %r13d    # 0x1f98c
movl 0x11878(%rip), %esi     # 0x1f968
movq %r14, %rdi
callq 0x68a0
leaq 0x117f9(%rip), %r10     # 0x1f8f8
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 0x117d3(%rip)           # 0x1f8f0
pushq $0x1
pushq %rax
pushq $0x0
callq 0x6280
addq $0x30, %rsp
movq %rax, 0x1175e(%rip)     # 0x1f890
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 0x11720(%rip), %rdi     # 0x1f880
movl $0x10000, %edx          # imm = 0x10000
movq %rbx, %rsi
callq 0x65d0
movq %rax, 0x11704(%rip)     # 0x1f878
movq 0x11705(%rip), %rdi     # 0x1f880
movq 0x1170e(%rip), %rsi     # 0x1f890
movl 0x11800(%rip), %edx     # 0x1f988
movl 0x117fe(%rip), %ecx     # 0x1f98c
movq 0xe8(%rdi), %rax
movslq 0x117cc(%rip), %r8      # 0x1f968
shlq $0x7, %r8
movl 0x38(%rax,%r8), %r8d
callq 0x6980
movq %rax, 0x116e7(%rip)     # 0x1f898
movq 0x116c8(%rip), %rdi     # 0x1f880
movq 0x116b9(%rip), %rsi     # 0x1f878
movq 0x115c2(%rip), %rax     # 0x1f788
movl 0xa434(%rip), %ecx      # 0x18600
shlq $0x4, %rcx
movq (%rax,%rcx), %rdx
callq 0x63f0
movq 0x116a0(%rip), %rdi     # 0x1f880
movq 0x116b1(%rip), %rsi     # 0x1f898
movq 0x1168a(%rip), %rdx     # 0x1f878
movl 0x11793(%rip), %r9d     # 0x1f988
movl 0x11791(%rip), %eax     # 0x1f98c
subq $0x8, %rsp
xorl %ecx, %ecx
xorl %r8d, %r8d
pushq %rax
callq 0x6400
addq $0x10, %rsp
movl 0xaf34(%rip), %edi      # 0x19148
shlq $0x4, %rdi
callq 0x6fcc
movq %rax, 0x1167c(%rip)     # 0x1f8a0
movq 0x11655(%rip), %rdi     # 0x1f880
movq 0x11666(%rip), %rsi     # 0x1f898
movq 0x116b7(%rip), %rdx     # 0x1f8f0
movq 0x11648(%rip), %rcx     # 0x1f888
callq 0x69b0
movq %rax, 0x1169c(%rip)     # 0x1f8e8
callq 0xe99c
testl %eax, %eax
jne 0xe271
movq 0x11624(%rip), %rdi     # 0x1f880
leaq 0x82d(%rip), %r8        # 0xea90
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x6350
movq 0x11608(%rip), %rdi     # 0x1f880
movl $0x98, %esi
callq 0x6090
movq %rax, %rbx
movq 0x115f4(%rip), %rdi     # 0x1f880
movq 0x115fd(%rip), %rsi     # 0x1f890
movq %rax, %rdx
callq 0x6800
movq 0x115de(%rip), %rdi     # 0x1f880
movq 0x115df(%rip), %rsi     # 0x1f888
movq 0xa398(%rip), %rdx      # 0x18648
leaq 0x20(%rsp), %rcx
callq 0x67a0
testl %eax, %eax
jne 0xe2cd
movl $0xffffffff, 0x28(%rsp) # imm = 0xFFFFFFFF
movw $0xffff, 0x2c(%rsp)     # imm = 0xFFFF
movq 0x115ac(%rip), %rdi     # 0x1f880
movq 0x115ad(%rip), %rsi     # 0x1f888
movq 0xa32e(%rip), %rdx      # 0x18610
leaq 0x10(%rsp), %rcx
callq 0x67a0
testl %eax, %eax
jne 0xe2ff
movl $0x0, 0x18(%rsp)
movw $0x0, 0x1c(%rsp)
movq 0x1157a(%rip), %rdi     # 0x1f880
leaq 0x20(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rsi
callq 0x6300
movq 0x11561(%rip), %rdi     # 0x1f880
leaq 0x3cb3(%rip), %rsi      # 0x11fd9
xorl %edx, %edx
callq 0x6840
movq %rax, 0x11574(%rip)     # 0x1f8a8
movq 0x11545(%rip), %rdi     # 0x1f880
leaq 0x3c9f(%rip), %rsi      # 0x11fe1
xorl %edx, %edx
callq 0x6840
movq %rax, 0x11560(%rip)     # 0x1f8b0
leaq 0x11559(%rip), %rbx     # 0x1f8b0
movq 0x11522(%rip), %rdi     # 0x1f880
leaq 0x3c8d(%rip), %rsi      # 0x11ff2
xorl %edx, %edx
callq 0x6840
movq %rax, 0x11545(%rip)     # 0x1f8b8
movq 0x11506(%rip), %rdi     # 0x1f880
movq 0x1150f(%rip), %rsi     # 0x1f890
movq %rbx, %rdx
movl $0x1, %ecx
callq 0x6480
movq 0x114eb(%rip), %rdi     # 0x1f880
leaq 0x3c63(%rip), %rsi      # 0x11fff
xorl %edx, %edx
callq 0x6840
movq %rax, 0x11516(%rip)     # 0x1f8c0
movq 0x114cf(%rip), %rdi     # 0x1f880
movq 0x114d8(%rip), %rsi     # 0x1f890
leaq 0xc(%rsp), %r10
movl $0x6, %ecx
movq %rax, %rdx
movl $0x20, %r8d
xorl %r9d, %r9d
pushq $0x1
pushq %r10
callq 0x68d0
addq $0x10, %rsp
movl $0x20000, 0x115bb(%rip) # imm = 0x20000
callq 0x8e08
callq 0xeab9
movq 0x1148a(%rip), %rdi     # 0x1f880
movq 0x11493(%rip), %rsi     # 0x1f890
callq 0x6540
movq 0x11477(%rip), %rdi     # 0x1f880
xorl %esi, %esi
callq 0x66a0
leaq 0x11609(%rip), %rsi     # 0x1fa20
movl $0x1, %edi
callq 0x6140
leaq 0x11608(%rip), %rsi     # 0x1fa30
movl $0x1, %edi
callq 0x6140
xorps %xmm0, %xmm0
movups %xmm0, 0x115d4(%rip)    # 0x1fa10
movq 0x1143d(%rip), %rdi     # 0x1f880
leaq 0x3bc1(%rip), %rsi      # 0x1200b
xorl %edx, %edx
callq 0x6840
testq %rax, %rax
movl $0x1f, %ecx
cmovneq %rax, %rcx
movq %rcx, 0x115a4(%rip)     # 0x1fa08
movq 0x11415(%rip), %rdi     # 0x1f880
movq 0x11416(%rip), %rsi     # 0x1f888
movq 0x1146f(%rip), %rdx     # 0x1f8e8
movq 0x11470(%rip), %rcx     # 0x1f8f0
callq 0xf9d4
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq