// File: /workspace/github_cpp_makefile_star2_O2/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), %ebp
pushq $0x40
popq %rcx
movl %ebp, %eax
cltd
idivl %ecx
movslq %eax, %r13
shll $0x6, %eax
movl %ebp, %ecx
subl %eax, %ecx
pushq $0x1
popq %r12
shlq %cl, %r12
incl %ebp
xorl %eax, %eax
leaq 0xd8(%rsp), %r14
leaq 0x8(%rsp), %r15
cmpq $0x10, %rax
jne 0x41c9
orq %r12, 0xd8(%rsp,%r13,8)
movq $0x411b, 0x10(%rsp)     # imm = 0x411B
andq $0x0, 0x8(%rsp)
movl %ebp, %edi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r15, %r8
callq 0x3260
testl %eax, %eax
je 0x4206
movq 0x10(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0x3360
movl 0x18(%rsp), %eax
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jb 0x41d7
cmpl $0xc, %eax
je 0x4206
cmpl $0x16, %eax
je 0x41e6
cmpl $0x21, %eax
jne 0x420e
movl 0x50(%rsp), %ecx
movl $0x0, %eax
cmpq 0x18(%rbx), %rcx
jne 0x415d
jmp 0x4215
andq $0x0, 0xd8(%rsp,%rax,8)
incq %rax
jmp 0x415d
movq %rbx, %rdi
leaq 0x18(%rsp), %rsi
callq 0x406c
jmp 0x420e
movl 0x50(%rsp), %esi
movl 0x54(%rsp), %edx
cmpl 0x2c(%rbx), %esi
jne 0x41f8
cmpl 0x30(%rbx), %edx
je 0x420e
movl %esi, 0x2c(%rbx)
movl %edx, 0x30(%rbx)
movq (%rbx), %rdi
callq 0x32c0
movq %rbx, %rdi
callq 0x3f94
xorl %eax, %eax
jmp 0x415d
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop