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

```asm
<ftn2c_string_copy>:
  endbr64
  push   %r12
  cmpb   $0x0,(%rdi)
  mov    %rsi,%r10
  mov    %ecx,%esi
  je     L21
  test   %edx,%edx
  jle    L21
  mov    $0x1,%eax
  nopl   0x0(%rax)
L147:
  cmpb   $0x0,(%rdi,%rax,1)
  mov    %eax,%r12d
  mov    %rax,%r11
  setne  %r9b
  cmp    %eax,%edx
  setg   %cl
  add    $0x1,%rax
  test   %cl,%r9b
  jne    L147
  sub    $0x1,%r11
L225:
  cmpb   $0x20,(%rdi,%r11,1)
  jne    L207
  lea    -0x1(%r12),%eax
  cltq
  cs nopw 0x0(%rax,%rax,1)
L65:
  mov    %eax,%r12d
  sub    $0x1,%rax
  cmpb   $0x20,(%rdi,%rax,1)
  je     L65
L207:
  test   %r10,%r10
  je     L270
  cmp    %r12d,%esi
  jl     L234
  test   %r8b,%r8b
  jne    L125
  cmp    %r12d,%esi
  je     L234
L125:
  test   %r12d,%r12d
  jle    L252
  lea    0x1(%rdi),%r9
  mov    %r10,%rdx
  lea    -0x1(%r12),%eax
  mov    %r12d,%ecx
  sub    %r9,%rdx
  cmp    $0xe,%rdx
  jbe    L95
  cmp    $0x6,%eax
  jbe    L95
  cmp    $0xe,%eax
  jbe    L137
  mov    %r12d,%edx
  xor    %eax,%eax
  shr    $0x4,%edx
  shl    $0x4,%rdx
L280:
  movdqu (%rdi,%rax,1),%xmm0
  movups %xmm0,(%r10,%rax,1)
  add    $0x10,%rax
  cmp    %rdx,%rax
  jne    L280
  mov    %r12d,%edx
  and    $0xfffffff0,%edx
  mov    %edx,%eax
  cmp    %r12d,%edx
  je     L34
  mov    %r12d,%ecx
  sub    %edx,%ecx
  lea    -0x1(%rcx),%r9d
  cmp    $0x6,%r9d
  jbe    L284
L155:
  mov    (%rdi,%rdx,1),%r9
  mov    %r9,(%r10,%rdx,1)
  mov    %ecx,%edx
  and    $0xfffffff8,%edx
  add    %edx,%eax
  cmp    %edx,%ecx
  je     L34
L284:
  movslq %eax,%rdx
  movzbl (%rdi,%rdx,1),%ecx
  mov    %cl,(%r10,%rdx,1)
  lea    0x1(%rax),%edx
  cmp    %edx,%r12d
  jle    L34
  movslq %edx,%rdx
  movzbl (%rdi,%rdx,1),%ecx
  mov    %cl,(%r10,%rdx,1)
  lea    0x2(%rax),%edx
  cmp    %edx,%r12d
  jle    L34
  movslq %edx,%rdx
  movzbl (%rdi,%rdx,1),%ecx
  mov    %cl,(%r10,%rdx,1)
  lea    0x3(%rax),%edx
  cmp    %edx,%r12d
  jle    L34
  movslq %edx,%rdx
  movzbl (%rdi,%rdx,1),%ecx
  mov    %cl,(%r10,%rdx,1)
  lea    0x4(%rax),%edx
  cmp    %edx,%r12d
  jle    L34
  movslq %edx,%rdx
  movzbl (%rdi,%rdx,1),%ecx
  mov    %cl,(%r10,%rdx,1)
  lea    0x5(%rax),%edx
  cmp    %edx,%r12d
  jle    L34
  movslq %edx,%rdx
  add    $0x6,%eax
  movzbl (%rdi,%rdx,1),%ecx
  mov    %cl,(%r10,%rdx,1)
  cmp    %eax,%r12d
  jle    L34
  cltq
  movzbl (%rdi,%rax,1),%edx
  mov    %dl,(%r10,%rax,1)
L34:
  movslq %r12d,%rax
L286:
  test   %r8b,%r8b
  je     L236
  cmp    %eax,%esi
  jle    L270
  lea    -0x1(%rsi),%edx
  lea    (%r10,%rax,1),%rdi
  mov    %edx,%esi
  sub    %eax,%esi
  lea    0x1(%rsi),%rdx
  movzbl %r8b,%esi
  call   <memset@plt>
L270:
  mov    %r12d,%eax
  pop    %r12
  ret
  nopl   0x0(%rax)
L236:
  movb   $0x0,(%r10,%rax,1)
  mov    %r12d,%eax
  pop    %r12
  ret
  nopl   0x0(%rax,%rax,1)
L95:
  mov    %r12d,%ecx
  xor    %eax,%eax
  nopl   (%rax)
L25:
  movzbl (%rdi,%rax,1),%edx
  mov    %dl,(%r10,%rax,1)
  add    $0x1,%rax
  cmp    %rcx,%rax
  jne    L25
  jmp    L34
  nopl   0x0(%rax,%rax,1)
L21:
  mov    $0xffffffffffffffff,%r11
  xor    %r12d,%r12d
  jmp    L225
L252:
  xor    %eax,%eax
  jmp    L286
L137:
  xor    %edx,%edx
  xor    %eax,%eax
  jmp    L155
L234:
  mov    $0xffffffff,%r12d
  jmp    L270
```

assistant: ```c
int ftn2c_string_copy(unsigned char *src, unsigned char *dest, int lsrc, int ldest, unsigned char pad) {
  int i;
  for (i = 0; src[i] != 0 && i < lsrc; i++)
    ;
  lsrc = i;
  while (src[lsrc - 1] == ' ')
    lsrc--;
  if (dest == NULL)
    return (lsrc);
  if (lsrc > ldest)
    return (-1);
  if (pad == 0 && lsrc == ldest)
    return (-1);
  for (i = 0; i < lsrc; i++)
    dest[i] = src[i];
  if (pad)
    while (i < ldest)
      dest[i++] = pad;
  else
    dest[i] = pad;
  return (lsrc);
}
```