// File: /workspace/github_c_makefile_star2_O2/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 0x5ecf
testl %eax, %eax
je 0x9a53
xorb $0x20, 0x4(%r12)
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movl %r13d, %edx
movl %ebp, %ecx
callq 0x9d3f
movl 0xd35c(%rip), %eax      # 0x16dc8
testb %al, %al
js 0x9d30
movq 0x18(%rsp), %r13
shrq $0x20, %r13
andl $0x28d, %r13d           # imm = 0x28D
testb $0x20, %al
jne 0x9ad4
movl %ebx, %edi
movl %r14d, %esi
callq 0x5ecf
testl %eax, %eax
movl $0x101, %eax            # imm = 0x101
cmovel %r15d, %eax
leaq 0xaa40(%rip), %rcx      # 0x144e4
leaq 0xaa35(%rip), %rdx      # 0x144e0
cmoveq %rcx, %rdx
movl (%rdx), %ebp
btl $0x18, %eax
jb 0x9b0a
movq 0xd0e2(%rip), %rcx      # 0x16ba0
movl %eax, %edx
shlq $0x4, %rdx
movups (%rcx,%rdx), %xmm0
movaps %xmm0, (%rsp)
movl %eax, %r15d
jmp 0x9b5f
movzwl %r13w, %r13d
orl $0x20, %r13d
movl 0xa9fd(%rip), %r15d     # 0x144e0
movl %ebx, %edi
movl %r14d, %esi
callq 0x5ecf
movq 0xd0ac(%rip), %rcx      # 0x16ba0
testl %eax, %eax
je 0x9b4f
movups 0x1000(%rcx), %xmm0
movaps %xmm0, (%rsp)
movl $0x101, %ebp            # imm = 0x101
jmp 0x9b5f
leaq 0x20(%rsp), %rcx
orw $-0x1, 0x6(%rcx)
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 0xd161(%rip), %rdi      # 0x16c98
movq 0xd1d2(%rip), %rsi      # 0x16d10
movq 0xd15b(%rip), %rdx      # 0x16ca0
movq %rsp, %r8
callq 0x56e0
jmp 0x9b5f
movups 0x1010(%rcx), %xmm0
movaps %xmm0, (%rsp)
movl $0x100, %ebp            # imm = 0x100
testb $0x2, 0xd262(%rip)      # 0x16dc8
jne 0x9c61
movq 0xd195(%rip), %rdi      # 0x16d08
movl 0xd24a(%rip), %r8d      # 0x16dc4
movl %r8d, %edx
imull %ebx, %edx
addl 0xd232(%rip), %edx      # 0x16db8
movl 0xd234(%rip), %ecx      # 0x16dc0
imull %r14d, %ecx
addl 0xd226(%rip), %ecx      # 0x16dbc
decl %r8d
movq %rsp, %r15
pushq $0x1
popq %rbp
movq %r15, %rsi
movl %ebp, %r9d
callq 0x53d0
movq 0xd157(%rip), %rdi      # 0x16d08
movl 0xd20d(%rip), %edx      # 0x16dc4
imull %ebx, %edx
addl 0xd1f8(%rip), %edx      # 0x16db8
movl 0xd1f9(%rip), %r9d      # 0x16dc0
movl %r9d, %ecx
imull %r14d, %ecx
addl 0xd1e8(%rip), %ecx      # 0x16dbc
decl %r9d
movq %r15, %rsi
movl %ebp, %r8d
callq 0x53d0
movq 0xd11f(%rip), %rdi      # 0x16d08
leal 0x1(%rbx), %eax
imull 0xd1d1(%rip), %eax      # 0x16dc4
movl 0xd1bf(%rip), %ecx      # 0x16db8
leal (%rcx,%rax), %edx
decl %edx
movl 0xd1bb(%rip), %r9d      # 0x16dc0
movl %r9d, %ecx
imull %r14d, %ecx
addl 0xd1aa(%rip), %ecx      # 0x16dbc
decl %r9d
movq %r15, %rsi
movl %ebp, %r8d
callq 0x53d0
movq 0xd0e1(%rip), %rdi      # 0x16d08
movl 0xd196(%rip), %r8d      # 0x16dc4
imull %r8d, %ebx
addl 0xd180(%rip), %ebx      # 0x16db8
movl 0xd17e(%rip), %eax      # 0x16dbc
incl %r14d
imull 0xd177(%rip), %r14d     # 0x16dc0
leal (%rax,%r14), %ecx
decl %ecx
movq %r15, %rsi
movl %ebx, %edx
movl %ebp, %r9d
callq 0x53d0
jmp 0x9d30
movl 0xd165(%rip), %eax      # 0x16dcc
cmpq $0x7, %rax
ja 0x9d30
leaq 0x3de0(%rip), %rcx      # 0xda58
movslq (%rcx,%rax,4), %rdx
addq %rcx, %rdx
movq 0x18(%rsp), %rsi
movq %rsi, %rax
jmpq *%rdx
movq 0xd078(%rip), %rdi      # 0x16d08
movl 0xd12d(%rip), %r8d      # 0x16dc4
imull %r8d, %ebx
addl 0xd117(%rip), %ebx      # 0x16db8
movl 0xd115(%rip), %eax      # 0x16dbc
incl %r14d
imull 0xd10e(%rip), %r14d     # 0x16dc0
leal (%rax,%r14), %ecx
addl $-0x2, %ecx
movq %rsp, %rsi
pushq $0x2
popq %r9
movl %ebx, %edx
jmp 0x9c57
movq 0xd03d(%rip), %rdi      # 0x16d08
imull 0xd0f2(%rip), %ebx      # 0x16dc4
addl 0xd0e0(%rip), %ebx      # 0x16db8
movl 0xd0e1(%rip), %r9d      # 0x16dc0
imull %r9d, %r14d
addl 0xd0d2(%rip), %r14d     # 0x16dbc
movq %rsp, %rsi
pushq $0x2
popq %r8
movl %ebx, %edx
movl %r14d, %ecx
jmp 0x9c57
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 0x9d3f
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq