ylfeng/ReF-Decompile-dataset huggingface dataset:
user: 请将以下的汇编代码转换成C语言代码:

```asm
<round_div>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %edi,-0x14(%rbp)
  mov    %esi,-0x18(%rbp)
  mov    -0x14(%rbp),%eax
  cltd
  idivl  -0x18(%rbp)
  mov    %eax,-0x8(%rbp)
  mov    -0x14(%rbp),%eax
  cltd
  idivl  -0x18(%rbp)
  mov    %edx,%eax
  add    %eax,%eax
  mov    %eax,-0x4(%rbp)
  mov    -0x4(%rbp),%eax
  cmp    -0x18(%rbp),%eax
  jg     L21
  mov    -0x4(%rbp),%eax
  cmp    -0x18(%rbp),%eax
  jne    L8
  mov    -0x8(%rbp),%eax
  and    $0x1,%eax
  test   %eax,%eax
  je     L8
L21:
  addl   $0x1,-0x8(%rbp)
L8:
  mov    -0x8(%rbp),%eax
  pop    %rbp
  ret
```

assistant: ```c
int round_div(int x, int y) {
  int quotient = x / y;
  int dblremain = (x % y) << 1;
  if ((dblremain > y) || (dblremain == y) && (quotient & 1))
    quotient++;
  return quotient;
}
```
user: 这段汇编代码用C语言表示是什么样的?

```asm
<round_div>:
  endbr64
  mov    %edi,%eax
  cltd
  idiv   %esi
  mov    %eax,%ecx
  add    %edx,%edx
  cmp    %edx,%esi
  jl     L8
  jne    L1
  test   $0x1,%al
  je     L1
L8:
  lea    0x1(%rax),%ecx
L1:
  mov    %ecx,%eax
  ret
```

assistant: ```c
int round_div(int x, int y) {
  int quotient = x / y;
  int dblremain = (x % y) << 1;
  if ((dblremain > y) || (dblremain == y) && (quotient & 1))
    quotient++;
  return quotient;
}
```
user: 请将以下的汇编代码转换成C语言代码:

```asm
<round_div>:
  endbr64
  mov    %edi,%eax
  cltd
  idiv   %esi
  add    %edx,%edx
  mov    %eax,%r8d
  cmp    %edx,%esi
  jl     L4
  je     L27
L23:
  mov    %r8d,%eax
  ret
  nopl   0x0(%rax,%rax,1)
L27:
  test   $0x1,%al
  je     L23
L4:
  lea    0x1(%rax),%r8d
  mov    %r8d,%eax
  ret
```

assistant: ```c
int round_div(int x, int y) {
  int quotient = x / y;
  int dblremain = (x % y) << 1;
  if ((dblremain > y) || (dblremain == y) && (quotient & 1))
    quotient++;
  return quotient;
}
```
user: Converte this assembly snippet into its equivalent C code:

```asm
<round_div>:
  endbr64
  mov    %edi,%eax
  cltd
  idiv   %esi
  add    %edx,%edx
  mov    %eax,%r8d
  cmp    %edx,%esi
  jl     L21
  je     L8
L27:
  mov    %r8d,%eax
  ret
  nopl   0x0(%rax,%rax,1)
L8:
  test   $0x1,%al
  je     L27
L21:
  lea    0x1(%rax),%r8d
  mov    %r8d,%eax
  ret
```

assistant: ```c
int round_div(int x, int y) {
  int quotient = x / y;
  int dblremain = (x % y) << 1;
  if ((dblremain > y) || (dblremain == y) && (quotient & 1))
    quotient++;
  return quotient;
}
```
user: 下面的汇编指令对应的C源代码是什么:

```asm
<cpu_has_msr>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x20,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  lea    -0xc(%rbp),%rsi
  lea    -0x10(%rbp),%rcx
  lea    -0x14(%rbp),%rdx
  lea    -0x18(%rbp),%rax
  mov    %rsi,%r8
  mov    %rax,%rsi
  mov    $0x1,%edi
  call   <__get_cpuid@plt>
  test   %rax,%rax
  je     L6
  mov    -0xc(%rbp),%eax
  and    $0x20,%eax
  jmp    L25
L6:
  mov    $0x0,%eax
L25:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L1
  call   <__stack_chk_fail@plt>
L1:
  leave
  ret
```

