// File: /workspace/github_c_makefile_star2_O3/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 0x8db6(%rip), %esi      # 0x18dfc
xorl %ecx, %ecx
subl %esi, %edx
movl $0x0, %eax
js 0x1005e
movl 0xf8c1(%rip), %eax      # 0x1f918
decl %eax
cmpl %eax, %edx
cmovll %edx, %eax
cltd
idivl 0xf8c7(%rip)            # 0x1f92c
movl %eax, %r8d
movl 0x44(%rdi), %eax
subl %esi, %eax
js 0x1007c
movl 0xf8a7(%rip), %ecx      # 0x1f91c
decl %ecx
cmpl %ecx, %eax
cmovll %eax, %ecx
pushq %rbx
subq $0x40, %rsp
movl %ecx, %eax
cltd
idivl 0xf89e(%rip)            # 0x1f928
movl 0x50(%rdi), %esi
movl (%rdi), %edx
cmpl $0x6, %edx
jne 0x10110
cmpl 0xf951(%rip), %r8d      # 0x1f9ec
jne 0x100a9
cmpl 0xf94d(%rip), %eax      # 0x1f9f0
je 0x10233
movl 0xf885(%rip), %edi      # 0x1f934
testl $0x8010, %edi           # imm = 0x8010
je 0x10233
movl %edi, %r9d
shrb $0x4, %r9b
movl 0xf920(%rip), %ecx      # 0x1f9e8
testl %ecx, %ecx
sete %r10b
testb %r10b, %r9b
jne 0x10233
movl $0x1, %r9d
leal -0x1(%r9), %r10d
movzbl %r10b, %r10d
btl %r10d, %ecx
jb 0x10152
incl %r9d
cmpl $0xc, %r9d
jne 0x100dd
movl %r8d, 0xf8f1(%rip)      # 0x1f9ec
movl %eax, 0xf8ef(%rip)      # 0x1f9f0
btl $0x9, %edi
setae %r11b
movl $0x20, %ecx
jmp 0x1018f
movl 0x54(%rdi), %r9d
leal -0xc(%r9), %ecx
cmpl $-0xb, %ecx
jb 0x10233
xorl %ecx, %ecx
movl 0xf80b(%rip), %edi      # 0x1f934
cmpl $0x5, %edx
jne 0x10157
movl %edi, %r10d
shrl $0xe, %r10d
andl $0x1, %r10d
movl %r9d, %r11d
andl $0xe, %r11d
cmpl $0x4, %r11d
sete %r11b
orb %r10b, %r11b
je 0x10157
jmp 0x10233
movl $0x20, %ecx
movl %r8d, 0xf88e(%rip)      # 0x1f9ec
movl %eax, 0xf88c(%rip)      # 0x1f9f0
btl $0x9, %edi
setae %r10b
jb 0x10186
cmpl $0x5, %edx
sete %r11b
cmpl $0xc, %r9d
sete %bl
orb %r11b, %bl
movb $0x1, %r11b
jne 0x1018f
jmp 0x10197
cmpl $0xc, %r9d
jne 0x10197
xorl %r11d, %r11d
orl $0x3, %ecx
movl %r11d, %r10d
jmp 0x101b5
cmpl $0x8, %r9d
jl 0x101a5
addl %r9d, %ecx
addl $0x78, %ecx
jmp 0x101b5
addl %r9d, %ecx
cmpl $0x4, %r9d
jl 0x101b3
addl $0x3c, %ecx
jmp 0x101b5
decl %ecx
btl $0xe, %edi
jb 0x101ca
movl %esi, %edi
andl $0x8, %edi
andl $0x5, %esi
leal (%rdi,%rsi,4), %esi
addl %ecx, %esi
movl %esi, %ecx
testb %r10b, %r10b
je 0x101f2
cmpl $0xde, %r8d
jg 0x10233
cmpl $0xde, %eax
jg 0x10233
addl $0x20, %ecx
addl $0x21, %r8d
addl $0x21, %eax
leaq 0x24d1(%rip), %rdx      # 0x126c1
jmp 0x10210
incl %r8d
incl %eax
xorl %esi, %esi
cmpl $0x5, %edx
sete %sil
shll $0x5, %esi
orl $0x4d, %esi
movl %esi, (%rsp)
leaq 0x24a3(%rip), %rdx      # 0x126b3
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 0x8127
addq $0x40, %rsp
popq %rbx
retq