user: Please show me the C implementation that matches the assembly code listed below:

```asm
<xrectsel>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x78,%rsp
  mov    %rdi,0x18(%rsp)
  xor    %edi,%edi
  mov    %rsi,0x20(%rsp)
  mov    %rdx,0x28(%rsp)
  mov    %rcx,0x30(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x68(%rsp)
  xor    %eax,%eax
  call   <XOpenDisplay@plt>
  test   %rax,%rax
  je     L13
  mov    %rax,%rdi
  mov    %rax,%r14
  xor    %r15d,%r15d
  xor    %r12d,%r12d
  call   <DefaultRootWindow@plt>
  mov    %r14,%rdi
  mov    %eax,0x14(%rsp)
  mov    %eax,%ebx
  mov    D90(%rip),%rax
  mov    (%rax),%esi
  call   <XCreateFontCursor@plt>
  sub    $0x8,%rsp
  mov    %ebx,%esi
  mov    %eax,0x44(%rsp)
  mov    %eax,%edi
  mov    D159(%rip),%rax
  mov    (%rax),%r8d
  mov    D72(%rip),%rax
  mov    (%rax),%ecx
  mov    D8(%rip),%rax
  mov    %r8d,%r9d
  or     (%rax),%ecx
  mov    D65(%rip),%rax
  or     (%rax),%ecx
  mov    D138(%rip),%rax
  mov    (%rax),%eax
  push   %rax
  mov    D158(%rip),%rax
  push   %rdi
  mov    %r14,%rdi
  mov    (%rax),%eax
  push   %rax
  mov    D162(%rip),%rax
  mov    (%rax),%edx
  call   <XGrabPointer@plt>
  mov    D83(%rip),%rax
  mov    %ebx,%esi
  mov    %r14,%rdi
  movl   $0x1,0x64(%rsp)
  xor    %ebx,%ebx
  mov    (%rax),%eax
  mov    %eax,0x6c(%rsp)
  mov    D84(%rip),%rax
  mov    (%rax),%eax
  mov    %eax,0x68(%rsp)
  mov    D76(%rip),%rax
  add    $0x20,%rsp
  lea    0x44(%rsp),%rcx
  lea    0x50(%rsp),%r13
  mov    (%rax),%edx
  mov    D125(%rip),%rax
  or     (%rax),%edx
  mov    D152(%rip),%rax
  or     (%rax),%edx
  call   <XCreateGC@plt>
  movl   $0x0,0xc(%rsp)
  mov    D127(%rip),%rbp
  mov    %eax,0x38(%rsp)
  movl   $0x0,0x10(%rsp)
  movl   $0x0,0x4(%rsp)
  movl   $0x0,0x8(%rsp)
  nopw   0x0(%rax,%rax,1)
L24:
  mov    %r13,%rsi
  mov    %r14,%rdi
  call   <XNextEvent@plt>
  mov    0x50(%rsp),%rax
  cmp    0x0(%rbp),%rax
  je     L36
  mov    D150(%rip),%rdx
  cmp    (%rdx),%rax
  je     L46
  mov    D21(%rip),%rcx
  cmp    (%rcx),%rax
  jne    L24
  sub    $0x8,%rsp
  mov    %r15d,%r9d
  mov    %ebx,%r8d
  mov    %r12d,%ecx
  mov    0xc(%rsp),%ebp
  mov    %r14,%rdi
  push   %rbp
  mov    0x48(%rsp),%r13d
  mov    0x24(%rsp),%esi
  mov    %r13d,%edx
  call   <XDrawRectangle@plt>
  mov    %r14,%rdi
  call   <XFlush@plt>
  mov    D138(%rip),%rax
  mov    %r14,%rdi
  mov    (%rax),%esi
  call   <XUngrabPointer@plt>
  mov    0x4c(%rsp),%esi
  mov    %r14,%rdi
  call   <XFreeCursor@plt>
  mov    %r13d,%esi
  mov    %r14,%rdi
  call   <XFreeGC@plt>
  mov    $0x1,%esi
  mov    %r14,%rdi
  call   <XSync@plt>
  mov    0x28(%rsp),%rax
  mov    %r14,%rdi
  mov    %r12d,(%rax)
  mov    0x30(%rsp),%rax
  mov    %ebx,(%rax)
  mov    0x38(%rsp),%rax
  mov    %r15d,(%rax)
  mov    0x40(%rsp),%rax
  mov    %ebp,(%rax)
  call   <XCloseDisplay@plt>
  pop    %rax
  pop    %rdx
L13:
  mov    0x68(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L63
  add    $0x78,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L36:
  mov    0x58(%rsp),%r12d
  mov    0x5c(%rsp),%ebx
  xor    %r15d,%r15d
  movl   $0x0,0x4(%rsp)
  movl   $0x1,0x8(%rsp)
  mov    %ebx,0xc(%rsp)
  mov    %r12d,0x10(%rsp)
  jmp    L24
  nopw   0x0(%rax,%rax,1)
L46:
  mov    0x8(%rsp),%r9d
  test   %r9d,%r9d
  je     L24
  sub    $0x8,%rsp
  mov    %ebx,%r8d
  mov    %r15d,%r9d
  mov    %r12d,%ecx
  mov    0xc(%rsp),%eax
  mov    %r14,%rdi
  push   %rax
  mov    0x48(%rsp),%edx
  mov    0x24(%rsp),%esi
  call   <XDrawRectangle@plt>
  mov    0x68(%rsp),%r12d
  mov    0x6c(%rsp),%ebx
  pop    %rdi
  pop    %r8
  mov    0x10(%rsp),%eax
  mov    %eax,%r15d
  sub    %r12d,%r15d
  cmp    %r12d,%eax
  jge    L75
  mov    %r12d,%r15d
  mov    %eax,%r12d
  sub    %eax,%r15d
L75:
  mov    0xc(%rsp),%eax
  mov    %eax,%esi
  sub    %ebx,%esi
  mov    %esi,0x4(%rsp)
  cmp    %ebx,%eax
  jge    L88
  sub    %eax,%ebx
  mov    %ebx,0x4(%rsp)
  mov    %eax,%ebx
L88:
  sub    $0x8,%rsp
  mov    %r12d,%ecx
  mov    %r15d,%r9d
  mov    %ebx,%r8d
  mov    0xc(%rsp),%eax
  mov    %r14,%rdi
  push   %rax
  mov    0x48(%rsp),%edx
  mov    0x24(%rsp),%esi
  call   <XDrawRectangle@plt>
  mov    %r14,%rdi
  call   <XFlush@plt>
  pop    %rcx
  pop    %rsi
  jmp    L24
L63:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void xrectsel(unsigned *x_sel, unsigned *y_sel, unsigned *w_sel, unsigned *h_sel) {
  Display *dpy = XOpenDisplay(NULL);
  if (!dpy)
    return;
  Window root = DefaultRootWindow(dpy);
  XEvent ev;
  GC sel_gc;
  XGCValues sel_gv;
  int btn_pressed = 0;
  int x = 0, y = 0;
  unsigned int width = 0, height = 0;
  int start_x = 0, start_y = 0;
  Cursor cursor;
  cursor = XCreateFontCursor(dpy, XC_crosshair);
  XGrabPointer(dpy, root, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime);
  sel_gv.function = GXinvert;
  sel_gv.subwindow_mode = IncludeInferiors;
  sel_gv.line_width = 1;
  sel_gc = XCreateGC(dpy, root, GCFunction | GCSubwindowMode | GCLineWidth, &sel_gv);
  for (;;) {
    XNextEvent(dpy, &ev);
    if (ev.type == ButtonPress) {
      btn_pressed = 1;
      x = start_x = ev.xbutton.x_root;
      y = start_y = ev.xbutton.y_root;
      width = height = 0;
    } else if (ev.type == MotionNotify) {
      if (!btn_pressed)
        continue;
      XDrawRectangle(dpy, root, sel_gc, x, y, width, height);
      x = ev.xbutton.x_root;
      y = ev.xbutton.y_root;
      if (x > start_x) {
        width = x - start_x;
        x = start_x;
      } else {
        width = start_x - x;
      }
      if (y > start_y) {
        height = y - start_y;
        y = start_y;
      } else {
        height = start_y - y;
      }
      XDrawRectangle(dpy, root, sel_gc, x, y, width, height);
      XFlush(dpy);
    } else if (ev.type == ButtonRelease)
      break;
  }
  XDrawRectangle(dpy, root, sel_gc, x, y, width, height);
  XFlush(dpy);
  XUngrabPointer(dpy, CurrentTime);
  XFreeCursor(dpy, cursor);
  XFreeGC(dpy, sel_gc);
  XSync(dpy, 1);
  *x_sel = x;
  *y_sel = y;
  *w_sel = width;
  *h_sel = height;
  XCloseDisplay(dpy);
}
```