user: Converte this assembly snippet into its equivalent C code:

```asm
<stable_grail_smart_merge_with_x_buf>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %rdi,-0x28(%rbp)
  mov    %rsi,-0x30(%rbp)
  mov    %rdx,-0x38(%rbp)
  mov    %ecx,-0x3c(%rbp)
  mov    %r8d,-0x40(%rbp)
  mov    -0x40(%rbp),%eax
  neg    %eax
  mov    %eax,-0x18(%rbp)
  movl   $0x0,-0x14(%rbp)
  mov    -0x30(%rbp),%rax
  mov    (%rax),%eax
  mov    %eax,-0x10(%rbp)
  mov    -0x10(%rbp),%eax
  mov    %eax,-0xc(%rbp)
  mov    -0x10(%rbp),%edx
  mov    -0x3c(%rbp),%eax
  add    %edx,%eax
  mov    %eax,-0x8(%rbp)
  mov    -0x38(%rbp),%rax
  mov    (%rax),%edx
  mov    $0x1,%eax
  sub    %edx,%eax
  mov    %eax,-0x4(%rbp)
  jmp    L21
L68:
  mov    -0x14(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rax
  mov    (%rax),%edx
  mov    -0x10(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rcx
  mov    -0x28(%rbp),%rax
  add    %rcx,%rax
  mov    (%rax),%rax
  mov    (%rax),%ecx
  mov    %edx,%eax
  sub    %ecx,%eax
  sub    -0x4(%rbp),%eax
  test   %eax,%eax
  jns    L52
  mov    -0x14(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x14(%rbp)
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x18(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x18(%rbp)
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  add    %rax,%rdx
  mov    (%rcx),%rax
  mov    %rax,(%rdx)
  jmp    L21
L52:
  mov    -0x10(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x10(%rbp)
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x18(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x18(%rbp)
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  add    %rax,%rdx
  mov    (%rcx),%rax
  mov    %rax,(%rdx)
L21:
  mov    -0x14(%rbp),%eax
  cmp    -0xc(%rbp),%eax
  jge    L67
  mov    -0x10(%rbp),%eax
  cmp    -0x8(%rbp),%eax
  jl     L68
L67:
  mov    -0x14(%rbp),%eax
  cmp    -0xc(%rbp),%eax
  jge    L30
  mov    -0xc(%rbp),%eax
  sub    -0x14(%rbp),%eax
  mov    %eax,%edx
  mov    -0x30(%rbp),%rax
  mov    %edx,(%rax)
  jmp    L33
L66:
  subl   $0x1,-0xc(%rbp)
  mov    -0xc(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  subl   $0x1,-0x8(%rbp)
  mov    -0x8(%rbp),%edx
  movslq %edx,%rdx
  lea    0x0(,%rdx,8),%rcx
  mov    -0x28(%rbp),%rdx
  add    %rcx,%rdx
  mov    (%rax),%rax
  mov    %rax,(%rdx)
L33:
  mov    -0x14(%rbp),%eax
  cmp    -0xc(%rbp),%eax
  jl     L66
  jmp    L7
L30:
  mov    -0x8(%rbp),%eax
  sub    -0x10(%rbp),%eax
  mov    %eax,%edx
  mov    -0x30(%rbp),%rax
  mov    %edx,(%rax)
  mov    -0x38(%rbp),%rax
  mov    -0x4(%rbp),%edx
  mov    %edx,(%rax)
L7:
  nop
  pop    %rbp
  ret
```

assistant: ```c
void stable_grail_smart_merge_with_x_buf(int **arr, int *alen1, int *atype, int len2, int lkeys) {
  int p0 = -lkeys, p1 = 0, p2 = *alen1, q1 = p2, q2 = p2 + len2;
  int ftype = 1 - *atype;
  while (p1 < q1 && p2 < q2) {
    if ((*(*(arr + p1)) - *(*(arr + p2))) - ftype < 0) {
      arr[p0++] = arr[p1++];
    } else {
      arr[p0++] = arr[p2++];
    }
  }
  if (p1 < q1) {
    *alen1 = q1 - p1;
    while (p1 < q1) {
      arr[--q2] = arr[--q1];
    }
  } else {
    *alen1 = q2 - p2;
    *atype = ftype;
  }
}
```