// File: /workspace/github_c_makefile_star2_O3/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:
movl 0x40(%rdi), %edx
xorl %ecx, %ecx
subl 0x10238(%rip), %edx     # 0x20d24
movl $0x0, %eax
js 0x10b00
movl 0x10217(%rip), %eax     # 0x20d10
decl %eax
cmpl %eax, %edx
cmovll %edx, %eax
cltd
idivl 0x10225(%rip)           # 0x20d2c
movl %eax, %r8d
movl 0x44(%rdi), %eax
subl 0x1020d(%rip), %eax     # 0x20d20
js 0x10b22
movl 0x101f9(%rip), %ecx     # 0x20d14
decl %ecx
cmpl %ecx, %eax
cmovll %eax, %ecx
pushq %rbx
subq $0x40, %rsp
movl %ecx, %eax
cltd
idivl 0x101f8(%rip)           # 0x20d28
movl 0x50(%rdi), %esi
movl (%rdi), %edx
cmpl $0x6, %edx
jne 0x10bb6
cmpl 0x10353(%rip), %r8d     # 0x20e94
jne 0x10b4f
cmpl 0x1034f(%rip), %eax     # 0x20e98
je 0x10cd9
movl 0x101df(%rip), %edi     # 0x20d34
testl $0x8010, %edi           # imm = 0x8010
je 0x10cd9
movl %edi, %r9d
shrb $0x4, %r9b
movl 0x10322(%rip), %ecx     # 0x20e90
testl %ecx, %ecx
sete %r10b
testb %r10b, %r9b
jne 0x10cd9
movl $0x1, %r9d
leal -0x1(%r9), %r10d
movzbl %r10b, %r10d
btl %r10d, %ecx
jb 0x10bf8
incl %r9d
cmpl $0xc, %r9d
jne 0x10b83
movl %r8d, 0x102f3(%rip)     # 0x20e94
movl %eax, 0x102f1(%rip)     # 0x20e98
btl $0x9, %edi
setae %r11b
movl $0x20, %ecx
jmp 0x10c35
movl 0x54(%rdi), %r9d
leal -0xc(%r9), %ecx
cmpl $-0xb, %ecx
jb 0x10cd9
xorl %ecx, %ecx
movl 0x10165(%rip), %edi     # 0x20d34
cmpl $0x5, %edx
jne 0x10bfd
movl %edi, %r10d
shrl $0xe, %r10d
andl $0x1, %r10d
movl %r9d, %r11d
andl $0xe, %r11d
cmpl $0x4, %r11d
sete %r11b
orb %r10b, %r11b
je 0x10bfd
jmp 0x10cd9
movl $0x20, %ecx
movl %r8d, 0x10290(%rip)     # 0x20e94
movl %eax, 0x1028e(%rip)     # 0x20e98
btl $0x9, %edi
setae %r10b
jb 0x10c2c
cmpl $0x5, %edx
sete %r11b
cmpl $0xc, %r9d
sete %bl
orb %r11b, %bl
movb $0x1, %r11b
jne 0x10c35
jmp 0x10c3d
cmpl $0xc, %r9d
jne 0x10c3d
xorl %r11d, %r11d
orl $0x3, %ecx
movl %r11d, %r10d
jmp 0x10c5b
cmpl $0x8, %r9d
jl 0x10c4b
addl %r9d, %ecx
addl $0x78, %ecx
jmp 0x10c5b
addl %r9d, %ecx
cmpl $0x4, %r9d
jl 0x10c59
addl $0x3c, %ecx
jmp 0x10c5b
decl %ecx
btl $0xe, %edi
jb 0x10c70
movl %esi, %edi
andl $0x8, %edi
andl $0x5, %esi
leal (%rdi,%rsi,4), %esi
addl %ecx, %esi
movl %esi, %ecx
testb %r10b, %r10b
je 0x10c98
cmpl $0xde, %r8d
jg 0x10cd9
cmpl $0xde, %eax
jg 0x10cd9
addl $0x20, %ecx
addl $0x21, %r8d
addl $0x21, %eax
leaq 0x6bdb(%rip), %rdx      # 0x17871
jmp 0x10cb6
incl %r8d
incl %eax
xorl %esi, %esi
cmpl $0x5, %edx
sete %sil
shll $0x5, %esi
orl $0x4d, %esi
movl %esi, (%rsp)
leaq 0x6bad(%rip), %rdx      # 0x17863
leaq 0x10(%rsp), %rdi
movl $0x28, %esi
movl %eax, %r9d
xorl %eax, %eax
callq 0x60d0
movslq %eax, %rsi
leaq 0x10(%rsp), %rdi
xorl %edx, %edx
callq 0x8138
addq $0x40, %rsp
popq %rbx
retq