// File: /workspace/github_cpp_makefile_star2_O1/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
movb $0x1, %r15b
movq %rsp, %r12
xorps %xmm0, %xmm0
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
leaq 0x10(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r12, %r8
callq 0x3220
testl %eax, %eax
jne 0x4485
movq %rbx, %rdi
callq 0x41de
testb $0x1, %r15b
jne 0x4416
jmp 0x451d
movq 0x10(%rbx), %rdi
leaq 0x98(%rsp), %rsi
callq 0x3340
movl 0x98(%rsp), %eax
cmpl $0x15, %eax
jg 0x44bc
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x44e0
movq %rbx, %rdi
leaq 0x98(%rsp), %rsi
callq 0x4320
jmp 0x447a
cmpl $0x16, %eax
je 0x44e7
cmpl $0x21, %eax
jne 0x447a
movl 0xd0(%rsp), %eax
cmpq 0x18(%rbx), %rax
movzbl %r15b, %r15d
movl $0x0, %eax
cmovel %eax, %r15d
jmp 0x447a
cmpl $0xc, %eax
je 0x4472
jmp 0x447a
movl 0xd0(%rsp), %esi
cmpl 0x2c(%rbx), %esi
jne 0x4503
movl 0xd4(%rsp), %eax
cmpl 0x30(%rbx), %eax
je 0x447a
movl %esi, 0x2c(%rbx)
movl 0xd4(%rsp), %edx
movl %edx, 0x30(%rbx)
movq (%rbx), %rdi
callq 0x3280
jmp 0x4472
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop