user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<do_checksum>:
  endbr64
  push   %r12
  push   %rbp
  push   %rbx
  mov    %esi,%eax
  mov    %edx,%ebp
  movzbl (%rdi),%edx
  sar    $0x4,%dl
  movsbl %dl,%ecx
  cmp    $0x6,%dl
  je     L124
  mov    $0x0,%edx
  cmp    $0x4,%ecx
  jne    L194
  mov    (%rdi),%ebx
  shl    $0x2,%ebx
  mov    %rdi,%r12
  mov    $0x0,%r8d
L224:
  test   %ebx,%ebx
  js     L209
  add    $0xffffff80,%eax
  cmp    $0x4,%eax
  ja     L113
  mov    %eax,%eax
  lea    D16(%rip),%rdx
  movslq (%rdx,%rax,4),%rax
  add    %rdx,%rax
  notrack jmp *%rax
L124:
  mov    0x4(%rdi),%edx
  cmp    %esi,%edx
  je     L43
  mov    $0x8,%ebx
  jmp    L40
L213:
  movslq %ebx,%rdx
  mov    (%rdi,%rdx,1),%edx
  add    $0x4,%ebx
L158:
  cmp    %eax,%edx
  je     L202
L40:
  cmp    $0x85,%edx
  je     L213
  cmp    $0x86,%edx
  je     L176
  mov    $0x0,%edx
L194:
  mov    %edx,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L176:
  movslq %ebx,%rsi
  add    %rdi,%rsi
  mov    (%rsi),%edx
  mov    0x4(%rsi),%esi
  lea    0x8(%rbx,%rsi,8),%ebx
  jmp    L158
L202:
  mov    %rdi,%r8
  mov    $0x0,%r12d
  jmp    L224
  movslq %ebx,%rbx
  add    %rdi,%rbx
  movl   $0x0,(%rbx)
  cmp    $0x6,%ecx
  je     L15
  lea    0x8(%r12),%rdi
  mov    $0x8,%esi
  call   <in_cksum@plt>
  mov    %eax,%r12d
L181:
  lea    0x80(%rbp),%edi
  call   <ntohs@plt>
  add    %eax,%r12d
  mov    %ebp,%esi
  mov    %rbx,%rdi
  call   <in_cksum@plt>
  add    %r12d,%eax
  mov    %eax,%edx
  sar    $0x10,%edx
  movzwl %ax,%eax
  add    %eax,%edx
  mov    %edx,%eax
  sar    $0x10,%eax
  add    %edx,%eax
  not    %eax
  and    $0xffff,%eax
  mov    %eax,(%rbx)
  mov    $0x1,%edx
  jmp    L194
  mov    %rdi,%r8
  mov    $0x8,%ebx
  mov    $0x0,%r12d
  movslq %ebx,%rbx
  add    %rdi,%rbx
  movl   $0x0,(%rbx)
  cmp    $0x6,%ecx
  je     L120
  lea    0x8(%r12),%rdi
  mov    $0x8,%esi
  call   <in_cksum@plt>
  mov    %eax,%r12d
L117:
  lea    0x81(%rbp),%edi
  call   <ntohs@plt>
  add    %eax,%r12d
  mov    %ebp,%esi
  mov    %rbx,%rdi
  call   <in_cksum@plt>
  add    %r12d,%eax
  mov    %eax,%edx
  sar    $0x10,%edx
  movzwl %ax,%eax
  add    %eax,%edx
  mov    %edx,%eax
  sar    $0x10,%eax
  add    %edx,%eax
  not    %eax
  and    $0xffff,%eax
  mov    %eax,(%rbx)
  mov    $0x1,%edx
  jmp    L194
L120:
  mov    $0x20,%esi
  mov    %r8,%rdi
  call   <in_cksum@plt>
  mov    %eax,%r12d
  jmp    L117
  mov    $0x8,%ebx
  movslq %ebx,%rbx
  add    %rdi,%rbx
  movl   $0x0,(%rbx)
  mov    %ebp,%esi
  mov    %rbx,%rdi
  call   <in_cksum@plt>
  mov    %eax,%edx
  sar    $0x10,%edx
  movzwl %ax,%eax
  add    %eax,%edx
  mov    %edx,%eax
  sar    $0x10,%eax
  add    %edx,%eax
  not    %eax
  and    $0xffff,%eax
  mov    %eax,(%rbx)
  mov    $0x1,%edx
  jmp    L194
  mov    %rdi,%r8
  mov    $0x8,%ebx
  mov    $0x0,%edx
  cmp    $0x6,%ecx
  jne    L194
  movslq %ebx,%rbx
  add    %rdi,%rbx
  mov    $0x20,%esi
  mov    %r8,%rdi
  call   <in_cksum@plt>
  mov    %eax,%r12d
  lea    0x83(%rbp),%edi
  call   <ntohs@plt>
  add    %eax,%r12d
  movl   $0x0,(%rbx)
  mov    %ebp,%esi
  mov    %rbx,%rdi
  call   <in_cksum@plt>
  add    %r12d,%eax
  mov    %eax,%edx
  sar    $0x10,%edx
  movzwl %ax,%eax
  add    %eax,%edx
  mov    %edx,%eax
  sar    $0x10,%eax
  add    %edx,%eax
  not    %eax
  and    $0xffff,%eax
  mov    %eax,(%rbx)
  mov    $0x1,%edx
  jmp    L194
  mov    $0x0,%r12d
  movl   $0x0,0x4(%r12)
  mov    %ebp,%esi
  mov    %r12,%rdi
  call   <in_cksum@plt>
  mov    %eax,%edx
  sar    $0x10,%edx
  movzwl %ax,%eax
  add    %eax,%edx
  mov    %edx,%eax
  sar    $0x10,%eax
  add    %edx,%eax
  not    %eax
  and    $0xffff,%eax
  mov    %eax,0x4(%r12)
  mov    $0x1,%edx
  jmp    L194
L209:
  mov    $0xfffffffe,%edx
  jmp    L194
L113:
  mov    $0xffffffff,%edx
  jmp    L194
L3:
  mov    $0xffffffff,%edx
  jmp    L194
  lea    0x8(%rdi),%rbx
  movl   $0x0,0x8(%rdi)
  mov    %rdi,%r8
L15:
  mov    $0x20,%esi
  mov    %r8,%rdi
  call   <in_cksum@plt>
  mov    %eax,%r12d
  jmp    L181
L43:
  add    $0xffffff80,%eax
  cmp    $0x4,%eax
  ja     L3
  mov    %eax,%eax
  lea    D12(%rip),%rdx
  movslq (%rdx,%rax,4),%rax
  add    %rdx,%rax
  notrack jmp *%rax
```

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);
}
```