// File: manikandan5[P]Image-Matching-Stitching-Warping/./CImg.h
// Function: cimg_library::CImgDisplay::_handle_events(_XEvent const*)
void _handle_events(const XEvent *const pevent) {
      Display *const dpy = cimg::X11_attr().display;
      XEvent event = *pevent;
      switch (event.type) {
      case ClientMessage : {
        if ((int)event.xclient.message_type==(int)_wm_protocol_atom &&
            (int)event.xclient.data.l[0]==(int)_wm_window_atom) {
          XUnmapWindow(cimg::X11_attr().display,_window);
          _is_closed = _is_event = true;
          pthread_cond_broadcast(&cimg::X11_attr().wait_event);
        }
      } break;
      case ConfigureNotify : {
        while (XCheckWindowEvent(dpy,_window,StructureNotifyMask,&event)) {}
        const unsigned int nw = event.xconfigure.width, nh = event.xconfigure.height;
        const int nx = event.xconfigure.x, ny = event.xconfigure.y;
        if (nw && nh && (nw!=_window_width || nh!=_window_height)) {
          _window_width = nw; _window_height = nh; _mouse_x = _mouse_y = -1;
          XResizeWindow(dpy,_window,_window_width,_window_height);
          _is_resized = _is_event = true;
          pthread_cond_broadcast(&cimg::X11_attr().wait_event);
        }
        if (nx!=_window_x || ny!=_window_y) {
          _window_x = nx; _window_y = ny; _is_moved = _is_event = true;
          pthread_cond_broadcast(&cimg::X11_attr().wait_event);
        }
      } break;
      case Expose : {
        while (XCheckWindowEvent(dpy,_window,ExposureMask,&event)) {}
        _paint(false);
        if (_is_fullscreen) {
          XWindowAttributes attr;
          XGetWindowAttributes(dpy,_window,&attr);
          while (attr.map_state!=IsViewable) XSync(dpy,0);
          XSetInputFocus(dpy,_window,RevertToParent,CurrentTime);
        }
      } break;
      case ButtonPress : {
        do {
          _mouse_x = event.xmotion.x; _mouse_y = event.xmotion.y;
          if (_mouse_x<0 || _mouse_y<0 || _mouse_x>=width() || _mouse_y>=height()) _mouse_x = _mouse_y = -1;
          switch (event.xbutton.button) {
          case 1 : set_button(1); break;
          case 3 : set_button(2); break;
          case 2 : set_button(3); break;
          }
        } while (XCheckWindowEvent(dpy,_window,ButtonPressMask,&event));
      } break;
      case ButtonRelease : {
        do {
          _mouse_x = event.xmotion.x; _mouse_y = event.xmotion.y;
          if (_mouse_x<0 || _mouse_y<0 || _mouse_x>=width() || _mouse_y>=height()) _mouse_x = _mouse_y = -1;
          switch (event.xbutton.button) {
          case 1 : set_button(1,false); break;
          case 3 : set_button(2,false); break;
          case 2 : set_button(3,false); break;
          case 4 : set_wheel(1); break;
          case 5 : set_wheel(-1); break;
          }
        } while (XCheckWindowEvent(dpy,_window,ButtonReleaseMask,&event));
      } break;
      case KeyPress : {
        char tmp = 0; KeySym ksym;
        XLookupString(&event.xkey,&tmp,1,&ksym,0);
        set_key((unsigned int)ksym,true);
      } break;
      case KeyRelease : {
        char keys_return[32];  // Check that the key has been physically unpressed.
        XQueryKeymap(dpy,keys_return);
        const unsigned int kc = event.xkey.keycode, kc1 = kc/8, kc2 = kc%8;
        const bool is_key_pressed = kc1>=32?false:(keys_return[kc1]>>kc2)&1;
        if (!is_key_pressed) {
          char tmp = 0; KeySym ksym;
          XLookupString(&event.xkey,&tmp,1,&ksym,0);
          set_key((unsigned int)ksym,false);
        }
      } break;
      case EnterNotify: {
        while (XCheckWindowEvent(dpy,_window,EnterWindowMask,&event)) {}
        _mouse_x = event.xmotion.x;
        _mouse_y = event.xmotion.y;
        if (_mouse_x<0 || _mouse_y<0 || _mouse_x>=width() || _mouse_y>=height()) _mouse_x = _mouse_y = -1;
      } break;
      case LeaveNotify : {
        while (XCheckWindowEvent(dpy,_window,LeaveWindowMask,&event)) {}
        _mouse_x = _mouse_y =-1; _is_event = true;
        pthread_cond_broadcast(&cimg::X11_attr().wait_event);
      } break;
      case MotionNotify : {
        while (XCheckWindowEvent(dpy,_window,PointerMotionMask,&event)) {}
        _mouse_x = event.xmotion.x;
        _mouse_y = event.xmotion.y;
        if (_mouse_x<0 || _mouse_y<0 || _mouse_x>=width() || _mouse_y>=height()) _mouse_x = _mouse_y = -1;
        _is_event = true;
        pthread_cond_broadcast(&cimg::X11_attr().wait_event);
      } break;
      }
    }

