user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<tcp4_checksum>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r13
  push   %r12
  mov    %rcx,%r12
  push   %rbx
  mov    %r8d,%ebx
  sub    $0x38,%rsp
  mov    %rdx,-0x48(%rbp)
  mov    %rdi,-0x38(%rbp)
  mov    %rsp,%rcx
  mov    %rsi,-0x50(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x28(%rbp)
  mov    D7(%rip),%rax
  movslq (%rax),%rax
  add    $0xf,%rax
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rcx
  and    $0xfffffffffffffff0,%rdx
  cmp    %rcx,%rsp
  je     L39
L28:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L28
L39:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  jne    L4
L6:
  lea    -0x36(%rbp),%rsi
  mov    $0x1,%edx
  lea    -0x38(%rbp),%r13
  mov    %rsp,%rdi
  call   <memcpy@plt>
  lea    -0x37(%rbp),%rsi
  lea    0x1(%rsp),%rdi
  mov    $0x1,%edx
  call   <memcpy@plt>
  mov    $0x1,%edx
  mov    %r13,%rsi
  lea    0x3(%rsp),%rdi
  movb   $0x0,0x2(%rsp)
  call   <memcpy@plt>
  lea    0x10(%rbx),%edi
  call   <htons@plt>
  lea    -0x2a(%rbp),%rsi
  lea    0x4(%rsp),%rdi
  mov    $0x1,%edx
  mov    %al,-0x2a(%rbp)
  call   <memcpy@plt>
  lea    -0x50(%rbp),%rsi
  lea    0x5(%rsp),%rdi
  mov    $0x1,%edx
  call   <memcpy@plt>
  lea    -0x4f(%rbp),%rsi
  lea    0x6(%rsp),%rdi
  mov    $0x1,%edx
  call   <memcpy@plt>
  lea    -0x4e(%rbp),%rsi
  lea    0x7(%rsp),%rdi
  mov    $0x1,%edx
  call   <memcpy@plt>
  lea    -0x4d(%rbp),%rsi
  lea    0x8(%rsp),%rdi
  mov    $0x1,%edx
  call   <memcpy@plt>
  movzbl -0x4c(%rbp),%eax
  lea    -0x29(%rbp),%rsi
  lea    0x9(%rsp),%rdi
  mov    $0x1,%edx
  shl    $0x4,%eax
  add    -0x48(%rbp),%al
  mov    %al,-0x29(%rbp)
  call   <memcpy@plt>
  lea    -0x44(%rbp),%rsi
  lea    0xa(%rsp),%rdi
  mov    $0x1,%edx
  call   <memcpy@plt>
  lea    -0x43(%rbp),%rsi
  lea    0xb(%rsp),%rdi
  mov    $0x1,%edx
  call   <memcpy@plt>
  xor    %eax,%eax
  lea    -0x42(%rbp),%rsi
  lea    0xe(%rsp),%rdi
  mov    $0x1,%edx
  mov    %ax,0xc(%rsp)
  call   <memcpy@plt>
  lea    0xf(%rsp),%rdi
  mov    %ebx,%edx
  mov    %r12,%rsi
  call   <memcpy@plt>
  lea    0xf(%rbx),%esi
  mov    %rsp,%rdi
  call   <checksum@plt>
  mov    -0x28(%rbp),%rdx
  sub    %fs:0x28,%rdx
  jne    L5
  lea    -0x18(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %rbp
  ret
  nopw   0x0(%rax,%rax,1)
L4:
  orq    $0x0,-0x8(%rsp,%rdx,1)
  jmp    L6
L5:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
uint16_t tcp4_checksum(struct ip iphdr, struct tcphdr tcphdr, uint8_t *tcp_options, int tcp_opt_len) {
  uint16_t svalue;
  char buf[IP_MAXPACKET], cvalue;
  char *ptr;
  int chksumlen = 0;
  ptr = &buf[0];
  memcpy(ptr, &iphdr.ip_src.s_addr, sizeof(iphdr.ip_src.s_addr));
  ptr += sizeof(iphdr.ip_src.s_addr);
  chksumlen += sizeof(iphdr.ip_src.s_addr);
  memcpy(ptr, &iphdr.ip_dst.s_addr, sizeof(iphdr.ip_dst.s_addr));
  ptr += sizeof(iphdr.ip_dst.s_addr);
  chksumlen += sizeof(iphdr.ip_dst.s_addr);
  *ptr = 0;
  ptr++;
  chksumlen += 1;
  memcpy(ptr, &iphdr.ip_p, sizeof(iphdr.ip_p));
  ptr += sizeof(iphdr.ip_p);
  chksumlen += sizeof(iphdr.ip_p);
  svalue = htons(sizeof(tcphdr) + tcp_opt_len);
  memcpy(ptr, &svalue, sizeof(svalue));
  ptr += sizeof(svalue);
  chksumlen += sizeof(svalue);
  memcpy(ptr, &tcphdr.th_sport, sizeof(tcphdr.th_sport));
  ptr += sizeof(tcphdr.th_sport);
  chksumlen += sizeof(tcphdr.th_sport);
  memcpy(ptr, &tcphdr.th_dport, sizeof(tcphdr.th_dport));
  ptr += sizeof(tcphdr.th_dport);
  chksumlen += sizeof(tcphdr.th_dport);
  memcpy(ptr, &tcphdr.th_seq, sizeof(tcphdr.th_seq));
  ptr += sizeof(tcphdr.th_seq);
  chksumlen += sizeof(tcphdr.th_seq);
  memcpy(ptr, &tcphdr.th_ack, sizeof(tcphdr.th_ack));
  ptr += sizeof(tcphdr.th_ack);
  chksumlen += sizeof(tcphdr.th_ack);
  cvalue = (tcphdr.th_off << 4) + tcphdr.th_x2;
  memcpy(ptr, &cvalue, sizeof(cvalue));
  ptr += sizeof(cvalue);
  chksumlen += sizeof(cvalue);
  memcpy(ptr, &tcphdr.th_flags, sizeof(tcphdr.th_flags));
  ptr += sizeof(tcphdr.th_flags);
  chksumlen += sizeof(tcphdr.th_flags);
  memcpy(ptr, &tcphdr.th_win, sizeof(tcphdr.th_win));
  ptr += sizeof(tcphdr.th_win);
  chksumlen += sizeof(tcphdr.th_win);
  *ptr = 0;
  ptr++;
  *ptr = 0;
  ptr++;
  chksumlen += 2;
  memcpy(ptr, &tcphdr.th_urp, sizeof(tcphdr.th_urp));
  ptr += sizeof(tcphdr.th_urp);
  chksumlen += sizeof(tcphdr.th_urp);
  memcpy(ptr, tcp_options, tcp_opt_len);
  ptr += tcp_opt_len;
  chksumlen += tcp_opt_len;
  return checksum((uint16_t *)buf, chksumlen);
}
```