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

```asm
<sorter_grail_common_sort>:
  endbr64
  push   %r15
  mov    $0x1,%r9d
  push   %r14
  push   %r13
  push   %r12
  mov    %esi,%r12d
  push   %rbp
  mov    %rdi,%rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdx,0x8(%rsp)
  mov    %ecx,0x10(%rsp)
  cmp    $0xf,%esi
  jle    L30
L76:
  add    %r9d,%r9d
  mov    %r9d,%eax
  imul   %r9d,%eax
  cmp    %r12d,%eax
  jl     L76
  lea    -0x1(%r12),%eax
  mov    %r12d,%esi
  mov    %rbp,%rdi
  mov    %r9d,0x4(%rsp)
  cltd
  idiv   %r9d
  lea    0x1(%rax),%r15d
  lea    (%r15,%r9,1),%ecx
  mov    %ecx,%edx
  mov    %ecx,%ebx
  mov    %ecx,0x1c(%rsp)
  call   <sorter_grail_find_keys@plt>
  mov    0x4(%rsp),%r9d
  cmp    %eax,%ebx
  mov    %eax,0x14(%rsp)
  jg     L118
  movslq %ebx,%rax
  mov    0x10(%rsp),%r8d
  mov    0x8(%rsp),%rcx
  sub    %ebx,%r12d
  lea    0x0(%rbp,%rax,4),%r13
  mov    %r9d,%edx
  mov    %r12d,%esi
  mov    %r13,%rdi
  call   <sorter_grail_build_blocks@plt>
  mov    0x4(%rsp),%r9d
  movl   $0x1,0x4(%rsp)
  mov    %r9d,%eax
L172:
  lea    (%r9,%r9,1),%r14d
  cmp    %r12d,%r14d
  jge    L11
  mov    %r15d,%edx
  mov    0x4(%rsp),%edi
  mov    %r15d,%ebx
  sar    $0x3,%edx
  sar    %ebx
  imul   %r15d,%edx
  test   %edi,%edi
  cmovne %eax,%ebx
  mov    %r15d,%eax
  mov    %r14d,%r15d
  mov    %eax,%r14d
  mov    %edx,0x18(%rsp)
  jmp    L120
L155:
  cmp    %r15d,0x18(%rsp)
  jl     L61
L78:
  xor    %edx,%edx
  cmp    0x10(%rsp),%ebx
  cmovle 0x8(%rsp),%rdx
  mov    %ebx,%r8d
  mov    $0x1,%r9d
L83:
  sub    $0x8,%rsp
  mov    %r15d,%ecx
  mov    %r13,%rsi
  mov    %rbp,%rdi
  push   %rdx
  mov    %r12d,%edx
  call   <sorter_grail_combine_blocks@plt>
  lea    (%r15,%r15,1),%eax
  pop    %rdx
  mov    %r15d,%r9d
  pop    %rcx
  cmp    %r12d,%eax
  jge    L11
  mov    %eax,%r15d
L120:
  mov    0x4(%rsp),%esi
  test   %esi,%esi
  jne    L78
  cmp    $0x4,%r14d
  jg     L155
L61:
  movslq 0x14(%rsp),%rdx
  movslq %r15d,%rax
  mov    $0x1,%edi
  imul   %rdx,%rax
  mov    %rax,%rdx
  shr    $0x3f,%rdx
  add    %rax,%rdx
  sar    %rdx
  je     L137
  cmp    $0x1,%r14d
  jle    L137
  nopl   0x0(%rax,%rax,1)
L82:
  add    %edi,%edi
  lea    0x7(%rdx),%rax
  test   %rdx,%rdx
  cmovs  %rax,%rdx
  sar    $0x3,%rdx
  cmp    %r14d,%edi
  jge    L137
  test   %rdx,%rdx
  jne    L82
L137:
  lea    0x0(,%r9,4),%eax
  xor    %r9d,%r9d
  cltd
  idiv   %edi
  xor    %edx,%edx
  mov    %eax,%r8d
  jmp    L83
  nopl   0x0(%rax,%rax,1)
L118:
  cmp    $0x3,%eax
  jg     L64
  jmp    L132
  nopw   0x0(%rax,%rax,1)
L133:
  sar    %r9d
L64:
  cmp    %r9d,%eax
  jl     L133
  movslq %r9d,%rax
  sub    %r9d,%r12d
  mov    %r9d,%edx
  xor    %r8d,%r8d
  lea    0x0(%rbp,%rax,4),%r13
  xor    %ecx,%ecx
  mov    %r12d,%esi
  mov    %r9d,0x4(%rsp)
  mov    %r13,%rdi
  call   <sorter_grail_build_blocks@plt>
  mov    0x4(%rsp),%r9d
  xor    %eax,%eax
  movl   $0x0,0x4(%rsp)
  mov    %r9d,0x1c(%rsp)
  mov    %r9d,%r15d
  jmp    L172
  nop
L11:
  mov    0x1c(%rsp),%ebx
  mov    %rbp,%rdi
  mov    %ebx,%esi
  call   <sorter_binary_insertion_sort@plt>
  add    $0x28,%rsp
  mov    %r12d,%edx
  mov    %ebx,%esi
  mov    %rbp,%rdi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    10c0 <sorter_grail_merge_without_buffer@plt>
  nopl   0x0(%rax)
L30:
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    10d0 <sorter_binary_insertion_sort@plt>
L132:
  add    $0x28,%rsp
  mov    %r12d,%esi
  mov    %rbp,%rdi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    10b0 <sorter_grail_lazy_stable_sort@plt>
```

