user: What would the C source look like for the assembly code provided here:

```asm
<colour_to_mono>:
  endbr64
  mov    %ecx,%r10d
  add    $0x7,%ecx
  test   %r10d,%r10d
  cmovns %r10d,%ecx
  imul   %edx,%esi
  sar    $0x3,%ecx
  test   %esi,%esi
  jle    L58
  cmp    $0x7,%r10d
  push   %r14
  pxor   %xmm4,%xmm4
  pxor   %xmm3,%xmm3
  push   %r13
  mov    $0x1,%r13d
  push   %r12
  mov    $0x1,%r12d
  cmovg  %ecx,%r12d
  push   %rbp
  xor    %r9d,%r9d
  push   %rbx
  mov    %r8,%rbx
  mov    %esi,%r8d
  xor    %esi,%esi
  mov    %r12d,%eax
  mov    %r12d,%r11d
  shr    $0x4,%eax
  and    $0xfffffff0,%r11d
  test   %ecx,%ecx
  lea    -0x1(%rax),%ebp
  cmovg  %ecx,%r13d
  add    $0x1,%rbp
  shl    $0x4,%rbp
  nopl   0x0(%rax)
L186:
  mov    %r9d,%r14d
  xor    %eax,%eax
  cmp    $0x7,%r10d
  jle    L147
  cmp    $0x7f,%r10d
  jle    L102
  movslq %esi,%rax
  pxor   %xmm0,%xmm0
  add    %rdi,%rax
  lea    0x0(%rbp,%rax,1),%rdx
  nopl   0x0(%rax,%rax,1)
L21:
  movdqu (%rax),%xmm1
  add    $0x10,%rax
  movdqa %xmm1,%xmm2
  punpckhbw %xmm4,%xmm1
  punpcklbw %xmm4,%xmm2
  movdqa %xmm2,%xmm5
  punpckhwd %xmm3,%xmm2
  punpcklwd %xmm3,%xmm5
  paddd  %xmm5,%xmm0
  paddd  %xmm2,%xmm0
  movdqa %xmm1,%xmm2
  punpckhwd %xmm3,%xmm1
  punpcklwd %xmm3,%xmm2
  paddd  %xmm2,%xmm0
  paddd  %xmm1,%xmm0
  cmp    %rdx,%rax
  jne    L21
  movdqa %xmm0,%xmm1
  psrldq $0x8,%xmm1
  paddd  %xmm1,%xmm0
  movdqa %xmm0,%xmm1
  psrldq $0x4,%xmm1
  paddd  %xmm1,%xmm0
  movd   %xmm0,%eax
  cmp    %r11d,%r12d
  je     L36
  mov    %r11d,%edx
L159:
  lea    (%rsi,%rdx,1),%r14d
  movslq %r14d,%r14
  movzbl (%rdi,%r14,1),%r14d
  add    %r14d,%eax
  lea    0x1(%rdx),%r14d
  cmp    %r14d,%ecx
  jle    L36
  add    %esi,%r14d
  movslq %r14d,%r14
  movzbl (%rdi,%r14,1),%r14d
  add    %r14d,%eax
  lea    0x2(%rdx),%r14d
  cmp    %r14d,%ecx
  jle    L36
  add    %esi,%r14d
  movslq %r14d,%r14
  movzbl (%rdi,%r14,1),%r14d
  add    %r14d,%eax
  lea    0x3(%rdx),%r14d
  cmp    %r14d,%ecx
  jle    L36
  add    %esi,%r14d
  movslq %r14d,%r14
  movzbl (%rdi,%r14,1),%r14d
  add    %r14d,%eax
  lea    0x4(%rdx),%r14d
  cmp    %r14d,%ecx
  jle    L36
  add    %esi,%r14d
  movslq %r14d,%r14
  movzbl (%rdi,%r14,1),%r14d
  add    %r14d,%eax
  lea    0x5(%rdx),%r14d
  cmp    %r14d,%ecx
  jle    L36
  add    %esi,%r14d
  movslq %r14d,%r14
  movzbl (%rdi,%r14,1),%r14d
  add    %r14d,%eax
  lea    0x6(%rdx),%r14d
  cmp    %r14d,%ecx
  jle    L36
  add    %esi,%r14d
  movslq %r14d,%r14
  movzbl (%rdi,%r14,1),%r14d
  add    %r14d,%eax
  lea    0x7(%rdx),%r14d
  cmp    %r14d,%ecx
  jle    L36
  add    %esi,%r14d
  movslq %r14d,%r14
  movzbl (%rdi,%r14,1),%r14d
  add    %r14d,%eax
  lea    0x8(%rdx),%r14d
  cmp    %r14d,%ecx
  jle    L36
  add    %esi,%r14d
  movslq %r14d,%r14
  movzbl (%rdi,%r14,1),%r14d
  add    %r14d,%eax
  lea    0x9(%rdx),%r14d
  cmp    %r14d,%ecx
  jle    L36
  add    %esi,%r14d
  movslq %r14d,%r14
  movzbl (%rdi,%r14,1),%r14d
  add    %r14d,%eax
  lea    0xa(%rdx),%r14d
  cmp    %r14d,%ecx
  jle    L36
  add    %esi,%r14d
  movslq %r14d,%r14
  movzbl (%rdi,%r14,1),%r14d
  add    %r14d,%eax
  lea    0xb(%rdx),%r14d
  cmp    %r14d,%ecx
  jle    L36
  add    %esi,%r14d
  movslq %r14d,%r14
  movzbl (%rdi,%r14,1),%r14d
  add    %r14d,%eax
  lea    0xc(%rdx),%r14d
  cmp    %r14d,%ecx
  jle    L36
  add    %esi,%r14d
  movslq %r14d,%r14
  movzbl (%rdi,%r14,1),%r14d
  add    %r14d,%eax
  lea    0xd(%rdx),%r14d
  cmp    %r14d,%ecx
  jle    L36
  add    %esi,%r14d
  add    $0xe,%edx
  movslq %r14d,%r14
  movzbl (%rdi,%r14,1),%r14d
  add    %r14d,%eax
  cmp    %edx,%ecx
  jle    L36
  add    %esi,%edx
  movslq %edx,%rdx
  movzbl (%rdi,%rdx,1),%edx
  add    %edx,%eax
  nopl   0x0(%rax,%rax,1)
L36:
  cltd
  lea    0x0(%r13,%r9,1),%r14d
  idiv   %ecx
L147:
  movslq %r14d,%rdx
  add    $0x1,%r9d
  add    %ecx,%esi
  mov    %al,(%rbx,%rdx,1)
  cmp    %r8d,%r9d
  jne    L186
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
L102:
  xor    %eax,%eax
  xor    %edx,%edx
  jmp    L159
L58:
  ret
```

assistant: ```c
void colour_to_mono(unsigned char *img, int width, int height, int bitsperpixel, unsigned char *mono) {
  int i, j, v;
  int bytesperpixel = bitsperpixel / 8;
  for (i = 0; i < width * height; i++) {
    v = 0;
    for (j = 0; j < bytesperpixel; j++) {
      v += img[i * bytesperpixel + j];
    }
    mono[i + j] = v / bytesperpixel;
  }
}
```