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

```asm
<png_find_best_filter>:
  endbr64
  push   %r15
  push   %r14
  mov    %ecx,%r14d
  push   %r13
  mov    %esi,%r13d
  push   %r12
  push   %rbp
  mov    %rdi,%rbp
  push   %rbx
  mov    %edx,%ebx
  sar    $0x3,%ebx
  imul   %ebx,%r13d
  sub    $0x78,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x68(%rsp)
  xor    %eax,%eax
  call   <make_num_bits_table@plt>
  test   %r14d,%r14d
  jle    L3
  movl   $0x5,0x3c(%rsp)
  mov    %r13d,%r14d
L12:
  mov    $0x2000,%esi
  mov    $0x1,%edi
  call   <calloc@plt>
  mov    $0x2000,%esi
  mov    $0x1,%edi
  mov    %rax,0x8(%rsp)
  call   <calloc@plt>
  mov    $0x2000,%esi
  mov    $0x1,%edi
  mov    %rax,0x10(%rsp)
  call   <calloc@plt>
  mov    $0x2000,%esi
  mov    $0x1,%edi
  mov    %rax,0x18(%rsp)
  call   <calloc@plt>
  mov    $0x2000,%esi
  mov    $0x1,%edi
  mov    %rax,0x20(%rsp)
  call   <calloc@plt>
  xor    %edi,%edi
  mov    %rax,0x28(%rsp)
  lea    -0x1(%rbx),%eax
  movslq %eax,%rdx
  sub    %r14d,%eax
  movzbl 0x0(%rbp,%rdx,1),%r15d
  cltq
  movzbl 0x0(%rbp,%rax,1),%esi
  xor    %eax,%eax
  mov    %r15d,%edx
  mov    %r15d,%ecx
  mov    %r15b,%al
  sub    %esi,%edx
  mov    %cl,%ah
  movzbl %dl,%edx
  movzwl %ax,%eax
  mov    %edx,%ecx
  shl    $0x18,%edx
  shl    $0x10,%ecx
  or     %ecx,%eax
  or     %edx,%eax
  xor    %edx,%edx
  mov    %eax,0x58(%rsp)
  call   <PaethPredictor@plt>
  pxor   %xmm0,%xmm0
  movl   $0x0,0x50(%rsp)
  sub    %eax,%r15d
  movaps %xmm0,0x40(%rsp)
  mov    %r15b,0x5c(%rsp)
  cmp    %r13d,%ebx
  jge    L39
  sub    %ebx,%r13d
  mov    %r14d,%eax
  movslq %ebx,%rbx
  movl   $0x0,0x38(%rsp)
  lea    -0x1(%r13),%edx
  neg    %eax
  lea    0x58(%rsp),%r13
  mov    $0x1,%r12d
  cltq
  lea    0x1(%rbp,%rdx,1),%rdx
  lea    0x0(%rbp,%rax,1),%r15
  add    %rdx,%rax
  movslq %r14d,%rbp
  mov    %rax,0x30(%rsp)
  lea    0x60(%rsp),%r14
  nopl   (%rax)
L173:
  lea    (%r15,%rbp,1),%rax
  movzbl (%r15,%rbp,1),%edi
  mov    %rbp,%rsi
  movzbl (%rax,%rbx,1),%ecx
  lea    0x0(%rbp,%rbx,1),%rax
  neg    %rsi
  add    %r15,%rax
  mov    %ecx,%r9d
  movzbl (%rax,%rsi,1),%esi
  xor    %eax,%eax
  mov    %ecx,%r8d
  sub    %edi,%r9d
  mov    %cl,%al
  mov    %cl,0x7(%rsp)
  mov    %r9d,%edx
  lea    (%rdi,%rsi,1),%r9d
  mov    %dl,%ah
  mov    %ecx,%edx
  sar    %r9d
  sub    %esi,%edx
  sub    %r9d,%r8d
  movzwl %ax,%eax
  movzbl %dl,%edx
  shl    $0x18,%r8d
  shl    $0x10,%edx
  or     %edx,%eax
  movzbl (%r15),%edx
  or     %r8d,%eax
  mov    %eax,0x60(%rsp)
  call   <PaethPredictor@plt>
  movzbl 0x58(%rsp),%ecx
  mov    %r12d,%edx
  mov    %eax,%r8d
  movzbl 0x7(%rsp),%eax
  sub    %r8d,%eax
  mov    %al,0x64(%rsp)
  movzbl 0x60(%rsp),%eax
  shl    $0x8,%eax
  or     %ecx,%eax
  and    $0x7,%ecx
  sar    $0x3,%eax
  shl    %cl,%edx
  xor    %ecx,%ecx
  cltq
  add    0x8(%rsp),%rax
  cmpb   $0x0,(%rax)
  sete   %cl
  test   %edx,%ecx
  je     L20
  addl   $0x1,0x38(%rsp)
  mov    %dl,(%rax)
  mov    0x38(%rsp),%eax
  mov    %eax,0x40(%rsp)
L20:
  movzbl 0x61(%rsp),%eax
  movzbl 0x59(%rsp),%ecx
  mov    %r12d,%edx
  shl    $0x8,%eax
  or     %ecx,%eax
  and    $0x7,%ecx
  sar    $0x3,%eax
  shl    %cl,%edx
  xor    %ecx,%ecx
  cltq
  add    0x10(%rsp),%rax
  cmpb   $0x0,(%rax)
  sete   %cl
  test   %edx,%ecx
  je     L33
  addl   $0x1,0x44(%rsp)
  mov    %dl,(%rax)
L33:
  movzbl 0x62(%rsp),%eax
  movzbl 0x5a(%rsp),%ecx
  mov    %r12d,%edx
  shl    $0x8,%eax
  or     %ecx,%eax
  and    $0x7,%ecx
  sar    $0x3,%eax
  shl    %cl,%edx
  xor    %ecx,%ecx
  cltq
  add    0x18(%rsp),%rax
  cmpb   $0x0,(%rax)
  sete   %cl
  test   %edx,%ecx
  je     L51
  addl   $0x1,0x48(%rsp)
  mov    %dl,(%rax)
L51:
  movzbl 0x63(%rsp),%eax
  movzbl 0x5b(%rsp),%ecx
  mov    %r12d,%edx
  shl    $0x8,%eax
  or     %ecx,%eax
  and    $0x7,%ecx
  sar    $0x3,%eax
  shl    %cl,%edx
  xor    %ecx,%ecx
  cltq
  add    0x20(%rsp),%rax
  cmpb   $0x0,(%rax)
  sete   %cl
  test   %edx,%ecx
  je     L79
  addl   $0x1,0x4c(%rsp)
  mov    %dl,(%rax)
L79:
  movzbl 0x64(%rsp),%eax
  movzbl 0x5c(%rsp),%ecx
  mov    %r12d,%edx
  shl    $0x8,%eax
  or     %ecx,%eax
  and    $0x7,%ecx
  sar    $0x3,%eax
  shl    %cl,%edx
  xor    %ecx,%ecx
  cltq
  add    0x28(%rsp),%rax
  cmpb   $0x0,(%rax)
  sete   %cl
  test   %edx,%ecx
  je     L19
  addl   $0x1,0x50(%rsp)
  mov    %dl,(%rax)
L19:
  mov    $0x5,%edx
  mov    %r14,%rsi
  mov    %r13,%rdi
  add    $0x1,%r15
  call   <memcpy@plt>
  cmp    0x30(%rsp),%r15
  jne    L173
L39:
  mov    D8(%rip),%rdx
  mov    0x40(%rsp),%eax
  mov    $0x1,%r13d
  mov    (%rdx),%edx
  cmp    %edx,%eax
  cmovg  %edx,%eax
  mov    0x44(%rsp),%edx
  cmp    %edx,%eax
  jg     L95
  mov    %eax,%edx
  xor    %r13d,%r13d
L95:
  cmpl   $0x2,0x3c(%rsp)
  je     L60
  mov    0x48(%rsp),%eax
  cmp    %edx,%eax
  jl     L42
  mov    %edx,%eax
L127:
  cmpl   $0x3,0x3c(%rsp)
  je     L60
  mov    0x4c(%rsp),%edx
  cmp    %eax,%edx
  jl     L9
  mov    %eax,%edx
L102:
  cmpl   $0x5,0x3c(%rsp)
  jne    L60
  cmp    0x50(%rsp),%edx
  mov    $0x4,%eax
  cmovg  %eax,%r13d
L60:
  mov    0x8(%rsp),%rdi
  call   <free@plt>
  mov    0x10(%rsp),%rdi
  call   <free@plt>
  mov    0x18(%rsp),%rdi
  call   <free@plt>
  mov    0x20(%rsp),%rdi
  call   <free@plt>
  mov    0x28(%rsp),%rdi
  call   <free@plt>
  mov    0x68(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L7
  add    $0x78,%rsp
  mov    %r13d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L3:
  movl   $0x2,0x3c(%rsp)
  cmovne %r13d,%r14d
  jmp    L12
L42:
  mov    $0x2,%r13d
  jmp    L127
L9:
  mov    $0x3,%r13d
  jmp    L102
L7:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int png_find_best_filter(unsigned char *src, unsigned width, int bpp, int y) {
  make_num_bits_table();
  int num_filters = y > 0 ? 5 : 2;
  int bytes_per_pixel = bpp >> 3;
  int w = width * bytes_per_pixel;
  int back_x = bytes_per_pixel;
  int back_y = y ? width * bytes_per_pixel : 0;
  unsigned char *pairs[5];
  pairs[0] = calloc(1, 8192);
  pairs[1] = calloc(1, 8192);
  pairs[2] = calloc(1, 8192);
  pairs[3] = calloc(1, 8192);
  pairs[4] = calloc(1, 8192);
  unsigned char old[5];
  int l = bytes_per_pixel - 1;
  old[0] = src[l];
  old[1] = src[l];
  old[2] = src[l] - src[l - back_y];
  old[3] = src[l] - src[l - back_y];
  old[4] = src[l] - PaethPredictor(0, src[l - back_y], 0);
  int different_pairs[5] = {0, 0, 0, 0, 0};
  int x;
  for (x = bytes_per_pixel; x < w; x++) {
    unsigned char dest[5];
    dest[0] = src[x];
    dest[1] = src[x] - src[x - back_x];
    dest[2] = src[x] - src[x - back_y];
    dest[3] = src[x] - (src[x - back_x] + src[x - back_y]) / 2;
    dest[4] = src[x] - PaethPredictor(src[x - back_x], src[x - back_y], src[x - back_x - back_y]);
    int i;
    for (i = 0; i < 5; i++) {
      int v = dest[i] << 8 | old[i];
      int p = v >> 3;
      int b = 1 << (v & 7);
      if (!pairs[i][p] & b) {
        pairs[i][p] |= b;
        different_pairs[i]++;
      }
    }
    memcpy(old, dest, sizeof(old));
  }
  int f;
  int best_nr = 0;
  int best_energy = INT_MAX;
  for (f = 0; f < num_filters; f++) {
    int energy = different_pairs[f];
    if (energy < best_energy) {
      best_nr = f;
      best_energy = energy;
    }
  }
  free(pairs[0]);
  free(pairs[1]);
  free(pairs[2]);
  free(pairs[3]);
  free(pairs[4]);
  return best_nr;
}
```