// File: /workspace/github_c_makefile_star2_O3/impact-eintr[P]st/x.c
// Function: xdrawcursor
void
xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
{
	Color drawcol;
	XRenderColor colbg;

	/* remove the old cursor */
	if (selected(ox, oy))
		og.mode ^= ATTR_REVERSE;
	xdrawglyph(og, ox, oy);

	if (IS_SET(MODE_HIDE))
		return;

	/*
	 * Select the right color for the right mode.
	 */
	g.mode &= ATTR_BOLD|ATTR_ITALIC|ATTR_UNDERLINE|ATTR_STRUCK|ATTR_WIDE;

	if (IS_SET(MODE_REVERSE)) {
		g.mode |= ATTR_REVERSE;
		g.bg = defaultfg;
		if (selected(cx, cy)) {
			drawcol = dc.col[defaultcs];
			g.fg = defaultrcs;
		} else {
			drawcol = dc.col[defaultrcs];
			g.fg = defaultcs;
		}
	} else {
		if (selected(cx, cy)) {
			g.fg = defaultfg;
			g.bg = defaultrcs;
		} else {
			/** this is the main part of the dynamic cursor color patch */
			g.bg = g.fg;
			g.fg = defaultbg;
		}

		/**
		 * and this is the second part of the dynamic cursor color patch.
		 * it handles the `drawcol` variable
		*/
		if (IS_TRUECOL(g.bg)) {
			colbg.alpha = 0xffff;
			colbg.red = TRUERED(g.bg);
			colbg.green = TRUEGREEN(g.bg);
			colbg.blue = TRUEBLUE(g.bg);
			XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg, &drawcol);
		} else {
			drawcol = dc.col[g.bg];
		}
	}

	/* draw the new one */
	if (IS_SET(MODE_FOCUSED)) {
		switch (win.cursor) {
		case 7: /* st extension */
			g.u = 0x2603; /* snowman (U+2603) */
			/* FALLTHROUGH */
		case 0: /* Blinking Block */
		case 1: /* Blinking Block (Default) */
		case 2: /* Steady Block */
			xdrawglyph(g, cx, cy);
			break;
		case 3: /* Blinking Underline */
		case 4: /* Steady Underline */
			XftDrawRect(xw.draw, &drawcol,
					win.hborderpx + cx * win.cw,
					win.vborderpx + (cy + 1) * win.ch - \
						cursorthickness,
					win.cw, cursorthickness);
			break;
		case 5: /* Blinking bar */
		case 6: /* Steady bar */
			XftDrawRect(xw.draw, &drawcol,
					win.hborderpx + cx * win.cw,
					win.vborderpx + cy * win.ch,
					cursorthickness, win.ch);
			break;
		}
	} else {
		XftDrawRect(xw.draw, &drawcol,
				win.hborderpx + cx * win.cw,
				win.vborderpx + cy * win.ch,
				win.cw - 1, 1);
		XftDrawRect(xw.draw, &drawcol,
				win.hborderpx + cx * win.cw,
				win.vborderpx + cy * win.ch,
				1, win.ch - 1);
		XftDrawRect(xw.draw, &drawcol,
				win.hborderpx + (cx + 1) * win.cw - 1,
				win.vborderpx + cy * win.ch,
				1, win.ch - 1);
		XftDrawRect(xw.draw, &drawcol,
				win.hborderpx + cx * win.cw,
				win.vborderpx + (cy + 1) * win.ch - 1,
				win.cw, 1);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %ebp
movl %r8d, %r13d
movq %rcx, %r15
movq %rdx, 0x18(%rsp)
movl %esi, %r14d
movl %edi, %ebx
leaq 0x60(%rsp), %r12
movl %r8d, %edi
movl %r9d, %esi
callq 0x640e
testl %eax, %eax
je 0xa3db
xorb $0x20, 0x4(%r12)
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movl %r13d, %edx
movl %ebp, %ecx
callq 0xa6d5
movl 0xd9d4(%rip), %eax      # 0x17dc8
testb %al, %al
js 0xa6c6
movq 0x18(%rsp), %r13
shrq $0x20, %r13
andl $0x28d, %r13d           # imm = 0x28D
testb $0x20, %al
jne 0xa45c
movl %ebx, %edi
movl %r14d, %esi
callq 0x640e
testl %eax, %eax
movl $0x101, %eax            # imm = 0x101
cmovel %r15d, %eax
leaq 0xb0b8(%rip), %rcx      # 0x154e4
leaq 0xb0ad(%rip), %rdx      # 0x154e0
cmoveq %rcx, %rdx
movl (%rdx), %ebp
btl $0x18, %eax
jb 0xa492
movq 0xd75a(%rip), %rcx      # 0x17ba0
movl %eax, %edx
shlq $0x4, %rdx
movups (%rcx,%rdx), %xmm0
movaps %xmm0, (%rsp)
movl %eax, %r15d
jmp 0xa4e8
movzwl %r13w, %r13d
orl $0x20, %r13d
movl 0xb075(%rip), %r15d     # 0x154e0
movl %ebx, %edi
movl %r14d, %esi
callq 0x640e
movq 0xd724(%rip), %rcx      # 0x17ba0
testl %eax, %eax
je 0xa4d8
movups 0x1000(%rcx), %xmm0
movaps %xmm0, (%rsp)
movl $0x101, %ebp            # imm = 0x101
jmp 0xa4e8
leaq 0x20(%rsp), %rcx
movw $0xffff, 0x6(%rcx)      # imm = 0xFFFF
movl %eax, %edx
shrl $0x8, %edx
movl $0xff00, %esi           # imm = 0xFF00
andl %esi, %edx
movw %dx, (%rcx)
andl %eax, %esi
movw %si, 0x2(%rcx)
shll $0x8, %eax
movw %ax, 0x4(%rcx)
movq 0xd7d8(%rip), %rdi      # 0x17c98
movq 0xd849(%rip), %rsi      # 0x17d10
movq 0xd7d2(%rip), %rdx      # 0x17ca0
movq %rsp, %r8
callq 0x56e0
jmp 0xa4e8
movups 0x1010(%rcx), %xmm0
movaps %xmm0, (%rsp)
movl $0x100, %ebp            # imm = 0x100
testb $0x2, 0xd8d9(%rip)      # 0x17dc8
jne 0xa5f3
movq 0xd80c(%rip), %rdi      # 0x17d08
movl 0xd8c1(%rip), %r8d      # 0x17dc4
movl %r8d, %edx
imull %ebx, %edx
addl 0xd8a9(%rip), %edx      # 0x17db8
movl 0xd8ab(%rip), %ecx      # 0x17dc0
imull %r14d, %ecx
addl 0xd89d(%rip), %ecx      # 0x17dbc
decl %r8d
movq %rsp, %r15
movq %r15, %rsi
movl $0x1, %r9d
callq 0x53d0
movq 0xd7ce(%rip), %rdi      # 0x17d08
movl 0xd884(%rip), %edx      # 0x17dc4
imull %ebx, %edx
addl 0xd86f(%rip), %edx      # 0x17db8
movl 0xd870(%rip), %r9d      # 0x17dc0
movl %r9d, %ecx
imull %r14d, %ecx
addl 0xd85f(%rip), %ecx      # 0x17dbc
decl %r9d
movq %r15, %rsi
movl $0x1, %r8d
callq 0x53d0
movq 0xd793(%rip), %rdi      # 0x17d08
leal 0x1(%rbx), %eax
imull 0xd845(%rip), %eax      # 0x17dc4
movl 0xd833(%rip), %ecx      # 0x17db8
leal (%rcx,%rax), %edx
decl %edx
movl 0xd82f(%rip), %r9d      # 0x17dc0
movl %r9d, %ecx
imull %r14d, %ecx
addl 0xd81e(%rip), %ecx      # 0x17dbc
decl %r9d
movq %r15, %rsi
movl $0x1, %r8d
callq 0x53d0
movq 0xd752(%rip), %rdi      # 0x17d08
movl 0xd807(%rip), %r8d      # 0x17dc4
imull %r8d, %ebx
addl 0xd7f1(%rip), %ebx      # 0x17db8
movl 0xd7ef(%rip), %eax      # 0x17dbc
incl %r14d
imull 0xd7e8(%rip), %r14d     # 0x17dc0
leal (%rax,%r14), %ecx
decl %ecx
movq %r15, %rsi
movl %ebx, %edx
movl $0x1, %r9d
callq 0x53d0
jmp 0xa6c6
movl 0xd7d3(%rip), %eax      # 0x17dcc
cmpq $0x7, %rax
ja 0xa6c6
leaq 0x447e(%rip), %rcx      # 0xea88
movslq (%rcx,%rax,4), %rdx
addq %rcx, %rdx
movq 0x18(%rsp), %rsi
movq %rsi, %rax
jmpq *%rdx
movq 0xd6e6(%rip), %rdi      # 0x17d08
movl 0xd79b(%rip), %r8d      # 0x17dc4
imull %r8d, %ebx
addl 0xd785(%rip), %ebx      # 0x17db8
movl 0xd783(%rip), %eax      # 0x17dbc
incl %r14d
imull 0xd77c(%rip), %r14d     # 0x17dc0
leal (%rax,%r14), %ecx
addl $-0x2, %ecx
movq %rsp, %rsi
movl %ebx, %edx
movl $0x2, %r9d
jmp 0xa5e9
movq 0xd6a9(%rip), %rdi      # 0x17d08
imull 0xd75e(%rip), %ebx      # 0x17dc4
addl 0xd74c(%rip), %ebx      # 0x17db8
movl 0xd74d(%rip), %r9d      # 0x17dc0
imull %r9d, %r14d
addl 0xd73e(%rip), %r14d     # 0x17dbc
movq %rsp, %rsi
movl %ebx, %edx
movl %r14d, %ecx
movl $0x2, %r8d
jmp 0xa5e9
movl $0x2603, %eax           # imm = 0x2603
movabsq $-0x1000000000000, %rcx # imm = 0xFFFF000000000000
andq %rcx, %rsi
movzwl %r13w, %ecx
shlq $0x20, %rcx
movl %eax, %edi
orq %rsi, %rdi
orq %rcx, %rdi
shlq $0x20, %r15
movl %ebp, %esi
orq %r15, %rsi
movl %ebx, %edx
movl %r14d, %ecx
callq 0xa6d5
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq