// File: /workspace/github_cpp_makefile_star2_O3/rfotino[P]consolite-emulator/src/window.cpp
// Function: EmuWindow::eventLoop()
void EmuWindow::eventLoop() {
  // Get the file descriptor for the connection to the X server,
  // so that we can listen for input on a timer instead of blocking
  // indefinitely on XNextEvent. The reason for this is we need to wake
  // up every 1/60 of a second to repaint.
  int x11_fd = ConnectionNumber(_display);
  fd_set event_fds;
  struct timeval timer;
  // The running variable is set to false when the user
  // closes the window, which breaks out of the event loop.
  bool running = true;
  while (running) {
    // Set up the set of file descriptors for select()
    FD_ZERO(&event_fds);
    FD_SET(x11_fd, &event_fds);
    // Set timer to 1/60 of a second
    timer.tv_usec = 16667;
    timer.tv_sec = 0;
    if (0 == select(x11_fd + 1, &event_fds, 0, 0, &timer)) {
      // Timer expired
      _draw();
      continue;
    }
    // We received an event so handle it here
    XEvent event;
    XNextEvent(_display, &event);
    switch (event.type) {
    case KeyPress:
    case KeyRelease:
      _updateKeyState(event.xkey);
      break;
    case Expose:
      // Draw to the window
      _draw();
      break;
    case ConfigureNotify:
      // The window was resized, redraw scaled
      if (event.xconfigure.width != _width ||
          event.xconfigure.height != _height) {
        _width = event.xconfigure.width;
        _height = event.xconfigure.height;
        cairo_xlib_surface_set_size(_surface, _width, _height);
        _draw();
      }
      break;
    case ClientMessage:
      // Hit the exit button
      if ((unsigned)event.xclient.data.l[0] == _wmDeleteMessage) {
        running = false;
      }
      break;
    default:
      break;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rdi, %rbx
movq 0x10(%rdi), %rax
movl 0x10(%rax), %r14d
leal 0x3f(%r14), %eax
testl %r14d, %r14d
cmovnsl %r14d, %eax
movl %eax, %edx
andl $-0x40, %edx
movl %r14d, %ecx
subl %edx, %ecx
movl $0x1, %ebp
shlq %cl, %rbp
sarl $0x6, %eax
movslq %eax, %r13
incl %r14d
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r15
movq %rsp, %r12
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
orq %rbp, 0x10(%rsp,%r13,8)
movq $0x411b, 0x8(%rsp)      # imm = 0x411B
movq $0x0, (%rsp)
movl %r14d, %edi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r12, %r8
callq 0x3220
testl %eax, %eax
jne 0x443d
movq %rbx, %rdi
callq 0x41c6
xorps %xmm0, %xmm0
jmp 0x43d9
movq 0x10(%rbx), %rdi
leaq 0x98(%rsp), %rsi
callq 0x3340
movl 0x98(%rsp), %eax
cmpl $0x15, %eax
jg 0x4474
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x4494
movq %rbx, %rdi
leaq 0x98(%rsp), %rsi
callq 0x42de
jmp 0x4438
cmpl $0x16, %eax
je 0x449b
cmpl $0x21, %eax
jne 0x4438
movl 0xd0(%rsp), %eax
cmpq 0x18(%rbx), %rax
xorps %xmm0, %xmm0
jne 0x43d9
jmp 0x44c6
cmpl $0xc, %eax
je 0x4430
jmp 0x4438
movl 0xd0(%rsp), %esi
movl 0xd4(%rsp), %edx
cmpl 0x2c(%rbx), %esi
jne 0x44b3
cmpl 0x30(%rbx), %edx
je 0x4438
movl %esi, 0x2c(%rbx)
movl %edx, 0x30(%rbx)
movq (%rbx), %rdi
callq 0x3280
jmp 0x4430
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq