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

```asm
<median>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %edx,-0x44(%rbp)
  mov    %ecx,-0x48(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movl   $0x0,-0x24(%rbp)
  jmp    L84
L178:
  movl   $0x0,-0x20(%rbp)
  jmp    L11
L27:
  cmpl   $0x0,-0x24(%rbp)
  jle    L29
  mov    -0x48(%rbp),%eax
  sub    $0x1,%eax
  cmp    %eax,-0x24(%rbp)
  jge    L29
  cmpl   $0x0,-0x20(%rbp)
  jle    L29
  mov    -0x44(%rbp),%eax
  sub    $0x1,%eax
  cmp    %eax,-0x20(%rbp)
  jge    L29
  movl   $0xffffffff,-0x1c(%rbp)
  jmp    L24
L124:
  movl   $0xffffffff,-0x18(%rbp)
  jmp    L53
L162:
  mov    -0x24(%rbp),%edx
  mov    -0x1c(%rbp),%eax
  add    %edx,%eax
  imul   -0x44(%rbp),%eax
  mov    -0x20(%rbp),%ecx
  mov    -0x18(%rbp),%edx
  add    %ecx,%edx
  add    %edx,%eax
  movslq %eax,%rdx
  mov    -0x40(%rbp),%rax
  add    %rax,%rdx
  mov    -0x1c(%rbp),%eax
  lea    0x1(%rax),%ecx
  mov    %ecx,%eax
  add    %eax,%eax
  add    %eax,%ecx
  mov    -0x18(%rbp),%eax
  add    $0x1,%eax
  add    %ecx,%eax
  movzbl (%rdx),%edx
  cltq
  mov    %dl,-0x11(%rbp,%rax,1)
  addl   $0x1,-0x18(%rbp)
L53:
  cmpl   $0x1,-0x18(%rbp)
  jle    L162
  addl   $0x1,-0x1c(%rbp)
L24:
  cmpl   $0x1,-0x1c(%rbp)
  jle    L124
  movl   $0x0,-0x1c(%rbp)
  jmp    L41
L98:
  movl   $0x0,-0x18(%rbp)
  jmp    L167
L179:
  mov    -0x18(%rbp),%eax
  cltq
  movzbl -0x11(%rbp,%rax,1),%edx
  mov    -0x18(%rbp),%eax
  add    $0x1,%eax
  cltq
  movzbl -0x11(%rbp,%rax,1),%eax
  cmp    %al,%dl
  jbe    L107
  mov    -0x18(%rbp),%eax
  cltq
  movzbl -0x11(%rbp,%rax,1),%eax
  mov    %al,-0x25(%rbp)
  mov    -0x18(%rbp),%eax
  add    $0x1,%eax
  cltq
  movzbl -0x11(%rbp,%rax,1),%edx
  mov    -0x18(%rbp),%eax
  cltq
  mov    %dl,-0x11(%rbp,%rax,1)
  mov    -0x18(%rbp),%eax
  add    $0x1,%eax
  cltq
  movzbl -0x25(%rbp),%edx
  mov    %dl,-0x11(%rbp,%rax,1)
L107:
  addl   $0x1,-0x18(%rbp)
L167:
  mov    $0x8,%eax
  sub    -0x1c(%rbp),%eax
  cmp    %eax,-0x18(%rbp)
  jl     L179
  addl   $0x1,-0x1c(%rbp)
L41:
  cmpl   $0x7,-0x1c(%rbp)
  jle    L98
  mov    -0x24(%rbp),%eax
  imul   -0x44(%rbp),%eax
  mov    %eax,%edx
  mov    -0x20(%rbp),%eax
  add    %edx,%eax
  movslq %eax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rax,%rdx
  movzbl -0xd(%rbp),%eax
  mov    %al,(%rdx)
  jmp    L175
L29:
  mov    -0x24(%rbp),%eax
  imul   -0x44(%rbp),%eax
  mov    %eax,%edx
  mov    -0x20(%rbp),%eax
  add    %edx,%eax
  movslq %eax,%rdx
  mov    -0x40(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x24(%rbp),%eax
  imul   -0x44(%rbp),%eax
  mov    %eax,%edx
  mov    -0x20(%rbp),%eax
  add    %edx,%eax
  movslq %eax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rax,%rdx
  movzbl (%rcx),%eax
  mov    %al,(%rdx)
L175:
  addl   $0x1,-0x20(%rbp)
L11:
  mov    -0x20(%rbp),%eax
  cmp    -0x44(%rbp),%eax
  jl     L27
  addl   $0x1,-0x24(%rbp)
L84:
  mov    -0x24(%rbp),%eax
  cmp    -0x48(%rbp),%eax
  jl     L178
  nop
  mov    -0x8(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L128
  call   <__stack_chk_fail@plt>
L128:
  leave
  ret
```

assistant: ```c
void median(unsigned char *out, unsigned char *in, int w, int h) {
  int i, j, m, n;
  unsigned char sort[9];
  unsigned char tmp;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (i > 0 && i < h - 1 && j > 0 && j < w - 1) {
        for (m = -1; m <= +1; m++) {
          for (n = -1; n <= +1; n++) {
            sort[(m + 1) * 3 + (n + 1)] = in[(i + m) * w + (j + n)];
          }
        }
        for (m = 0; m < 8; m++) {
          for (n = 0; n < 8 - m; n++) {
            if (sort[n] > sort[n + 1]) {
              tmp = sort[n];
              sort[n] = sort[n + 1];
              sort[n + 1] = tmp;
            }
          }
        }
        out[i * w + j] = sort[4];
      } else {
        out[i * w + j] = in[i * w + j];
      }
    }
  }
}
```