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

```asm
<position_near>:
  endbr64
  push   %r13
  mov    %edi,%r13d
  push   %r12
  push   %rbp
  mov    %edx,%ebp
  push   %rbx
  mov    %esi,%ebx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  lea    0xc(%rsp),%rdx
  push   $0x0
  lea    0x1c(%rsp),%rax
  push   %rax
  mov    D48(%rip),%rax
  mov    (%rax),%r9d
  mov    D44(%rip),%rax
  lea    0x20(%rsp),%r8
  mov    (%rax),%ecx
  mov    D43(%rip),%rax
  mov    (%rax),%esi
  call   <XtVaGetValues@plt>
  mov    0x24(%rsp),%eax
  mov    %r13d,%edi
  add    %eax,%eax
  add    %eax,0x1c(%rsp)
  add    %eax,0x20(%rsp)
  call   <XtScreen@plt>
  mov    %eax,%edi
  call   <WidthOfScreen@plt>
  mov    %r13d,%edi
  mov    %eax,%r12d
  call   <XtScreen@plt>
  mov    %eax,%edi
  call   <HeightOfScreen@plt>
  movslq %r12d,%rdx
  mov    %r12d,%ecx
  imul   $0x55555556,%rdx,%rdx
  sar    $0x1f,%ecx
  shr    $0x20,%rdx
  sub    %ecx,%edx
  pop    %rcx
  pop    %rsi
  xor    %ecx,%ecx
  lea    (%r12,%r12,1),%esi
  cmp    %ebx,%edx
  mov    0xc(%rsp),%edi
  movslq %esi,%rdx
  setl   %cl
  sar    $0x1f,%esi
  imul   $0x55555556,%rdx,%rdx
  shr    $0x20,%rdx
  sub    %esi,%edx
  mov    %eax,%esi
  cmp    %ebx,%edx
  setl   %dl
  sar    $0x1f,%esi
  movzbl %dl,%edx
  lea    0x1(%rcx,%rdx,1),%ecx
  movslq %eax,%rdx
  imul   $0x55555556,%rdx,%rdx
  shr    $0x20,%rdx
  sub    %esi,%edx
  lea    0x3(%rcx),%esi
  cmp    %ebp,%edx
  cmovl  %esi,%ecx
  lea    (%rax,%rax,1),%esi
  movslq %esi,%rdx
  sar    $0x1f,%esi
  imul   $0x55555556,%rdx,%rdx
  shr    $0x20,%rdx
  sub    %esi,%edx
  lea    0x3(%rcx),%esi
  cmp    %ebp,%edx
  cmovl  %esi,%ecx
  mov    0x10(%rsp),%esi
  push   $0x0
  mov    %esi,%edx
  push   %rcx
  mov    D17(%rip),%rcx
  shr    $0x1f,%edx
  add    %esi,%edx
  mov    (%rcx),%r9d
  sar    %edx
  sub    %edx,%ebp
  mov    $0x0,%edx
  cmovs  %edx,%ebp
  sub    %esi,%eax
  mov    %edi,%esi
  shr    $0x1f,%esi
  add    %edi,%esi
  sar    %esi
  sub    %esi,%ebx
  mov    $0x0,%esi
  mov    %ebx,%edx
  cmovs  %esi,%edx
  sub    %edi,%r12d
  mov    %r13d,%edi
  cmp    %r12d,%edx
  cmovg  %r12d,%edx
  cmp    %eax,%ebp
  cmovle %ebp,%eax
  mov    %eax,%r8d
  mov    D7(%rip),%rax
  mov    (%rax),%ecx
  mov    D0(%rip),%rax
  mov    (%rax),%esi
  call   <XtVaSetValues@plt>
  pop    %rdi
  pop    %r8
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L9
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L9:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void position_near(Widget shell, int x, int y) {
  int max_x, max_y;
  Dimension width, height, border;
  int gravity;
  XtVaGetValues(shell, XtNwidth, &width, XtNheight, &height, XtNborderWidth, &border, NULL);
  width += 2 * border;
  height += 2 * border;
  max_x = WidthOfScreen(XtScreen(shell));
  max_y = HeightOfScreen(XtScreen(shell));
  gravity = 1;
  if (x > max_x / 3)
    gravity += 1;
  if (x > max_x * 2 / 3)
    gravity += 1;
  if (y > max_y / 3)
    gravity += 3;
  if (y > max_y * 2 / 3)
    gravity += 3;
  max_x -= width;
  max_y -= height;
  x -= ((Position)width / 2);
  if (x < 0)
    x = 0;
  if (x > max_x)
    x = max_x;
  y -= ((Position)height / 2);
  if (y < 0)
    y = 0;
  if (y > max_y)
    y = max_y;
  XtVaSetValues(shell, XtNx, (Position)x, XtNy, (Position)y, XtNwinGravity, gravity, NULL);
}
```