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

```asm
<LMSsort2>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,0x8(%rsp)
  mov    %rsi,%r15
  mov    %rdx,%rbx
  mov    %rdx,0x38(%rsp)
  mov    %rcx,%r14
  mov    %rcx,0x20(%rsp)
  mov    %r8,0x18(%rsp)
  mov    %r9d,%ebp
  mov    %r9d,0x10(%rsp)
  cmp    %rcx,%rdx
  setne  %dil
  movzbl %dil,%edi
  call   <assert@plt>
  mov    $0x0,%ecx
  mov    0x80(%rsp),%edx
  mov    %r14,%rsi
  mov    %rbx,%rdi
  call   <getBuckets@plt>
  lea    -0x1(%rbp),%eax
  mov    %eax,0x34(%rsp)
  cmpl   $0x4,0x88(%rsp)
  je     L298
  movslq 0x34(%rsp),%rax
  mov    0x8(%rsp),%rsi
  movzbl (%rsi,%rax,1),%eax
  movzbl %al,%edi
  mov    %edi,0x14(%rsp)
  movzbl %al,%eax
  mov    0x20(%rsp),%rdi
  movslq (%rdi,%rax,4),%rax
  lea    (%r15,%rax,4),%rdx
  mov    0x10(%rsp),%eax
  sub    $0x2,%eax
  movslq %eax,%rcx
  movzbl (%rsi,%rcx,1),%esi
L27:
  mov    0x10(%rsp),%ebx
  add    %ebx,%eax
  mov    %eax,%ecx
  not    %ecx
  cmp    0x14(%rsp),%esi
  cmovl  %ecx,%eax
  lea    0x4(%rdx),%r13
  mov    %eax,(%rdx)
  test   %ebx,%ebx
  jle    L117
  mov    %ebx,%eax
  mov    %rax,0x28(%rsp)
  mov    $0x0,%ebp
  mov    $0x0,%r14d
  mov    %r14d,0x30(%rsp)
  jmp    L156
L298:
  movslq %eax,%rcx
  mov    0x8(%rsp),%rsi
  mov    (%rsi,%rcx,4),%eax
  mov    %eax,0x14(%rsp)
  cltq
  mov    0x20(%rsp),%rdi
  movslq (%rdi,%rax,4),%rax
  lea    (%r15,%rax,4),%rdx
  mov    0x10(%rsp),%eax
  sub    $0x2,%eax
  mov    -0x4(%rsi,%rcx,4),%esi
  jmp    L27
L322:
  cmpl   $0x4,0x88(%rsp)
  je     L85
  movslq %ebx,%rax
  mov    0x8(%rsp),%rcx
  lea    (%rcx,%rax,1),%r12
  movzbl 0x1(%rcx,%rax,1),%eax
  cmp    %al,(%r12)
  setae  %dil
  movzbl %dil,%edi
  call   <assert@plt>
  movzbl (%r12),%r12d
L244:
  mov    %r13,%r14
  mov    0x14(%rsp),%eax
  cmp    %eax,%r12d
  je     L76
  cltq
  sub    %r15,%r13
  sar    $0x2,%r13
  mov    0x20(%rsp),%rsi
  mov    %r13d,(%rsi,%rax,4)
  movslq %r12d,%rax
  movslq (%rsi,%rax,4),%rax
  lea    (%r15,%rax,4),%r14
L76:
  mov    %r14,%rax
  sub    %r15,%rax
  sar    $0x2,%rax
  cmp    %rbp,%rax
  setg   %dil
  movzbl %dil,%edi
  call   <assert@plt>
  sub    $0x1,%ebx
  lea    (%r12,%r12,1),%edx
  cmpl   $0x4,0x88(%rsp)
  je     L263
  movslq %ebx,%rax
  mov    0x8(%rsp),%rdi
  movzbl (%rdi,%rax,1),%eax
L73:
  cmp    %eax,%r12d
  setg   %al
  movzbl %al,%eax
  or     %edx,%eax
  movslq %eax,%rdx
  mov    0x18(%rsp),%rcx
  lea    (%rcx,%rdx,4),%rdx
  mov    0x30(%rsp),%esi
  cmp    %esi,(%rdx)
  je     L169
  add    0x10(%rsp),%ebx
  mov    %esi,(%rdx)
L169:
  mov    %ebx,%edx
  not    %edx
  test   $0x1,%al
  cmovne %edx,%ebx
  lea    0x4(%r14),%r13
  mov    %ebx,(%r14)
  movl   $0x0,(%r15,%rbp,4)
  mov    %r12d,0x14(%rsp)
L313:
  add    $0x1,%rbp
  cmp    %rbp,0x28(%rsp)
  je     L224
L156:
  mov    (%r15,%rbp,4),%ebx
  test   %ebx,%ebx
  jle    L289
  mov    0x10(%rsp),%eax
  cmp    %ebx,%eax
  jg     L322
  addl   $0x1,0x30(%rsp)
  sub    %eax,%ebx
  jmp    L322
L85:
  movslq %ebx,%rax
  shl    $0x2,%rax
  mov    0x8(%rsp),%rcx
  lea    (%rcx,%rax,1),%r12
  mov    0x4(%rcx,%rax,1),%eax
  cmp    %eax,(%r12)
  setge  %dil
  movzbl %dil,%edi
  call   <assert@plt>
  mov    (%r12),%r12d
  jmp    L244
L263:
  movslq %ebx,%rax
  mov    0x8(%rsp),%rsi
  mov    (%rsi,%rax,4),%eax
  jmp    L73
L289:
  jns    L313
  not    %ebx
  mov    %ebx,(%r15,%rbp,4)
  jmp    L313
L224:
  mov    0x30(%rsp),%r14d
L4:
  mov    0x34(%rsp),%eax
  test   %eax,%eax
  js     L192
  mov    0x10(%rsp),%esi
  jmp    L295
L117:
  mov    $0x0,%r14d
  jmp    L4
L46:
  sub    %esi,%ecx
  mov    %ecx,(%rdi)
L177:
  sub    $0x1,%eax
  js     L84
L295:
  movslq %eax,%rdx
  shl    $0x2,%rdx
  lea    (%r15,%rdx,1),%rdi
  mov    (%rdi),%ecx
  cmp    %esi,%ecx
  jge    L177
  test   %ecx,%ecx
  jle    L177
  add    %esi,%ecx
  mov    %ecx,(%rdi)
  sub    $0x1,%eax
  movslq %eax,%r8
  lea    -0x4(%r15,%rdx,1),%rdi
  mov    (%rdi),%ecx
  cmp    %ecx,%esi
  jle    L46
  lea    -0x4(%r15,%r8,4),%rdx
L222:
  sub    $0x1,%eax
  mov    %rdx,%rdi
  sub    $0x4,%rdx
  mov    0x4(%rdx),%ecx
  cmp    %esi,%ecx
  jl     L222
  jmp    L46
L42:
  cmpl   $0x4,0x88(%rsp)
  je     L193
  movslq %ebx,%rax
  mov    0x8(%rsp),%rdi
  lea    (%rdi,%rax,1),%r12
  movzbl 0x1(%rdi,%rax,1),%eax
  cmp    %al,(%r12)
  setbe  %dil
  movzbl %dil,%edi
  call   <assert@plt>
  movzbl (%r12),%r12d
L353:
  mov    %r14,%r13
  mov    0x14(%rsp),%eax
  cmp    %eax,%r12d
  je     L276
  cltq
  sub    %r15,%r14
  sar    $0x2,%r14
  mov    0x20(%rsp),%rcx
  mov    %r14d,(%rcx,%rax,4)
  movslq %r12d,%rax
  movslq (%rcx,%rax,4),%rax
  lea    (%r15,%rax,4),%r13
L276:
  mov    %r13,%rax
  sub    %r15,%rax
  sar    $0x2,%rax
  cmp    %rbp,%rax
  setle  %dil
  movzbl %dil,%edi
  call   <assert@plt>
  sub    $0x1,%ebx
  lea    (%r12,%r12,1),%edx
  cmpl   $0x4,0x88(%rsp)
  je     L202
  movslq %ebx,%rax
  mov    0x8(%rsp),%rsi
  movzbl (%rsi,%rax,1),%eax
L336:
  cmp    %eax,%r12d
  setl   %al
  movzbl %al,%eax
  or     %edx,%eax
  movslq %eax,%rdx
  mov    0x18(%rsp),%rcx
  lea    (%rcx,%rdx,4),%rdx
  mov    0x28(%rsp),%esi
  cmp    %esi,(%rdx)
  je     L253
  add    0x10(%rsp),%ebx
  mov    %esi,(%rdx)
L253:
  mov    $0xfffffffe,%edx
  sub    %ebx,%edx
  test   $0x1,%al
  cmovne %edx,%ebx
  lea    -0x4(%r13),%r14
  mov    %ebx,-0x4(%r13)
  movl   $0x0,(%r15,%rbp,4)
  mov    %r12d,0x14(%rsp)
L268:
  sub    $0x1,%rbp
  test   %ebp,%ebp
  js     L203
L205:
  mov    (%r15,%rbp,4),%ebx
  test   %ebx,%ebx
  jle    L268
  mov    0x10(%rsp),%eax
  cmp    %ebx,%eax
  jg     L42
  addl   $0x1,0x28(%rsp)
  sub    %eax,%ebx
  jmp    L42
L193:
  movslq %ebx,%rax
  shl    $0x2,%rax
  mov    0x8(%rsp),%rdi
  lea    (%rdi,%rax,1),%r12
  mov    0x4(%rdi,%rax,1),%eax
  cmp    %eax,(%r12)
  setle  %dil
  movzbl %dil,%edi
  call   <assert@plt>
  mov    (%r12),%r12d
  jmp    L353
L202:
  movslq %ebx,%rax
  mov    0x8(%rsp),%rsi
  mov    (%rsi,%rax,4),%eax
  jmp    L336
L84:
  mov    $0x1,%ecx
  mov    0x80(%rsp),%edx
  mov    0x20(%rsp),%rbx
  mov    %rbx,%rsi
  mov    0x38(%rsp),%rdi
  call   <getBuckets@plt>
  lea    0x1(%r14),%eax
  mov    %eax,0x28(%rsp)
  movslq (%rbx),%rax
  lea    (%r15,%rax,4),%r14
  movslq 0x34(%rsp),%rbp
  movl   $0x0,0x14(%rsp)
  jmp    L205
L192:
  mov    $0x1,%ecx
  mov    0x80(%rsp),%edx
  mov    0x20(%rsp),%rsi
  mov    0x38(%rsp),%rdi
  call   <getBuckets@plt>
L203:
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

assistant: ```c
void LMSsort2(const void *T, int *SA, int *C, int *B, int *D, int n, int k, int cs) {
  int *b, i, j, t, d;
  int c0, c1;
  assert(C != B);
  getBuckets(C, B, k, 0);
  j = n - 1;
  b = SA + B[c1 = (cs == sizeof(int) ? ((int *)T)[(j)] : ((unsigned char *)T)[(j)])];
  --j;
  t = ((cs == sizeof(int) ? ((int *)T)[(j)] : ((unsigned char *)T)[(j)]) < c1);
  j += n;
  *b++ = (t & 1) ? ~j : j;
  for (i = 0, d = 0; i < n; ++i) {
    if (0 < (j = SA[i])) {
      if (n <= j) {
        d += 1;
        j -= n;
      }
      assert((cs == sizeof(int) ? ((int *)T)[(j)] : ((unsigned char *)T)[(j)]) >= (cs == sizeof(int) ? ((int *)T)[(j + 1)] : ((unsigned char *)T)[(j + 1)]));
      if ((c0 = (cs == sizeof(int) ? ((int *)T)[(j)] : ((unsigned char *)T)[(j)])) != c1) {
        B[c1] = b - SA;
        b = SA + B[c1 = c0];
      }
      assert(i < (b - SA));
      --j;
      t = c0;
      t = (t << 1) | ((cs == sizeof(int) ? ((int *)T)[(j)] : ((unsigned char *)T)[(j)]) < c1);
      if (D[t] != d) {
        j += n;
        D[t] = d;
      }
      *b++ = (t & 1) ? ~j : j;
      SA[i] = 0;
    } else if (j < 0) {
      SA[i] = ~j;
    }
  }
  for (i = n - 1; 0 <= i; --i) {
    if (0 < SA[i]) {
      if (SA[i] < n) {
        SA[i] += n;
        for (j = i - 1; SA[j] < n; --j) {
        }
        SA[j] -= n;
        i = j;
      }
    }
  }
  getBuckets(C, B, k, 1);
  for (i = n - 1, d += 1, b = SA + B[c1 = 0]; 0 <= i; --i) {
    if (0 < (j = SA[i])) {
      if (n <= j) {
        d += 1;
        j -= n;
      }
      assert((cs == sizeof(int) ? ((int *)T)[(j)] : ((unsigned char *)T)[(j)]) <= (cs == sizeof(int) ? ((int *)T)[(j + 1)] : ((unsigned char *)T)[(j + 1)]));
      if ((c0 = (cs == sizeof(int) ? ((int *)T)[(j)] : ((unsigned char *)T)[(j)])) != c1) {
        B[c1] = b - SA;
        b = SA + B[c1 = c0];
      }
      assert((b - SA) <= i);
      --j;
      t = c0;
      t = (t << 1) | ((cs == sizeof(int) ? ((int *)T)[(j)] : ((unsigned char *)T)[(j)]) > c1);
      if (D[t] != d) {
        j += n;
        D[t] = d;
      }
      *--b = (t & 1) ? ~(j + 1) : j;
      SA[i] = 0;
    }
  }
}
```