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

```asm
<stable_grail_combine_blocks>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x68,%rsp
  mov    %rdi,%r15
  mov    %rsi,0x50(%rsp)
  mov    %edx,%esi
  mov    %ecx,%edi
  mov    %ecx,0x38(%rsp)
  mov    %r8d,%r14d
  mov    %r9d,0x58(%rsp)
  lea    (%rcx,%rcx,1),%ecx
  mov    %ecx,0x3c(%rsp)
  mov    %edx,0x5c(%rsp)
  mov    %edx,%eax
  cltd
  idiv   %ecx
  mov    %eax,0x24(%rsp)
  mov    %edx,0x40(%rsp)
  cmp    %edx,%edi
  jl     L320
  sub    %edx,%esi
  mov    %esi,0x5c(%rsp)
  movl   $0x0,0x40(%rsp)
L320:
  cmpq   $0x0,0xa0(%rsp)
  je     L355
  movslq %r14d,%rdx
  shl    $0x3,%rdx
  mov    0x50(%rsp),%rsi
  sub    %rdx,%rsi
  mov    0xa0(%rsp),%rdi
  call   <memcpy@plt>
  cmpl   $0x0,0x24(%rsp)
  js     L62
  mov    0x24(%rsp),%eax
  test   %eax,%eax
  sete   %cl
  mov    0x40(%rsp),%edi
  test   %edi,%edi
  sete   0x47(%rsp)
  or     %eax,%edi
  je     L62
L265:
  movslq 0x3c(%rsp),%rax
  shl    $0x3,%rax
  mov    %rax,0x30(%rsp)
  mov    0x50(%rsp),%rax
  mov    %rax,0x28(%rsp)
  movslq %r14d,%rax
  shl    $0x3,%rax
  mov    %rax,0x8(%rsp)
  mov    %r14d,%eax
  neg    %eax
  cltq
  shl    $0x3,%rax
  mov    %rax,0x48(%rsp)
  movl   $0x0,0x20(%rsp)
  mov    %r14d,%eax
  mov    %r15,%r14
  mov    %eax,%r15d
  jmp    L13
L169:
  jne    L239
  movslq %ebx,%rdx
  mov    (%r14,%rdx,8),%rsi
  mov    (%r14,%rax,8),%rdx
  mov    (%rdx),%edx
  cmp    %edx,(%rsi)
  cmovg  %eax,%ebx
L239:
  add    $0x1,%rax
  add    0x8(%rsp),%rcx
  cmp    %eax,%ebp
  jle    L143
L392:
  mov    %r15d,%edx
  imul   %ebx,%edx
  movslq %edx,%rdx
  mov    (%r12,%rdx,8),%rdx
  mov    (%rcx),%rsi
  mov    (%rdx),%edx
  sub    (%rsi),%edx
  test   %edx,%edx
  jle    L169
  mov    %eax,%ebx
  jmp    L239
L143:
  mov    %r13d,0x1c(%rsp)
  cmp    %r13d,%ebx
  je     L206
  mov    %ebx,%eax
  imul   %r15d,%eax
  cltq
  lea    (%r12,%rax,8),%rsi
  movslq 0x10(%rsp),%rax
  lea    (%r12,%rax,8),%rdi
  mov    %r15d,%edx
  mov    $0x0,%eax
  call   <stable_grail_swap_n@plt>
  movslq %ebx,%rax
  lea    (%r14,%rax,8),%rsi
  lea    (%r14,%r13,8),%rdi
  mov    $0x0,%eax
  call   <stable_grail_swap1@plt>
  mov    0x18(%rsp),%eax
  cmp    %eax,%ebx
  je     L171
  mov    0x1c(%rsp),%edi
  cmp    %edi,%eax
  jne    L206
L171:
  mov    0x14(%rsp),%eax
  xor    0x18(%rsp),%eax
  xor    %eax,%ebx
  mov    %ebx,0x18(%rsp)
L206:
  add    $0x1,%r13
  add    %r15d,0x10(%rsp)
  lea    0x1(%r13),%eax
  cmp    %eax,%ebp
  jle    L114
L262:
  mov    %r13d,0x14(%rsp)
  lea    0x1(%r13),%eax
  cmp    %eax,%ebp
  jle    L206
  lea    0x1(%r13),%rax
  mov    0x10(%rsp),%edi
  lea    (%r15,%rdi,1),%edx
  movslq %edx,%rdx
  lea    (%r12,%rdx,8),%rcx
  mov    %r13d,%ebx
  jmp    L392
L114:
  mov    $0x0,%eax
  mov    $0x0,%r9d
  mov    0x20(%rsp),%ecx
  cmp    %ecx,0x24(%rsp)
  je     L238
L255:
  cmpq   $0x0,0xa0(%rsp)
  je     L175
  mov    %ebp,%ecx
  sub    %r9d,%ecx
  movslq 0x18(%rsp),%rdx
  lea    (%r14,%rdx,8),%rsi
  sub    $0x8,%rsp
  push   %rax
  mov    %r15d,%r8d
  mov    %r12,%rdx
  mov    %r14,%rdi
  mov    $0x0,%eax
  call   <stable_grail_merge_buffers_left_with_x_buf@plt>
  add    $0x10,%rsp
L157:
  addl   $0x1,0x20(%rsp)
  mov    0x20(%rsp),%eax
  cmp    %eax,0x24(%rsp)
  jl     L79
  mov    0x20(%rsp),%edi
  cmp    %edi,0x24(%rsp)
  sete   %cl
  mov    0x30(%rsp),%rdi
  add    %rdi,0x28(%rsp)
  test   %cl,%cl
  je     L13
  cmpb   $0x0,0x47(%rsp)
  jne    L79
L13:
  mov    0x28(%rsp),%r12
  mov    0x20(%rsp),%edi
  cmp    %edi,0x24(%rsp)
  je     L68
  mov    0x3c(%rsp),%eax
  cltd
  idiv   %r15d
  mov    %eax,%ebx
  mov    %eax,%ebp
  movzbl %cl,%ecx
  lea    (%rcx,%rax,1),%esi
  mov    %r14,%rdi
  mov    $0x0,%eax
  call   <stable_binary_insertion_sort@plt>
  mov    0x38(%rsp),%eax
  cltd
  idiv   %r15d
  mov    %eax,0x18(%rsp)
  mov    $0x0,%eax
  mov    $0x0,%r9d
  cmp    $0x1,%ebx
  jle    L255
L176:
  movl   $0x0,0x10(%rsp)
  mov    $0x0,%r13d
  jmp    L262
L272:
  mov    $0x0,%r9d
  jmp    L255
L175:
  mov    %ebp,%ecx
  sub    %r9d,%ecx
  movslq 0x18(%rsp),%rdx
  lea    (%r14,%rdx,8),%rsi
  push   %rax
  push   %r9
  mov    0x68(%rsp),%r9d
  mov    %r15d,%r8d
  mov    %r12,%rdx
  mov    %r14,%rdi
  mov    $0x0,%eax
  call   <stable_grail_merge_buffers_left@plt>
  add    $0x10,%rsp
  jmp    L157
L79:
  mov    %r15d,%r14d
  cmpq   $0x0,0xa0(%rsp)
  je     L50
L62:
  mov    0x5c(%rsp),%eax
  sub    $0x1,%eax
  js     L8
  cltq
  movslq %r14d,%rdx
  neg    %rdx
  mov    0x50(%rsp),%rsi
  lea    (%rsi,%rdx,8),%rcx
L366:
  mov    (%rcx,%rax,8),%rdx
  mov    %rdx,(%rsi,%rax,8)
  sub    $0x1,%rax
  test   %eax,%eax
  jns    L366
L8:
  movslq %r14d,%rdx
  shl    $0x3,%rdx
  mov    0x50(%rsp),%rdi
  sub    %rdx,%rdi
  mov    0xa0(%rsp),%rsi
  call   <memcpy@plt>
L27:
  add    $0x68,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L68:
  mov    0x40(%rsp),%eax
  cltd
  idiv   %r15d
  mov    %eax,%ebx
  mov    %eax,%ebp
  movzbl %cl,%ecx
  lea    (%rcx,%rax,1),%esi
  mov    %r14,%rdi
  mov    $0x0,%eax
  call   <stable_binary_insertion_sort@plt>
  mov    0x38(%rsp),%eax
  cltd
  idiv   %r15d
  mov    %eax,0x18(%rsp)
  cmp    $0x1,%ebx
  jg     L176
L238:
  mov    0x40(%rsp),%eax
  cltd
  idiv   %r15d
  mov    %edx,%eax
  mov    %edx,%r9d
  test   %edx,%edx
  je     L255
  test   %ebp,%ebp
  jle    L272
  mov    %r15d,%edx
  imul   %ebp,%edx
  movslq %edx,%rcx
  mov    (%r12,%rcx,8),%rcx
  mov    (%rcx),%esi
  sub    %r15d,%edx
  movslq %edx,%rdx
  lea    (%r12,%rdx,8),%rdx
  mov    $0x0,%r9d
L125:
  mov    (%rdx),%rcx
  cmp    (%rcx),%esi
  jge    L255
  add    $0x1,%r9d
  add    0x48(%rsp),%rdx
  cmp    %ebp,%r9d
  jne    L125
  mov    %ebp,%r9d
  jmp    L255
L355:
  mov    0x24(%rsp),%eax
  test   %eax,%eax
  js     L50
  sete   %cl
  mov    0x40(%rsp),%edi
  test   %edi,%edi
  sete   0x47(%rsp)
  or     %eax,%edi
  jne    L265
L50:
  cmpl   $0x0,0x58(%rsp)
  je     L27
  mov    0x5c(%rsp),%edi
  mov    %edi,%eax
  sub    $0x1,%eax
  js     L27
  cltq
  shl    $0x3,%rax
  mov    0x50(%rsp),%rcx
  lea    (%rcx,%rax,1),%rbx
  lea    -0x8(%rcx,%rax,1),%r12
  lea    -0x1(%rdi),%eax
  shl    $0x3,%rax
  sub    %rax,%r12
  movslq %r14d,%rbp
  neg    %rbp
  shl    $0x3,%rbp
L217:
  lea    0x0(%rbp,%rbx,1),%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <stable_grail_swap1@plt>
  sub    $0x8,%rbx
  cmp    %r12,%rbx
  jne    L217
  jmp    L27
```