assistant: ```c
void sorter_grail_common_sort(int64_t *arr, int Len, int64_t *extbuf, int LExtBuf) {
  int lblock, nkeys, findkeys, ptr, cbuf, lb, nk;
  int havebuf, chavebuf;
  long long s;
  if (Len < 16) {
    sorter_binary_insertion_sort(arr, Len);
    return;
  }
  lblock = 1;
  while (lblock * lblock < Len) {
    lblock *= 2;
  }
  nkeys = (Len - 1) / lblock + 1;
  findkeys = sorter_grail_find_keys(arr, Len, nkeys + lblock);
  havebuf = 1;
  if (findkeys < nkeys + lblock) {
    if (findkeys < 4) {
      sorter_grail_lazy_stable_sort(arr, Len);
      return;
    }
    nkeys = lblock;
    while (nkeys > findkeys) {
      nkeys /= 2;
    }
    havebuf = 0;
    lblock = 0;
  }
  ptr = lblock + nkeys;
  cbuf = havebuf ? lblock : nkeys;
  if (havebuf) {
    sorter_grail_build_blocks(arr + ptr, Len - ptr, cbuf, extbuf, LExtBuf);
  } else {
    sorter_grail_build_blocks(arr + ptr, Len - ptr, cbuf, NULL, 0);
  }
  while (Len - ptr > (cbuf *= 2)) {
    lb = lblock;
    chavebuf = havebuf;
    if (!havebuf) {
      if (nkeys > 4 && nkeys / 8 * nkeys >= cbuf) {
        lb = nkeys / 2;
        chavebuf = 1;
      } else {
        nk = 1;
        s = (long long)cbuf * findkeys / 2;
        while (nk < nkeys && s != 0) {
          nk *= 2;
          s /= 8;
        }
        lb = (2 * cbuf) / nk;
      }
    }
    sorter_grail_combine_blocks(arr, arr + ptr, Len - ptr, cbuf, lb, chavebuf, chavebuf && lb <= LExtBuf ? extbuf : NULL);
  }
  sorter_binary_insertion_sort(arr, ptr);
  sorter_grail_merge_without_buffer(arr, ptr, Len - ptr);
}
```