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

```asm
<do_checksum>:
  endbr64
  push   %r12
  mov    %rdi,%rax
  push   %rbp
  mov    %edx,%ebp
  push   %rbx
  movzbl (%rdi),%ecx
  sar    $0x4,%cl
  cmp    $0x6,%cl
  je     L13
  xor    %r8d,%r8d
  cmp    $0x4,%cl
  jne    L175
  mov    (%rdi),%ebx
  mov    %rdi,%r12
  xor    %edi,%edi
  lea    0x0(,%rbx,4),%edx
L151:
  test   %edx,%edx
  js     L133
  add    $0xffffff80,%esi
  cmp    $0x4,%esi
  ja     1080 <do_checksum.cold>
  lea    D14(%rip),%r8
  movslq (%r8,%rsi,4),%rsi
  add    %r8,%rsi
  notrack jmp *%rsi
  nopl   0x0(%rax,%rax,1)
L70:
  xor    %r8d,%r8d
L175:
  pop    %rbx
  mov    %r8d,%eax
  pop    %rbp
  pop    %r12
  ret
  nopl   0x0(%rax,%rax,1)
L13:
  mov    0x4(%rdi),%edi
  mov    $0x8,%edx
  cmp    %esi,%edi
  je     L181
L193:
  cmp    $0x85,%edi
  je     L22
  cmp    $0x86,%edi
  jne    L70
  movslq %edx,%r8
  add    %rax,%r8
  mov    (%r8),%edi
  mov    0x4(%r8),%r8d
  lea    0x8(%rdx,%r8,8),%edx
L227:
  cmp    %esi,%edi
  jne    L193
  mov    %rax,%rdi
  xor    %r12d,%r12d
  jmp    L151
  cs nopw 0x0(%rax,%rax,1)
L22:
  movslq %edx,%rdi
  add    $0x4,%edx
  mov    (%rax,%rdi,1),%edi
  jmp    L227
  nopl   0x0(%rax,%rax,1)
  movslq %edx,%rdx
  xor    %r8d,%r8d
  cmp    $0x6,%cl
  jne    L175
L158:
  mov    $0x20,%esi
  lea    (%rax,%rdx,1),%rbx
  call   <in_cksum@plt>
  lea    0x83(%rbp),%edi
  mov    %eax,%r12d
  call   <ntohs@plt>
  movl   $0x0,(%rbx)
  mov    %ebp,%esi
  mov    %rbx,%rdi
  add    %eax,%r12d
  call   <in_cksum@plt>
  mov    $0x1,%r8d
  add    %r12d,%eax
  mov    %eax,%edx
  movzwl %ax,%eax
  sar    $0x10,%edx
  add    %eax,%edx
  mov    %edx,%eax
  sar    $0x10,%eax
  add    %edx,%eax
  not    %eax
  and    $0xffff,%eax
  mov    %eax,(%rbx)
  jmp    L175
  nopw   0x0(%rax,%rax,1)
  movl   $0x0,0x4(%r12)
  mov    %ebp,%esi
  mov    %r12,%rdi
  call   <in_cksum@plt>
  mov    $0x1,%r8d
  mov    %eax,%edx
  movzwl %ax,%eax
  sar    $0x10,%edx
  add    %eax,%edx
  mov    %edx,%eax
  sar    $0x10,%eax
  add    %edx,%eax
  not    %eax
  and    $0xffff,%eax
  mov    %eax,0x4(%r12)
  jmp    L175
  nopl   0x0(%rax,%rax,1)
  movslq %edx,%rdx
L125:
  lea    (%rax,%rdx,1),%rbx
  movl   $0x0,(%rbx)
  cmp    $0x6,%cl
  je     L42
  lea    0x8(%r12),%rdi
  mov    $0x8,%esi
  call   <in_cksum@plt>
  mov    %eax,%r12d
L231:
  lea    0x81(%rbp),%edi
  call   <ntohs@plt>
  mov    %ebp,%esi
  mov    %rbx,%rdi
  add    %eax,%r12d
  call   <in_cksum@plt>
  mov    $0x1,%r8d
  add    %r12d,%eax
  mov    %eax,%edx
  movzwl %ax,%eax
  sar    $0x10,%edx
  add    %eax,%edx
  mov    %edx,%eax
  sar    $0x10,%eax
  add    %edx,%eax
  not    %eax
  and    $0xffff,%eax
  mov    %eax,(%rbx)
  jmp    L175
  movslq %edx,%rdx
  lea    (%rax,%rdx,1),%rbx
  movl   $0x0,(%rbx)
  cmp    $0x6,%cl
  je     L167
  lea    0x8(%r12),%rdi
  mov    $0x8,%esi
  call   <in_cksum@plt>
  mov    %eax,%r12d
L162:
  lea    0x80(%rbp),%edi
  call   <ntohs@plt>
  mov    %ebp,%esi
  mov    %rbx,%rdi
  add    %eax,%r12d
  call   <in_cksum@plt>
  mov    $0x1,%r8d
  add    %r12d,%eax
  mov    %eax,%edx
  movzwl %ax,%eax
  sar    $0x10,%edx
  add    %eax,%edx
  mov    %edx,%eax
  sar    $0x10,%eax
  add    %edx,%eax
  not    %eax
  and    $0xffff,%eax
  mov    %eax,(%rbx)
  jmp    L175
  nopl   0x0(%rax,%rax,1)
  movslq %edx,%rdx
L4:
  lea    (%rax,%rdx,1),%rbx
  mov    %ebp,%esi
  movl   $0x0,(%rbx)
  mov    %rbx,%rdi
  call   <in_cksum@plt>
  mov    $0x1,%r8d
  mov    %eax,%edx
  movzwl %ax,%eax
  sar    $0x10,%edx
  add    %eax,%edx
  mov    %edx,%eax
  sar    $0x10,%eax
  add    %edx,%eax
  not    %eax
  and    $0xffff,%eax
  mov    %eax,(%rbx)
  jmp    L175
  nopl   0x0(%rax)
L42:
  mov    $0x20,%esi
  call   <in_cksum@plt>
  mov    %eax,%r12d
  jmp    L231
  movl   $0x0,0x8(%rax)
  lea    0x8(%rax),%rbx
  mov    %rax,%rdi
L167:
  mov    $0x20,%esi
  call   <in_cksum@plt>
  mov    %eax,%r12d
  jmp    L162
  nopw   0x0(%rax,%rax,1)
L181:
  add    $0xffffff80,%edi
  cmp    $0x4,%edi
  ja     L237
  lea    D1(%rip),%rsi
  movslq (%rsi,%rdi,4),%rdx
  add    %rsi,%rdx
  notrack jmp *%rdx
  mov    %rax,%rdi
  mov    $0x8,%edx
  jmp    L158
  mov    %rax,%rdi
  mov    $0x8,%edx
  xor    %r12d,%r12d
  jmp    L125
  mov    $0x8,%edx
  jmp    L4
L133:
  mov    $0xfffffffe,%r8d
  jmp    L175
```

assistant: ```c
int do_checksum(char *buf, int protocol, int len) {
  struct ip *iph_p = NULL;
  struct ip6_hdr *ip6h_p = NULL;
  int ip_hl;
  int sum = 0;
  int ip_version = buf[0] >> 4;
  if (ip_version == 6) {
    int next_header;
    ip6h_p = (struct ip6_hdr *)buf;
    next_header = ip6h_p->ip6_ctlun.ip6_un1.ip6_un1_nxt;
    ip_hl = sizeof(struct ip6_hdr);
    while (next_header != protocol) {
      switch (next_header) {
      case IPPROTO_FRAGMENT:
        next_header = ((struct ip6_frag *)(buf + ip_hl))->ip6f_nxt;
        ip_hl += sizeof(struct ip6_frag);
        break;
      case IPPROTO_DSTOPTS:
        next_header = ((struct ip6_dest *)(buf + ip_hl))->ip6d_nxt;
        ip_hl += (((struct ip6_dest *)(buf + ip_hl))->ip6d_len * 8) + 8;
        break;
      default:
        return 0;
      }
    }
  } else if (ip_version == 4) {
    iph_p = (struct ip *)buf;
    ip_hl = iph_p->ip_hl << 2;
  } else {
    return (0);
  }
  if (ip_hl < 0)
    return -2;
  switch (protocol) {
  case IPPROTO_UDP: {
    struct udphdr *udph_p = (struct udphdr *)(buf + ip_hl);
    udph_p->uh_sum = 0;
    if (ip_version == 6) {
      sum = in_cksum((unsigned short *)&ip6h_p->ip6_src, 32);
    } else {
      sum = in_cksum((void *)&iph_p->ip_src, 8);
    }
    sum += ntohs(IPPROTO_UDP + len);
    sum += in_cksum((unsigned short *)udph_p, len);
    udph_p->uh_sum = (sum = (sum >> 16) + (sum & 0xffff), (~(sum + (sum >> 16)) & 0xffff));
    break;
  }
  case IPPROTO_TCP: {
    struct tcphdr *tcph_p = (struct tcphdr *)(buf + ip_hl);
    tcph_p->th_sum = 0;
    if (ip_version == 6) {
      sum = in_cksum((unsigned short *)&ip6h_p->ip6_src, 32);
    } else {
      sum = in_cksum((void *)&iph_p->ip_src, 8);
    }
    sum += ntohs(IPPROTO_TCP + len);
    sum += in_cksum((unsigned short *)tcph_p, len);
    tcph_p->th_sum = (sum = (sum >> 16) + (sum & 0xffff), (~(sum + (sum >> 16)) & 0xffff));
    break;
  }
  case IPPROTO_ICMP: {
    struct icmp *icmph_p = (struct icmp *)(buf + ip_hl);
    icmph_p->icmp_cksum = 0;
    sum = in_cksum((unsigned short *)icmph_p, len);
    icmph_p->icmp_cksum = (sum = (sum >> 16) + (sum & 0xffff), (~(sum + (sum >> 16)) & 0xffff));
    break;
  }
  case IPPROTO_ICMPV6: {
    struct icmp6_hdr *icmp6h_p = (struct icmp6_hdr *)(buf + ip_hl);
    if (ip_version == 6) {
      sum = in_cksum((unsigned short *)&ip6h_p->ip6_src, 32);
    } else {
      return 0;
    }
    sum += ntohs(IPPROTO_ICMPV6 + len);
    icmp6h_p->icmp6_cksum = 0;
    sum += in_cksum((unsigned short *)icmp6h_p, len);
    icmp6h_p->icmp6_cksum = (sum = (sum >> 16) + (sum & 0xffff), (~(sum + (sum >> 16)) & 0xffff));
    break;
  }
  case IPPROTO_IP: {
    iph_p->ip_sum = 0;
    sum = in_cksum((unsigned short *)iph_p, len);
    iph_p->ip_sum = (sum = (sum >> 16) + (sum & 0xffff), (~(sum + (sum >> 16)) & 0xffff));
    break;
  }
  default: {
    return (-1);
  }
  }
  return (1);
}
```