// File: /workspace/github_c_makefile_star2_O1/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 %rbx
subq $0x178, %rsp            # imm = 0x178
movl %esi, %ebx
movl %edi, %ebp
callq 0x62c0
movl %eax, 0xc(%rsp)
xorl %edi, %edi
callq 0x6300
movq %rax, 0x10d30(%rip)     # 0x1df60
testq %rax, %rax
jne 0xd243
leaq 0x3d30(%rip), %rdi      # 0x10f6c
xorl %eax, %eax
callq 0x6f56
movq 0x10d16(%rip), %rdi     # 0x1df60
callq 0x64d0
movl %eax, 0x10df3(%rip)     # 0x1e048
movq 0x10e74(%rip), %rdi     # 0x1e0d0
testq %rdi, %rdi
je 0xd292
xorl %esi, %esi
xorl %edx, %edx
callq 0x6500
testq %rax, %rax
je 0xd292
movq %rax, %r14
movq 0x10ce7(%rip), %rdi     # 0x1df60
leaq 0xf0(%rsp), %r15
movq %rax, %rsi
movq %r15, %rdx
callq 0x6840
movl 0x14(%r15), %edx
jmp 0xd2ac
movq 0x10cc7(%rip), %rdi     # 0x1df60
movl 0x10da9(%rip), %esi     # 0x1e048
callq 0x62e0
movq %rax, %r14
movl $0x20, %edx
movl %edx, 0x10d9e(%rip)     # 0x1e050
movq 0x10ca7(%rip), %rdi     # 0x1df60
movl 0x10d89(%rip), %esi     # 0x1e048
leaq 0x30(%rsp), %r15
movl $0x4, %ecx
movq %r15, %r8
callq 0x6250
movq (%r15), %rax
movq %rax, 0x10cf5(%rip)     # 0x1dfd0
callq 0x6990
testl %eax, %eax
jne 0xd2f2
leaq 0x3c95(%rip), %rdi      # 0x10f80
xorl %eax, %eax
callq 0x6f56
movq 0x10daf(%rip), %rax     # 0x1e0a8
testq %rax, %rax
leaq 0x3cd7(%rip), %rdi      # 0x10fda
cmovneq %rax, %rdi
movq %rdi, 0x10e22(%rip)     # 0x1e130
xorps %xmm0, %xmm0
callq 0xd7cc
callq 0xda5e
movq 0x10c3e(%rip), %rdi     # 0x1df60
movq 0x10ca7(%rip), %rdx     # 0x1dfd0
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x62a0
movq %rax, 0x10c2e(%rip)     # 0x1df68
callq 0xb5b6
cmpb $0x1, 0x10d6a(%rip)     # 0x1e0b0
jne 0xd364
imull 0x10d35(%rip), %ebp     # 0x1e084
addl $0x18, %ebp
movl %ebp, 0x10d20(%rip)     # 0x1e078
imull 0x10d21(%rip), %ebx     # 0x1e080
addl $0x18, %ebx
jmp 0xd36a
movl %ebp, 0x10d0e(%rip)     # 0x1e078
movl %ebx, 0x10d0c(%rip)     # 0x1e07c
movl 0x10ce6(%rip), %eax     # 0x1e05c
testb $0x10, %al
je 0xd3ae
movq 0x10bdf(%rip), %rcx     # 0x1df60
movq 0xe8(%rcx), %rcx
movslq 0x10cb9(%rip), %rdx     # 0x1e048
shlq $0x7, %rdx
movl 0x18(%rcx,%rdx), %ecx
movl 0x10cb7(%rip), %edx     # 0x1e054
subl 0x10cd5(%rip), %ecx     # 0x1e078
addl %edx, %ecx
addl $-0x2, %ecx
movl %ecx, 0x10ca6(%rip)     # 0x1e054
testb $0x20, %al
je 0xd3e2
movq 0x10ba7(%rip), %rax     # 0x1df60
movq 0xe8(%rax), %rax
movslq 0x10c81(%rip), %rcx     # 0x1e048
shlq $0x7, %rcx
movl 0x1c(%rax,%rcx), %eax
movl 0x10c83(%rip), %ecx     # 0x1e058
subl %ebx, %eax
addl %ecx, %eax
addl $-0x2, %eax
movl %eax, 0x10c76(%rip)     # 0x1e058
movq 0x10a7f(%rip), %rax     # 0x1de68
movl 0x10a6d(%rip), %ecx     # 0x1de5c
shlq $0x4, %rcx
movq (%rax,%rcx), %rax
movq %rax, 0x10be2(%rip)     # 0x1dfe0
movq %rax, 0x10beb(%rip)     # 0x1dff0
movl $0x1, %eax
movl %eax, 0x10be8(%rip)     # 0x1dff8
movq $0x23a00f, 0x10c05(%rip) # imm = 0x23A00F
movq 0x10b46(%rip), %rcx     # 0x1df68
movq %rcx, 0x10c0f(%rip)     # 0x1e038
movq 0x10b30(%rip), %rdi     # 0x1df60
movl 0x10c1e(%rip), %edx     # 0x1e054
movl 0x10c1c(%rip), %ecx     # 0x1e058
movl 0x10c35(%rip), %r8d     # 0x1e078
movl 0x10c06(%rip), %r10d    # 0x1e050
leaq 0x10b87(%rip), %r11     # 0x1dfd8
movq %r14, %rsi
movl %ebx, %r9d
pushq %r11
pushq $0x281a                 # imm = 0x281A
pushq 0x10b6c(%rip)           # 0x1dfd0
pushq %rax
pushq %r10
pushq $0x0
callq 0x6270
addq $0x30, %rsp
movq %rax, 0x10af7(%rip)     # 0x1df70
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 0x10ab9(%rip), %rdi     # 0x1df60
movl 0x10bcb(%rip), %edx     # 0x1e078
movl 0x10bc9(%rip), %ecx     # 0x1e07c
movl 0x10b96(%rip), %r8d     # 0x1e050
movq %rax, %rsi
callq 0x6910
movq %rax, 0x10aaf(%rip)     # 0x1df78
movq 0x10a90(%rip), %rdi     # 0x1df60
movl $0x10000, %edx          # imm = 0x10000
movq %rax, %rsi
movq %rbx, %rcx
callq 0x65b0
movq %rax, 0x10a71(%rip)     # 0x1df58
movq 0x10a72(%rip), %rdi     # 0x1df60
movq 0x10973(%rip), %rcx     # 0x1de68
movl 0x10961(%rip), %edx     # 0x1de5c
shlq $0x4, %rdx
movq (%rcx,%rdx), %rdx
movq %rax, %rsi
callq 0x63e0
movq 0x10a4e(%rip), %rdi     # 0x1df60
movq 0x10a5f(%rip), %rsi     # 0x1df78
movq 0x10a38(%rip), %rdx     # 0x1df58
movl 0x10b51(%rip), %r9d     # 0x1e078
movl 0x10b4f(%rip), %eax     # 0x1e07c
subq $0x8, %rsp
xorl %ecx, %ecx
xorl %r8d, %r8d
pushq %rax
callq 0x63f0
addq $0x10, %rsp
movl 0xa00e(%rip), %edi      # 0x17554
shlq $0x4, %rdi
callq 0x6f2c
movq %rax, 0x10a2a(%rip)     # 0x1df80
movq 0x10a03(%rip), %rdi     # 0x1df60
movq 0x10a14(%rip), %rsi     # 0x1df78
movq 0x10a65(%rip), %rdx     # 0x1dfd0
movq 0x109f6(%rip), %rcx     # 0x1df68
callq 0x6940
movq %rax, 0x10a4a(%rip)     # 0x1dfc8
callq 0xdcbc
testl %eax, %eax
jne 0xd5a3
movq 0x109d2(%rip), %rdi     # 0x1df60
leaq 0x81b(%rip), %r8        # 0xddb0
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x6340
movq 0x109b6(%rip), %rdi     # 0x1df60
movl $0x98, %esi
callq 0x6090
movq %rax, %rbx
movq 0x109a2(%rip), %rdi     # 0x1df60
movq 0x109ab(%rip), %rsi     # 0x1df70
movq %rax, %rdx
callq 0x67c0
movq 0x1098c(%rip), %rdi     # 0x1df60
movq 0x1098d(%rip), %rsi     # 0x1df68
movq 0x10a7e(%rip), %rax     # 0x1e060
movq 0x38(%rax), %rdx
leaq 0x20(%rsp), %rcx
callq 0x6760
testl %eax, %eax
jne 0xd603
movl $0xffffffff, 0x28(%rsp) # imm = 0xFFFFFFFF
movw $0xffff, 0x2c(%rsp)     # imm = 0xFFFF
movq 0x10956(%rip), %rdi     # 0x1df60
movq 0x10957(%rip), %rsi     # 0x1df68
movq 0x10a48(%rip), %rax     # 0x1e060
movq (%rax), %rdx
leaq 0x10(%rsp), %rcx
callq 0x6760
testl %eax, %eax
jne 0xd638
movl $0x0, 0x18(%rsp)
movw $0x0, 0x1c(%rsp)
movq 0x10921(%rip), %rdi     # 0x1df60
leaq 0x20(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rsi
callq 0x62f0
movq 0x10908(%rip), %rdi     # 0x1df60
leaq 0x393d(%rip), %rsi      # 0x10f9c
xorl %edx, %edx
callq 0x6800
movq %rax, 0x1091b(%rip)     # 0x1df88
movq 0x108ec(%rip), %rdi     # 0x1df60
leaq 0x3929(%rip), %rsi      # 0x10fa4
xorl %edx, %edx
callq 0x6800
movq %rax, 0x10907(%rip)     # 0x1df90
leaq 0x10900(%rip), %rbx     # 0x1df90
movq 0x108c9(%rip), %rdi     # 0x1df60
leaq 0x3917(%rip), %rsi      # 0x10fb5
xorl %edx, %edx
callq 0x6800
movq %rax, 0x108ec(%rip)     # 0x1df98
movq 0x108ad(%rip), %rdi     # 0x1df60
movq 0x108b6(%rip), %rsi     # 0x1df70
movq %rbx, %rdx
movl $0x1, %ecx
callq 0x6470
movq 0x10892(%rip), %rdi     # 0x1df60
leaq 0x38ed(%rip), %rsi      # 0x10fc2
xorl %edx, %edx
callq 0x6800
movq %rax, 0x108bd(%rip)     # 0x1dfa0
movq 0x10876(%rip), %rdi     # 0x1df60
movq 0x1087f(%rip), %rsi     # 0x1df70
leaq 0xc(%rsp), %r10
movl $0x6, %ecx
movq %rax, %rdx
movl $0x20, %r8d
xorl %r9d, %r9d
pushq $0x1
pushq %r10
callq 0x6870
addq $0x10, %rsp
movl $0x20000, 0x1096a(%rip) # imm = 0x20000
callq 0x8d69
callq 0xddd9
movq 0x10831(%rip), %rdi     # 0x1df60
movq 0x1083a(%rip), %rsi     # 0x1df70
callq 0x6520
movq 0x1081e(%rip), %rdi     # 0x1df60
xorl %esi, %esi
callq 0x6670
leaq 0x109a8(%rip), %rsi     # 0x1e0f8
movl $0x1, %edi
callq 0x6140
leaq 0x109a7(%rip), %rsi     # 0x1e108
movl $0x1, %edi
callq 0x6140
xorps %xmm0, %xmm0
movups %xmm0, 0x10973(%rip)    # 0x1e0e8
movq 0x107e4(%rip), %rdi     # 0x1df60
leaq 0x384b(%rip), %rsi      # 0x10fce
xorl %edx, %edx
callq 0x6800
testq %rax, %rax
movl $0x1f, %ecx
cmovneq %rax, %rcx
movq %rcx, 0x10943(%rip)     # 0x1e0e0
movq 0x107bc(%rip), %rdi     # 0x1df60
movq 0x107bd(%rip), %rsi     # 0x1df68
movq 0x10816(%rip), %rdx     # 0x1dfc8
movq 0x10817(%rip), %rcx     # 0x1dfd0
callq 0xf060
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r14
popq %r15
popq %rbp
retq