assistant: ```c
bool cpu_has_msr() {
  unsigned int a, b, c, d;
  if (__get_cpuid(1, &a, &b, &c, &d)) {
    return (d & (1 << 5));
  }
  return false;
}
```
user: 下面的汇编指令对应的C源代码是什么:

```asm
<cpu_has_msr>:
  endbr64
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  lea    0x10(%rsp),%rcx
  lea    0xc(%rsp),%rdx
  lea    0x8(%rsp),%rsi
  lea    0x14(%rsp),%r8
  mov    $0x1,%edi
  call   <__get_cpuid@plt>
  mov    %rax,%rdx
  mov    $0x0,%eax
  test   %rdx,%rdx
  jne    L8
L21:
  mov    0x18(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L26
  add    $0x28,%rsp
  ret
L8:
  mov    0x14(%rsp),%eax
  and    $0x20,%eax
  jmp    L21
L26:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
bool cpu_has_msr() {
  unsigned int a, b, c, d;
  if (__get_cpuid(1, &a, &b, &c, &d)) {
    return (d & (1 << 5));
  }
  return false;
}
```
user: 这段汇编代码用C语言表示是什么样的？

```asm
<cpu_has_msr>:
  endbr64
  sub    $0x28,%rsp
  mov    $0x1,%edi
  lea    0x14(%rsp),%r8
  lea    0x10(%rsp),%rcx
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  lea    0xc(%rsp),%rdx
  lea    0x8(%rsp),%rsi
  call   <__get_cpuid@plt>
  mov    %rax,%r8
  xor    %eax,%eax
  test   %r8,%r8
  je     L7
  mov    0x14(%rsp),%eax
  and    $0x20,%eax
L7:
  mov    0x18(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L8
  add    $0x28,%rsp
  ret
L8:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
bool cpu_has_msr() {
  unsigned int a, b, c, d;
  if (__get_cpuid(1, &a, &b, &c, &d)) {
    return (d & (1 << 5));
  }
  return false;
}
```
user: Converte this assembly snippet into its equivalent C code:

```asm
<cpu_has_msr>:
  endbr64
  sub    $0x28,%rsp
  mov    $0x1,%edi
  lea    0x14(%rsp),%r8
  lea    0x10(%rsp),%rcx
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  lea    0xc(%rsp),%rdx
  lea    0x8(%rsp),%rsi
  call   <__get_cpuid@plt>
  mov    %rax,%r8
  xor    %eax,%eax
  test   %r8,%r8
  je     L4
  mov    0x14(%rsp),%eax
  and    $0x20,%eax
L4:
  mov    0x18(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L17
  add    $0x28,%rsp
  ret
L17:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
bool cpu_has_msr() {
  unsigned int a, b, c, d;
  if (__get_cpuid(1, &a, &b, &c, &d)) {
    return (d & (1 << 5));
  }
  return false;
}
```
user: 提供的汇编代码用C语言表示会是什么样子:

```asm
<__v2__sigjmp_save>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x10,%rsp
  mov    %rdi,-0x8(%rbp)
  mov    %esi,-0xc(%rbp)
  cmpl   $0x0,-0xc(%rbp)
  je     L10
  mov    -0x8(%rbp),%rax
  lea    0x4(%rax),%rdx
  mov    D5(%rip),%rax
  mov    (%rax),%eax
  mov    $0x0,%esi
  mov    %eax,%edi
  call   <__sigprocmask@plt>
  test   %rax,%rax
  jne    L10
  mov    $0x1,%edx
  jmp    L24
L10:
  mov    $0x0,%edx
L24:
  mov    -0x8(%rbp),%rax
  mov    %edx,(%rax)
  mov    $0x0,%eax
  leave
  ret
```

assistant: ```c
int __v2__sigjmp_save(sigjmp_buf env, int savemask) {
  env[0].__mask_was_saved = (savemask && __sigprocmask(SIG_BLOCK, (sigset_t *)NULL, &env[0].__saved_mask) == 0);
  return 0;
}
```
user: 请将以下的汇编代码转换成C语言代码：

