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

```asm
<stable_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    L14
L172:
  add    %r9d,%r9d
  mov    %r9d,%eax
  imul   %r9d,%eax
  cmp    %r12d,%eax
  jl     L172
  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   <stable_grail_find_keys@plt>
  mov    0x4(%rsp),%r9d
  cmp    %eax,%ebx
  mov    %eax,0x14(%rsp)
  jg     L125
  movslq %ebx,%rax
  mov    0x10(%rsp),%r8d
  mov    0x8(%rsp),%rcx
  sub    %ebx,%r12d
  lea    0x0(%rbp,%rax,8),%r13
  mov    %r9d,%edx
  mov    %r12d,%esi
  mov    %r13,%rdi
  call   <stable_grail_build_blocks@plt>
  mov    0x4(%rsp),%r9d
  movl   $0x1,0x4(%rsp)
  mov    %r9d,%eax
L2:
  lea    (%r9,%r9,1),%r14d
  cmp    %r12d,%r14d
  jge    L162
  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    L130
L146:
  cmp    %r15d,0x18(%rsp)
  jl     L118
L46:
  xor    %edx,%edx
  cmp    0x10(%rsp),%ebx
  cmovle 0x8(%rsp),%rdx
  mov    %ebx,%r8d
  mov    $0x1,%r9d
L179:
  sub    $0x8,%rsp
  mov    %r15d,%ecx
  mov    %r13,%rsi
  mov    %rbp,%rdi
  push   %rdx
  mov    %r12d,%edx
  call   <stable_grail_combine_blocks@plt>
  lea    (%r15,%r15,1),%eax
  pop    %rdx
  mov    %r15d,%r9d
  pop    %rcx
  cmp    %r12d,%eax
  jge    L162
  mov    %eax,%r15d
L130:
  mov    0x4(%rsp),%esi
  test   %esi,%esi
  jne    L46
  cmp    $0x4,%r14d
  jg     L146
L118:
  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     L91
  cmp    $0x1,%r14d
  jle    L91
  nopl   0x0(%rax,%rax,1)
L178:
  add    %edi,%edi
  lea    0x7(%rdx),%rax
  test   %rdx,%rdx
  cmovs  %rax,%rdx
  sar    $0x3,%rdx
  cmp    %r14d,%edi
  jge    L91
  test   %rdx,%rdx
  jne    L178
L91:
  lea    0x0(,%r9,4),%eax
  xor    %r9d,%r9d
  cltd
  idiv   %edi
  xor    %edx,%edx
  mov    %eax,%r8d
  jmp    L179
  nopl   0x0(%rax,%rax,1)
L125:
  cmp    $0x3,%eax
  jg     L80
  jmp    L104
  nopw   0x0(%rax,%rax,1)
L20:
  sar    %r9d
L80:
  cmp    %r9d,%eax
  jl     L20
  movslq %r9d,%rax
  sub    %r9d,%r12d
  mov    %r9d,%edx
  xor    %r8d,%r8d
  lea    0x0(%rbp,%rax,8),%r13
  xor    %ecx,%ecx
  mov    %r12d,%esi
  mov    %r9d,0x4(%rsp)
  mov    %r13,%rdi
  call   <stable_grail_build_blocks@plt>
  mov    0x4(%rsp),%r9d
  xor    %eax,%eax
  movl   $0x0,0x4(%rsp)
  mov    %r9d,0x1c(%rsp)
  mov    %r9d,%r15d
  jmp    L2
  nop
L162:
  mov    0x1c(%rsp),%ebx
  mov    %rbp,%rdi
  mov    %ebx,%esi
  call   <stable_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    10f0 <stable_grail_merge_without_buffer@plt>
  nopl   0x0(%rax)
L14:
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    10d0 <stable_binary_insertion_sort@plt>
L104:
  add    $0x28,%rsp
  mov    %r12d,%esi
  mov    %rbp,%rdi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    10b0 <stable_grail_lazy_stable_sort@plt>
```

assistant: ```c
void stable_grail_common_sort(int **arr, int Len, int **extbuf, int LExtBuf) {
  int lblock, nkeys, findkeys, ptr, cbuf, lb, nk;
  int havebuf, chavebuf;
  long long s;
  if (Len < 16) {
    stable_binary_insertion_sort(arr, Len);
    return;
  }
  lblock = 1;
  while (lblock * lblock < Len) {
    lblock *= 2;
  }
  nkeys = (Len - 1) / lblock + 1;
  findkeys = stable_grail_find_keys(arr, Len, nkeys + lblock);
  havebuf = 1;
  if (findkeys < nkeys + lblock) {
    if (findkeys < 4) {
      stable_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) {
    stable_grail_build_blocks(arr + ptr, Len - ptr, cbuf, extbuf, LExtBuf);
  } else {
    stable_grail_build_blocks(arr + ptr, Len - ptr, cbuf, 0, 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;
      }
    }
    stable_grail_combine_blocks(arr, arr + ptr, Len - ptr, cbuf, lb, chavebuf, chavebuf && lb <= LExtBuf ? extbuf : 0);
  }
  stable_binary_insertion_sort(arr, ptr);
  stable_grail_merge_without_buffer(arr, ptr, Len - ptr);
}
```