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

```asm
<c_monochrome>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %esi,0x8(%rsp)
  test   %esi,%esi
  je     L115
  movzbl %cl,%eax
  mov    %rdi,%r15
  mov    %edx,%ebx
  mov    %ecx,%r14d
  mov    %eax,0xc(%rsp)
  xor    %r12d,%r12d
L118:
  mov    %r12d,%r13d
  lea    (%r15,%r13,1),%rbp
  cmp    $0x2,%r14b
  jbe    L2
  movzbl 0x0(%rbp),%eax
  movzbl 0x1(%r15,%r13,1),%edx
  movzbl 0x2(%r15,%r13,1),%r8d
  cmp    $0x5,%bl
  ja     L174
  lea    D8(%rip),%rdi
  movzbl %bl,%r9d
  movslq (%rdi,%r9,4),%r9
  add    %rdi,%r9
  notrack jmp *%r9
  nopl   0x0(%rax)
L2:
  movzwl 0x0(%rbp),%eax
  mov    %eax,%edx
  mov    %eax,%r9d
  and    $0x1f,%eax
  shr    $0x6,%dx
  shr    $0xb,%r9w
  and    $0x1f,%edx
  movzbl %r9b,%r8d
  test   %bl,%bl
  jne    L80
  movzbl %al,%r8d
  mov    %r9d,%eax
L80:
  pxor   %xmm0,%xmm0
  movzbl %dl,%edx
  pxor   %xmm1,%xmm1
  movzbl %al,%eax
  cvtsi2sd %r8d,%xmm0
  mulsd  D39(%rip),%xmm0
  cvtsi2sd %edx,%xmm1
  mulsd  D2(%rip),%xmm1
  addsd  %xmm1,%xmm0
  pxor   %xmm1,%xmm1
  cvtsi2sd %eax,%xmm1
  mulsd  D4(%rip),%xmm1
  addsd  %xmm1,%xmm0
  call   <round@plt>
  cmp    $0x3,%r14b
  je     L71
  cmp    $0x4,%r14b
  je     L11
  cmp    $0x2,%r14b
  je     L50
L34:
  add    0xc(%rsp),%r12d
  cmp    %r12d,0x8(%rsp)
  ja     L118
L115:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  mov    %r8d,%r9d
  movzbl %al,%r8d
  mov    %edx,%eax
  mov    %r9d,%edx
  jmp    L80
  nopl   0x0(%rax)
  mov    %r8d,%r9d
  movzbl %dl,%r8d
  mov    %eax,%edx
  mov    %r9d,%eax
  jmp    L80
  nopl   0x0(%rax)
  mov    %edx,%r9d
  mov    %eax,%edx
  mov    %r9d,%eax
  jmp    L80
  nopl   (%rax)
  mov    %r8d,%r9d
  movzbl %dl,%r8d
  mov    %r9d,%edx
  jmp    L80
  nop
L71:
  mov    %al,0x0(%rbp)
  mov    %al,0x1(%r15,%r13,1)
  mov    %al,0x2(%r15,%r13,1)
  jmp    L34
  nop
L50:
  movzbl %al,%esi
  movzbl %al,%eax
  mov    %esi,%edx
  shl    $0x6,%esi
  shl    $0xb,%edx
  or     %esi,%edx
  or     %edx,%eax
  mov    %ax,0x0(%rbp)
  jmp    L34
  nopl   0x0(%rax,%rax,1)
L11:
  test   %al,%al
  jne    L3
  movl   $0x0,0x0(%rbp)
  jmp    L34
L3:
  movzbl %al,%eax
  mov    %eax,%edx
  mov    %eax,%esi
  shl    $0x8,%edx
  shl    $0x10,%esi
  or     %esi,%edx
  or     %edx,%eax
  or     $0xff000000,%eax
  mov    %eax,0x0(%rbp)
  jmp    L34
L174:
  mov    %r8d,%r9d
  movzbl %al,%r8d
  mov    %r9d,%eax
  jmp    L80
```

tool_calls: name: retrieve_data
arguments: data_tag: D39
datatype: f64
name: retrieve_data
arguments: data_tag: D2
datatype: f64
name: retrieve_data
arguments: data_tag: D4
datatype: f64

tool: D39: 0.2126

tool: D2: 0.7152

tool: D4: 0.0722

assistant: ```c
void c_monochrome(char *pixels, unsigned int size, unsigned char color_order, unsigned char bytes_per_pixel) {
  unsigned int idx;
  unsigned char r;
  unsigned char g;
  unsigned char b;
  unsigned char m;
  unsigned short rgb565;
  for (idx = 0; idx < size; idx += bytes_per_pixel) {
    if (bytes_per_pixel >= 3) {
      switch (color_order) {
      case 1:
        r = *(pixels + idx);
        b = *(pixels + idx + 1);
        g = *(pixels + idx + 2);
        break;
      case 2:
        b = *(pixels + idx);
        g = *(pixels + idx + 1);
        r = *(pixels + idx + 2);
        break;
      case 3:
        b = *(pixels + idx);
        r = *(pixels + idx + 1);
        g = *(pixels + idx + 2);
        break;
      case 4:
        g = *(pixels + idx);
        b = *(pixels + idx + 1);
        r = *(pixels + idx + 2);
        break;
      case 5:
        g = *(pixels + idx);
        r = *(pixels + idx + 1);
        b = *(pixels + idx + 2);
        break;
      default:
        r = *(pixels + idx);
        g = *(pixels + idx + 1);
        b = *(pixels + idx + 2);
      }
    } else {
      rgb565 = *((unsigned short *)(pixels + idx));
      g = (rgb565 >> 6) & 31;
      if (color_order == 0) {
        r = rgb565 & 31;
        b = (rgb565 >> 11) & 31;
      } else {
        b = rgb565 & 31;
        r = (rgb565 >> 11) & 31;
      }
    }
    m = (unsigned char)round(0.2126 * r + 0.7152 * g + 0.0722 * b);
    switch (bytes_per_pixel) {
    case 4:
      if (m == 0) {
        *((unsigned int *)(pixels + idx)) = m | (m << 8) | (m << 16);
      } else {
        *((unsigned int *)(pixels + idx)) = m | (m << 8) | (m << 16) | 0xFF000000;
      }
      break;
    case 3:
      *(pixels + idx) = m;
      *(pixels + idx + 1) = m;
      *(pixels + idx + 2) = m;
      break;
    case 2:
      rgb565 = 0;
      rgb565 = (m << 11) | (m << 6) | m;
      *((unsigned short *)(pixels + idx)) = rgb565;
      break;
    }
  }
}
```