// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x138f0
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x13960
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x6, (%rax)
jne 0x13628
movl -0x18(%rbp), %eax
cmpl 0xf208(%rip), %eax      # 0x2278c
jne 0x13596
movl -0x1c(%rbp), %eax
cmpl 0xf201(%rip), %eax      # 0x22790
jne 0x13596
jmp 0x13801
movl 0xf138(%rip), %eax      # 0x226d4
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x135b9
movl 0xf12a(%rip), %eax      # 0x226d4
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
jne 0x135b9
jmp 0x13801
movl 0xf115(%rip), %eax      # 0x226d4
andl $0x10, %eax
cmpl $0x0, %eax
je 0x135d5
cmpl $0x0, 0xf1ba(%rip)      # 0x22788
jne 0x135d5
jmp 0x13801
movl $0x1, -0x10(%rbp)
xorl %eax, %eax
cmpl $0xb, -0x10(%rbp)
movb %al, -0x51(%rbp)
jg 0x13609
movl 0xf19b(%rip), %eax      # 0x22788
movl -0x10(%rbp), %ecx
subl $0x1, %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x13612
jmp 0x1361f
jmp 0x13614
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x135dc
movl $0x20, -0x14(%rbp)
jmp 0x1367b
movq -0x8(%rbp), %rax
movl 0x54(%rax), %eax
movl %eax, -0x10(%rbp)
cmpl $0x1, -0x10(%rbp)
jl 0x1363e
cmpl $0xb, -0x10(%rbp)
jle 0x13643
jmp 0x13801
movq -0x8(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x13674
movl 0xf082(%rip), %eax      # 0x226d4
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
je 0x13661
jmp 0x13801
cmpl $0x4, -0x10(%rbp)
je 0x1366d
cmpl $0x5, -0x10(%rbp)
jne 0x13672
jmp 0x13801
jmp 0x13674
movl $0x0, -0x14(%rbp)
movl -0x18(%rbp), %eax
movl %eax, 0xf108(%rip)      # 0x2278c
movl -0x1c(%rbp), %eax
movl %eax, 0xf103(%rip)      # 0x22790
movl 0xf041(%rip), %eax      # 0x226d4
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
jne 0x136a6
movq -0x8(%rbp), %rax
cmpl $0x5, (%rax)
je 0x136ac
cmpl $0xc, -0x10(%rbp)
jne 0x136b7
movl -0x14(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x14(%rbp)
jmp 0x136f7
cmpl $0x8, -0x10(%rbp)
jl 0x136d0
movl -0x10(%rbp), %eax
addl $0x80, %eax
subl $0x8, %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x136f5
cmpl $0x4, -0x10(%rbp)
jl 0x136e7
movl -0x10(%rbp), %eax
addl $0x40, %eax
subl $0x4, %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x136f3
movl -0x10(%rbp), %eax
subl $0x1, %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x136f5
jmp 0x136f7
movl 0xefd7(%rip), %eax      # 0x226d4
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
jne 0x1374a
movl -0x20(%rbp), %edx
andl $0x1, %edx
xorl %eax, %eax
movl $0x4, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl -0x20(%rbp), %esi
andl $0x8, %esi
xorl %ecx, %ecx
movl $0x8, %edx
cmpl $0x0, %esi
cmovnel %edx, %ecx
addl %ecx, %eax
movl -0x20(%rbp), %esi
andl $0x4, %esi
xorl %ecx, %ecx
movl $0x10, %edx
cmpl $0x0, %esi
cmovnel %edx, %ecx
addl %ecx, %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl 0xef84(%rip), %eax      # 0x226d4
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x137a2
leaq -0x50(%rbp), %rdi
movl -0x14(%rbp), %ecx
movl -0x18(%rbp), %r8d
addl $0x1, %r8d
movl -0x1c(%rbp), %r9d
addl $0x1, %r9d
movq -0x8(%rbp), %rax
movl (%rax), %esi
movl $0x4d, %eax
movl $0x6d, %edx
cmpl $0x5, %esi
cmovel %edx, %eax
movl $0x28, %esi
leaq 0x2188(%rip), %rdx      # 0x1591b
movl %eax, (%rsp)
movb $0x0, %al
callq 0x60c0
movl %eax, -0xc(%rbp)
jmp 0x137f2
cmpl $0xdf, -0x18(%rbp)
jge 0x137ee
cmpl $0xdf, -0x1c(%rbp)
jge 0x137ee
leaq -0x50(%rbp), %rdi
movl -0x14(%rbp), %ecx
addl $0x20, %ecx
movl -0x18(%rbp), %r8d
addl $0x20, %r8d
addl $0x1, %r8d
movl -0x1c(%rbp), %r9d
addl $0x20, %r9d
addl $0x1, %r9d
movl $0x28, %esi
leaq 0x2147(%rip), %rdx      # 0x15929
movb $0x0, %al
callq 0x60c0
movl %eax, -0xc(%rbp)
jmp 0x137f0
jmp 0x13801
jmp 0x137f2
leaq -0x50(%rbp), %rdi
movslq -0xc(%rbp), %rsi
xorl %edx, %edx
callq 0x8350
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)