assistant: ```c
void stable_grail_combine_blocks(int **keys, int **arr, int len, int LL, int lblock, int havebuf, int **xbuf) {
  int M, b, NBlk, midkey, lrest, u, p, v, kc, nbl2, llast;
  int **arr1;
  M = len / (2 * LL);
  lrest = len % (2 * LL);
  if (lrest <= LL) {
    len -= lrest;
    lrest = 0;
  }
  if (xbuf) {
    memcpy((xbuf), (arr - lblock), (lblock) * sizeof(int *));
  }
  for (b = 0; b <= M; b++) {
    if (b == M && lrest == 0) {
      break;
    }
    arr1 = arr + b * 2 * LL;
    NBlk = (b == M ? lrest : 2 * LL) / lblock;
    stable_binary_insertion_sort(keys, NBlk + (b == M ? 1 : 0));
    midkey = LL / lblock;
    for (u = 1; u < NBlk; u++) {
      p = u - 1;
      for (v = u; v < NBlk; v++) {
        kc = (*(*(arr1 + p * lblock)) - *(*(arr1 + v * lblock)));
        if (kc > 0 || (kc == 0 && (*(*(keys + p)) - *(*(keys + v))) > 0)) {
          p = v;
        }
      }
      if (p != u - 1) {
        stable_grail_swap_n(arr1 + (u - 1) * lblock, arr1 + p * lblock, lblock);
        stable_grail_swap1(keys + (u - 1), keys + p);
        if (midkey == u - 1 || midkey == p) {
          midkey ^= (u - 1) ^ p;
        }
      }
    }
    nbl2 = llast = 0;
    if (b == M) {
      llast = lrest % lblock;
    }
    if (llast != 0) {
      while (nbl2 < NBlk && (*(*(arr1 + NBlk * lblock)) - *(*(arr1 + (NBlk - nbl2 - 1) * lblock))) < 0) {
        nbl2++;
      }
    }
    if (xbuf) {
      stable_grail_merge_buffers_left_with_x_buf(keys, keys + midkey, arr1, NBlk - nbl2, lblock, nbl2, llast);
    } else {
      stable_grail_merge_buffers_left(keys, keys + midkey, arr1, NBlk - nbl2, lblock, havebuf, nbl2, llast);
    }
  }
  if (xbuf) {
    for (p = len; --p >= 0;) {
      arr[p] = arr[p - lblock];
    }
    memcpy((arr - lblock), (xbuf), (lblock) * sizeof(int *));
  } else if (havebuf) {
    while (--len >= 0) {
      stable_grail_swap1(arr + len, arr + len - lblock);
    }
  }
}
```