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

```asm
<ss_swapmerge>:
  endbr64
  push   %r15
  mov    %rdi,%r15
  push   %r14
  mov    %r8,%r14
  push   %r13
  mov    %rcx,%r13
  push   %r12
  push   %rbp
  mov    %rdx,%rbp
  push   %rbx
  mov    %rsi,%rbx
  sub    $0x468,%rsp
  mov    %r9,0x28(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x458(%rsp)
  xor    %eax,%eax
  movslq 0x4a0(%rsp),%rax
  movl   $0x0,0xc(%rsp)
  movl   $0x0,0x48(%rsp)
  mov    %rax,0x18(%rsp)
L35:
  mov    %r14,%rax
  sub    %r13,%rax
  mov    %rax,%r12
  mov    %rax,0x20(%rsp)
  sar    $0x2,%r12
  cmp    0x18(%rsp),%r12
  jg     L323
  cmp    %r13,%rbp
  jae    L83
  cmp    %r14,%r13
  jb     L293
  nopl   0x0(%rax)
L83:
  testb  $0x1,0xc(%rsp)
  jne    L73
  testb  $0x2,0xc(%rsp)
  je     L106
  movslq 0x0(%rbp),%rax
  lea    (%rbx,%rax,4),%rdx
  mov    -0x4(%rbp),%eax
  test   %eax,%eax
  js     L198
L409:
  movslq %eax,%rsi
  mov    0x4a8(%rsp),%ecx
  xor    %eax,%eax
  mov    %r15,%rdi
  lea    (%rbx,%rsi,4),%rsi
  call   <ss_compare@plt>
  test   %eax,%eax
  je     L73
  nopl   (%rax)
L106:
  testb  $0x4,0xc(%rsp)
  je     L216
  movslq (%r14),%rax
  lea    (%rbx,%rax,4),%rdx
  mov    -0x4(%r14),%eax
  test   %eax,%eax
  jns    L330
  not    %eax
L330:
  movslq %eax,%rsi
  mov    0x4a8(%rsp),%ecx
  xor    %eax,%eax
  mov    %r15,%rdi
  lea    (%rbx,%rsi,4),%rsi
  call   <ss_compare@plt>
  test   %eax,%eax
  jne    L216
  notl   (%r14)
L216:
  mov    $0x1,%edi
  xor    %eax,%eax
  call   <assert@plt>
  mov    0x48(%rsp),%eax
  test   %eax,%eax
  je     L45
  sub    $0x1,%eax
  mov    %eax,0x48(%rsp)
  cltq
  shl    $0x5,%rax
  mov    0x50(%rsp,%rax,1),%rbp
  mov    0x58(%rsp,%rax,1),%r13
  mov    0x60(%rsp,%rax,1),%r14
  mov    0x68(%rsp,%rax,1),%eax
  mov    %eax,0xc(%rsp)
  jmp    L35
  nopl   0x0(%rax,%rax,1)
L73:
  notl   0x0(%rbp)
  jmp    L106
  nopl   0x0(%rax,%rax,1)
L323:
  mov    %r13,%rax
  sub    %rbp,%rax
  mov    %rax,0x30(%rsp)
  sar    $0x2,%rax
  cmp    0x18(%rsp),%rax
  jg     L383
  cmp    %r13,%rbp
  jae    L83
  sub    $0x8,%rsp
  mov    %rbx,%rsi
  mov    %r15,%rdi
  mov    %r14,%r8
  mov    0x4b0(%rsp),%eax
  mov    %r13,%rcx
  mov    %rbp,%rdx
  push   %rax
  mov    0x38(%rsp),%r9
  xor    %eax,%eax
  call   <ss_mergeforward@plt>
  pop    %rsi
  pop    %rdi
  jmp    L83
  nopl   0x0(%rax)
L45:
  mov    0x458(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L130
  add    $0x468,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L293:
  sub    $0x8,%rsp
  mov    %r14,%r8
  mov    %r13,%rcx
  mov    %rbp,%rdx
  mov    0x4b0(%rsp),%eax
  mov    %rbx,%rsi
  mov    %r15,%rdi
  push   %rax
  mov    0x38(%rsp),%r9
  xor    %eax,%eax
  call   <ss_mergebackward@plt>
  pop    %r8
  pop    %r9
  jmp    L83
  nopl   0x0(%rax,%rax,1)
L198:
  not    %eax
  jmp    L409
  nopw   0x0(%rax,%rax,1)
L383:
  mov    0x30(%rsp),%rcx
  cmp    %rcx,0x20(%rsp)
  cmovg  %eax,%r12d
  mov    %r12d,%r9d
  sar    %r9d
  test   %r12d,%r12d
  jle    L424
  mov    %r13,%rax
  mov    %rbp,0x38(%rsp)
  mov    %r12d,%r13d
  mov    %r9d,%ebp
  mov    %r14,0x40(%rsp)
  mov    %rax,%r12
  mov    %rbx,%r14
  mov    0x4a8(%rsp),%ebx
  movl   $0x0,0x10(%rsp)
  jmp    L44
  nopw   0x0(%rax,%rax,1)
L173:
  mov    %ebp,%r13d
  mov    %r13d,%ebp
  sar    %ebp
  test   %r13d,%r13d
  jle    L15
L44:
  movslq 0x10(%rsp),%rax
  movslq %ebp,%rdx
  add    %rdx,%rax
  mov    $0xfffffffffffffffc,%rdx
  lea    0x0(,%rax,4),%rcx
  sub    %rcx,%rdx
  movslq (%r12,%rdx,1),%rdx
  test   %edx,%edx
  jns    L291
  not    %edx
  movslq %edx,%rdx
L291:
  movslq (%r12,%rax,4),%rsi
  lea    (%r14,%rdx,4),%rdx
  test   %esi,%esi
  jns    L70
  not    %esi
  movslq %esi,%rsi
L70:
  xor    %eax,%eax
  lea    (%r14,%rsi,4),%rsi
  mov    %ebx,%ecx
  mov    %r15,%rdi
  call   <ss_compare@plt>
  test   %eax,%eax
  jns    L173
  mov    0x10(%rsp),%eax
  lea    0x1(%rax,%rbp,1),%eax
  mov    %eax,0x10(%rsp)
  mov    %r13d,%eax
  not    %eax
  and    $0x1,%eax
  sub    %eax,%ebp
  mov    %ebp,%r13d
  mov    %r13d,%ebp
  sar    %ebp
  test   %r13d,%r13d
  jg     L44
L15:
  mov    0x10(%rsp),%edx
  mov    %r14,%rbx
  mov    0x38(%rsp),%rbp
  mov    %r12,%r13
  mov    0x40(%rsp),%r14
  test   %edx,%edx
  jg     L7
L424:
  movslq 0x0(%r13),%rax
  lea    (%rbx,%rax,4),%rdx
  mov    -0x4(%r13),%eax
  test   %eax,%eax
  jns    L235
  not    %eax
L235:
  movslq %eax,%rsi
  mov    0x4a8(%rsp),%ecx
  xor    %eax,%eax
  mov    %r15,%rdi
  lea    (%rbx,%rsi,4),%rsi
  call   <ss_compare@plt>
  test   %eax,%eax
  jne    L83
  notl   0x0(%r13)
  jmp    L83
  nopw   0x0(%rax,%rax,1)
L7:
  movslq %edx,%rax
  mov    %r13,%rsi
  shl    $0x2,%rax
  sub    %rax,%r12
  lea    0x0(%r13,%rax,1),%rdi
  xor    %eax,%eax
  mov    %rdi,0x10(%rsp)
  mov    %r12,%rdi
  mov    %r12,0x38(%rsp)
  call   <ss_blockswap@plt>
  mov    0x10(%rsp),%rdi
  cmp    %rdi,%r14
  jbe    L144
  mov    (%rdi),%eax
  test   %eax,%eax
  js     L312
  cmp    0x38(%rsp),%rbp
  jae    L144
  mov    0x0(%r13),%r9d
  mov    %r13,%r12
  test   %r9d,%r9d
  jns    L30
  nopl   0x0(%rax)
L427:
  mov    0x4(%r12),%r8d
  add    $0x4,%r12
  test   %r8d,%r8d
  js     L427
  mov    %r14,%rax
  mov    %r13,%rsi
  mov    $0x2,%edx
  sub    %r12,%rax
  mov    %rax,0x20(%rsp)
  jmp    L434
  nopl   0x0(%rax,%rax,1)
L144:
  mov    %r13,%r12
  mov    %r13,%rsi
  xor    %edx,%edx
L434:
  mov    0x48(%rsp),%r11d
  mov    0xc(%rsp),%eax
  xor    %edi,%edi
  cmp    $0x1f,%r11d
  mov    %eax,%ecx
  setle  %dil
  and    $0x4,%eax
  and    $0x3,%ecx
  mov    %eax,0xc(%rsp)
  lea    0x1(%r11),%eax
  mov    %ecx,0x4c(%rsp)
  mov    0x20(%rsp),%rcx
  mov    %eax,0x40(%rsp)
  cmp    %rcx,0x30(%rsp)
  jle    L295
  test   $0x2,%dl
  je     L356
  cmp    %r12,%r13
  mov    %edx,%eax
  sete   %r9b
  xor    $0x6,%eax
  test   %r9b,%r9b
  cmovne %eax,%edx
L356:
  xor    %eax,%eax
  mov    %edx,0x30(%rsp)
  mov    %rsi,0x20(%rsp)
  call   <assert@plt>
  movslq 0x48(%rsp),%rax
  mov    0x20(%rsp),%rsi
  mov    0x30(%rsp),%edx
  mov    0x38(%rsp),%rcx
  shl    $0x5,%rax
  mov    0x10(%rsp),%r13
  mov    %rsi,0x60(%rsp,%rax,1)
  mov    %edx,%esi
  and    $0x3,%edx
  or     0xc(%rsp),%edx
  and    $0x4,%esi
  or     0x4c(%rsp),%esi
  mov    %rbp,0x50(%rsp,%rax,1)
  mov    %r12,%rbp
  mov    %rcx,0x58(%rsp,%rax,1)
  mov    %esi,0x68(%rsp,%rax,1)
  mov    0x40(%rsp),%eax
  mov    %edx,0xc(%rsp)
  mov    %eax,0x48(%rsp)
  jmp    L35
L312:
  not    %eax
  mov    %r13,%rsi
  mov    $0x1,%edx
  mov    %eax,(%rdi)
  cmp    %r12,%rbp
  jb     L286
L72:
  mov    %r13,%r12
  jmp    L434
  xchg   %ax,%ax
L286:
  mov    -0x4(%rsi),%r10d
  sub    $0x4,%rsi
  test   %r10d,%r10d
  js     L286
  mov    %rsi,%rax
  mov    $0x5,%edx
  sub    %rbp,%rax
  mov    %rax,0x30(%rsp)
  jmp    L72
  nop
L295:
  xor    %eax,%eax
  mov    %edx,0x30(%rsp)
  mov    %rsi,0x20(%rsp)
  call   <assert@plt>
  mov    0x30(%rsp),%edx
  movslq 0x48(%rsp),%rax
  mov    0x10(%rsp),%rdi
  mov    0x38(%rsp),%r13
  mov    %edx,%ecx
  shl    $0x5,%rax
  and    $0x4,%edx
  or     0x4c(%rsp),%edx
  and    $0x3,%ecx
  or     0xc(%rsp),%ecx
  mov    %r14,0x60(%rsp,%rax,1)
  mov    %r12,0x50(%rsp,%rax,1)
  mov    0x20(%rsp),%r14
  mov    %rdi,0x58(%rsp,%rax,1)
  mov    %ecx,0x68(%rsp,%rax,1)
  mov    0x40(%rsp),%eax
  mov    %edx,0xc(%rsp)
  mov    %eax,0x48(%rsp)
  jmp    L35
L30:
  mov    %r13,%rsi
  mov    $0x2,%edx
  jmp    L434
L130:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void ss_swapmerge(const unsigned char *T, const int *PA, int *first, int *middle, int *last, int *buf, int bufsize, int depth) {
  struct {
    int *a, *b, *c;
    int d;
  } stack[(32)];
  int *l, *r, *lm, *rm;
  int m, len, half;
  int ssize;
  int check, next;
  for (check = 0, ssize = 0;;) {
    if ((last - middle) <= bufsize) {
      if ((first < middle) && (middle < last)) {
        ss_mergebackward(T, PA, first, middle, last, buf, depth);
      }
      do {
        if (((check)&1) || (((check)&2) && (ss_compare(T, PA + ((0 <= (*((first)-1))) ? (*((first)-1)) : (~(*((first)-1)))), PA + *(first), depth) == 0))) {
          *(first) = ~*(first);
        }
        if (((check)&4) && ((ss_compare(T, PA + ((0 <= (*((last)-1))) ? (*((last)-1)) : (~(*((last)-1)))), PA + *(last), depth) == 0))) {
          *(last) = ~*(last);
        }
      } while (0);
      do {
        assert(0 <= ssize);
        if (ssize == 0) {
          return;
        }
        (first) = stack[--ssize].a, (middle) = stack[ssize].b, (last) = stack[ssize].c, (check) = stack[ssize].d;
      } while (0);
      continue;
    }
    if ((middle - first) <= bufsize) {
      if (first < middle) {
        ss_mergeforward(T, PA, first, middle, last, buf, depth);
      }
      do {
        if (((check)&1) || (((check)&2) && (ss_compare(T, PA + ((0 <= (*((first)-1))) ? (*((first)-1)) : (~(*((first)-1)))), PA + *(first), depth) == 0))) {
          *(first) = ~*(first);
        }
        if (((check)&4) && ((ss_compare(T, PA + ((0 <= (*((last)-1))) ? (*((last)-1)) : (~(*((last)-1)))), PA + *(last), depth) == 0))) {
          *(last) = ~*(last);
        }
      } while (0);
      do {
        assert(0 <= ssize);
        if (ssize == 0) {
          return;
        }
        (first) = stack[--ssize].a, (middle) = stack[ssize].b, (last) = stack[ssize].c, (check) = stack[ssize].d;
      } while (0);
      continue;
    }
    for (m = 0, len = (((middle - first) < (last - middle)) ? (middle - first) : (last - middle)), half = len >> 1; 0 < len; len = half, half >>= 1) {
      if (ss_compare(T, PA + ((0 <= (*(middle + m + half))) ? (*(middle + m + half)) : (~(*(middle + m + half)))), PA + ((0 <= (*(middle - m - half - 1))) ? (*(middle - m - half - 1)) : (~(*(middle - m - half - 1)))), depth) < 0) {
        m += half + 1;
        half -= (len & 1) ^ 1;
      }
    }
    if (0 < m) {
      lm = middle - m, rm = middle + m;
      ss_blockswap(lm, middle, m);
      l = r = middle, next = 0;
      if (rm < last) {
        if (*rm < 0) {
          *rm = ~*rm;
          if (first < lm) {
            for (; *--l < 0;) {
            }
            next |= 4;
          }
          next |= 1;
        } else if (first < lm) {
          for (; *r < 0; ++r) {
          }
          next |= 2;
        }
      }
      if ((l - first) <= (last - r)) {
        do {
          assert(ssize < (32));
          stack[ssize].a = (r), stack[ssize].b = (rm), stack[ssize].c = (last), stack[ssize++].d = ((next & 3) | (check & 4));
        } while (0);
        middle = lm, last = l, check = (check & 3) | (next & 4);
      } else {
        if ((next & 2) && (r == middle)) {
          next ^= 6;
        }
        do {
          assert(ssize < (32));
          stack[ssize].a = (first), stack[ssize].b = (lm), stack[ssize].c = (l), stack[ssize++].d = ((check & 3) | (next & 4));
        } while (0);
        first = r, middle = rm, check = (next & 3) | (check & 4);
      }
    } else {
      if (ss_compare(T, PA + ((0 <= (*(middle - 1))) ? (*(middle - 1)) : (~(*(middle - 1)))), PA + *middle, depth) == 0) {
        *middle = ~*middle;
      }
      do {
        if (((check)&1) || (((check)&2) && (ss_compare(T, PA + ((0 <= (*((first)-1))) ? (*((first)-1)) : (~(*((first)-1)))), PA + *(first), depth) == 0))) {
          *(first) = ~*(first);
        }
        if (((check)&4) && ((ss_compare(T, PA + ((0 <= (*((last)-1))) ? (*((last)-1)) : (~(*((last)-1)))), PA + *(last), depth) == 0))) {
          *(last) = ~*(last);
        }
      } while (0);
      do {
        assert(0 <= ssize);
        if (ssize == 0) {
          return;
        }
        (first) = stack[--ssize].a, (middle) = stack[ssize].b, (last) = stack[ssize].c, (check) = stack[ssize].d;
      } while (0);
    }
  }
}
```