user: 请将这段汇编代码片段转换成等效的C代码:

```asm
<median_img>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x168,%rsp
  mov    %rdi,-0x188(%rbp)
  mov    %esi,%edx
  mov    %ecx,%edi
  mov    %r9d,%eax
  mov    %fs:0x28,%rcx
  mov    %rcx,-0x38(%rbp)
  xor    %ecx,%ecx
  mov    %eax,%ecx
  imul   %eax,%ecx
  mov    %ecx,%esi
  shr    $0x1f,%esi
  add    %esi,%ecx
  sar    %ecx
  mov    %ecx,%r14d
  mov    $0x0,%r11d
  mov    $0x0,%r12d
  jmp    L14
L27:
  mov    $0x0,%ebx
  jmp    L103
L124:
  lea    (%r12,%r8,1),%ecx
  mov    %ecx,%esi
  imul   %edx,%esi
  lea    (%rdi,%rbx,1),%ecx
  add    %esi,%ecx
  movslq %ecx,%rsi
  mov    -0x188(%rbp),%rcx
  add    %rcx,%rsi
  mov    %r11d,%ecx
  lea    0x1(%rcx),%r10d
  mov    %r10d,%r11d
  movzbl (%rsi),%esi
  movslq %ecx,%rcx
  mov    %sil,-0x180(%rbp,%rcx,1)
  add    $0x1,%ebx
L103:
  cmp    %eax,%ebx
  jl     L124
  add    $0x1,%r12d
L14:
  cmp    %eax,%r12d
  jl     L27
  nop
L15:
  movzbl -0x180(%rbp),%eax
  movzbl %al,%r15d
  mov    $0x0,%r12d
  mov    %r12d,%esi
  mov    %r12d,%r13d
  mov    $0x0,%ebx
  jmp    L181
L166:
  movslq %ebx,%rax
  movzbl -0x180(%rbp,%rax,1),%eax
  movzbl %al,%eax
  mov    %eax,-0x18c(%rbp)
  add    $0x1,%ebx
L181:
  mov    %r11d,%eax
  cmp    %eax,%ebx
  jl     L166
  cmp    %r15d,-0x18c(%rbp)
  jne    L52
  mov    %esi,%eax
  add    $0x1,%eax
  mov    %eax,%esi
  jmp    L37
L52:
  mov    -0x18c(%rbp),%edi
  cmp    %r15d,%edi
  jle    L148
  mov    %r13d,%eax
  lea    0x1(%rax),%r13d
  mov    %edi,%edx
  cltq
  mov    %dl,-0x110(%rbp,%rax,1)
  jmp    L37
L148:
  mov    %r12d,%eax
  lea    0x1(%rax),%r12d
  movzbl -0x18c(%rbp),%edx
  cltq
  mov    %dl,-0xa0(%rbp,%rax,1)
L37:
  cmp    %r14d,%r12d
  jg     L198
  mov    %esi,%eax
  add    %r12d,%eax
  cmp    %eax,%r14d
  jg     L137
  mov    %r15d,%eax
  mov    -0x38(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L161
  jmp    L114
L137:
  mov    $0x0,%ebx
  jmp    L112
L77:
  movslq %ebx,%rax
  movzbl -0x110(%rbp,%rax,1),%edx
  movslq %ebx,%rax
  mov    %dl,-0x180(%rbp,%rax,1)
  add    $0x1,%ebx
L112:
  cmp    %r13d,%ebx
  jl     L77
  mov    %esi,%eax
  add    %r12d,%eax
  sub    %eax,%r14d
  mov    %r13d,%r11d
  jmp    L15
L198:
  mov    $0x0,%ebx
  jmp    L5
L30:
  movslq %ebx,%rax
  movzbl -0xa0(%rbp,%rax,1),%edx
  movslq %ebx,%rax
  mov    %dl,-0x180(%rbp,%rax,1)
  add    $0x1,%ebx
L5:
  cmp    %r12d,%ebx
  jl     L30
  mov    %r12d,%r11d
  jmp    L15
L114:
  call   <__stack_chk_fail@plt>
L161:
  add    $0x168,%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
```

assistant: ```c
median_img(img, width, height, x, y, size) unsigned char *img;
register int width, height, x, y, size;
{
  register int med, p, q, r;
  register int i, j, k, v, cindex;
  unsigned char seq[100], up[100], down[100];
  cindex = size * size / 2;
  k = 0;
  for (j = 0; j < size; j++)
    for (i = 0; i < size; i++)
      seq[k++] = img[(j + y) * width + (x + i)];
find_med:
  med = seq[0];
  p = q = r = 0;
  for (i = 0; i < k; i++)
    v = seq[i];
  if (v == med)
    r++;
  else if (v > med)
    up[p++] = v;
  else
    down[q++] = v;
  if (q <= cindex)
    if (q + r >= cindex)
      return (med);
    else {
      for (i = 0; i < p; i++)
        seq[i] = up[i];
      cindex = cindex - (q + r);
      k = p;
      goto find_med;
    }
  else {
    for (i = 0; i < q; i++)
      seq[i] = down[i];
    k = q;
    goto find_med;
  }
}
```