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

	/* from urxvt */
	if (e->xbutton.type == MotionNotify) {
		if (x == ox && y == oy)
			return;
		if (!IS_SET(MODE_MOUSEMOTION) && !IS_SET(MODE_MOUSEMANY))
			return;
		/* MOUSE_MOTION: no reporting if no button is pressed */
		if (IS_SET(MODE_MOUSEMOTION) && oldbutton == 3)
			return;

		button = oldbutton + 32;
		ox = x;
		oy = y;
	} else {
		if (!IS_SET(MODE_MOUSESGR) && e->xbutton.type == ButtonRelease) {
			button = 3;
		} else {
			button -= Button1;
			if (button >= 7)
				button += 128 - 7;
			else if (button >= 3)
				button += 64 - 3;
		}
		if (e->xbutton.type == ButtonPress) {
			oldbutton = button;
			ox = x;
			oy = y;
		} else if (e->xbutton.type == ButtonRelease) {
			oldbutton = 3;
			/* MODE_MOUSEX10: no button release reporting */
			if (IS_SET(MODE_MOUSEX10))
				return;
			if (button == 64 || button == 65)
				return;
		}
	}

	if (!IS_SET(MODE_MOUSEX10)) {
		button += ((state & ShiftMask  ) ? 4  : 0)
			+ ((state & Mod4Mask   ) ? 8  : 0)
			+ ((state & ControlMask) ? 16 : 0);
	}

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

	ttywrite(buf, len, 0);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
callq 0xcd34
movl %eax, %ebx
movq %r14, %rdi
callq 0xcd58
movl 0x50(%r14), %esi
movl (%r14), %edx
cmpl $0x6, %edx
jne 0xcb8e
cmpl 0xa333(%rip), %ebx      # 0x16e80
jne 0xcb5b
cmpl 0xa32f(%rip), %eax      # 0x16e84
je 0xcc9f
movl 0xa267(%rip), %edi      # 0x16dc8
testw $0x8010, %di            # imm = 0x8010
je 0xcc9f
movl %edi, %r8d
shrb $0x4, %r8b
movl 0x7b57(%rip), %ecx      # 0x146d0
cmpl $0x3, %ecx
sete %r9b
testb %r9b, %r8b
jne 0xcc9f
addl $0x20, %ecx
jmp 0xcbe1
movl 0xa234(%rip), %edi      # 0x16dc8
movl %edi, %ecx
andl $0x200, %ecx            # imm = 0x200
movl %edx, %r8d
xorl $0x5, %r8d
orl %ecx, %r8d
jne 0xcbad
pushq $0x3
popq %rcx
jmp 0xcbef
movl 0x54(%r14), %r8d
xorl %r9d, %r9d
cmpl $0x4, %r8d
setl %r9b
negl %r9d
orl $0x3c, %r9d
cmpl $0x8, %r8d
pushq $0x78
popq %rcx
cmovll %r9d, %ecx
addl %r8d, %ecx
cmpl $0x5, %edx
je 0xcbef
cmpl $0x4, %edx
jne 0xcc14
movl %ecx, 0x7aef(%rip)      # 0x146d0
movl %ebx, 0xa299(%rip)      # 0x16e80
movl %eax, 0xa297(%rip)      # 0x16e84
jmp 0xcc14
movl $0x3, 0x7ad7(%rip)      # 0x146d0
btl $0xe, %edi
jb 0xcc9f
movl %ecx, %r8d
andl $-0x2, %r8d
cmpl $0x40, %r8d
je 0xcc9f
btl $0xe, %edi
jb 0xcc2e
movl %esi, %r8d
shrl $0x3, %r8d
andl $0x8, %r8d
andl $0x5, %esi
leal (%r8,%rsi,4), %esi
addl %esi, %ecx
btl $0x9, %edi
jb 0xcc5e
movl $0xdf, %edx
cmpl %edx, %ebx
setl %sil
cmpl %edx, %eax
setl %dl
andb %sil, %dl
cmpb $0x1, %dl
jne 0xcc9f
addl $0x20, %ecx
addl $0x21, %ebx
addl $0x21, %eax
leaq 0x16ac(%rip), %rdx      # 0xe308
jmp 0xcc7b
incl %ebx
incl %eax
xorl %esi, %esi
cmpl $0x5, %edx
sete %sil
shll $0x5, %esi
orl $0x4d, %esi
movl %esi, (%rsp)
leaq 0x167f(%rip), %rdx      # 0xe2fa
leaq 0x10(%rsp), %rdi
pushq $0x28
popq %rsi
movl %ebx, %r8d
movl %eax, %r9d
xorl %eax, %eax
callq 0x50b0
movslq %eax, %rsi
leaq 0x10(%rsp), %rdi
xorl %edx, %edx
callq 0x673c
addq $0x38, %rsp
popq %rbx
popq %r14
retq