// Assembly:
subq $0x208, %rsp            # imm = 0x208
movq %rdi, 0x200(%rsp)
movq %rsi, 0x1f8(%rsp)
movq 0x200(%rsp), %rax
movq %rax, 0x38(%rsp)
callq 0x37200
movq 0x2068(%rax), %rax
movq %rax, 0x1f0(%rsp)
movq 0x1f8(%rsp), %rsi
leaq 0x130(%rsp), %rdi
movl $0xc0, %edx
callq 0x5420
movl 0x130(%rsp), %eax
addl $-0x2, %eax
movl %eax, %ecx
movq %rcx, 0x40(%rsp)
subl $0x1f, %eax
ja 0x3c58d
movq 0x40(%rsp), %rax
leaq 0x8c5c4(%rip), %rcx     # 0xc830c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x38(%rsp), %rcx
movq 0x158(%rsp), %rax
movq 0x4c8(%rcx), %rcx
cmpl %ecx, %eax
jne 0x3bdcd
movq 0x38(%rsp), %rcx
movq 0x168(%rsp), %rax
movq 0x4c0(%rcx), %rcx
cmpl %ecx, %eax
jne 0x3bdcd
callq 0x37200
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq 0x2068(%rcx), %rdi
movq 0x4d0(%rax), %rsi
callq 0x57b0
movq 0x38(%rsp), %rax
movb $0x1, 0x463(%rax)
movb 0x463(%rax), %cl
andb $0x1, %cl
movb %cl, 0x460(%rax)
callq 0x37200
movq %rax, %rdi
addq $0x10, %rdi
callq 0x51a0
jmp 0x3c58d
jmp 0x3bdd4
movq 0x38(%rsp), %rax
movq 0x1f0(%rsp), %rdi
movq 0x4d0(%rax), %rsi
movl $0x20000, %edx          # imm = 0x20000
leaq 0x130(%rsp), %rcx
callq 0x5380
cmpl $0x0, %eax
je 0x3be01
jmp 0x3bdd4
movl 0x168(%rsp), %eax
movl %eax, 0x12c(%rsp)
movl 0x16c(%rsp), %eax
movl %eax, 0x128(%rsp)
movl 0x160(%rsp), %eax
movl %eax, 0x124(%rsp)
movl 0x164(%rsp), %eax
movl %eax, 0x120(%rsp)
cmpl $0x0, 0x12c(%rsp)
je 0x3bef0
cmpl $0x0, 0x128(%rsp)
je 0x3bef0
movq 0x38(%rsp), %rcx
movl 0x12c(%rsp), %eax
movl 0x40(%rcx), %ecx
cmpl %ecx, %eax
jne 0x3be7b
movq 0x38(%rsp), %rcx
movl 0x128(%rsp), %eax
movl 0x44(%rcx), %ecx
cmpl %ecx, %eax
je 0x3bef0
movq 0x38(%rsp), %rax
movl 0x12c(%rsp), %ecx
movl %ecx, 0x40(%rax)
movl 0x128(%rsp), %ecx
movl %ecx, 0x44(%rax)
movl $0xffffffff, 0x458(%rax) # imm = 0xFFFFFFFF
movl 0x458(%rax), %ecx
movl %ecx, 0x454(%rax)
movq 0x1f0(%rsp), %rdi
movq 0x4d0(%rax), %rsi
movl 0x40(%rax), %edx
movl 0x44(%rax), %ecx
callq 0x5790
movq 0x38(%rsp), %rax
movb $0x1, 0x463(%rax)
movb 0x463(%rax), %cl
andb $0x1, %cl
movb %cl, 0x461(%rax)
callq 0x37200
movq %rax, %rdi
addq $0x10, %rdi
callq 0x51a0
movq 0x38(%rsp), %rcx
movl 0x124(%rsp), %eax
movl 0x44c(%rcx), %ecx
cmpl %ecx, %eax
jne 0x3bf1c
movq 0x38(%rsp), %rcx
movl 0x120(%rsp), %eax
movl 0x450(%rcx), %ecx
cmpl %ecx, %eax
je 0x3bf62
movq 0x38(%rsp), %rax
movl 0x124(%rsp), %ecx
movl %ecx, 0x44c(%rax)
movl 0x120(%rsp), %ecx
movl %ecx, 0x450(%rax)
movb $0x1, 0x463(%rax)
movb 0x463(%rax), %cl
andb $0x1, %cl
movb %cl, 0x462(%rax)
callq 0x37200
movq %rax, %rdi
addq $0x10, %rdi
callq 0x51a0
jmp 0x3c58d
jmp 0x3bf69
movq 0x38(%rsp), %rax
movq 0x1f0(%rsp), %rdi
movq 0x4d0(%rax), %rsi
movl $0x8000, %edx           # imm = 0x8000
leaq 0x130(%rsp), %rcx
callq 0x5380
cmpl $0x0, %eax
je 0x3bf96
jmp 0x3bf69
movq 0x38(%rsp), %rdi
xorl %esi, %esi
callq 0x3c5f0
movq 0x38(%rsp), %rax
testb $0x1, 0x30(%rax)
je 0x3c00b
movq 0x38(%rsp), %rax
movq 0x1f0(%rsp), %rdi
movq 0x4d0(%rax), %rsi
leaq 0x98(%rsp), %rdx
callq 0x5990
cmpl $0x2, 0xf4(%rsp)
je 0x3bfe9
movq 0x1f0(%rsp), %rdi
xorl %esi, %esi
callq 0x5a60
jmp 0x3bfce
movq 0x38(%rsp), %rax
movq 0x1f0(%rsp), %rdi
movq 0x4d0(%rax), %rsi
movl $0x2, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x53f0
jmp 0x3c58d
jmp 0x3c012
movq 0x38(%rsp), %rax
movl 0x170(%rsp), %ecx
movl %ecx, 0x454(%rax)
movl 0x174(%rsp), %ecx
movl %ecx, 0x458(%rax)
movl 0x454(%rax), %eax
cmpl $0x0, %eax
jl 0x3c088
movq 0x38(%rsp), %rax
movl 0x458(%rax), %eax
cmpl $0x0, %eax
jl 0x3c088
movq 0x38(%rsp), %rdi
movl 0x454(%rdi), %eax
movl %eax, 0x34(%rsp)
callq 0x17aa0
movl %eax, %ecx
movl 0x34(%rsp), %eax
cmpl %ecx, %eax
jge 0x3c088
movq 0x38(%rsp), %rdi
movl 0x458(%rdi), %eax
movl %eax, 0x30(%rsp)
callq 0x17bc0
movl %eax, %ecx
movl 0x30(%rsp), %eax
cmpl %ecx, %eax
jl 0x3c0a3
movq 0x38(%rsp), %rax
movl $0xffffffff, 0x458(%rax) # imm = 0xFFFFFFFF
movl 0x458(%rax), %ecx
movl %ecx, 0x454(%rax)
movl 0x184(%rsp), %eax
movl %eax, 0x2c(%rsp)
subl $0x1, %eax
je 0x3c0cb
jmp 0x3c0b5
movl 0x2c(%rsp), %eax
subl $0x2, %eax
je 0x3c0f4
jmp 0x3c0c0
movl 0x2c(%rsp), %eax
subl $0x3, %eax
je 0x3c0de
jmp 0x3c108
movq 0x38(%rsp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x3c770
jmp 0x3c108
movq 0x38(%rsp), %rdi
movl $0x2, %esi
movl $0x1, %edx
callq 0x3c770
jmp 0x3c108
movq 0x38(%rsp), %rdi
movl $0x3, %esi
movl $0x1, %edx
callq 0x3c770
jmp 0x3c10a
movq 0x38(%rsp), %rax
movq 0x1f0(%rsp), %rdi
movq 0x4d0(%rax), %rsi
movl $0x4, %edx
leaq 0x130(%rsp), %rcx
callq 0x5380
cmpl $0x0, %eax
jne 0x3c012
jmp 0x3c58d
jmp 0x3c140
movq 0x38(%rsp), %rax
movl 0x170(%rsp), %ecx
movl %ecx, 0x454(%rax)
movl 0x174(%rsp), %ecx
movl %ecx, 0x458(%rax)
movl 0x454(%rax), %eax
cmpl $0x0, %eax
jl 0x3c1b6
movq 0x38(%rsp), %rax
movl 0x458(%rax), %eax
cmpl $0x0, %eax
jl 0x3c1b6
movq 0x38(%rsp), %rdi
movl 0x454(%rdi), %eax
movl %eax, 0x28(%rsp)
callq 0x17aa0
movl %eax, %ecx
movl 0x28(%rsp), %eax
cmpl %ecx, %eax
jge 0x3c1b6
movq 0x38(%rsp), %rdi
movl 0x458(%rdi), %eax
movl %eax, 0x24(%rsp)
callq 0x17bc0
movl %eax, %ecx
movl 0x24(%rsp), %eax
cmpl %ecx, %eax
jl 0x3c1d1
movq 0x38(%rsp), %rax
movl $0xffffffff, 0x458(%rax) # imm = 0xFFFFFFFF
movl 0x458(%rax), %ecx
movl %ecx, 0x454(%rax)
movl 0x184(%rsp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, 0x18(%rsp)
subl $0x4, %eax
ja 0x3c254
movq 0x18(%rsp), %rax
leaq 0x8c19a(%rip), %rcx     # 0xc838c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x38(%rsp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x3c770
jmp 0x3c254
movq 0x38(%rsp), %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x3c770
jmp 0x3c254
movq 0x38(%rsp), %rdi
movl $0x3, %esi
xorl %edx, %edx
callq 0x3c770
jmp 0x3c254
movq 0x38(%rsp), %rdi
movl $0x1, %esi
callq 0x3c840
jmp 0x3c254
movq 0x38(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x3c840
jmp 0x3c256
movq 0x38(%rsp), %rax
movq 0x1f0(%rsp), %rdi
movq 0x4d0(%rax), %rsi
movl $0x8, %edx
leaq 0x130(%rsp), %rcx
callq 0x5380
cmpl $0x0, %eax
jne 0x3c140
jmp 0x3c58d
movb $0x0, 0x97(%rsp)
leaq 0x130(%rsp), %rdi
leaq 0x97(%rsp), %rsi
movl $0x1, %edx
leaq 0x88(%rsp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x5490
movq 0x38(%rsp), %rdi
movq 0x88(%rsp), %rax
movl %eax, %esi
movl $0x1, %edx
callq 0x3c8a0
jmp 0x3c58d
movq 0x1f0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x55f0
movl 0x184(%rsp), %eax
movl %eax, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
shrl $0x3, %eax
movl %eax, 0x58(%rsp)
movl 0x5c(%rsp), %eax
andl $0x7, %eax
movl %eax, 0x54(%rsp)
cmpl $0x20, 0x58(%rsp)
jb 0x3c319
xorl %eax, %eax
movl %eax, 0x14(%rsp)
jmp 0x3c32f
movl 0x58(%rsp), %eax
movsbl 0x60(%rsp,%rax), %eax
movl 0x54(%rsp), %ecx
sarl %cl, %eax
andl $0x1, %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0x53(%rsp)
testb $0x1, 0x53(%rsp)
jne 0x3c37f
movb $0x0, 0x52(%rsp)
leaq 0x130(%rsp), %rdi
leaq 0x52(%rsp), %rsi
movl $0x1, %edx
leaq 0x48(%rsp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x5490
movq 0x38(%rsp), %rdi
movq 0x48(%rsp), %rax
movl %eax, %esi
xorl %edx, %edx
callq 0x3c8a0
jmp 0x3c58d
jmp 0x3c386
movq 0x38(%rsp), %rax
movq 0x1f0(%rsp), %rdi
movq 0x4d0(%rax), %rsi
movl $0x10, %edx
leaq 0x130(%rsp), %rcx
callq 0x5380
cmpl $0x0, %eax
je 0x3c3b3
jmp 0x3c386
movq 0x38(%rsp), %rax
movl 0x170(%rsp), %ecx
movl %ecx, 0x454(%rax)
movl 0x174(%rsp), %ecx
movl %ecx, 0x458(%rax)
movl 0x454(%rax), %eax
cmpl $0x0, %eax
jl 0x3c429
movq 0x38(%rsp), %rax
movl 0x458(%rax), %eax
cmpl $0x0, %eax
jl 0x3c429
movq 0x38(%rsp), %rdi
movl 0x454(%rdi), %eax
movl %eax, 0x10(%rsp)
callq 0x17aa0
movl %eax, %ecx
movl 0x10(%rsp), %eax
cmpl %ecx, %eax
jge 0x3c429
movq 0x38(%rsp), %rdi
movl 0x458(%rdi), %eax
movl %eax, 0xc(%rsp)
callq 0x17bc0
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jl 0x3c444
movq 0x38(%rsp), %rax
movl $0xffffffff, 0x458(%rax) # imm = 0xFFFFFFFF
movl 0x458(%rax), %ecx
movl %ecx, 0x454(%rax)
jmp 0x3c58d
jmp 0x3c44b
movq 0x38(%rsp), %rax
movq 0x1f0(%rsp), %rdi
movq 0x4d0(%rax), %rsi
movl $0x20, %edx
leaq 0x130(%rsp), %rcx
callq 0x5380
cmpl $0x0, %eax
je 0x3c478
jmp 0x3c44b
movq 0x38(%rsp), %rax
movl $0xffffffff, 0x458(%rax) # imm = 0xFFFFFFFF
movl 0x458(%rax), %ecx
movl %ecx, 0x454(%rax)
movb $0x1, 0x463(%rax)
callq 0x37200
movq %rax, %rdi
addq $0x10, %rdi
callq 0x51a0
jmp 0x3c58d
jmp 0x3c4b2
movq 0x38(%rsp), %rax
movq 0x1f0(%rsp), %rdi
movq 0x4d0(%rax), %rsi
movl $0x40, %edx
leaq 0x130(%rsp), %rcx
callq 0x5380
cmpl $0x0, %eax
je 0x3c4df
jmp 0x3c4b2
movq 0x38(%rsp), %rax
movl 0x170(%rsp), %ecx
movl %ecx, 0x454(%rax)
movl 0x174(%rsp), %ecx
movl %ecx, 0x458(%rax)
movl 0x454(%rax), %eax
cmpl $0x0, %eax
jl 0x3c555
movq 0x38(%rsp), %rax
movl 0x458(%rax), %eax
cmpl $0x0, %eax
jl 0x3c555
movq 0x38(%rsp), %rdi
movl 0x454(%rdi), %eax
movl %eax, 0x8(%rsp)
callq 0x17aa0
movl %eax, %ecx
movl 0x8(%rsp), %eax
cmpl %ecx, %eax
jge 0x3c555
movq 0x38(%rsp), %rdi
movl 0x458(%rdi), %eax
movl %eax, 0x4(%rsp)
callq 0x17bc0
movl %eax, %ecx
movl 0x4(%rsp), %eax
cmpl %ecx, %eax
jl 0x3c570
movq 0x38(%rsp), %rax
movl $0xffffffff, 0x458(%rax) # imm = 0xFFFFFFFF
movl 0x458(%rax), %ecx
movl %ecx, 0x454(%rax)
movq 0x38(%rsp), %rax
movb $0x1, 0x463(%rax)
callq 0x37200
movq %rax, %rdi
addq $0x10, %rdi
callq 0x51a0
addq $0x208, %rsp            # imm = 0x208
retq
nopw %cs:(%rax,%rax)
nop