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

```asm
<slam_encode>:
  endbr64
  mov    %rdx,%rax
  shr    $0x38,%rdx
  mov    (%rdi),%r8
  mov    %rdi,%r9
  jne    L145
  mov    %rax,%rdx
  shr    $0x30,%rdx
  jne    L26
  mov    %rax,%rdx
  shr    $0x28,%rdx
  test   %dl,%dl
  jne    L150
  mov    %rax,%rdx
  shr    $0x20,%rdx
  test   %dl,%dl
  jne    L125
  mov    %rax,%rdx
  shr    $0x18,%rdx
  test   $0xff000000,%eax
  jne    L195
  mov    %rax,%rdx
  shr    $0x10,%rdx
  test   $0xff0000,%eax
  jne    L16
  mov    %rax,%rdx
  shr    $0x8,%rdx
  test   $0xff,%ah
  jne    L119
  mov    %rax,%rdx
  mov    $0x1,%ecx
  xor    %edi,%edi
  test   %al,%al
  jne    L134
  xor    %edi,%edi
  mov    $0x1,%r10d
  mov    $0x1,%ecx
L142:
  add    %r8,%r10
  cmp    %r10,%rsi
  jbe    L175
  lea    0x1(%r8),%rsi
  test   $0xe0,%dl
  je     L96
  lea    0x1(%rcx),%edx
  movslq %ecx,%rdi
  shl    $0x5,%edx
  mov    %dl,(%r8)
L51:
  lea    -0x1(%rdi),%edx
  mov    %rax,%r11
  lea    0x0(,%rdx,8),%ecx
  shr    %cl,%r11
  mov    %r11b,0x1(%r8)
  test   %edx,%edx
  je     L37
  lea    -0x2(%rdi),%edx
  mov    %rax,%r11
  lea    0x0(,%rdx,8),%ecx
  shr    %cl,%r11
  mov    %r11b,0x2(%r8)
  test   %edx,%edx
  je     L37
  lea    -0x3(%rdi),%edx
  mov    %rax,%r10
  lea    0x0(,%rdx,8),%ecx
  shr    %cl,%r10
  mov    %r10b,0x3(%r8)
  test   %edx,%edx
  je     L37
  lea    -0x4(%rdi),%edx
  mov    %rax,%r11
  lea    0x0(,%rdx,8),%ecx
  shr    %cl,%r11
  mov    %r11b,0x4(%r8)
  test   %edx,%edx
  je     L37
  lea    -0x5(%rdi),%edx
  mov    %rax,%r10
  lea    0x0(,%rdx,8),%ecx
  shr    %cl,%r10
  mov    %r10b,0x5(%r8)
  test   %edx,%edx
  je     L37
  lea    -0x6(%rdi),%edx
  mov    %rax,%r11
  lea    0x0(,%rdx,8),%ecx
  shr    %cl,%r11
  mov    %r11b,0x6(%r8)
  test   %edx,%edx
  je     L37
  lea    -0x7(%rdi),%edx
  mov    %rax,%r10
  lea    0x0(,%rdx,8),%ecx
  shr    %cl,%r10
  mov    %r10b,0x7(%r8)
  test   %edx,%edx
  je     L37
  mov    %al,0x8(%r8)
L37:
  add    %rdi,%rsi
  xor    %eax,%eax
  mov    %rsi,(%r9)
  ret
  nopl   0x0(%rax,%rax,1)
L96:
  shl    $0x5,%ecx
  or     %edx,%ecx
  mov    %cl,(%r8)
  test   %edi,%edi
  jne    L51
  mov    %rsi,(%r9)
  xor    %eax,%eax
  ret
L145:
  mov    $0x8,%ecx
  mov    $0x7,%edi
  nopl   0x0(%rax,%rax,1)
L134:
  movslq %ecx,%r10
  jmp    L142
L26:
  mov    $0x7,%ecx
  mov    $0x6,%edi
  jmp    L134
L150:
  mov    $0x6,%ecx
  mov    $0x5,%edi
  jmp    L134
L125:
  mov    $0x5,%ecx
  mov    $0x4,%edi
  jmp    L134
L195:
  mov    $0x4,%ecx
  mov    $0x3,%edi
  jmp    L134
L16:
  mov    $0x3,%ecx
  mov    $0x2,%edi
  jmp    L134
L119:
  mov    $0x2,%ecx
  mov    $0x1,%edi
  jmp    L134
L175:
  mov    $0xffffffff,%eax
  ret
```

assistant: ```c
int slam_encode(unsigned char **ptr, unsigned char *end, unsigned long value) {
  unsigned char *data = *ptr;
  int bytes;
  bytes = sizeof(value);
  while ((bytes > 0) && ((0xff & (value >> ((bytes - 1) << 3))) == 0)) {
    bytes--;
  }
  if (bytes <= 0) {
    bytes = 1;
  }
  if (data + bytes >= end) {
    return -1;
  }
  if ((0xe0 & (value >> ((bytes - 1) << 3))) == 0) {
    *data = (bytes << 5) | (value >> ((bytes - 1) << 3));
  } else {
    bytes++;
    *data = (bytes << 5);
  }
  bytes--;
  data++;
  while (bytes) {
    *(data++) = 0xff & (value >> ((bytes - 1) << 3));
    bytes--;
  }
  *ptr = data;
  return 0;
}
```