```asm
<__v2__sigjmp_save>:
  endbr64
  push   %rbx
  mov    %rdi,%rbx
  test   %esi,%esi
  jne    L14
L19:
  mov    %esi,(%rbx)
  mov    $0x0,%eax
  pop    %rbx
  ret
L14:
  lea    0x4(%rdi),%rdx
  mov    $0x0,%esi
  mov    D5(%rip),%rax
  mov    (%rax),%edi
  call   <__sigprocmask@plt>
  test   %rax,%rax
  sete   %sil
  movzbl %sil,%esi
  jmp    L19
```

assistant: ```c
int __v2__sigjmp_save(sigjmp_buf env, int savemask) {
  env[0].__mask_was_saved = (savemask && __sigprocmask(SIG_BLOCK, (sigset_t *)NULL, &env[0].__saved_mask) == 0);
  return 0;
}
```
user: What would the C source look like for the assembly code provided here?

```asm
<__v2__sigjmp_save>:
  endbr64
  push   %rbx
  mov    %rdi,%rbx
  test   %esi,%esi
  jne    L5
  mov    %esi,(%rbx)
  xor    %eax,%eax
  pop    %rbx
  ret
  nopw   0x0(%rax,%rax,1)
L5:
  mov    D6(%rip),%rax
  lea    0x4(%rdi),%rdx
  xor    %esi,%esi
  mov    (%rax),%edi
  call   <__sigprocmask@plt>
  xor    %esi,%esi
  test   %rax,%rax
  sete   %sil
  xor    %eax,%eax
  mov    %esi,(%rbx)
  pop    %rbx
  ret
```

assistant: ```c
int __v2__sigjmp_save(sigjmp_buf env, int savemask) {
  env[0].__mask_was_saved = (savemask && __sigprocmask(SIG_BLOCK, (sigset_t *)NULL, &env[0].__saved_mask) == 0);
  return 0;
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<__v2__sigjmp_save>:
  endbr64
  push   %rbx
  mov    %rdi,%rbx
  test   %esi,%esi
  jne    L8
  mov    %esi,(%rbx)
  xor    %eax,%eax
  pop    %rbx
  ret
  nopw   0x0(%rax,%rax,1)
L8:
  mov    D0(%rip),%rax
  lea    0x4(%rdi),%rdx
  xor    %esi,%esi
  mov    (%rax),%edi
  call   <__sigprocmask@plt>
  xor    %esi,%esi
  test   %rax,%rax
  sete   %sil
  xor    %eax,%eax
  mov    %esi,(%rbx)
  pop    %rbx
  ret
```

assistant: ```c
int __v2__sigjmp_save(sigjmp_buf env, int savemask) {
  env[0].__mask_was_saved = (savemask && __sigprocmask(SIG_BLOCK, (sigset_t *)NULL, &env[0].__saved_mask) == 0);
  return 0;
}
```
user: 请将以下的汇编代码转换成C语言代码:

```asm
<pwskip>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %rdi,-0x8(%rbp)
  jmp    L20
L32:
  addq   $0x1,-0x8(%rbp)
L20:
  mov    -0x8(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  je     L39
  mov    -0x8(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x3a,%al
  je     L39
  mov    -0x8(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0xa,%al
  jne    L32
L39:
  mov    -0x8(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  je     L4
  mov    -0x8(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x8(%rbp)
  movb   $0x0,(%rax)
  jmp    L43
L4:
  mov    -0x8(%rbp),%rax
  add    $0x1,%rax
  movb   $0x0,(%rax)
L43:
  mov    -0x8(%rbp),%rax
  pop    %rbp
  ret
```

assistant: ```c
char *pwskip(char *p) {
  while (*p && *p != ':' && *p != '\n')
    ++p;
  if (*p)
    *p++ = 0;
  else
    p[1] = 0;
  return (p);
}
```
user: Converte this assembly snippet into its equivalent C code:

