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

```asm
<median_filter>:
  endbr64
  push   %r15
  mov    %r8d,%eax
  push   %r14
  imul   %r8d,%eax
  push   %r13
  mov    %rcx,%r13
  push   %r12
  push   %rbp
  mov    %rdx,%rbp
  push   %rbx
  mov    %rdi,%rbx
  sub    $0xd8,%rsp
  mov    %rsi,0x50(%rsp)
  mov    %rcx,0xb8(%rsp)
  mov    %rdx,0xb0(%rsp)
  mov    %fs:0x28,%rdx
  mov    %rdx,0xc8(%rsp)
  mov    %r8d,%edx
  mov    %eax,0xc4(%rsp)
  cltq
  shr    $0x1f,%edx
  add    %r8d,%edx
  mov    %edx,%edi
  sar    %edi
  mov    %edi,0x24(%rsp)
  mov    %edi,%r15d
  lea    (%rax,%rax,1),%rdi
  call   <malloc@plt>
  mov    $0xa,%edi
  mov    %rax,%r14
  call   <putchar@plt>
  movslq %r15d,%rdi
  sub    %rdi,%rbp
  mov    %rdi,0x78(%rsp)
  mov    %rbp,0x80(%rsp)
  cmp    %rbp,%rdi
  jge    L76
  mov    %rdi,%rax
  lea    (%r15,%r15,1),%edx
  sub    %rdi,%r13
  mov    %rdi,0x40(%rsp)
  neg    %eax
  mov    %rdx,0x30(%rsp)
  movslq %eax,%rsi
  mov    %eax,0x3c(%rsp)
  mov    %rdx,%rax
  add    %rsi,%rax
  mov    %rsi,0xa0(%rsp)
  add    %rdi,%rax
  mov    %r13,0x88(%rsp)
  mov    %rdx,%r13
  lea    0x8(%rbx,%rax,8),%rax
  mov    %rax,0x10(%rsp)
  mov    %rdi,%rax
  add    %rsi,%rdi
  lea    0x1(%rax,%rsi,1),%rax
  mov    %rdi,0x48(%rsp)
  add    %rdi,%rdi
  add    %rax,%rax
  mov    %rdi,0x90(%rsp)
  mov    %rax,0x98(%rsp)
  lea    (%rbx,%rsi,8),%rax
  lea    0x1(%rdx),%ebx
  mov    %rax,0xa8(%rsp)
  mov    %edx,%eax
  shr    $0x3,%eax
  mov    %ebx,0x20(%rsp)
  and    $0xfffffff8,%ebx
  sub    $0x1,%eax
  add    $0x1,%rax
  shl    $0x4,%rax
  mov    %rax,%r12
  mov    %ebx,%eax
  sub    %r15d,%eax
  mov    %eax,0x38(%rsp)
  mov    %rsi,%rax
  neg    %rax
  add    %rax,%rax
  mov    %rax,0x68(%rsp)
  mov    %edx,%eax
  sub    %ebx,%eax
  mov    %eax,0x28(%rsp)
  add    $0x1,%eax
  mov    %eax,0x2c(%rsp)
L51:
  mov    0x40(%rsp),%rax
  mov    %eax,%esi
  imul   $0xcccccccd,%eax,%eax
  add    $0x19999998,%eax
  ror    %eax
  cmp    $0x19999998,%eax
  jbe    L165
L140:
  mov    0x88(%rsp),%rax
  cmp    %rax,0x78(%rsp)
  jge    L113
  add    0xa0(%rsp),%rax
  mov    0x40(%rsp),%rdi
  mov    %rax,0x58(%rsp)
  mov    0xa8(%rsp),%rax
  mov    0x48(%rsp),%rbp
  lea    (%rax,%rdi,8),%rax
  mov    %rax,0x60(%rsp)
  mov    0x98(%rsp),%rax
  mov    %rax,0x8(%rsp)
  mov    0x90(%rsp),%rax
  mov    %rax,(%rsp)
  lea    0xc4(%rsp),%rax
  mov    %rax,0x70(%rsp)
  mov    0x24(%rsp),%eax
  lea    0x1(%rax,%rax,1),%eax
  mov    %eax,0x1c(%rsp)
  xchg   %ax,%ax
L45:
  mov    0x24(%rsp),%eax
  mov    0x3c(%rsp),%ecx
  xor    %r8d,%r8d
  mov    0x60(%rsp),%rdi
  mov    %eax,%r15d
  sub    0x48(%rsp),%r15d
  add    %ebp,%r15d
  cmp    %ecx,%eax
  jl     L98
  nopl   0x0(%rax,%rax,1)
L16:
  mov    0x8(%rsp),%rax
  mov    (%rdi),%rcx
  movslq %r8d,%r9
  lea    (%r14,%r9,2),%rdx
  lea    (%rcx,%rax,1),%rsi
  mov    %rdx,%rax
  sub    %rsi,%rax
  cmp    $0xc,%rax
  jbe    L193
  cmp    $0x2,%r13d
  jbe    L193
  cmp    $0x6,%r13d
  jbe    L103
  mov    (%rsp),%rax
  lea    (%rcx,%rax,1),%rsi
  xor    %eax,%eax
  nopl   0x0(%rax)
L120:
  movdqu (%rsi,%rax,1),%xmm0
  movups %xmm0,(%rdx,%rax,1)
  add    $0x10,%rax
  cmp    %r12,%rax
  jne    L120
  lea    (%r8,%rbx,1),%esi
  cmp    %ebx,0x20(%rsp)
  je     L4
  cmpl   $0x2,0x28(%rsp)
  mov    0x2c(%rsp),%r10d
  jbe    L127
  mov    0x38(%rsp),%edx
  mov    %ebx,%eax
L0:
  lea    (%rax,%rbp,1),%r11
  add    %r9,%rax
  mov    (%rcx,%r11,2),%r11
  mov    %r11,(%r14,%rax,2)
  mov    %r10d,%eax
  and    $0xfffffffc,%eax
  add    %eax,%edx
  add    %eax,%esi
  cmp    %r10d,%eax
  je     L4
L86:
  lea    (%rdx,%r15,1),%eax
  mov    0x24(%rsp),%r10d
  movslq %esi,%rsi
  cltq
  lea    (%rsi,%rsi,1),%r9
  movzwl (%rcx,%rax,2),%eax
  mov    %ax,(%r14,%rsi,2)
  lea    0x1(%rdx),%esi
  cmp    %edx,%r10d
  jle    L4
  lea    (%rsi,%r15,1),%eax
  add    $0x2,%edx
  cltq
  movzwl (%rcx,%rax,2),%eax
  mov    %ax,0x2(%r14,%r9,1)
  cmp    %esi,%r10d
  jle    L4
  add    %r15d,%edx
  movslq %edx,%rdx
  movzwl (%rcx,%rdx,2),%eax
  mov    %ax,0x4(%r14,%r9,1)
L4:
  add    0x1c(%rsp),%r8d
  add    $0x8,%rdi
  cmp    0x10(%rsp),%rdi
  jne    L16
L98:
  mov    0x70(%rsp),%rsi
  mov    %r14,%rdi
  xor    %eax,%eax
  add    $0x1,%rbp
  call   <median_of@plt>
  mov    0x50(%rsp),%rcx
  mov    0x40(%rsp),%rsi
  mov    (%rsp),%rdi
  mov    %eax,%r8d
  addq   $0x2,0x8(%rsp)
  mov    (%rcx,%rsi,8),%rax
  mov    0x68(%rsp),%rcx
  add    %rdi,%rax
  add    $0x2,%rdi
  mov    %r8w,(%rax,%rcx,1)
  mov    %rdi,(%rsp)
  cmp    0x58(%rsp),%rbp
  jne    L45
L113:
  addq   $0x1,0x40(%rsp)
  mov    0x40(%rsp),%rax
  addq   $0x8,0x10(%rsp)
  cmp    0x80(%rsp),%rax
  jne    L51
L76:
  mov    %r14,%rdi
  call   <free@plt>
  mov    0x24(%rsp),%esi
  mov    0x50(%rsp),%rdi
  xor    %eax,%eax
  mov    0xb8(%rsp),%rcx
  mov    0xb0(%rsp),%rdx
  sub    $0x1,%rcx
  sub    $0x1,%rdx
  call   <fix_edges@plt>
  mov    0xc8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L13
  add    $0xd8,%rsp
  mov    $0x1,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  cs nopw 0x0(%rax,%rax,1)
L193:
  mov    (%rsp),%rsi
  mov    0x30(%rsp),%r9
  xor    %eax,%eax
  add    %rcx,%rsi
  xchg   %ax,%ax
L21:
  movzwl (%rsi,%rax,2),%ecx
  mov    %cx,(%rdx,%rax,2)
  mov    %rax,%rcx
  add    $0x1,%rax
  cmp    %r9,%rcx
  jne    L21
  jmp    L4
L103:
  mov    0x20(%rsp),%r10d
  mov    0x3c(%rsp),%edx
  mov    %r8d,%esi
  xor    %eax,%eax
  jmp    L0
L127:
  mov    0x38(%rsp),%edx
  jmp    L86
L165:
  lea    D5(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  jmp    L140
L13:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: label: D5
datatype: string

tool: D5: %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);
}
```