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

```asm
<median_filter>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x78,%rsp
  mov    %rdi,%rbx
  mov    %rsi,%r14
  mov    %rdx,%r13
  mov    %rdx,0x58(%rsp)
  mov    %rcx,0x28(%rsp)
  mov    %r8d,%eax
  mov    %fs:0x28,%rdx
  mov    %rdx,0x68(%rsp)
  xor    %edx,%edx
  mov    %r8d,%edx
  shr    $0x1f,%edx
  add    %r8d,%edx
  mov    %edx,%esi
  sar    %esi
  mov    %esi,%ebp
  mov    %esi,0x4(%rsp)
  imul   %r8d,%eax
  mov    %eax,0x64(%rsp)
  cltq
  lea    (%rax,%rax,1),%rdi
  call   <malloc@plt>
  mov    %rax,%r15
  mov    $0xa,%edi
  call   <putchar@plt>
  movslq %ebp,%rax
  mov    %rax,0x30(%rsp)
  sub    %rax,%r13
  mov    %r13,0x38(%rsp)
  cmp    %r13,%rax
  jge    L16
  mov    %ebp,%esi
  mov    %rax,%r13
  mov    %rax,0x48(%rsp)
  neg    %esi
  mov    %esi,0x20(%rsp)
  movslq %esi,%rdx
  lea    (%rdx,%rax,1),%rcx
  lea    0x0(%rbp,%rbp,1),%eax
  mov    %eax,%eax
  add    %rcx,%rax
  lea    0x8(%rbx,%rax,8),%r12
  lea    (%rcx,%rcx,1),%rax
  mov    %rax,0x40(%rsp)
  lea    (%rbx,%rdx,8),%rax
  mov    %rax,0x50(%rsp)
  lea    0x1(%rbp,%rbp,1),%eax
  mov    %eax,(%rsp)
  jmp    L62
L56:
  mov    0x28(%rsp),%rax
  mov    0x30(%rsp),%rbx
  sub    %rbx,%rax
  mov    %rax,0x8(%rsp)
  cmp    %rax,%rbx
  jge    L50
  mov    0x50(%rsp),%rax
  lea    (%rax,%r13,8),%rax
  mov    %rax,0x18(%rsp)
  mov    0x40(%rsp),%rbx
  mov    0x48(%rsp),%rbp
  mov    0x4(%rsp),%eax
  add    %eax,%eax
  mov    %eax,0x24(%rsp)
  lea    0x64(%rsp),%rax
  mov    %rax,0x10(%rsp)
L23:
  mov    0x20(%rsp),%esi
  cmp    %esi,0x4(%rsp)
  jl     L22
  mov    0x24(%rsp),%edi
  mov    0x18(%rsp),%r8
  mov    $0x0,%r9d
L92:
  movslq %r9d,%rax
  lea    (%r15,%rax,2),%rsi
  mov    $0x0,%eax
  mov    %rbx,%rcx
  add    (%r8),%rcx
L97:
  movzwl (%rcx,%rax,2),%edx
  mov    %dx,(%rsi,%rax,2)
  mov    %rax,%rdx
  add    $0x1,%rax
  cmp    %rdi,%rdx
  jne    L97
  add    (%rsp),%r9d
  add    $0x8,%r8
  cmp    %r12,%r8
  jne    L92
L22:
  mov    0x10(%rsp),%rsi
  mov    %r15,%rdi
  mov    $0x0,%eax
  call   <median_of@plt>
  mov    (%r14,%r13,8),%rdx
  mov    %ax,(%rdx,%rbp,2)
  add    $0x1,%rbp
  add    $0x2,%rbx
  cmp    0x8(%rsp),%rbp
  jne    L23
L50:
  add    $0x1,%r13
  add    $0x8,%r12
  cmp    0x38(%rsp),%r13
  je     L16
L62:
  mov    %r13d,%esi
  movslq %r13d,%rax
  imul   $0x66666667,%rax,%rax
  sar    $0x22,%rax
  mov    %r13d,%edx
  sar    $0x1f,%edx
  sub    %edx,%eax
  lea    (%rax,%rax,4),%eax
  add    %eax,%eax
  cmp    %r13d,%eax
  jne    L56
  lea    D9(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L56
L16:
  mov    %r15,%rdi
  call   <free@plt>
  mov    0x28(%rsp),%rcx
  sub    $0x1,%rcx
  mov    0x58(%rsp),%rdx
  sub    $0x1,%rdx
  mov    0x4(%rsp),%esi
  mov    %r14,%rdi
  mov    $0x0,%eax
  call   <fix_edges@plt>
  mov    0x68(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L3
  mov    $0x1,%eax
  add    $0x78,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L3:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: data_label: D9
type: string

tool: D9: %d 

assistant: ```c
int median_filter(the_image, out_image, rows, cols, size)
int size;
short **the_image, **out_image;
long rows, cols;
{
  int a, b, count, i, j, k, length, sd2, sd2p1, ss, width;
  short *elements;
  sd2 = size / 2;
  sd2p1 = sd2 + 1;
  ss = size * size;
  elements = (short *)malloc(ss * sizeof(short));
  printf("\n");
  for (i = sd2; i < rows - sd2; i++) {
    if ((i % 10) == 0)
      printf("%d ", i);
    for (j = sd2; j < cols - sd2; j++) {
      count = 0;
      for (a = -sd2; a < sd2p1; a++) {
        for (b = -sd2; b < sd2p1; b++) {
          elements[count] = the_image[i + a][j + b];
          count++;
        }
      }
      out_image[i][j] = median_of(elements, &ss);
    }
  }
  free(elements);
  fix_edges(out_image, sd2, rows - 1, cols - 1);
  return (1);
}
```