```asm
<pwskip>:
  endbr64
  movzbl (%rdi),%eax
  cmp    $0x3a,%al
  ja     L3
  movabs $0x400000000000401,%rdx
  bt     %rax,%rdx
  jb     L23
L3:
  movabs $0x400000000000401,%rdx
L30:
  add    $0x1,%rdi
  movzbl (%rdi),%eax
  cmp    $0x3a,%al
  ja     L30
  bt     %rax,%rdx
  jae    L30
L23:
  test   %al,%al
  je     L28
  lea    0x1(%rdi),%rax
  movb   $0x0,(%rdi)
  ret
L28:
  movb   $0x0,0x1(%rdi)
  mov    %rdi,%rax
  ret
```

assistant: ```c
char *pwskip(char *p) {
  while (*p && *p != ':' && *p != '\n')
    ++p;
  if (*p)
    *p++ = 0;
  else
    p[1] = 0;
  return (p);
}
```
user: What would the C source look like for the assembly code provided here:

```asm
<pwskip>:
  endbr64
  nopl   0x0(%rax)
L6:
  movzbl (%rdi),%eax
  test   %al,%al
  je     L21
  cmp    $0x3a,%al
  je     L4
  mov    %rdi,%rdx
  add    $0x1,%rdi
  cmp    $0xa,%al
  jne    L6
L7:
  movb   $0x0,(%rdx)
  lea    0x1(%rdx),%rax
  ret
  cs nopw 0x0(%rax,%rax,1)
L21:
  movb   $0x0,0x1(%rdi)
  mov    %rdi,%rax
  ret
  nopl   0x0(%rax,%rax,1)
L4:
  test   %al,%al
  je     L21
  mov    %rdi,%rdx
  jmp    L7
```

assistant: ```c
char *pwskip(char *p) {
  while (*p && *p != ':' && *p != '\n')
    ++p;
  if (*p)
    *p++ = 0;
  else
    p[1] = 0;
  return (p);
}
```
user: Demonstrate the C code that generates the assembly output below:

```asm
<pwskip>:
  endbr64
  nopl   0x0(%rax)
L7:
  movzbl (%rdi),%eax
  test   %al,%al
  je     L6
  cmp    $0x3a,%al
  je     L18
  mov    %rdi,%rdx
  add    $0x1,%rdi
  cmp    $0xa,%al
  jne    L7
L48:
  movb   $0x0,(%rdx)
  lea    0x1(%rdx),%rax
  ret
  cs nopw 0x0(%rax,%rax,1)
L6:
  movb   $0x0,0x1(%rdi)
  mov    %rdi,%rax
  ret
  nopl   0x0(%rax,%rax,1)
L18:
  test   %al,%al
  je     L6
  mov    %rdi,%rdx
  jmp    L48
```

assistant: ```c
char *pwskip(char *p) {
  while (*p && *p != ':' && *p != '\n')
    ++p;
  if (*p)
    *p++ = 0;
  else
    p[1] = 0;
  return (p);
}
```
user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<feed_text_iterator_invalidate>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x10,%rsp
  mov    %rdi,-0x8(%rbp)
  mov    -0x8(%rbp),%rax
  mov    %rax,%rdi
  call   <feed_text_iterator_invalidate_line@plt>
  mov    -0x8(%rbp),%rax
  mov    %rax,%rdi
  call   <feed_text_iterator_invalidate_glyph@plt>
  nop
  leave
  ret
```

assistant: ```c
void feed_text_iterator_invalidate(struct feed_text_iterator *const p_text_iterator) {
  feed_text_iterator_invalidate_line(p_text_iterator);
  feed_text_iterator_invalidate_glyph(p_text_iterator);
}
```
user: 请将以下的汇编代码转换成C语言代码：

```asm
<feed_text_iterator_invalidate>:
  endbr64
  push   %rbx
  mov    %rdi,%rbx
  call   <feed_text_iterator_invalidate_line@plt>
  mov    %rbx,%rdi
  call   <feed_text_iterator_invalidate_glyph@plt>
  pop    %rbx
  ret
```

assistant: ```c
void feed_text_iterator_invalidate(struct feed_text_iterator *const p_text_iterator) {
  feed_text_iterator_invalidate_line(p_text_iterator);
  feed_text_iterator_invalidate_glyph(p_text_iterator);
}
```
user: 请将以下的汇编代码转换成C语言代码:

```asm
<feed_text_iterator_invalidate>:
  endbr64
  push   %rbp
  mov    %rdi,%rbp
  call   <feed_text_iterator_invalidate_line@plt>
  mov    %rbp,%rdi
  pop    %rbp
  jmp    1070 <feed_text_iterator_invalidate_glyph@plt>
```

assistant: ```c
void feed_text_iterator_invalidate(struct feed_text_iterator *const p_text_iterator) {
  feed_text_iterator_invalidate_line(p_text_iterator);
  feed_text_iterator_invalidate_glyph(p_text_iterator);
}
```
user: 提供的汇编代码用C语言表示会是什么样子:

```asm
<feed_text_iterator_invalidate>:
  endbr64
  push   %rbp
  mov    %rdi,%rbp
  call   <feed_text_iterator_invalidate_line@plt>
  mov    %rbp,%rdi
  pop    %rbp
  jmp    1070 <feed_text_iterator_invalidate_glyph@plt>
```

assistant: ```c
void feed_text_iterator_invalidate(struct feed_text_iterator *const p_text_iterator) {
  feed_text_iterator_invalidate_line(p_text_iterator);
  feed_text_iterator_invalidate_glyph(p_text_iterator);
}
```
user: Translate the below assembly code into C programming language:

```asm
<usb_lld_shutdown>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    $0x2,%edi
  call   <st103_set_cntr@plt>
  mov    $0x0,%eax
  call   <usb_lld_sys_shutdown@plt>
  nop
  pop    %rbp
  ret
```

assistant: ```c
void usb_lld_shutdown(void) {
  st103_set_cntr((0x0002));
  usb_lld_sys_shutdown();
}
```
user: 这段汇编代码用C语言表示是什么样的：

```asm
<usb_lld_shutdown>:
  endbr64
  sub    $0x8,%rsp
  mov    $0x2,%edi
  call   <st103_set_cntr@plt>
  mov    $0x0,%eax
  call   <usb_lld_sys_shutdown@plt>
  add    $0x8,%rsp
  ret
```

assistant: ```c
void usb_lld_shutdown(void) {
  st103_set_cntr((0x0002));
  usb_lld_sys_shutdown();
}
```
user: Converte this assembly snippet into its equivalent C code:

```asm
<usb_lld_shutdown>:
  endbr64
  sub    $0x8,%rsp
  mov    $0x2,%edi
  call   <st103_set_cntr@plt>
  xor    %eax,%eax
  add    $0x8,%rsp
  jmp    1060 <usb_lld_sys_shutdown@plt>
```

assistant: ```c
void usb_lld_shutdown(void) {
  st103_set_cntr((0x0002));
  usb_lld_sys_shutdown();
}
```
user: What is the c source code of the assembly code below:

```asm
<usb_lld_shutdown>:
  endbr64
  sub    $0x8,%rsp
  mov    $0x2,%edi
  call   <st103_set_cntr@plt>
  xor    %eax,%eax
  add    $0x8,%rsp
  jmp    1060 <usb_lld_sys_shutdown@plt>
```

assistant: ```c
void usb_lld_shutdown(void) {
  st103_set_cntr((0x0002));
  usb_lld_sys_shutdown();
}
```
user: What is the c source code of the assembly code below:

```asm
<shardcache_byte_escape>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x70,%rsp
  mov    %esi,%eax
  mov    %rdx,-0x50(%rbp)
  mov    %rcx,-0x58(%rbp)
  mov    %r8,-0x60(%rbp)
  mov    %r9,-0x68(%rbp)
  mov    %edi,%edx
  mov    %dl,-0x44(%rbp)
  mov    %al,-0x48(%rbp)
  cmpq   $0x0,-0x58(%rbp)
  jne    L51
  mov    $0x0,%eax
  jmp    L82
L51:
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x30(%rbp)
  cmpq   $0x0,-0x30(%rbp)
  jne    L49
  mov    $0x0,%eax
  jmp    L82
L49:
  mov    -0x58(%rbp),%rax
  mov    %rax,-0x28(%rbp)
  mov    -0x50(%rbp),%rax
  mov    %rax,-0x10(%rbp)
  movq   $0x0,-0x8(%rbp)
  movq   $0x0,-0x18(%rbp)
  movq   $0x0,-0x20(%rbp)
  jmp    L17
L76:
  movl   $0x0,-0x34(%rbp)
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  cmp    %al,-0x44(%rbp)
  jne    L15
  addq   $0x1,-0x18(%rbp)
L15:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  cmp    %al,-0x44(%rbp)
  je     L74
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%edx
  movzbl -0x48(%rbp),%eax
  cmp    %al,%dl
  jne    L11
L74:
  movl   $0x1,-0x34(%rbp)
L11:
  cmpl   $0x0,-0x34(%rbp)
  je     L90
  addq   $0x1,-0x28(%rbp)
  mov    -0x28(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    -0x30(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,-0x30(%rbp)
  mov    -0x30(%rbp),%rdx
  mov    -0x8(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  lea    -0x48(%rbp),%rax
  mov    $0x1,%edx
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <memcpy@plt>
  addq   $0x1,-0x8(%rbp)
L90:
  mov    -0x30(%rbp),%rdx
  mov    -0x8(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x10(%rbp),%rax
  mov    $0x1,%edx
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <memcpy@plt>
  addq   $0x1,-0x10(%rbp)
  addq   $0x1,-0x8(%rbp)
  addq   $0x1,-0x20(%rbp)
L17:
  mov    -0x20(%rbp),%rax
  cmp    -0x58(%rbp),%rax
  jb     L76
  mov    -0x60(%rbp),%rax
  mov    -0x30(%rbp),%rdx
  mov    %rdx,(%rax)
  mov    -0x68(%rbp),%rax
  mov    -0x28(%rbp),%rdx
  mov    %rdx,(%rax)
  mov    -0x18(%rbp),%rax
L82:
  leave
  ret
```

assistant: ```c
unsigned long shardcache_byte_escape(char ch, char esc, char *buffer, unsigned long len, char **dest, unsigned long *newlen) {
  char *newbuf;
  unsigned long buflen;
  unsigned long i;
  unsigned long cnt;
  int escape;
  char *p;
  unsigned long off;
  if (len == 0)
    return 0;
  newbuf = (char *)malloc(len);
  if (!newbuf)
    return 0;
  buflen = len;
  p = buffer;
  off = 0;
  cnt = 0;
  for (i = 0; i < len; i++) {
    escape = 0;
    if (*p == ch)
      cnt++;
    if (*p == ch || *p == esc)
      escape = 1;
    if (escape) {
      buflen++;
      newbuf = (char *)realloc(newbuf, buflen + 1);
      memcpy(newbuf + off, &esc, 1);
      off++;
    }
    memcpy(newbuf + off, p, 1);
    p++;
    off++;
  }
  *dest = newbuf;
  *newlen = buflen;
  return cnt;
}
```
user: 请从给定的汇编指令推导出C源代码:

```asm
<shardcache_byte_escape>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %rcx,%rbp
  mov    %r8,0x18(%rsp)
  mov    %r9,0x20(%rsp)
  mov    %sil,0x2c(%rsp)
  test   %rcx,%rcx
  jne    L39
L50:
  mov    %rbp,%rax
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L39:
  mov    %rdx,%rbx
  mov    %edi,%r14d
  mov    %rcx,%rdi
  call   <malloc@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L78
  lea    (%rbx,%rbp,1),%r15
  mov    $0x0,%r12d
  movq   $0x0,0x10(%rsp)
  lea    0x2c(%rsp),%rax
  mov    %rax,0x8(%rsp)
  jmp    L0
L70:
  addq   $0x1,0x10(%rsp)
L74:
  lea    0x1(%rbp),%rax
  mov    %rax,(%rsp)
  lea    0x2(%rbp),%rsi
  mov    %r13,%rdi
  call   <realloc@plt>
  mov    %rax,%r13
  lea    (%rax,%r12,1),%rdi
  mov    $0x1,%edx
  mov    0x8(%rsp),%rsi
  call   <memcpy@plt>
  add    $0x1,%r12
  mov    (%rsp),%rbp
L13:
  lea    0x0(%r13,%r12,1),%rdi
  mov    $0x1,%edx
  mov    %rbx,%rsi
  call   <memcpy@plt>
  add    $0x1,%rbx
  add    $0x1,%r12
  cmp    %r15,%rbx
  je     L30
L0:
  movzbl (%rbx),%eax
  cmp    %r14b,%al
  je     L70
  cmp    0x2c(%rsp),%al
  jne    L13
  jmp    L74
L30:
  mov    0x18(%rsp),%rax
  mov    %r13,(%rax)
  mov    0x20(%rsp),%rax
  mov    %rbp,(%rax)
  mov    0x10(%rsp),%rbp
  jmp    L50
L78:
  mov    $0x0,%ebp
  jmp    L50
```

assistant: ```c
unsigned long shardcache_byte_escape(char ch, char esc, char *buffer, unsigned long len, char **dest, unsigned long *newlen) {
  char *newbuf;
  unsigned long buflen;
  unsigned long i;
  unsigned long cnt;
  int escape;
  char *p;
  unsigned long off;
  if (len == 0)
    return 0;
  newbuf = (char *)malloc(len);
  if (!newbuf)
    return 0;
  buflen = len;
  p = buffer;
  off = 0;
  cnt = 0;
  for (i = 0; i < len; i++) {
    escape = 0;
    if (*p == ch)
      cnt++;
    if (*p == ch || *p == esc)
      escape = 1;
    if (escape) {
      buflen++;
      newbuf = (char *)realloc(newbuf, buflen + 1);
      memcpy(newbuf + off, &esc, 1);
      off++;
    }
    memcpy(newbuf + off, p, 1);
    p++;
    off++;
  }
  *dest = newbuf;
  *newlen = buflen;
  return cnt;
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<shardcache_byte_escape>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %r8,0x18(%rsp)
  mov    %r9,0x20(%rsp)
  mov    %sil,0x2c(%rsp)
  test   %rcx,%rcx
  jne    L77
L16:
  xor    %r12d,%r12d
L64:
  add    $0x38,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L77:
  mov    %edi,%ebx
  mov    %rcx,%rdi
  mov    %rdx,%r13
  mov    %rcx,%rbp
  call   <malloc@plt>
  test   %rax,%rax
  je     L16
  mov    %rax,%r14
  lea    0x0(%r13,%rbp,1),%rax
  xor    %r15d,%r15d
  xor    %r12d,%r12d
  mov    %rax,(%rsp)
  lea    0x2c(%rsp),%rax
  mov    %rax,0x10(%rsp)
  jmp    L52
  nopl   0x0(%rax,%rax,1)
L41:
  cmp    0x2c(%rsp),%al
  je     L19
L23:
  lea    (%r14,%r15,1),%rdi
  mov    %r13,%rsi
  mov    $0x1,%edx
  add    $0x1,%r13
  call   <memcpy@plt>
  add    $0x1,%r15
  cmp    (%rsp),%r13
  je     L33
L52:
  movzbl 0x0(%r13),%eax
  cmp    %bl,%al
  jne    L41
  add    $0x1,%r12
L19:
  lea    0x1(%rbp),%rax
  lea    0x2(%rbp),%rsi
  mov    %r14,%rdi
  mov    %rax,0x8(%rsp)
  call   <realloc@plt>
  mov    0x10(%rsp),%rsi
  mov    $0x1,%edx
  lea    (%rax,%r15,1),%rdi
  mov    %rax,%r14
  add    $0x1,%r15
  call   <memcpy@plt>
  mov    0x8(%rsp),%rbp
  jmp    L23
L33:
  mov    0x18(%rsp),%rax
  mov    %r14,(%rax)
  mov    0x20(%rsp),%rax
  mov    %rbp,(%rax)
  jmp    L64
```

assistant: ```c
unsigned long shardcache_byte_escape(char ch, char esc, char *buffer, unsigned long len, char **dest, unsigned long *newlen) {
  char *newbuf;
  unsigned long buflen;
  unsigned long i;
  unsigned long cnt;
  int escape;
  char *p;
  unsigned long off;
  if (len == 0)
    return 0;
  newbuf = (char *)malloc(len);
  if (!newbuf)
    return 0;
  buflen = len;
  p = buffer;
  off = 0;
  cnt = 0;
  for (i = 0; i < len; i++) {
    escape = 0;
    if (*p == ch)
      cnt++;
    if (*p == ch || *p == esc)
      escape = 1;
    if (escape) {
      buflen++;
      newbuf = (char *)realloc(newbuf, buflen + 1);
      memcpy(newbuf + off, &esc, 1);
      off++;
    }
    memcpy(newbuf + off, p, 1);
    p++;
    off++;
  }
  *dest = newbuf;
  *newlen = buflen;
  return cnt;
}
```
user: 请将这段汇编代码片段转换成等效的C代码:

```asm
<shardcache_byte_escape>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %r8,0x18(%rsp)
  mov    %r9,0x20(%rsp)
  mov    %sil,0x2c(%rsp)
  test   %rcx,%rcx
  jne    L75
L10:
  xor    %r12d,%r12d
L2:
  add    $0x38,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L75:
  mov    %edi,%ebx
  mov    %rcx,%rdi
  mov    %rdx,%r13
  mov    %rcx,%rbp
  call   <malloc@plt>
  test   %rax,%rax
  je     L10
  mov    %rax,%r14
  lea    0x0(%r13,%rbp,1),%rax
  xor    %r15d,%r15d
  xor    %r12d,%r12d
  mov    %rax,(%rsp)
  lea    0x2c(%rsp),%rax
  mov    %rax,0x10(%rsp)
  jmp    L25
  nopl   0x0(%rax,%rax,1)
L16:
  cmp    0x2c(%rsp),%al
  je     L51
L13:
  lea    (%r14,%r15,1),%rdi
  mov    %r13,%rsi
  mov    $0x1,%edx
  add    $0x1,%r13
  call   <memcpy@plt>
  add    $0x1,%r15
  cmp    (%rsp),%r13
  je     L58
L25:
  movzbl 0x0(%r13),%eax
  cmp    %bl,%al
  jne    L16
  add    $0x1,%r12
L51:
  lea    0x1(%rbp),%rax
  lea    0x2(%rbp),%rsi
  mov    %r14,%rdi
  mov    %rax,0x8(%rsp)
  call   <realloc@plt>
  mov    0x10(%rsp),%rsi
  mov    $0x1,%edx
  lea    (%rax,%r15,1),%rdi
  mov    %rax,%r14
  add    $0x1,%r15
  call   <memcpy@plt>
  mov    0x8(%rsp),%rbp
  jmp    L13
L58:
  mov    0x18(%rsp),%rax
  mov    %r14,(%rax)
  mov    0x20(%rsp),%rax
  mov    %rbp,(%rax)
  jmp    L2
```

assistant: ```c
unsigned long shardcache_byte_escape(char ch, char esc, char *buffer, unsigned long len, char **dest, unsigned long *newlen) {
  char *newbuf;
  unsigned long buflen;
  unsigned long i;
  unsigned long cnt;
  int escape;
  char *p;
  unsigned long off;
  if (len == 0)
    return 0;
  newbuf = (char *)malloc(len);
  if (!newbuf)
    return 0;
  buflen = len;
  p = buffer;
  off = 0;
  cnt = 0;
  for (i = 0; i < len; i++) {
    escape = 0;
    if (*p == ch)
      cnt++;
    if (*p == ch || *p == esc)
      escape = 1;
    if (escape) {
      buflen++;
      newbuf = (char *)realloc(newbuf, buflen + 1);
      memcpy(newbuf + off, &esc, 1);
      off++;
    }
    memcpy(newbuf + off, p, 1);
    p++;
    off++;
  }
  *dest = newbuf;
  *newlen = buflen;
  return cnt;
}
```