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

```asm
<inet6_rth_reverse>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x18(%rbp),%rax
  mov    (%rax),%eax
  cmp    $0x80,%eax
  jne    L0
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x10(%rbp)
  mov    -0x40(%rbp),%rax
  mov    %rax,-0x8(%rbp)
  mov    -0x10(%rbp),%rcx
  mov    -0x8(%rbp),%rax
  mov    $0x10,%edx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memmove@plt>
  mov    -0x10(%rbp),%rax
  mov    (%rax),%eax
  shl    $0x3,%eax
  cltq
  shr    $0x2,%rax
  mov    %eax,-0x1c(%rbp)
  movl   $0x0,-0x20(%rbp)
  jmp    L52
L28:
  mov    -0x10(%rbp),%rax
  mov    0x8(%rax),%rdx
  mov    -0x20(%rbp),%eax
  cltq
  shl    $0x2,%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  mov    %eax,-0x24(%rbp)
  mov    -0x10(%rbp),%rax
  mov    0x8(%rax),%rdx
  mov    -0x1c(%rbp),%eax
  sub    $0x1,%eax
  sub    -0x20(%rbp),%eax
  cltq
  shl    $0x2,%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x8(%rbp),%rax
  mov    0x8(%rax),%rdx
  mov    -0x20(%rbp),%eax
  cltq
  shl    $0x2,%rax
  add    %rax,%rdx
  mov    (%rcx),%eax
  mov    %eax,(%rdx)
  mov    -0x8(%rbp),%rax
  mov    0x8(%rax),%rdx
  mov    -0x1c(%rbp),%eax
  sub    $0x1,%eax
  sub    -0x20(%rbp),%eax
  cltq
  shl    $0x2,%rax
  add    %rax,%rdx
  mov    -0x24(%rbp),%eax
  mov    %eax,(%rdx)
  addl   $0x1,-0x20(%rbp)
L52:
  mov    -0x1c(%rbp),%eax
  mov    %eax,%edx
  shr    $0x1f,%edx
  add    %edx,%eax
  sar    %eax
  cmp    %eax,-0x20(%rbp)
  jl     L28
  mov    -0x1c(%rbp),%eax
  and    $0x1,%eax
  test   %eax,%eax
  je     L26
  mov    -0x38(%rbp),%rax
  cmp    -0x40(%rbp),%rax
  je     L26
  mov    -0x10(%rbp),%rax
  mov    0x8(%rax),%rdx
  mov    -0x1c(%rbp),%eax
  mov    %eax,%ecx
  shr    $0x1f,%ecx
  add    %ecx,%eax
  sar    %eax
  cltq
  shl    $0x2,%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x8(%rbp),%rax
  mov    0x8(%rax),%rdx
  mov    -0x1c(%rbp),%eax
  mov    %eax,%esi
  shr    $0x1f,%esi
  add    %esi,%eax
  sar    %eax
  cltq
  shl    $0x2,%rax
  add    %rax,%rdx
  mov    (%rcx),%eax
  mov    %eax,(%rdx)
L26:
  mov    -0x8(%rbp),%rax
  mov    -0x1c(%rbp),%edx
  mov    %edx,0x4(%rax)
  mov    $0x0,%eax
  jmp    L59
L0:
  mov    $0xffffffff,%eax
L59:
  leave
  ret
```

assistant: ```c
int inet6_rth_reverse(const void *in, void *out) {
  struct ip6_rthdr *in_rthdr = (struct ip6_rthdr *)in;
  switch (in_rthdr->ip6r_type) {
    struct ip6_rthdr0 *in_rthdr0;
    struct ip6_rthdr0 *out_rthdr0;
  case IPV6_RTHDR_TYPE_0:
    in_rthdr0 = (struct ip6_rthdr0 *)in;
    out_rthdr0 = (struct ip6_rthdr0 *)out;
    memmove(out_rthdr0, in_rthdr0, sizeof(struct ip6_rthdr0));
    int total = in_rthdr0->ip6r0_len * 8 / sizeof(struct in6_addr);
    for (int i = 0; i < total / 2; ++i) {
      struct in6_addr temp = in_rthdr0->ip6r0_addr[i];
      out_rthdr0->ip6r0_addr[i] = in_rthdr0->ip6r0_addr[total - 1 - i];
      out_rthdr0->ip6r0_addr[total - 1 - i] = temp;
    }
    if (total % 2 != 0 && in != out)
      out_rthdr0->ip6r0_addr[total / 2] = in_rthdr0->ip6r0_addr[total / 2];
    out_rthdr0->ip6r0_segleft = total;
    return 0;
  }
  return -1;
}
```