// File: /workspace/github_c_makefile_star2_O2/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 0x703f
testl %eax, %eax
je 0xb38f
xorb $0x20, 0x4(%rbx)
movq %r15, %rdi
xorl %esi, %esi
movl %ebp, %edx
movl %r13d, %ecx
callq 0xb6dd
movl 0x1360c(%rip), %eax     # 0x1e9b0
testb %al, %al
js 0xb6ce
movq 0x8(%rsp), %r15
shrq $0x20, %r15
andl $0xa8d, %r15d           # imm = 0xA8D
testb $0x20, %al
jne 0xb3de
movq (%rsp), %rdi
movl %r14d, %esi
callq 0x703f
testl %eax, %eax
je 0xb41a
movl $0x103, %r13d           # imm = 0x103
movl 0xc220(%rip), %ebp      # 0x175fc
jmp 0xb437
movzwl %r15w, %r15d
orl $0x20, %r15d
movl 0xc20f(%rip), %r13d     # 0x175fc
movq (%rsp), %rdi
movl %r14d, %esi
callq 0x703f
movq 0x13398(%rip), %rcx     # 0x1e798
testl %eax, %eax
je 0xb450
movups 0x1020(%rcx), %xmm0
movaps %xmm0, 0x10(%rsp)
movl $0x103, %ebp            # imm = 0x103
jmp 0xb4ad
movq %r12, %r13
shrq $0x20, %r13
testb $0x20, 0x4(%rbx)
movl %r12d, %ebp
cmovel %r13d, %ebp
cmovel %r12d, %r13d
btl $0x18, %r13d
jb 0xb463
movq 0x1335a(%rip), %rax     # 0x1e798
movl %r13d, %ecx
shlq $0x4, %rcx
movups (%rax,%rcx), %xmm0
movaps %xmm0, 0x10(%rsp)
jmp 0xb4ad
movups 0x1030(%rcx), %xmm0
movaps %xmm0, 0x10(%rsp)
movl $0x102, %ebp            # imm = 0x102
jmp 0xb4ad
leaq 0x20(%rsp), %rcx
orw $-0x1, 0x6(%rcx)
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 0x133fb(%rip), %rdi     # 0x1e890
movq 0x13464(%rip), %rsi     # 0x1e900
movq 0x133f5(%rip), %rdx     # 0x1e898
leaq 0x10(%rsp), %r8
callq 0x67d0
movl 0x134fd(%rip), %eax     # 0x1e9b0
testb $0x2, %al
jne 0xb5b6
movq 0x13436(%rip), %rdi     # 0x1e8f8
movl 0x134e3(%rip), %r8d     # 0x1e9ac
movl %r8d, %edx
movq (%rsp), %rbx
imull %ebx, %edx
addl 0x134c7(%rip), %edx     # 0x1e9a0
movl 0x134c9(%rip), %ecx     # 0x1e9a8
imull %r14d, %ecx
addl 0x134bb(%rip), %ecx     # 0x1e9a4
decl %r8d
leaq 0x10(%rsp), %r15
pushq $0x1
popq %rbp
movq %r15, %rsi
movl %ebp, %r9d
callq 0x6430
movq 0x133f2(%rip), %rdi     # 0x1e8f8
movl 0x134a0(%rip), %edx     # 0x1e9ac
imull %ebx, %edx
addl 0x1348b(%rip), %edx     # 0x1e9a0
movl 0x1348c(%rip), %r9d     # 0x1e9a8
movl %r9d, %ecx
imull %r14d, %ecx
addl 0x1347b(%rip), %ecx     # 0x1e9a4
decl %r9d
movq %r15, %rsi
movl %ebp, %r8d
callq 0x6430
movq 0x133ba(%rip), %rdi     # 0x1e8f8
leal 0x1(%rbx), %eax
imull 0x13464(%rip), %eax     # 0x1e9ac
movl 0x13452(%rip), %ecx     # 0x1e9a0
leal (%rcx,%rax), %edx
decl %edx
movl 0x1344e(%rip), %r9d     # 0x1e9a8
movl %r9d, %ecx
imull %r14d, %ecx
addl 0x1343d(%rip), %ecx     # 0x1e9a4
decl %r9d
movq %r15, %rsi
movl %ebp, %r8d
callq 0x6430
movq 0x1337c(%rip), %rdi     # 0x1e8f8
movl 0x13429(%rip), %r8d     # 0x1e9ac
imull %r8d, %ebx
addl 0x13413(%rip), %ebx     # 0x1e9a0
movl 0x13411(%rip), %eax     # 0x1e9a4
incl %r14d
imull 0x1340a(%rip), %r14d    # 0x1e9a8
leal (%rax,%r14), %ecx
decl %ecx
movq %r15, %rsi
movl %ebx, %edx
movl %ebp, %r9d
callq 0x6430
jmp 0xb6ce
movl 0x133f8(%rip), %ecx     # 0x1e9b4
cmpq $0x8, %rcx
ja 0xb6ce
leaq 0x5497(%rip), %rdx      # 0x10a64
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
btl $0xb, %eax
jb 0xb6ce
movzwl %r15w, %eax
shlq $0x20, %rax
movabsq $-0xffff00000001, %rcx  # imm = 0xFFFF0000FFFFFFFF
movq 0x8(%rsp), %rdi
andq %rcx, %rdi
orq %rax, %rdi
jmp 0xb6b9
btl $0xb, %eax
jb 0xb6ce
movq 0x132e5(%rip), %rdi     # 0x1e8f8
movl 0x13392(%rip), %r8d     # 0x1e9ac
movq (%rsp), %rdx
imull %r8d, %edx
addl 0x13378(%rip), %edx     # 0x1e9a0
movl 0x13376(%rip), %eax     # 0x1e9a4
incl %r14d
imull 0x1336f(%rip), %r14d    # 0x1e9a8
leal (%rax,%r14), %ecx
decl %ecx
leaq 0x10(%rsp), %rsi
pushq $0x1
popq %r9
jmp 0xb5ac
btl $0xb, %eax
jb 0xb6ce
movq 0x1329e(%rip), %rdi     # 0x1e8f8
movq (%rsp), %rdx
imull 0x13347(%rip), %edx     # 0x1e9ac
addl 0x13335(%rip), %edx     # 0x1e9a0
movl 0x13336(%rip), %r9d     # 0x1e9a8
imull %r9d, %r14d
addl 0x13327(%rip), %r14d    # 0x1e9a4
leaq 0x10(%rsp), %rsi
pushq $0x1
popq %r8
movl %r14d, %ecx
jmp 0xb5ac
btl $0xb, %eax
jb 0xb6ce
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 0xb8dc
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq