// File: /workspace/github_c_makefile_star2_O3/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 0x1146c(%rip), %rdi     # 0x1f880
callq 0x64e0
movl %eax, 0x11549(%rip)     # 0x1f968
movq 0x1145a(%rip), %rdi     # 0x1f880
movl %eax, %esi
callq 0x62e0
movq %rax, 0x114bc(%rip)     # 0x1f8f0
callq 0x6a20
testl %eax, %eax
jne 0xe44b
leaq 0x3b99(%rip), %rdi      # 0x11fdd
xorl %eax, %eax
callq 0x6ff6
movq 0x11576(%rip), %rdi     # 0x1f9c8
testq %rdi, %rdi
jne 0xe45e
movq 0xa1aa(%rip), %rdi      # 0x18608
movq %rdi, 0x1156b(%rip)     # 0x1f9d0
xorps %xmm0, %xmm0
callq 0xd60f
callq 0xec4a
movq 0x11407(%rip), %rdi     # 0x1f880
movl 0x114e9(%rip), %esi     # 0x1f968
callq 0x6610
movq %rax, 0x113fd(%rip)     # 0x1f888
callq 0xbe87
cmpb $0x0, 0x11549(%rip)     # 0x1f9e0
jne 0xe4bb
movl 0x114f1(%rip), %eax     # 0x1f990
imull 0x114f5(%rip), %r14d    # 0x1f99c
leal (%r14,%rax,2), %r14d
movl 0x114e3(%rip), %eax     # 0x1f994
imull 0x114e0(%rip), %ebx     # 0x1f998
leal (%rbx,%rax,2), %ebx
movl %r14d, 0x114c6(%rip)    # 0x1f988
movl %ebx, 0x114c4(%rip)     # 0x1f98c
movl 0x114aa(%rip), %eax     # 0x1f978
testb $0x10, %al
je 0xe503
movq 0x113a7(%rip), %rcx     # 0x1f880
movq 0xe8(%rcx), %rcx
movslq 0x11481(%rip), %rdx     # 0x1f968
shlq $0x7, %rdx
movl 0x18(%rcx,%rdx), %ecx
movl 0x1147b(%rip), %edx     # 0x1f970
subl %r14d, %ecx
addl %edx, %ecx
addl $-0x2, %ecx
movl %ecx, 0x1146d(%rip)     # 0x1f970
testb $0x20, %al
je 0xe537
movq 0x11372(%rip), %rax     # 0x1f880
movq 0xe8(%rax), %rax
movslq 0x1144c(%rip), %rcx     # 0x1f968
shlq $0x7, %rcx
movl 0x1c(%rax,%rcx), %eax
movl 0x1144a(%rip), %ecx     # 0x1f974
subl %ebx, %eax
addl %ecx, %eax
addl $-0x2, %eax
movl %eax, 0x1143d(%rip)     # 0x1f974
movq 0x1124a(%rip), %rax     # 0x1f788
movl 0xa0bc(%rip), %ecx      # 0x18600
shlq $0x4, %rcx
movq (%rax,%rcx), %rax
movq %rax, 0x113ad(%rip)     # 0x1f900
movq %rax, 0x113b6(%rip)     # 0x1f910
movl $0x1, 0x113b4(%rip)     # 0x1f918
movq $0x23a00f, 0x113d1(%rip) # imm = 0x23A00F
movq 0x11312(%rip), %rax     # 0x1f888
movq %rax, 0x113db(%rip)     # 0x1f958
movq 0x11474(%rip), %rdi     # 0x1f9f8
testq %rdi, %rdi
je 0xe59a
xorl %esi, %esi
xorl %edx, %edx
callq 0x6520
movq %rax, %rbx
testq %rax, %rax
jne 0xe5af
movq 0x112df(%rip), %rdi     # 0x1f880
movl 0x113c1(%rip), %esi     # 0x1f968
callq 0x62f0
movq %rax, %rbx
movq 0x112ca(%rip), %r14     # 0x1f880
movl 0x113b4(%rip), %ebp     # 0x1f970
movl 0x113b1(%rip), %r15d    # 0x1f974
movl 0x113be(%rip), %r12d    # 0x1f988
movl 0x113bb(%rip), %r13d    # 0x1f98c
movl 0x11391(%rip), %esi     # 0x1f968
movq %r14, %rdi
callq 0x68a0
leaq 0x11312(%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 0x112ec(%rip)           # 0x1f8f0
pushq $0x1
pushq %rax
pushq $0x0
callq 0x6280
addq $0x30, %rsp
movq %rax, 0x11277(%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 0x11239(%rip), %rdi     # 0x1f880
movl $0x10000, %edx          # imm = 0x10000
movq %rbx, %rsi
callq 0x65d0
movq %rax, 0x1121d(%rip)     # 0x1f878
movq 0x1121e(%rip), %rdi     # 0x1f880
movq 0x11227(%rip), %rsi     # 0x1f890
movl 0x11319(%rip), %edx     # 0x1f988
movl 0x11317(%rip), %ecx     # 0x1f98c
movq 0xe8(%rdi), %rax
movslq 0x112e5(%rip), %r8      # 0x1f968
shlq $0x7, %r8
movl 0x38(%rax,%r8), %r8d
callq 0x6980
movq %rax, 0x11200(%rip)     # 0x1f898
movq 0x111e1(%rip), %rdi     # 0x1f880
movq 0x111d2(%rip), %rsi     # 0x1f878
movq 0x110db(%rip), %rax     # 0x1f788
movl 0x9f4d(%rip), %ecx      # 0x18600
shlq $0x4, %rcx
movq (%rax,%rcx), %rdx
callq 0x63f0
movq 0x111b9(%rip), %rdi     # 0x1f880
movq 0x111ca(%rip), %rsi     # 0x1f898
movq 0x111a3(%rip), %rdx     # 0x1f878
movl 0x112ac(%rip), %r9d     # 0x1f988
movl 0x112aa(%rip), %eax     # 0x1f98c
subq $0x8, %rsp
xorl %ecx, %ecx
xorl %r8d, %r8d
pushq %rax
callq 0x6400
addq $0x10, %rsp
movl 0xaa4d(%rip), %edi      # 0x19148
shlq $0x4, %rdi
callq 0x6fcc
movq %rax, 0x11195(%rip)     # 0x1f8a0
movq 0x1116e(%rip), %rdi     # 0x1f880
movq 0x1117f(%rip), %rsi     # 0x1f898
movq 0x111d0(%rip), %rdx     # 0x1f8f0
movq 0x11161(%rip), %rcx     # 0x1f888
callq 0x69b0
movq %rax, 0x111b5(%rip)     # 0x1f8e8
callq 0xee83
testl %eax, %eax
jne 0xe758
movq 0x1113d(%rip), %rdi     # 0x1f880
leaq 0x824(%rip), %r8        # 0xef6e
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x6350
movq 0x11121(%rip), %rdi     # 0x1f880
movl $0x98, %esi
callq 0x6090
movq %rax, %rbx
movq 0x1110d(%rip), %rdi     # 0x1f880
movq 0x11116(%rip), %rsi     # 0x1f890
movq %rax, %rdx
callq 0x6800
movq 0x110f7(%rip), %rdi     # 0x1f880
movq 0x110f8(%rip), %rsi     # 0x1f888
movq 0x9eb1(%rip), %rdx      # 0x18648
leaq 0x20(%rsp), %rcx
callq 0x67a0
testl %eax, %eax
jne 0xe7b4
movl $0xffffffff, 0x28(%rsp) # imm = 0xFFFFFFFF
movw $0xffff, 0x2c(%rsp)     # imm = 0xFFFF
movq 0x110c5(%rip), %rdi     # 0x1f880
movq 0x110c6(%rip), %rsi     # 0x1f888
movq 0x9e47(%rip), %rdx      # 0x18610
leaq 0x10(%rsp), %rcx
callq 0x67a0
testl %eax, %eax
jne 0xe7e6
movl $0x0, 0x18(%rsp)
movw $0x0, 0x1c(%rsp)
movq 0x11093(%rip), %rdi     # 0x1f880
leaq 0x20(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rsi
callq 0x6300
movq 0x1107a(%rip), %rdi     # 0x1f880
leaq 0x37ec(%rip), %rsi      # 0x11ff9
xorl %edx, %edx
callq 0x6840
movq %rax, 0x1108d(%rip)     # 0x1f8a8
movq 0x1105e(%rip), %rdi     # 0x1f880
leaq 0x37d8(%rip), %rsi      # 0x12001
xorl %edx, %edx
callq 0x6840
movq %rax, 0x11079(%rip)     # 0x1f8b0
leaq 0x11072(%rip), %rbx     # 0x1f8b0
movq 0x1103b(%rip), %rdi     # 0x1f880
leaq 0x37c6(%rip), %rsi      # 0x12012
xorl %edx, %edx
callq 0x6840
movq %rax, 0x1105e(%rip)     # 0x1f8b8
movq 0x1101f(%rip), %rdi     # 0x1f880
movq 0x11028(%rip), %rsi     # 0x1f890
movq %rbx, %rdx
movl $0x1, %ecx
callq 0x6480
movq 0x11004(%rip), %rdi     # 0x1f880
leaq 0x379c(%rip), %rsi      # 0x1201f
xorl %edx, %edx
callq 0x6840
movq %rax, 0x1102f(%rip)     # 0x1f8c0
movq 0x10fe8(%rip), %rdi     # 0x1f880
movq 0x10ff1(%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, 0x110d4(%rip) # imm = 0x20000
callq 0x91e3
callq 0xef97
movq 0x10fa3(%rip), %rdi     # 0x1f880
movq 0x10fac(%rip), %rsi     # 0x1f890
callq 0x6540
movq 0x10f90(%rip), %rdi     # 0x1f880
xorl %esi, %esi
callq 0x66a0
leaq 0x11122(%rip), %rsi     # 0x1fa20
movl $0x1, %edi
callq 0x6140
leaq 0x11121(%rip), %rsi     # 0x1fa30
movl $0x1, %edi
callq 0x6140
xorps %xmm0, %xmm0
movups %xmm0, 0x110ed(%rip)    # 0x1fa10
movq 0x10f56(%rip), %rdi     # 0x1f880
leaq 0x36fa(%rip), %rsi      # 0x1202b
xorl %edx, %edx
callq 0x6840
testq %rax, %rax
movl $0x1f, %ecx
cmovneq %rax, %rcx
movq %rcx, 0x110bd(%rip)     # 0x1fa08
movq 0x10f2e(%rip), %rdi     # 0x1f880
movq 0x10f2f(%rip), %rsi     # 0x1f888
movq 0x10f88(%rip), %rdx     # 0x1f8e8
movq 0x10f89(%rip), %rcx     # 0x1f8f0
callq 0xfe70
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq