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

```asm
<_shiftR>:
  endbr64
  push   %rbp
  mov    %rdi,%rax
  xor    %r8d,%r8d
  mov    %rsi,%rdi
  push   %rbx
  sub    $0x18,%rsp
  mov    %fs:0x28,%rcx
  mov    %rcx,0x8(%rsp)
  xor    %ecx,%ecx
  mov    %edx,%ecx
  and    $0x7,%edx
  shr    $0x3,%cl
  movzbl %cl,%esi
  test   %cl,%cl
  je     L301
  movzbl %cl,%r8d
  xor    %ebp,%ebp
  cmp    $0x8,%r8d
  jb     L111
  lea    0x8(%rax),%r11
  mov    %rax,%r9
  movq   $0x0,(%rax)
  movq   $0x0,-0x8(%rax,%r8,1)
  and    $0xfffffffffffffff8,%r11
  sub    %r11,%r9
  add    %r8d,%r9d
  and    $0xfffffff8,%r9d
  cmp    $0x8,%r9d
  jb     L169
  mov    %r9d,%r10d
  xor    %r9d,%r9d
  and    $0xfffffff8,%r10d
L81:
  mov    %r9d,%ebx
  add    $0x8,%r9d
  mov    %rbp,(%r11,%rbx,1)
  cmp    %r10d,%r9d
  jb     L81
L169:
  cmp    $0x7,%cl
  ja     L345
L301:
  lea    (%rax,%r8,1),%r9
  lea    0x1(%rdi),%r10
  mov    %r9,%rcx
  sub    %r10,%rcx
  cmp    $0x6,%rcx
  jbe    L289
  mov    $0x7,%ecx
  sub    %esi,%ecx
  cmp    $0x6,%ecx
  jbe    L289
  mov    (%rdi),%rcx
  mov    $0x8,%r10d
  sub    %esi,%r10d
  mov    %rcx,(%r9)
  mov    %r10d,%r9d
  and    $0xfffffff8,%r9d
  lea    (%r9,%rsi,1),%ecx
  cmp    %r10d,%r9d
  je     L182
  movslq %r9d,%r9
  movzbl (%rdi,%r9,1),%r10d
  movslq %ecx,%r9
  mov    %r10b,(%rax,%r9,1)
  lea    0x1(%rcx),%r9d
  cmp    $0x7,%ecx
  je     L182
  mov    %r9d,%r10d
  movslq %r9d,%r9
  sub    %esi,%r10d
  movslq %r10d,%r10
  movzbl (%rdi,%r10,1),%r10d
  mov    %r10b,(%rax,%r9,1)
  lea    0x2(%rcx),%r9d
  cmp    $0x6,%ecx
  je     L182
  mov    %r9d,%r10d
  movslq %r9d,%r9
  sub    %esi,%r10d
  movslq %r10d,%r10
  movzbl (%rdi,%r10,1),%r10d
  mov    %r10b,(%rax,%r9,1)
  lea    0x3(%rcx),%r9d
  cmp    $0x5,%ecx
  je     L182
  mov    %r9d,%r10d
  movslq %r9d,%r9
  sub    %esi,%r10d
  movslq %r10d,%r10
  movzbl (%rdi,%r10,1),%r10d
  mov    %r10b,(%rax,%r9,1)
  lea    0x4(%rcx),%r9d
  cmp    $0x4,%ecx
  je     L182
  mov    %r9d,%r10d
  movslq %r9d,%r9
  sub    %esi,%r10d
  movslq %r10d,%r10
  movzbl (%rdi,%r10,1),%r10d
  mov    %r10b,(%rax,%r9,1)
  lea    0x5(%rcx),%r9d
  cmp    $0x3,%ecx
  je     L182
  mov    %r9d,%r10d
  movslq %r9d,%r9
  sub    %esi,%r10d
  movslq %r10d,%r10
  movzbl (%rdi,%r10,1),%r10d
  mov    %r10b,(%rax,%r9,1)
  lea    0x6(%rcx),%r9d
  cmp    $0x2,%ecx
  je     L182
  mov    %r9d,%ecx
  movslq %r9d,%r9
  sub    %esi,%ecx
  movslq %ecx,%rcx
  movzbl (%rdi,%rcx,1),%ecx
  mov    %cl,(%rax,%r9,1)
L182:
  mov    (%rax),%rcx
  mov    %rcx,(%rsp)
  test   %dl,%dl
  je     L345
  movslq %esi,%rcx
  movzbl %dl,%r11d
  movzbl (%rsp,%rcx,1),%r9d
  mov    %edx,%ecx
  mov    %r9d,%ebx
  sar    %cl,%ebx
  mov    %bl,(%rax,%r8,1)
  lea    0x1(%rsi),%r8d
  cmp    $0x7,%esi
  je     L345
  movslq %r8d,%r8
  mov    $0x8,%edi
  mov    %edx,%ecx
  movzbl (%rsp,%r8,1),%r10d
  sub    %r11d,%edi
  mov    %r10d,%r11d
  sar    %cl,%r11d
  mov    %edi,%ecx
  shl    %cl,%r9d
  or     %r9d,%r11d
  mov    %r11b,(%rax,%r8,1)
  lea    0x2(%rsi),%r8d
  cmp    $0x6,%esi
  je     L345
  movslq %r8d,%r8
  mov    %edx,%ecx
  movzbl (%rsp,%r8,1),%r9d
  mov    %r9d,%r11d
  sar    %cl,%r11d
  mov    %edi,%ecx
  shl    %cl,%r10d
  or     %r10d,%r11d
  mov    %r11b,(%rax,%r8,1)
  lea    0x3(%rsi),%r8d
  cmp    $0x5,%esi
  je     L345
  movslq %r8d,%r8
  mov    %edx,%ecx
  movzbl (%rsp,%r8,1),%r10d
  mov    %r10d,%r11d
  sar    %cl,%r11d
  mov    %edi,%ecx
  shl    %cl,%r9d
  or     %r9d,%r11d
  mov    %r11b,(%rax,%r8,1)
  lea    0x4(%rsi),%r8d
  cmp    $0x4,%esi
  je     L345
  movslq %r8d,%r8
  mov    %edx,%ecx
  movzbl (%rsp,%r8,1),%r9d
  mov    %r9d,%r11d
  sar    %cl,%r11d
  mov    %edi,%ecx
  shl    %cl,%r10d
  or     %r10d,%r11d
  mov    %r11b,(%rax,%r8,1)
  lea    0x5(%rsi),%r8d
  cmp    $0x3,%esi
  je     L345
  movslq %r8d,%r8
  mov    %edx,%ecx
  movzbl (%rsp,%r8,1),%r10d
  mov    %r10d,%r11d
  sar    %cl,%r11d
  mov    %edi,%ecx
  shl    %cl,%r9d
  or     %r9d,%r11d
  mov    %r11b,(%rax,%r8,1)
  lea    0x6(%rsi),%r11d
  cmp    $0x2,%esi
  je     L345
  movslq %r11d,%rbx
  mov    %edx,%ecx
  movzbl (%rsp,%rbx,1),%r8d
  mov    %r8d,%r9d
  sar    %cl,%r9d
  mov    %edi,%ecx
  shl    %cl,%r10d
  or     %r10d,%r9d
  mov    %r9b,(%rax,%rbx,1)
  cmp    $0x6,%r11d
  jne    L345
  movzbl 0x7(%rsp),%ecx
  cmp    $0x7,%esi
  movzbl %cl,%esi
  mov    %edx,%ecx
  je     L107
  sar    %cl,%esi
  mov    %edi,%ecx
  mov    %esi,%edx
  shl    %cl,%r8d
  or     %r8d,%edx
  mov    %dl,0x7(%rax)
  nopl   0x0(%rax,%rax,1)
L345:
  mov    0x8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L158
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  ret
  nopl   0x0(%rax,%rax,1)
L111:
  test   $0x4,%r8b
  jne    L126
  test   %r8d,%r8d
  je     L169
  movb   $0x0,(%rax)
  test   $0x2,%r8b
  je     L169
  xor    %r9d,%r9d
  mov    %r9w,-0x2(%rax,%r8,1)
  jmp    L169
  xchg   %ax,%ax
L289:
  movzbl (%rdi),%ecx
  mov    %cl,(%r9)
  lea    0x1(%rsi),%ecx
  cmp    $0x7,%esi
  je     L182
  movzbl 0x1(%rdi),%r9d
  movslq %ecx,%rcx
  mov    %r9b,(%rax,%rcx,1)
  lea    0x2(%rsi),%ecx
  cmp    $0x6,%esi
  je     L182
  movzbl 0x2(%rdi),%r9d
  movslq %ecx,%rcx
  mov    %r9b,(%rax,%rcx,1)
  lea    0x3(%rsi),%ecx
  cmp    $0x5,%esi
  je     L182
  movzbl 0x3(%rdi),%r9d
  movslq %ecx,%rcx
  mov    %r9b,(%rax,%rcx,1)
  lea    0x4(%rsi),%ecx
  cmp    $0x4,%esi
  je     L182
  movzbl 0x4(%rdi),%r9d
  movslq %ecx,%rcx
  mov    %r9b,(%rax,%rcx,1)
  lea    0x5(%rsi),%ecx
  cmp    $0x3,%esi
  je     L182
  movzbl 0x5(%rdi),%r9d
  movslq %ecx,%rcx
  mov    %r9b,(%rax,%rcx,1)
  lea    0x6(%rsi),%ecx
  cmp    $0x2,%esi
  je     L182
  movzbl 0x6(%rdi),%r10d
  movslq %ecx,%r9
  mov    %r10b,(%rax,%r9,1)
  cmp    $0x6,%ecx
  jne    L182
  mov    $0x7,%ecx
  sub    %esi,%ecx
  movslq %ecx,%rcx
  movzbl (%rdi,%rcx,1),%ecx
  mov    %cl,0x7(%rax)
  jmp    L182
L107:
  sar    %cl,%esi
  mov    %sil,0x7(%rax)
  jmp    L345
L126:
  movl   $0x0,(%rax)
  movl   $0x0,-0x4(%rax,%r8,1)
  jmp    L169
L158:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void _shiftR(unsigned char ans[8], unsigned char x[8], unsigned char r) {
  int i;
  int shiftbytes = r / 8;
  int shiftbits = r % 8;
  unsigned char temp[8];
  for (i = 0; i < shiftbytes; i++) {
    ans[i] = 0;
  }
  for (i = shiftbytes; i < 8; i++) {
    ans[i] = x[i - shiftbytes];
  }
  for (i = 0; i < 8; i++) {
    temp[i] = ans[i];
  }
  if (shiftbits > 0) {
    for (i = shiftbytes; i < 8; i++) {
      if (i == shiftbytes) {
        ans[i] = (temp[i] >> shiftbits);
      } else {
        ans[i] = (temp[i] >> shiftbits) | (temp[i - 1] << (8 - shiftbits));
      }
    }
  }
}
```