// File: /workspace/github_c_makefile_star2_O2/acidDrain[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;
	XWindowAttributes attr;
	XVisualInfo vis;

	if (!(xw.dpy = XOpenDisplay(NULL)))
		die("can't open display\n");
	xw.scr = XDefaultScreen(xw.dpy);

	if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
		parent = XRootWindow(xw.dpy, xw.scr);
		xw.depth = 32;
	} else {
		XGetWindowAttributes(xw.dpy, parent, &attr);
		xw.depth = attr.depth;
	}

	XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
	xw.vis = vis.visual;

	/* 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 = XCreateColormap(xw.dpy, parent, xw.vis, None);
	xloadcols();

	/* adjust fixed window geometry */
	switch (geometry) {
	case CellGeometry:
		win.w = 2 * borderpx + w * win.cw;
		win.h = 2 * borderpx + 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;

	xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
			win.w, win.h, 0, xw.depth, InputOutput,
			xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
			| CWEventMask | CWColormap, &xw.attrs);

	memset(&gcvalues, 0, sizeof(gcvalues));
	gcvalues.graphics_exposures = False;
	xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
	dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
	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 %r12
pushq %rbx
subq $0x180, %rsp            # imm = 0x180
movl %esi, %ebx
movl %edi, %ebp
callq 0x52c0
movl %eax, 0xc(%rsp)
xorl %edi, %edi
callq 0x5300
movq %rax, 0x116f0(%rip)     # 0x1cf60
testq %rax, %rax
jne 0xb88a
leaq 0x46e0(%rip), %rdi      # 0xff5c
xorl %eax, %eax
callq 0x5b16
movq 0x116d6(%rip), %rax     # 0x1cf60
movq %rax, %rdi
callq 0x54d0
movl %eax, 0x117b0(%rip)     # 0x1d048
movq 0x11831(%rip), %rdi     # 0x1d0d0
testq %rdi, %rdi
je 0xb8db
xorl %esi, %esi
xorl %edx, %edx
callq 0x5500
testq %rax, %rax
je 0xb8d5
movq %rax, %r14
movq 0x116a4(%rip), %rdi     # 0x1cf60
leaq 0xf8(%rsp), %r15
movq %rax, %rsi
movq %r15, %rdx
callq 0x5830
movl 0x14(%r15), %r15d
jmp 0xb8f0
movl 0x1176d(%rip), %eax     # 0x1d048
pushq $0x20
popq %r15
movq 0x1167a(%rip), %rdi     # 0x1cf60
movl %eax, %esi
callq 0x52e0
movq %rax, %r14
movl %r15d, 0x11759(%rip)    # 0x1d050
movq 0x11662(%rip), %rdi     # 0x1cf60
movl 0x11744(%rip), %esi     # 0x1d048
pushq $0x4
popq %rcx
leaq 0x30(%rsp), %r12
movl %r15d, %edx
movq %r12, %r8
callq 0x5250
movq (%r12), %rax
movq %rax, 0x116ae(%rip)     # 0x1cfd0
callq 0x5980
testl %eax, %eax
jne 0xb939
leaq 0x463e(%rip), %rdi      # 0xff70
xorl %eax, %eax
callq 0x5b16
movq 0x11768(%rip), %rax     # 0x1d0a8
testq %rax, %rax
leaq 0x4680(%rip), %rdi      # 0xffca
cmovneq %rax, %rdi
movq %rdi, 0x117db(%rip)     # 0x1d130
xorps %xmm0, %xmm0
callq 0xbe19
callq 0xc0a3
movq 0x115f7(%rip), %rdi     # 0x1cf60
movq 0x11660(%rip), %rdx     # 0x1cfd0
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x52a0
movq %rax, 0x115e7(%rip)     # 0x1cf68
callq 0x9dc7
cmpb $0x1, 0x11723(%rip)     # 0x1d0b0
jne 0xb9a3
imull 0x116ee(%rip), %ebp     # 0x1d084
addl $0x18, %ebp
imull 0x116e0(%rip), %ebx     # 0x1d080
addl $0x18, %ebx
movl %ebp, 0x116cf(%rip)     # 0x1d078
movl %ebx, 0x116cd(%rip)     # 0x1d07c
movl 0x116a7(%rip), %eax     # 0x1d05c
movq 0x115a4(%rip), %rdi     # 0x1cf60
testb $0x10, %al
je 0xb9e9
movq 0xe8(%rdi), %rcx
movslq 0x1167a(%rip), %rdx     # 0x1d048
shlq $0x7, %rdx
movl 0x18(%rcx,%rdx), %ecx
movl 0x11678(%rip), %edx     # 0x1d054
subl %ebp, %ecx
addl %edx, %ecx
addl $-0x2, %ecx
movl %ecx, 0x1166b(%rip)     # 0x1d054
movl 0x11669(%rip), %ecx     # 0x1d058
testb $0x20, %al
je 0xba16
movq 0xe8(%rdi), %rax
movslq 0x11647(%rip), %rdx     # 0x1d048
shlq $0x7, %rdx
movl 0x1c(%rax,%rdx), %eax
subl %ebx, %eax
addl %eax, %ecx
addl $-0x2, %ecx
movl %ecx, 0x11642(%rip)     # 0x1d058
movq 0x1144b(%rip), %rax     # 0x1ce68
movl 0x11439(%rip), %edx     # 0x1ce5c
shlq $0x4, %rdx
movq (%rax,%rdx), %rax
movq %rax, 0x115ae(%rip)     # 0x1cfe0
movq %rax, 0x115b7(%rip)     # 0x1cff0
pushq $0x1
popq %rax
movl %eax, 0x115b6(%rip)     # 0x1cff8
movq $0x23a00f, 0x115d3(%rip) # imm = 0x23A00F
movq 0x11514(%rip), %rdx     # 0x1cf68
movq %rdx, 0x115dd(%rip)     # 0x1d038
movl 0x115f3(%rip), %edx     # 0x1d054
movl 0x115e8(%rip), %r10d    # 0x1d050
leaq 0x11569(%rip), %r11     # 0x1cfd8
movq %r14, %rsi
movl %ebp, %r8d
movl %ebx, %r9d
pushq %r11
pushq $0x281a                 # imm = 0x281A
pushq 0x1154b(%rip)           # 0x1cfd0
pushq %rax
pushq %r10
pushq $0x0
callq 0x5270
addq $0x30, %rsp
movq %rax, 0x114d6(%rip)     # 0x1cf70
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rbx
movaps %xmm0, (%rbx)
movaps %xmm0, 0x10(%rbx)
movaps %xmm0, 0x20(%rbx)
movaps %xmm0, 0x30(%rbx)
movaps %xmm0, 0x40(%rbx)
movaps %xmm0, 0x50(%rbx)
movaps %xmm0, 0x60(%rbx)
movaps %xmm0, 0x70(%rbx)
movq 0x11498(%rip), %rdi     # 0x1cf60
movl 0x115aa(%rip), %edx     # 0x1d078
movl 0x115a8(%rip), %ecx     # 0x1d07c
movl 0x11575(%rip), %r8d     # 0x1d050
movq %rax, %rsi
callq 0x5900
movq %rax, 0x1148e(%rip)     # 0x1cf78
movq 0x1146f(%rip), %rdi     # 0x1cf60
movl $0x10000, %edx          # imm = 0x10000
movq %rax, %rsi
movq %rbx, %rcx
callq 0x55b0
movq %rax, 0x11450(%rip)     # 0x1cf58
movq 0x11451(%rip), %rdi     # 0x1cf60
movq 0x11352(%rip), %rcx     # 0x1ce68
movl 0x11340(%rip), %edx     # 0x1ce5c
shlq $0x4, %rdx
movq (%rcx,%rdx), %rdx
movq %rax, %rsi
callq 0x53e0
movq 0x1142d(%rip), %rdi     # 0x1cf60
movq 0x1143e(%rip), %rsi     # 0x1cf78
movq 0x11417(%rip), %rdx     # 0x1cf58
movl 0x11530(%rip), %r9d     # 0x1d078
movl 0x1152e(%rip), %eax     # 0x1d07c
subq $0x8, %rsp
xorl %ecx, %ecx
xorl %r8d, %r8d
pushq %rax
callq 0x53f0
popq %rcx
popq %rdx
movl 0xa9ef(%rip), %edi      # 0x16554
shlq $0x4, %rdi
callq 0x5aec
movq %rax, 0x1140b(%rip)     # 0x1cf80
movq 0x113e4(%rip), %rdi     # 0x1cf60
movq 0x113f5(%rip), %rsi     # 0x1cf78
movq 0x11446(%rip), %rdx     # 0x1cfd0
movq 0x113d7(%rip), %rcx     # 0x1cf68
callq 0x5930
movq %rax, 0x1142b(%rip)     # 0x1cfc8
callq 0xc2fb
testl %eax, %eax
jne 0xbbc2
movq 0x113b3(%rip), %rdi     # 0x1cf60
leaq 0x863(%rip), %r8        # 0xc417
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x5340
movq 0x11397(%rip), %rdi     # 0x1cf60
movl $0x98, %esi
callq 0x5090
movq %rax, %rbx
movq 0x11383(%rip), %rdi     # 0x1cf60
movq 0x1138c(%rip), %rsi     # 0x1cf70
movq %rax, %rdx
callq 0x57b0
movq 0x1136d(%rip), %rdi     # 0x1cf60
movq 0x1136e(%rip), %rsi     # 0x1cf68
movq 0x1145f(%rip), %rax     # 0x1d060
movq 0x38(%rax), %rdx
leaq 0x20(%rsp), %rcx
callq 0x5750
testl %eax, %eax
jne 0xbc1e
orl $-0x1, 0x28(%rsp)
orw $-0x1, 0x2c(%rsp)
movq 0x1133b(%rip), %rdi     # 0x1cf60
movq 0x1133c(%rip), %rsi     # 0x1cf68
movq 0x1142d(%rip), %rax     # 0x1d060
movq (%rax), %rdx
leaq 0x10(%rsp), %rcx
callq 0x5750
testl %eax, %eax
jne 0xbc4f
andl $0x0, 0x18(%rsp)
andw $0x0, 0x1c(%rsp)
movq 0x1130a(%rip), %rdi     # 0x1cf60
leaq 0x20(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rsi
callq 0x52f0
movq 0x112f1(%rip), %rdi     # 0x1cf60
leaq 0x4316(%rip), %rsi      # 0xff8c
xorl %edx, %edx
callq 0x57f0
movq %rax, 0x11304(%rip)     # 0x1cf88
movq 0x112d5(%rip), %rdi     # 0x1cf60
leaq 0x4302(%rip), %rsi      # 0xff94
xorl %edx, %edx
callq 0x57f0
movq %rax, 0x112f0(%rip)     # 0x1cf90
leaq 0x112e9(%rip), %r14     # 0x1cf90
movq 0x112b2(%rip), %rdi     # 0x1cf60
leaq 0x42f0(%rip), %rsi      # 0xffa5
xorl %edx, %edx
callq 0x57f0
movq %rax, 0x112d5(%rip)     # 0x1cf98
movq 0x11296(%rip), %rdi     # 0x1cf60
movq 0x1129f(%rip), %rsi     # 0x1cf70
pushq $0x1
popq %rbx
movq %r14, %rdx
movl %ebx, %ecx
callq 0x5470
movq 0x1127b(%rip), %rdi     # 0x1cf60
leaq 0x42c6(%rip), %rsi      # 0xffb2
xorl %edx, %edx
callq 0x57f0
movq %rax, 0x112a6(%rip)     # 0x1cfa0
movq 0x1125f(%rip), %rdi     # 0x1cf60
movq 0x11268(%rip), %rsi     # 0x1cf70
leaq 0xc(%rsp), %r10
pushq $0x6
popq %rcx
pushq $0x20
popq %r8
movq %rax, %rdx
xorl %r9d, %r9d
pushq $0x1
pushq %r10
callq 0x5860
popq %rcx
popq %rdx
movl $0x20000, 0x11359(%rip) # imm = 0x20000
callq 0x76cf
callq 0xc440
movq 0x11220(%rip), %rdi     # 0x1cf60
movq 0x11229(%rip), %rsi     # 0x1cf70
callq 0x5520
movq 0x1120d(%rip), %rdi     # 0x1cf60
xorl %esi, %esi
callq 0x5670
leaq 0x11397(%rip), %rsi     # 0x1d0f8
movl %ebx, %edi
callq 0x5140
leaq 0x11399(%rip), %rsi     # 0x1d108
movl %ebx, %edi
callq 0x5140
xorps %xmm0, %xmm0
movups %xmm0, 0x11368(%rip)    # 0x1d0e8
movq 0x111d9(%rip), %rdi     # 0x1cf60
leaq 0x4230(%rip), %rsi      # 0xffbe
xorl %edx, %edx
callq 0x57f0
testq %rax, %rax
pushq $0x1f
popq %rcx
cmovneq %rax, %rcx
movq %rcx, 0x1133a(%rip)     # 0x1d0e0
movq 0x111b3(%rip), %rdi     # 0x1cf60
movq 0x111b4(%rip), %rsi     # 0x1cf68
movq 0x1120d(%rip), %rdx     # 0x1cfc8
movq 0x1120e(%rip), %rcx     # 0x1cfd0
callq 0xd614
addq $0x180, %rsp            # imm = 0x180
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq