// File: /workspace/github_c_makefile_star2_O1/AtifChy[P]st/x.c
// Function: xdrawcursor
void
xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og, Line line, int len)
{
	Color drawcol;
	XRenderColor colbg;

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

	/* Redraw the line where cursor was previously.
	 * It will restore the ligatures broken by the cursor. */
	xdrawline(line, 0, oy, len);

	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|ATTR_BOXDRAW;

	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 */
			if (!(og.mode & ATTR_REVERSE)) {
				unsigned long col = g.bg;
				g.bg = g.fg;
				g.fg = col;
			}
		}

		/**
		 * 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 0: /* Blinking block */
		case 1: /* Blinking block (default) */
			if (IS_SET(MODE_BLINK))
				break;
			/* FALLTHROUGH */
		case 2: /* Steady block */
			xdrawglyph(g, cx, cy);
			break;
		case 3: /* Blinking underline */
			if (IS_SET(MODE_BLINK))
				break;
			/* FALLTHROUGH */
		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 */
			if (IS_SET(MODE_BLINK))
				break;
			/* FALLTHROUGH */
		case 6: /* Steady bar */
			XftDrawRect(xw.draw, &drawcol,
					win.hborderpx + cx * win.cw,
					win.vborderpx + cy * win.ch,
					cursorthickness, win.ch);
			break;
		case 7: /* Blinking st cursor */
			if (IS_SET(MODE_BLINK))
				break;
			/* FALLTHROUGH */
		case 8: /* Steady st cursor */
			g.u = stcursor;
			xdrawglyph(g, cx, cy);
			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
movq %rcx, %r12
movq %rdx, 0x8(%rsp)
movl %esi, %r14d
movq %rdi, (%rsp)
movl 0x78(%rsp), %r13d
movq 0x70(%rsp), %r15
leaq 0x60(%rsp), %rbx
movl %r8d, %edi
movl %r9d, %esi
callq 0x74a8
testl %eax, %eax
je 0xbc65
xorb $0x20, 0x4(%rbx)
movq %r15, %rdi
xorl %esi, %esi
movl %ebp, %edx
movl %r13d, %ecx
callq 0xbfbf
movl 0x13d26(%rip), %eax     # 0x1f9a0
testb %al, %al
js 0xbfb0
movq 0x8(%rsp), %r15
shrq $0x20, %r15
andl $0xa8d, %r15d           # imm = 0xA8D
testb $0x20, %al
jne 0xbcb4
movq (%rsp), %rdi
movl %r14d, %esi
callq 0x74a8
testl %eax, %eax
je 0xbcf4
movl $0x103, %r13d           # imm = 0x103
movl 0xc94a(%rip), %ebp      # 0x185fc
jmp 0xbd0a
movzwl %r15w, %r15d
orl $0x20, %r15d
movl 0xc939(%rip), %r13d     # 0x185fc
movq (%rsp), %rdi
movl %r14d, %esi
callq 0x74a8
movq 0x13ab2(%rip), %rcx     # 0x1f788
testl %eax, %eax
je 0xbd77
movups 0x1020(%rcx), %xmm0
movaps %xmm0, 0x10(%rsp)
movl $0x103, %ebp            # imm = 0x103
jmp 0xbd88
movq %r12, %r13
shrq $0x20, %r13
testb $0x20, 0x4(%rbx)
movl %r12d, %ebp
cmovel %r13d, %ebp
cmovel %r12d, %r13d
btl $0x18, %r13d
jb 0xbd2a
movq 0x13a70(%rip), %rax     # 0x1f788
movl %r13d, %ecx
shlq $0x4, %rcx
movups (%rax,%rcx), %xmm0
movaps %xmm0, 0x10(%rsp)
jmp 0xbd88
leaq 0x20(%rsp), %rcx
movw $0xffff, 0x6(%rcx)      # imm = 0xFFFF
movl %r13d, %eax
shrl $0x8, %eax
movl $0xff00, %edx           # imm = 0xFF00
andl %edx, %eax
movw %ax, (%rcx)
andl %r13d, %edx
movw %dx, 0x2(%rcx)
movl %r13d, %eax
shll $0x8, %eax
movw %ax, 0x4(%rcx)
movq 0x13b23(%rip), %rdi     # 0x1f880
movq 0x13b8c(%rip), %rsi     # 0x1f8f0
movq 0x13b1d(%rip), %rdx     # 0x1f888
leaq 0x10(%rsp), %r8
callq 0x67d0
jmp 0xbd88
movups 0x1030(%rcx), %xmm0
movaps %xmm0, 0x10(%rsp)
movl $0x102, %ebp            # imm = 0x102
movl 0x13c12(%rip), %eax     # 0x1f9a0
testb $0x2, %al
jne 0xbe9a
movq 0x13b4b(%rip), %rdi     # 0x1f8e8
movl 0x13bf8(%rip), %r8d     # 0x1f99c
movl %r8d, %edx
movq (%rsp), %rbx
imull %ebx, %edx
addl 0x13bdc(%rip), %edx     # 0x1f990
movl 0x13bde(%rip), %ecx     # 0x1f998
imull %r14d, %ecx
addl 0x13bd0(%rip), %ecx     # 0x1f994
decl %r8d
leaq 0x10(%rsp), %r15
movq %r15, %rsi
movl $0x1, %r9d
callq 0x6430
movq 0x13b07(%rip), %rdi     # 0x1f8e8
movl 0x13bb5(%rip), %edx     # 0x1f99c
imull %ebx, %edx
addl 0x13ba0(%rip), %edx     # 0x1f990
movl 0x13ba1(%rip), %r9d     # 0x1f998
movl %r9d, %ecx
imull %r14d, %ecx
addl 0x13b90(%rip), %ecx     # 0x1f994
decl %r9d
movq %r15, %rsi
movl $0x1, %r8d
callq 0x6430
movq 0x13acc(%rip), %rdi     # 0x1f8e8
leal 0x1(%rbx), %eax
imull 0x13b76(%rip), %eax     # 0x1f99c
movl 0x13b64(%rip), %ecx     # 0x1f990
leal (%rcx,%rax), %edx
decl %edx
movl 0x13b60(%rip), %r9d     # 0x1f998
movl %r9d, %ecx
imull %r14d, %ecx
addl 0x13b4f(%rip), %ecx     # 0x1f994
decl %r9d
movq %r15, %rsi
movl $0x1, %r8d
callq 0x6430
movq 0x13a8b(%rip), %rdi     # 0x1f8e8
movl 0x13b38(%rip), %r8d     # 0x1f99c
imull %r8d, %ebx
addl 0x13b22(%rip), %ebx     # 0x1f990
movl 0x13b20(%rip), %eax     # 0x1f994
incl %r14d
imull 0x13b19(%rip), %r14d    # 0x1f998
leal (%rax,%r14), %ecx
decl %ecx
movq %r15, %rsi
movl %ebx, %edx
movl $0x1, %r9d
callq 0x6430
jmp 0xbfb0
movl 0x13b04(%rip), %ecx     # 0x1f9a4
cmpq $0x8, %rcx
ja 0xbfb0
leaq 0x5bb7(%rip), %rdx      # 0x11a68
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
btl $0xb, %eax
jb 0xbfb0
movzwl %r15w, %eax
shlq $0x20, %rax
movabsq $-0xffff00000001, %rcx  # imm = 0xFFFF0000FFFFFFFF
movq 0x8(%rsp), %rdi
andq %rcx, %rdi
orq %rax, %rdi
jmp 0xbf9b
btl $0xb, %eax
jb 0xbfb0
movq 0x139f1(%rip), %rdi     # 0x1f8e8
movl 0x13a9e(%rip), %r8d     # 0x1f99c
movq (%rsp), %rdx
imull %r8d, %edx
addl 0x13a84(%rip), %edx     # 0x1f990
movl 0x13a82(%rip), %eax     # 0x1f994
incl %r14d
imull 0x13a7b(%rip), %r14d    # 0x1f998
leal (%rax,%r14), %ecx
decl %ecx
leaq 0x10(%rsp), %rsi
jmp 0xbe8a
btl $0xb, %eax
jb 0xbfb0
movq 0x139ae(%rip), %rdi     # 0x1f8e8
movq (%rsp), %rdx
imull 0x13a57(%rip), %edx     # 0x1f99c
addl 0x13a45(%rip), %edx     # 0x1f990
movl 0x13a46(%rip), %r9d     # 0x1f998
imull %r9d, %r14d
addl 0x13a37(%rip), %r14d    # 0x1f994
leaq 0x10(%rsp), %rsi
movl %r14d, %ecx
movl $0x1, %r8d
jmp 0xbe90
btl $0xb, %eax
jb 0xbfb0
movabsq $-0x1000000000000, %rax # imm = 0xFFFF000000000000
movq 0x8(%rsp), %rcx
andq %rax, %rcx
movzwl %r15w, %eax
shlq $0x20, %rax
leaq (%rax,%rcx), %rdi
addq $0x2603, %rdi           # imm = 0x2603
shlq $0x20, %r13
movl %ebp, %esi
orq %r13, %rsi
movq (%rsp), %rdx
movl %r14d, %ecx
callq 0xc202
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq