// File: /workspace/github_c_makefile_star2_O1/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, %r12
movq %rdx, 0x18(%rsp)
movl %esi, %r14d
movl %edi, %ebx
leaq 0x60(%rsp), %r15
movl %r8d, %edi
movl %r9d, %esi
callq 0x6338
testl %eax, %eax
je 0xa0e6
xorb $0x20, 0x4(%r15)
movq (%r15), %rdi
movq 0x8(%r15), %rsi
movl %r13d, %edx
movl %ebp, %ecx
callq 0xa3e0
movl 0xdcdb(%rip), %eax      # 0x17dd8
testb %al, %al
js 0xa3d1
movq 0x18(%rsp), %r13
shrq $0x20, %r13
andl $0x28d, %r13d           # imm = 0x28D
testb $0x20, %al
jne 0xa163
movl %ebx, %edi
movl %r14d, %esi
callq 0x6338
testl %eax, %eax
movl $0x101, %ebp            # imm = 0x101
cmovel %r12d, %ebp
leaq 0xb3bf(%rip), %rax      # 0x154f4
leaq 0xb3b4(%rip), %rcx      # 0x154f0
cmoveq %rax, %rcx
movl (%rcx), %r12d
btl $0x18, %ebp
jb 0xa199
movq 0xda60(%rip), %rax      # 0x17bb0
movl %ebp, %ecx
shlq $0x4, %rcx
movups (%rax,%rcx), %xmm0
movaps %xmm0, (%rsp)
jmp 0xa1f2
movzwl %r13w, %r13d
orl $0x20, %r13d
movl 0xb37f(%rip), %ebp      # 0x154f0
movl %ebx, %edi
movl %r14d, %esi
callq 0x6338
movq 0xda2e(%rip), %rcx      # 0x17bb0
testl %eax, %eax
je 0xa1e1
movups 0x1000(%rcx), %xmm0
movaps %xmm0, (%rsp)
movl $0x101, %r12d           # imm = 0x101
jmp 0xa1f2
leaq 0x20(%rsp), %rcx
movw $0xffff, 0x6(%rcx)      # imm = 0xFFFF
movl %ebp, %eax
shrl $0x8, %eax
movl $0xff00, %edx           # imm = 0xFF00
andl %edx, %eax
movw %ax, (%rcx)
andl %ebp, %edx
movw %dx, 0x2(%rcx)
movl %ebp, %eax
shll $0x8, %eax
movw %ax, 0x4(%rcx)
movq 0xdadf(%rip), %rdi      # 0x17ca8
movq 0xdb50(%rip), %rsi      # 0x17d20
movq 0xdad9(%rip), %rdx      # 0x17cb0
movq %rsp, %r8
callq 0x56f0
jmp 0xa1f2
movups 0x1010(%rcx), %xmm0
movaps %xmm0, (%rsp)
movl $0x100, %r12d           # imm = 0x100
testb $0x2, 0xdbdf(%rip)      # 0x17dd8
jne 0xa2fd
movq 0xdb12(%rip), %rdi      # 0x17d18
movl 0xdbc7(%rip), %r8d      # 0x17dd4
movl %r8d, %edx
imull %ebx, %edx
addl 0xdbaf(%rip), %edx      # 0x17dc8
movl 0xdbb1(%rip), %ecx      # 0x17dd0
imull %r14d, %ecx
addl 0xdba3(%rip), %ecx      # 0x17dcc
decl %r8d
movq %rsp, %r15
movq %r15, %rsi
movl $0x1, %r9d
callq 0x53d0
movq 0xdad4(%rip), %rdi      # 0x17d18
movl 0xdb8a(%rip), %edx      # 0x17dd4
imull %ebx, %edx
addl 0xdb75(%rip), %edx      # 0x17dc8
movl 0xdb76(%rip), %r9d      # 0x17dd0
movl %r9d, %ecx
imull %r14d, %ecx
addl 0xdb65(%rip), %ecx      # 0x17dcc
decl %r9d
movq %r15, %rsi
movl $0x1, %r8d
callq 0x53d0
movq 0xda99(%rip), %rdi      # 0x17d18
leal 0x1(%rbx), %eax
imull 0xdb4b(%rip), %eax      # 0x17dd4
movl 0xdb39(%rip), %ecx      # 0x17dc8
leal (%rcx,%rax), %edx
decl %edx
movl 0xdb35(%rip), %r9d      # 0x17dd0
movl %r9d, %ecx
imull %r14d, %ecx
addl 0xdb24(%rip), %ecx      # 0x17dcc
decl %r9d
movq %r15, %rsi
movl $0x1, %r8d
callq 0x53d0
movq 0xda58(%rip), %rdi      # 0x17d18
movl 0xdb0d(%rip), %r8d      # 0x17dd4
imull %r8d, %ebx
addl 0xdaf7(%rip), %ebx      # 0x17dc8
movl 0xdaf5(%rip), %eax      # 0x17dcc
incl %r14d
imull 0xdaee(%rip), %r14d     # 0x17dd0
leal (%rax,%r14), %ecx
decl %ecx
movq %r15, %rsi
movl %ebx, %edx
movl $0x1, %r9d
callq 0x53d0
jmp 0xa3d1
movl 0xdad9(%rip), %eax      # 0x17ddc
cmpq $0x7, %rax
ja 0xa3d1
leaq 0x4748(%rip), %rcx      # 0xea5c
movslq (%rcx,%rax,4), %rdx
addq %rcx, %rdx
movq 0x18(%rsp), %rsi
movq %rsi, %rax
jmpq *%rdx
movq 0xd9ec(%rip), %rdi      # 0x17d18
movl 0xdaa1(%rip), %r8d      # 0x17dd4
imull %r8d, %ebx
addl 0xda8b(%rip), %ebx      # 0x17dc8
movl 0xda89(%rip), %eax      # 0x17dcc
incl %r14d
imull 0xda82(%rip), %r14d     # 0x17dd0
leal (%rax,%r14), %ecx
addl $-0x2, %ecx
movq %rsp, %rsi
movl %ebx, %edx
movl $0x2, %r9d
jmp 0xa2f3
movq 0xd9af(%rip), %rdi      # 0x17d18
imull 0xda64(%rip), %ebx      # 0x17dd4
addl 0xda52(%rip), %ebx      # 0x17dc8
movl 0xda53(%rip), %r9d      # 0x17dd0
imull %r9d, %r14d
addl 0xda44(%rip), %r14d     # 0x17dcc
movq %rsp, %rsi
movl %ebx, %edx
movl %r14d, %ecx
movl $0x2, %r8d
jmp 0xa2f3
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, %rbp
movl %r12d, %esi
orq %rbp, %rsi
movl %ebx, %edx
movl %r14d, %ecx
callq 0xa3e0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq