// File: /workspace/github_c_makefile_star2_O1/odknt[P]st/x.c
// Function: mousereport
void
mousereport(XEvent *e)
{
	int len, btn, code;
	int x = evcol(e), y = evrow(e);
	int state = e->xbutton.state;
	char buf[40];
	static int ox, oy;

	if (e->type == MotionNotify) {
		if (x == ox && y == oy)
			return;
		if (!IS_SET(MODE_MOUSEMOTION) && !IS_SET(MODE_MOUSEMANY))
			return;
		/* MODE_MOUSEMOTION: no reporting if no button is pressed */
		if (IS_SET(MODE_MOUSEMOTION) && buttons == 0)
			return;
		/* Set btn to lowest-numbered pressed button, or 12 if no
		 * buttons are pressed. */
		for (btn = 1; btn <= 11 && !(buttons & (1<<(btn-1))); btn++)
			;
		code = 32;
	} else {
		btn = e->xbutton.button;
		/* Only buttons 1 through 11 can be encoded */
		if (btn < 1 || btn > 11)
			return;
		if (e->type == ButtonRelease) {
			/* MODE_MOUSEX10: no button release reporting */
			if (IS_SET(MODE_MOUSEX10))
				return;
			/* Don't send release events for the scroll wheel */
			if (btn == 4 || btn == 5)
				return;
		}
		code = 0;
	}

	ox = x;
	oy = y;

	/* Encode btn into code. If no button is pressed for a motion event in
	 * MODE_MOUSEMANY, then encode it as a release. */
	if ((!IS_SET(MODE_MOUSESGR) && e->type == ButtonRelease) || btn == 12)
		code += 3;
	else if (btn >= 8)
		code += 128 + btn - 8;
	else if (btn >= 4)
		code += 64 + btn - 4;
	else
		code += btn - 1;

	if (!IS_SET(MODE_MOUSEX10)) {
		code += ((state & ShiftMask  ) ?  4 : 0)
		      + ((state & Mod1Mask   ) ?  8 : 0) /* meta key: alt */
		      + ((state & ControlMask) ? 16 : 0);
	}

	if (IS_SET(MODE_MOUSESGR)) {
		len = snprintf(buf, sizeof(buf), "\033[<%d;%d;%d%c",
				code, x+1, y+1,
				e->type == ButtonRelease ? 'm' : 'M');
	} else if (x < 223 && y < 223) {
		len = snprintf(buf, sizeof(buf), "\033[M%c%c%c",
				32+code, 32+x+1, 32+y+1);
	} else {
		return;
	}

	ttywrite(buf, len, 0);
}

// Assembly:
movl 0x40(%rdi), %edx
movl 0x8422(%rip), %esi      # 0x17e0c
xorl %ecx, %ecx
subl %esi, %edx
movl $0x0, %eax
js 0xfa02
movl 0xef2d(%rip), %eax      # 0x1e928
decl %eax
cmpl %eax, %edx
cmovll %edx, %eax
cltd
idivl 0xef33(%rip)            # 0x1e93c
movl %eax, %r8d
movl 0x44(%rdi), %eax
subl %esi, %eax
js 0xfa20
movl 0xef13(%rip), %ecx      # 0x1e92c
decl %ecx
cmpl %ecx, %eax
cmovll %eax, %ecx
subq $0x38, %rsp
movl %ecx, %eax
cltd
idivl 0xef0b(%rip)            # 0x1e938
movl 0x50(%rdi), %esi
movl (%rdi), %edx
cmpl $0x6, %edx
jne 0xfa9d
cmpl 0xefbe(%rip), %r8d      # 0x1e9fc
jne 0xfa4c
cmpl 0xefba(%rip), %eax      # 0x1ea00
je 0xfb9e
movl 0xeef2(%rip), %ecx      # 0x1e944
testl $0x8010, %ecx           # imm = 0x8010
je 0xfb9e
shrb $0x4, %cl
movl 0xef90(%rip), %r9d      # 0x1e9f8
testl %r9d, %r9d
sete %dil
testb %dil, %cl
jne 0xfb9e
movl $0x1, %edi
leal -0x1(%rdi), %ecx
movzbl %cl, %r10d
movl $0x20, %ecx
btl %r10d, %r9d
jb 0xfad7
incl %edi
cmpl $0xc, %edi
jne 0xfa7d
movl $0xc, %edi
jmp 0xfad7
movl 0x54(%rdi), %edi
leal -0xc(%rdi), %ecx
cmpl $-0xb, %ecx
jb 0xfb9e
xorl %ecx, %ecx
cmpl $0x5, %edx
jne 0xfad7
movl %edi, %r9d
andl $0xe, %r9d
cmpl $0x4, %r9d
je 0xfb9e
movl $0x4000, %r9d           # imm = 0x4000
andl 0xee73(%rip), %r9d      # 0x1e944
jne 0xfb9e
movl %r8d, 0xef1e(%rip)      # 0x1e9fc
movl %eax, 0xef1c(%rip)      # 0x1ea00
movl 0xee59(%rip), %r9d      # 0x1e944
btl $0x9, %r9d
jb 0xfb15
cmpl $0x5, %edx
sete %r10b
cmpl $0xc, %edi
sete %r11b
orb %r10b, %r11b
jne 0xfb1a
cmpl $0x8, %edi
jl 0xfba3
addl %edi, %ecx
addl $0x78, %ecx
jmp 0xfb1d
cmpl $0xc, %edi
jne 0xfb05
orl $0x3, %ecx
btl $0xe, %r9d
jb 0xfb33
movl %esi, %edi
andl $0x8, %edi
andl $0x5, %esi
leal (%rdi,%rsi,4), %esi
addl %ecx, %esi
movl %esi, %ecx
btl $0x9, %r9d
jb 0xfb5d
cmpl $0xde, %r8d
jg 0xfb9e
cmpl $0xde, %eax
jg 0xfb9e
addl $0x20, %ecx
addl $0x21, %r8d
addl $0x21, %eax
leaq 0x1b46(%rip), %rdx      # 0x116a1
jmp 0xfb7b
incl %r8d
incl %eax
xorl %esi, %esi
cmpl $0x5, %edx
sete %sil
shll $0x5, %esi
orl $0x4d, %esi
movl %esi, (%rsp)
leaq 0x1b18(%rip), %rdx      # 0x11693
leaq 0x10(%rsp), %rdi
movl $0x28, %esi
movl %eax, %r9d
xorl %eax, %eax
callq 0x60c0
movslq %eax, %rsi
leaq 0x10(%rsp), %rdi
xorl %edx, %edx
callq 0x8045
addq $0x38, %rsp
retq
addl %edi, %ecx
cmpl $0x4, %edi
jl 0xfbb2
addl $0x3c, %ecx
jmp 0xfb1d
decl %ecx
jmp 0xfb1d