// File: /workspace/github_c_makefile_star2_O2/mcaimi[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;

  /* from urxvt */
  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)
          + ((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 %r14
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
callq 0xfb3d
movl %eax, %ebx
movq %r14, %rdi
callq 0xfb61
movl 0x50(%r14), %esi
movl (%r14), %edx
cmpl $0x6, %edx
jne 0xf981
cmpl 0x11572(%rip), %ebx     # 0x20e94
jne 0xf930
cmpl 0x1156e(%rip), %eax     # 0x20e98
je 0xfa90
movl 0x113fe(%rip), %edi     # 0x20d34
testw $0x8010, %di            # imm = 0x8010
je 0xfa90
movl %edi, %ecx
shrb $0x4, %cl
movl 0x11543(%rip), %r9d     # 0x20e90
testl %r9d, %r9d
sete %r8b
testb %r8b, %cl
jne 0xfa90
pushq $0x1
popq %r10
pushq $0xc
popq %r8
pushq $0x20
popq %rcx
cmpl $0xc, %r10d
je 0xf9c6
leal -0x1(%r10), %r11d
movzbl %r11b, %r11d
btl %r11d, %r9d
jb 0xf9c3
incl %r10d
jmp 0xf968
movl 0x54(%r14), %r8d
leal -0xc(%r8), %ecx
cmpl $-0xb, %ecx
jb 0xfa90
xorl %ecx, %ecx
movl 0x1139a(%rip), %edi     # 0x20d34
cmpl $0x5, %edx
jne 0xf9c6
movl %edi, %r9d
shrl $0xe, %r9d
andl $0x1, %r9d
movl %r8d, %r10d
andl $0xe, %r10d
cmpl $0x4, %r10d
sete %r10b
orb %r9b, %r10b
je 0xf9c6
jmp 0xfa90
movl %r10d, %r8d
movl %ebx, 0x114c8(%rip)     # 0x20e94
movl %eax, 0x114c6(%rip)     # 0x20e98
btl $0x9, %edi
jb 0xf9fe
cmpl $0x5, %edx
sete %r9b
cmpl $0xc, %r8d
sete %r10b
orb %r9b, %r10b
jne 0xfa04
cmpl $0x8, %r8d
jl 0xfa98
addl %r8d, %ecx
addl $0x78, %ecx
jmp 0xfa07
cmpl $0xc, %r8d
jne 0xf9ec
orl $0x3, %ecx
btl $0xe, %edi
jb 0xfa1f
movl %esi, %r8d
andl $0x8, %r8d
andl $0x5, %esi
leal (%r8,%rsi,4), %esi
addl %ecx, %esi
movl %esi, %ecx
btl $0x9, %edi
jb 0xfa4f
movl $0xdf, %edx
cmpl %edx, %ebx
setl %sil
cmpl %edx, %eax
setl %dl
andb %sil, %dl
cmpb $0x1, %dl
jne 0xfa90
addl $0x20, %ecx
addl $0x21, %ebx
addl $0x21, %eax
leaq 0x6df4(%rip), %rdx      # 0x16841
jmp 0xfa6c
incl %ebx
incl %eax
xorl %esi, %esi
cmpl $0x5, %edx
sete %sil
shll $0x5, %esi
orl $0x4d, %esi
movl %esi, (%rsp)
leaq 0x6dc7(%rip), %rdx      # 0x16833
leaq 0x10(%rsp), %rdi
pushq $0x28
popq %rsi
movl %ebx, %r8d
movl %eax, %r9d
xorl %eax, %eax
callq 0x60d0
movslq %eax, %rsi
leaq 0x10(%rsp), %rdi
xorl %edx, %edx
callq 0x7a9b
addq $0x38, %rsp
popq %rbx
popq %r14
retq
addl %r8d, %ecx
cmpl $0x4, %r8d
jl 0xfaa9
addl $0x3c, %ecx
jmp 0xfa07
decl %ecx
jmp 0xfa07