// File: /workspace/github_c_makefile_star2_O1/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 0x1082f(%rip), %edx     # 0x20d24
movl $0x0, %eax
js 0x10509
movl 0x1080e(%rip), %eax     # 0x20d10
decl %eax
cmpl %eax, %edx
cmovll %edx, %eax
cltd
idivl 0x1081c(%rip)           # 0x20d2c
movl %eax, %r8d
movl 0x44(%rdi), %eax
subl 0x10804(%rip), %eax     # 0x20d20
js 0x1052b
movl 0x107f0(%rip), %ecx     # 0x20d14
decl %ecx
cmpl %ecx, %eax
cmovll %eax, %ecx
subq $0x38, %rsp
movl %ecx, %eax
cltd
idivl 0x107f0(%rip)           # 0x20d28
movl 0x50(%rdi), %esi
movl (%rdi), %edx
cmpl $0x6, %edx
jne 0x105a8
cmpl 0x1094b(%rip), %r8d     # 0x20e94
jne 0x10557
cmpl 0x10947(%rip), %eax     # 0x20e98
je 0x106a9
movl 0x107d7(%rip), %ecx     # 0x20d34
testl $0x8010, %ecx           # imm = 0x8010
je 0x106a9
shrb $0x4, %cl
movl 0x1091d(%rip), %r9d     # 0x20e90
testl %r9d, %r9d
sete %dil
testb %dil, %cl
jne 0x106a9
movl $0x1, %edi
leal -0x1(%rdi), %ecx
movzbl %cl, %r10d
movl $0x20, %ecx
btl %r10d, %r9d
jb 0x105e2
incl %edi
cmpl $0xc, %edi
jne 0x10588
movl $0xc, %edi
jmp 0x105e2
movl 0x54(%rdi), %edi
leal -0xc(%rdi), %ecx
cmpl $-0xb, %ecx
jb 0x106a9
xorl %ecx, %ecx
cmpl $0x5, %edx
jne 0x105e2
movl %edi, %r9d
andl $0xe, %r9d
cmpl $0x4, %r9d
je 0x106a9
movl $0x4000, %r9d           # imm = 0x4000
andl 0x10758(%rip), %r9d     # 0x20d34
jne 0x106a9
movl %r8d, 0x108ab(%rip)     # 0x20e94
movl %eax, 0x108a9(%rip)     # 0x20e98
movl 0x1073e(%rip), %r9d     # 0x20d34
btl $0x9, %r9d
jb 0x10620
cmpl $0x5, %edx
sete %r10b
cmpl $0xc, %edi
sete %r11b
orb %r10b, %r11b
jne 0x10625
cmpl $0x8, %edi
jl 0x106ae
addl %edi, %ecx
addl $0x78, %ecx
jmp 0x10628
cmpl $0xc, %edi
jne 0x10610
orl $0x3, %ecx
btl $0xe, %r9d
jb 0x1063e
movl %esi, %edi
andl $0x8, %edi
andl $0x5, %esi
leal (%rdi,%rsi,4), %esi
addl %ecx, %esi
movl %esi, %ecx
btl $0x9, %r9d
jb 0x10668
cmpl $0xde, %r8d
jg 0x106a9
cmpl $0xde, %eax
jg 0x106a9
addl $0x20, %ecx
addl $0x21, %r8d
addl $0x21, %eax
leaq 0x71eb(%rip), %rdx      # 0x17851
jmp 0x10686
incl %r8d
incl %eax
xorl %esi, %esi
cmpl $0x5, %edx
sete %sil
shll $0x5, %esi
orl $0x4d, %esi
movl %esi, (%rsp)
leaq 0x71bd(%rip), %rdx      # 0x17843
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 0x8037
addq $0x38, %rsp
retq
addl %edi, %ecx
cmpl $0x4, %edi
jl 0x106bd
addl $0x3c, %ecx
jmp 0x10628
decl %ecx
jmp 0x10628