ylfeng/ReF-Decompile-dataset huggingface dataset:
user: What would the C source look like for the assembly code provided here:

```asm
<delete>:
  endbr64
  push   %rbp
  mov    %rdi,%rbp
  test   %rdi,%rdi
  je     L9
  call   <destroy@plt>
L9:
  mov    %rbp,%rdi
  pop    %rbp
  jmp    1060 <free@plt>
```

assistant: ```c
void delete (void *obj) {
  if (obj)
    destroy(obj);
  free(obj);
}
```
user: Converte this assembly snippet into its equivalent C code:

```asm
<delete>:
  endbr64
  push   %rbp
  mov    %rdi,%rbp
  test   %rdi,%rdi
  je     L6
  call   <destroy@plt>
L6:
  mov    %rbp,%rdi
  pop    %rbp
  jmp    1060 <free@plt>
```

assistant: ```c
void delete (void *obj) {
  if (obj)
    destroy(obj);
  free(obj);
}
```
user: Converte this assembly snippet into its equivalent C code:

```asm
<utf8_encode>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %edi,-0x4(%rbp)
  mov    %rsi,-0x10(%rbp)
  mov    %rdx,-0x18(%rbp)
  cmpl   $0x0,-0x4(%rbp)
  jns    L77
  mov    $0xffffffff,%eax
  jmp    L100
L77:
  cmpl   $0x7f,-0x4(%rbp)
  jg     L81
  mov    -0x4(%rbp),%eax
  mov    %eax,%edx
  mov    -0x10(%rbp),%rax
  mov    %dl,(%rax)
  mov    -0x18(%rbp),%rax
  movq   $0x1,(%rax)
  jmp    L40
L81:
  cmpl   $0x7ff,-0x4(%rbp)
  jg     L24
  mov    -0x4(%rbp),%eax
  sar    $0x6,%eax
  and    $0x1f,%eax
  sub    $0x40,%eax
  mov    %eax,%edx
  mov    -0x10(%rbp),%rax
  mov    %dl,(%rax)
  mov    -0x4(%rbp),%eax
  and    $0x3f,%eax
  lea    -0x80(%rax),%edx
  mov    -0x10(%rbp),%rax
  add    $0x1,%rax
  mov    %dl,(%rax)
  mov    -0x18(%rbp),%rax
  movq   $0x2,(%rax)
  jmp    L40
L24:
  cmpl   $0xffff,-0x4(%rbp)
  jg     L95
  mov    -0x4(%rbp),%eax
  sar    $0xc,%eax
  and    $0xf,%eax
  sub    $0x20,%eax
  mov    %eax,%edx
  mov    -0x10(%rbp),%rax
  mov    %dl,(%rax)
  mov    -0x4(%rbp),%eax
  sar    $0x6,%eax
  and    $0x3f,%eax
  lea    -0x80(%rax),%edx
  mov    -0x10(%rbp),%rax
  add    $0x1,%rax
  mov    %dl,(%rax)
  mov    -0x4(%rbp),%eax
  and    $0x3f,%eax
  lea    -0x80(%rax),%edx
  mov    -0x10(%rbp),%rax
  add    $0x2,%rax
  mov    %dl,(%rax)
  mov    -0x18(%rbp),%rax
  movq   $0x3,(%rax)
  jmp    L40
L95:
  cmpl   $0x10ffff,-0x4(%rbp)
  jg     L54
  mov    -0x4(%rbp),%eax
  sar    $0x12,%eax
  and    $0x7,%eax
  sub    $0x10,%eax
  mov    %eax,%edx
  mov    -0x10(%rbp),%rax
  mov    %dl,(%rax)
  mov    -0x4(%rbp),%eax
  sar    $0xc,%eax
  and    $0x3f,%eax
  lea    -0x80(%rax),%edx
  mov    -0x10(%rbp),%rax
  add    $0x1,%rax
  mov    %dl,(%rax)
  mov    -0x4(%rbp),%eax
  sar    $0x6,%eax
  and    $0x3f,%eax
  lea    -0x80(%rax),%edx
  mov    -0x10(%rbp),%rax
  add    $0x2,%rax
  mov    %dl,(%rax)
  mov    -0x4(%rbp),%eax
  and    $0x3f,%eax
  lea    -0x80(%rax),%edx
  mov    -0x10(%rbp),%rax
  add    $0x3,%rax
  mov    %dl,(%rax)
  mov    -0x18(%rbp),%rax
  movq   $0x4,(%rax)
  jmp    L40
L54:
  mov    $0xffffffff,%eax
  jmp    L100
L40:
  mov    $0x0,%eax
L100:
  pop    %rbp
  ret
```

assistant: ```c
int utf8_encode(int32_t codepoint, char *buffer, size_t *size) {
  if (codepoint < 0)
    return -1;
  else if (codepoint < 0x80) {
    buffer[0] = (char)codepoint;
    *size = 1;
  } else if (codepoint < 0x800) {
    buffer[0] = 0xC0 + ((codepoint & 0x7C0) >> 6);
    buffer[1] = 0x80 + ((codepoint & 0x03F));
    *size = 2;
  } else if (codepoint < 0x10000) {
    buffer[0] = 0xE0 + ((codepoint & 0xF000) >> 12);
    buffer[1] = 0x80 + ((codepoint & 0x0FC0) >> 6);
    buffer[2] = 0x80 + ((codepoint & 0x003F));
    *size = 3;
  } else if (codepoint <= 0x10FFFF) {
    buffer[0] = 0xF0 + ((codepoint & 0x1C0000) >> 18);
    buffer[1] = 0x80 + ((codepoint & 0x03F000) >> 12);
    buffer[2] = 0x80 + ((codepoint & 0x000FC0) >> 6);
    buffer[3] = 0x80 + ((codepoint & 0x00003F));
    *size = 4;
  } else
    return -1;
  return 0;
}
```
user: 请从给定的汇编指令推导出C源代码:

```asm
<utf8_encode>:
  endbr64
  mov    %edi,%eax
  test   %edi,%edi
  js     L34
  cmp    $0x7f,%edi
  jg     L22
  mov    %dil,(%rsi)
  movq   $0x1,(%rdx)
  mov    $0x0,%eax
  ret
L22:
  cmp    $0x7ff,%edi
  jg     L10
  mov    %edi,%ecx
  sar    $0x6,%ecx
  sub    $0x40,%ecx
  mov    %cl,(%rsi)
  and    $0x3f,%eax
  add    $0xffffff80,%eax
  mov    %al,0x1(%rsi)
  movq   $0x2,(%rdx)
  mov    $0x0,%eax
  ret
L10:
  cmp    $0xffff,%edi
  jg     L48
  mov    %edi,%ecx
  sar    $0xc,%ecx
  sub    $0x20,%ecx
  mov    %cl,(%rsi)
  mov    %edi,%ecx
  sar    $0x6,%ecx
  and    $0x3f,%ecx
  add    $0xffffff80,%ecx
  mov    %cl,0x1(%rsi)
  and    $0x3f,%eax
  add    $0xffffff80,%eax
  mov    %al,0x2(%rsi)
  movq   $0x3,(%rdx)
  mov    $0x0,%eax
  ret
L48:
  cmp    $0x10ffff,%edi
  jg     L11
  mov    %edi,%ecx
  sar    $0x12,%ecx
  sub    $0x10,%ecx
  mov    %cl,(%rsi)
  mov    %edi,%ecx
  sar    $0xc,%ecx
  and    $0x3f,%ecx
  add    $0xffffff80,%ecx
  mov    %cl,0x1(%rsi)
  mov    %edi,%ecx
  sar    $0x6,%ecx
  and    $0x3f,%ecx
  add    $0xffffff80,%ecx
  mov    %cl,0x2(%rsi)
  and    $0x3f,%eax
  add    $0xffffff80,%eax
  mov    %al,0x3(%rsi)
  movq   $0x4,(%rdx)
  mov    $0x0,%eax
  ret
L34:
  mov    $0xffffffff,%eax
  ret
L11:
  mov    $0xffffffff,%eax
  ret
```

assistant: ```c
int utf8_encode(int32_t codepoint, char *buffer, size_t *size) {
  if (codepoint < 0)
    return -1;
  else if (codepoint < 0x80) {
    buffer[0] = (char)codepoint;
    *size = 1;
  } else if (codepoint < 0x800) {
    buffer[0] = 0xC0 + ((codepoint & 0x7C0) >> 6);
    buffer[1] = 0x80 + ((codepoint & 0x03F));
    *size = 2;
  } else if (codepoint < 0x10000) {
    buffer[0] = 0xE0 + ((codepoint & 0xF000) >> 12);
    buffer[1] = 0x80 + ((codepoint & 0x0FC0) >> 6);
    buffer[2] = 0x80 + ((codepoint & 0x003F));
    *size = 3;
  } else if (codepoint <= 0x10FFFF) {
    buffer[0] = 0xF0 + ((codepoint & 0x1C0000) >> 18);
    buffer[1] = 0x80 + ((codepoint & 0x03F000) >> 12);
    buffer[2] = 0x80 + ((codepoint & 0x000FC0) >> 6);
    buffer[3] = 0x80 + ((codepoint & 0x00003F));
    *size = 4;
  } else
    return -1;
  return 0;
}
```
user: What would the C source look like for the assembly code provided here:

```asm
<utf8_encode>:
  endbr64
  mov    %edi,%eax
  test   %edi,%edi
  js     L26
  cmp    $0x7f,%edi
  jle    L10
  cmp    $0x7ff,%edi
  jg     L34
  mov    %edi,%ecx
  and    $0x3f,%eax
  sar    $0x6,%ecx
  add    $0xffffff80,%eax
  sub    $0x40,%ecx
  mov    %al,0x1(%rsi)
  xor    %eax,%eax
  mov    %cl,(%rsi)
  movq   $0x2,(%rdx)
  ret
  nopl   0x0(%rax,%rax,1)
L10:
  mov    %dil,(%rsi)
  xor    %eax,%eax
  movq   $0x1,(%rdx)
  ret
  nopl   (%rax)
L34:
  cmp    $0xffff,%edi
  jle    L22
  cmp    $0x10ffff,%edi
  jg     L26
  mov    %edi,%ecx
  and    $0x3f,%eax
  sar    $0x12,%ecx
  add    $0xffffff80,%eax
  sub    $0x10,%ecx
  mov    %al,0x3(%rsi)
  xor    %eax,%eax
  mov    %cl,(%rsi)
  mov    %edi,%ecx
  sar    $0xc,%ecx
  and    $0x3f,%ecx
  add    $0xffffff80,%ecx
  mov    %cl,0x1(%rsi)
  mov    %edi,%ecx
  sar    $0x6,%ecx
  and    $0x3f,%ecx
  add    $0xffffff80,%ecx
  mov    %cl,0x2(%rsi)
  movq   $0x4,(%rdx)
  ret
  nopl   0x0(%rax)
L22:
  mov    %edi,%ecx
  and    $0x3f,%eax
  sar    $0xc,%ecx
  add    $0xffffff80,%eax
  sub    $0x20,%ecx
  mov    %al,0x2(%rsi)
  xor    %eax,%eax
  mov    %cl,(%rsi)
  mov    %edi,%ecx
  sar    $0x6,%ecx
  and    $0x3f,%ecx
  add    $0xffffff80,%ecx
  mov    %cl,0x1(%rsi)
  movq   $0x3,(%rdx)
  ret
L26:
  mov    $0xffffffff,%eax
  ret
```

assistant: ```c
int utf8_encode(int32_t codepoint, char *buffer, size_t *size) {
  if (codepoint < 0)
    return -1;
  else if (codepoint < 0x80) {
    buffer[0] = (char)codepoint;
    *size = 1;
  } else if (codepoint < 0x800) {
    buffer[0] = 0xC0 + ((codepoint & 0x7C0) >> 6);
    buffer[1] = 0x80 + ((codepoint & 0x03F));
    *size = 2;
  } else if (codepoint < 0x10000) {
    buffer[0] = 0xE0 + ((codepoint & 0xF000) >> 12);
    buffer[1] = 0x80 + ((codepoint & 0x0FC0) >> 6);
    buffer[2] = 0x80 + ((codepoint & 0x003F));
    *size = 3;
  } else if (codepoint <= 0x10FFFF) {
    buffer[0] = 0xF0 + ((codepoint & 0x1C0000) >> 18);
    buffer[1] = 0x80 + ((codepoint & 0x03F000) >> 12);
    buffer[2] = 0x80 + ((codepoint & 0x000FC0) >> 6);
    buffer[3] = 0x80 + ((codepoint & 0x00003F));
    *size = 4;
  } else
    return -1;
  return 0;
}
```
user: 请将以下的汇编代码转换成C语言代码:

```asm
<utf8_encode>:
  endbr64
  mov    %edi,%eax
  test   %edi,%edi
  js     L41
  cmp    $0x7f,%edi
  jle    L12
  cmp    $0x7ff,%edi
  jg     L5
  mov    %edi,%ecx
  and    $0x3f,%eax
  sar    $0x6,%ecx
  add    $0xffffff80,%eax
  sub    $0x40,%ecx
  mov    %al,0x1(%rsi)
  xor    %eax,%eax
  mov    %cl,(%rsi)
  movq   $0x2,(%rdx)
  ret
  nopl   0x0(%rax,%rax,1)
L12:
  mov    %dil,(%rsi)
  xor    %eax,%eax
  movq   $0x1,(%rdx)
  ret
  nopl   (%rax)
L5:
  cmp    $0xffff,%edi
  jle    L31
  cmp    $0x10ffff,%edi
  jg     L41
  mov    %edi,%ecx
  and    $0x3f,%eax
  sar    $0x12,%ecx
  add    $0xffffff80,%eax
  sub    $0x10,%ecx
  mov    %al,0x3(%rsi)
  xor    %eax,%eax
  mov    %cl,(%rsi)
  mov    %edi,%ecx
  sar    $0xc,%ecx
  and    $0x3f,%ecx
  add    $0xffffff80,%ecx
  mov    %cl,0x1(%rsi)
  mov    %edi,%ecx
  sar    $0x6,%ecx
  and    $0x3f,%ecx
  add    $0xffffff80,%ecx
  mov    %cl,0x2(%rsi)
  movq   $0x4,(%rdx)
  ret
  nopl   0x0(%rax)
L31:
  mov    %edi,%ecx
  and    $0x3f,%eax
  sar    $0xc,%ecx
  add    $0xffffff80,%eax
  sub    $0x20,%ecx
  mov    %al,0x2(%rsi)
  xor    %eax,%eax
  mov    %cl,(%rsi)
  mov    %edi,%ecx
  sar    $0x6,%ecx
  and    $0x3f,%ecx
  add    $0xffffff80,%ecx
  mov    %cl,0x1(%rsi)
  movq   $0x3,(%rdx)
  ret
L41:
  mov    $0xffffffff,%eax
  ret
```

assistant: ```c
int utf8_encode(int32_t codepoint, char *buffer, size_t *size) {
  if (codepoint < 0)
    return -1;
  else if (codepoint < 0x80) {
    buffer[0] = (char)codepoint;
    *size = 1;
  } else if (codepoint < 0x800) {
    buffer[0] = 0xC0 + ((codepoint & 0x7C0) >> 6);
    buffer[1] = 0x80 + ((codepoint & 0x03F));
    *size = 2;
  } else if (codepoint < 0x10000) {
    buffer[0] = 0xE0 + ((codepoint & 0xF000) >> 12);
    buffer[1] = 0x80 + ((codepoint & 0x0FC0) >> 6);
    buffer[2] = 0x80 + ((codepoint & 0x003F));
    *size = 3;
  } else if (codepoint <= 0x10FFFF) {
    buffer[0] = 0xF0 + ((codepoint & 0x1C0000) >> 18);
    buffer[1] = 0x80 + ((codepoint & 0x03F000) >> 12);
    buffer[2] = 0x80 + ((codepoint & 0x000FC0) >> 6);
    buffer[3] = 0x80 + ((codepoint & 0x00003F));
    *size = 4;
  } else
    return -1;
  return 0;
}
```
user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<foo>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x20,%rsp
  mov    %edi,-0x14(%rbp)
  mov    %esi,-0x18(%rbp)
  movl   $0x0,-0x8(%rbp)
  jmp    L21
L7:
  cmpl   $0x0,-0x18(%rbp)
  jns    L9
  mov    -0x14(%rbp),%eax
  add    $0x1,%eax
  mov    %eax,-0x4(%rbp)
  jmp    L16
L9:
  mov    -0x18(%rbp),%eax
  sub    -0x14(%rbp),%eax
  mov    %eax,-0x4(%rbp)
L16:
  mov    -0x4(%rbp),%eax
  mov    %eax,%edi
  call   <bar@plt>
  addl   $0x1,-0x8(%rbp)
L21:
  mov    -0x14(%rbp),%eax
  cmp    %eax,-0x8(%rbp)
  jb     L7
  nop
  nop
  leave
  ret
```

assistant: ```c
void foo(int n, int m) {
  unsigned i;
  for (i = 0; i < n; ++i) {
    int x;
    if (m < 0)
      x = 1 + n;
    else
      x = m - n;
    bar(x);
  }
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<foo>:
  endbr64
  test   %edi,%edi
  je     L3
  push   %r12
  push   %rbp
  push   %rbx
  mov    %edi,%ebp
  mov    %esi,%r12d
  sub    %edi,%r12d
  lea    0x1(%rdi),%eax
  test   %esi,%esi
  cmovs  %eax,%r12d
  mov    $0x0,%ebx
L2:
  mov    %r12d,%edi
  call   <bar@plt>
  add    $0x1,%ebx
  cmp    %ebp,%ebx
  jne    L2
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L3:
  ret
```

assistant: ```c
void foo(int n, int m) {
  unsigned i;
  for (i = 0; i < n; ++i) {
    int x;
    if (m < 0)
      x = 1 + n;
    else
      x = m - n;
    bar(x);
  }
}
```
user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<foo>:
  endbr64
  test   %edi,%edi
  je     L18
  push   %r12
  mov    %esi,%r12d
  lea    0x1(%rdi),%eax
  sub    %edi,%r12d
  test   %esi,%esi
  push   %rbp
  mov    %edi,%ebp
  push   %rbx
  cmovs  %eax,%r12d
  xor    %ebx,%ebx
  nop
L16:
  mov    %r12d,%edi
  add    $0x1,%ebx
  call   <bar@plt>
  cmp    %ebp,%ebx
  jne    L16
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
  nopl   0x0(%rax)
L18:
  ret
```

assistant: ```c
void foo(int n, int m) {
  unsigned i;
  for (i = 0; i < n; ++i) {
    int x;
    if (m < 0)
      x = 1 + n;
    else
      x = m - n;
    bar(x);
  }
}
```
user: 请将这段汇编代码片段转换成等效的C代码:

```asm
<foo>:
  endbr64
  test   %edi,%edi
  je     L13
  push   %r12
  mov    %esi,%r12d
  lea    0x1(%rdi),%eax
  sub    %edi,%r12d
  test   %esi,%esi
  push   %rbp
  mov    %edi,%ebp
  push   %rbx
  cmovs  %eax,%r12d
  xor    %ebx,%ebx
  nop
L4:
  mov    %r12d,%edi
  add    $0x1,%ebx
  call   <bar@plt>
  cmp    %ebp,%ebx
  jne    L4
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
  nopl   0x0(%rax)
L13:
  ret
```

assistant: ```c
void foo(int n, int m) {
  unsigned i;
  for (i = 0; i < n; ++i) {
    int x;
    if (m < 0)
      x = 1 + n;
    else
      x = m - n;
    bar(x);
  }
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<buffer_copy>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %rdi,-0x18(%rbp)
  mov    %rsi,-0x20(%rbp)
  mov    %rdx,-0x28(%rbp)
  mov    -0x18(%rbp),%rax
  mov    %rax,-0x8(%rbp)
  mov    -0x28(%rbp),%rdx
  mov    -0x20(%rbp),%rsi
  mov    -0x8(%rbp),%rax
  mov    $0x0,%ecx
  mov    %rax,%rdi
  call   <buffer_copy_logic@plt>
  leave
  ret
```

assistant: ```c
size_t buffer_copy(void *buf, void *data, size_t length) {
  struct Buffer *buffer = buf;
  return buffer_copy_logic(buffer, data, length, 0);
}
```
user: 下面的汇编指令对应的C源代码是什么:

```asm
<buffer_copy>:
  endbr64
  sub    $0x8,%rsp
  mov    $0x0,%ecx
  call   <buffer_copy_logic@plt>
  add    $0x8,%rsp
  ret
```

assistant: ```c
size_t buffer_copy(void *buf, void *data, size_t length) {
  struct Buffer *buffer = buf;
  return buffer_copy_logic(buffer, data, length, 0);
}
```
user: What is the c source code of the assembly code below?

```asm
<buffer_copy>:
  endbr64
  xor    %ecx,%ecx
  jmp    1050 <buffer_copy_logic@plt>
```

assistant: ```c
size_t buffer_copy(void *buf, void *data, size_t length) {
  struct Buffer *buffer = buf;
  return buffer_copy_logic(buffer, data, length, 0);
}
```
user: What would the C source look like for the assembly code provided here?

```asm
<buffer_copy>:
  endbr64
  xor    %ecx,%ecx
  jmp    1050 <buffer_copy_logic@plt>
```

assistant: ```c
size_t buffer_copy(void *buf, void *data, size_t length) {
  struct Buffer *buffer = buf;
  return buffer_copy_logic(buffer, data, length, 0);
}
```
user: 请将以下的汇编代码转换成C语言代码：

```asm
<prn_printable>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %rdi,-0x28(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  lea    -0x20(%rbp),%rax
  mov    $0x4,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  movl   $0x0,-0x14(%rbp)
  jmp    L19
L99:
  cmpq   $0xffffffffffffffff,-0x10(%rbp)
  jne    L108
  mov    $0x3f,%edi
  call   <putchar@plt>
  addq   $0x1,-0x28(%rbp)
  addl   $0x1,-0x14(%rbp)
  lea    -0x20(%rbp),%rax
  mov    $0x4,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  jmp    L19
L108:
  cmpq   $0xfffffffffffffffe,-0x10(%rbp)
  jne    L11
  mov    $0x3f,%edi
  call   <putchar@plt>
  addl   $0x1,-0x14(%rbp)
  jmp    L39
L11:
  mov    -0x1c(%rbp),%eax
  mov    %eax,%edi
  call   <iswprint@plt>
  test   %eax,%eax
  jne    L17
  mov    $0x3f,%edi
  call   <putchar@plt>
  mov    -0x10(%rbp),%rax
  add    %rax,-0x28(%rbp)
  addl   $0x1,-0x14(%rbp)
  jmp    L19
L17:
  movl   $0x0,-0x18(%rbp)
  jmp    L65
L96:
  mov    -0x18(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  mov    %eax,%edi
  call   <putchar@plt>
  addl   $0x1,-0x18(%rbp)
L65:
  mov    -0x10(%rbp),%rax
  cmp    %eax,-0x18(%rbp)
  jl     L96
  mov    -0x10(%rbp),%rax
  add    %rax,-0x28(%rbp)
  mov    -0x1c(%rbp),%eax
  mov    %eax,%edi
  call   <wcwidth@plt>
  mov    %eax,%edx
  mov    -0x14(%rbp),%eax
  add    %edx,%eax
  mov    %eax,-0x14(%rbp)
L19:
  mov    D5(%rip),%rax
  mov    (%rax),%edx
  lea    -0x20(%rbp),%rcx
  mov    -0x28(%rbp),%rsi
  lea    -0x1c(%rbp),%rax
  mov    %rax,%rdi
  call   <mbrtowc@plt>
  mov    %rax,-0x10(%rbp)
  cmpq   $0x0,-0x10(%rbp)
  jne    L99
L39:
  mov    -0x14(%rbp),%eax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L100
  call   <__stack_chk_fail@plt>
L100:
  leave
  ret
```

assistant: ```c
int prn_printable(const char *s) {
  mbstate_t mbs;
  wchar_t wc;
  int i, n;
  size_t clen;
  memset(&mbs, 0, sizeof(mbs));
  n = 0;
  while ((clen = mbrtowc(&wc, s, MB_LEN_MAX, &mbs)) != 0) {
    if (clen == (size_t)-1) {
      putchar('?');
      s++;
      n++;
      memset(&mbs, 0, sizeof(mbs));
      continue;
    }
    if (clen == (size_t)-2) {
      putchar('?');
      n++;
      break;
    }
    if (!iswprint(wc)) {
      putchar('?');
      s += clen;
      n++;
      continue;
    }
    for (i = 0; i < (int)clen; i++)
      putchar((unsigned char)s[i]);
    s += clen;
    n += wcwidth(wc);
  }
  return (n);
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<prn_printable>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%r13
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  mov    %rsp,%rdi
  mov    $0x4,%edx
  mov    $0x0,%esi
  call   <memset@plt>
  mov    $0x0,%r14d
  mov    %rsp,%r15
  jmp    L46
L72:
  mov    $0x3f,%edi
  call   <putchar@plt>
  add    $0x1,%r13
  add    $0x1,%r14d
  mov    $0x4,%edx
  mov    $0x0,%esi
  mov    %r15,%rdi
  call   <memset@plt>
  jmp    L46
L0:
  mov    $0x3f,%edi
  call   <putchar@plt>
  add    $0x1,%r14d
L24:
  mov    0x8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L53
  mov    %r14d,%eax
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L82:
  mov    $0x3f,%edi
  call   <putchar@plt>
  add    %rbp,%r13
  add    $0x1,%r14d
  jmp    L46
L52:
  add    %rbp,%r13
  mov    0x4(%rsp),%edi
  call   <wcwidth@plt>
  add    %eax,%r14d
L46:
  lea    0x4(%rsp),%rdi
  mov    %r15,%rcx
  mov    D4(%rip),%rax
  mov    (%rax),%edx
  mov    %r13,%rsi
  call   <mbrtowc@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L24
  cmp    $0xffffffffffffffff,%rbp
  je     L72
  cmp    $0xfffffffffffffffe,%rbp
  je     L0
  mov    0x4(%rsp),%edi
  call   <iswprint@plt>
  test   %eax,%eax
  je     L82
  test   %ebp,%ebp
  jle    L52
  mov    %r13,%rbx
  lea    -0x1(%rbp),%eax
  lea    0x1(%r13,%rax,1),%r12
L59:
  movzbl (%rbx),%edi
  call   <putchar@plt>
  add    $0x1,%rbx
  cmp    %r12,%rbx
  jne    L59
  jmp    L52
L53:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int prn_printable(const char *s) {
  mbstate_t mbs;
  wchar_t wc;
  int i, n;
  size_t clen;
  memset(&mbs, 0, sizeof(mbs));
  n = 0;
  while ((clen = mbrtowc(&wc, s, MB_LEN_MAX, &mbs)) != 0) {
    if (clen == (size_t)-1) {
      putchar('?');
      s++;
      n++;
      memset(&mbs, 0, sizeof(mbs));
      continue;
    }
    if (clen == (size_t)-2) {
      putchar('?');
      n++;
      break;
    }
    if (!iswprint(wc)) {
      putchar('?');
      s += clen;
      n++;
      continue;
    }
    for (i = 0; i < (int)clen; i++)
      putchar((unsigned char)s[i]);
    s += clen;
    n += wcwidth(wc);
  }
  return (n);
}
```
user: What is the c source code of the assembly code below?

```asm
<prn_printable>:
  endbr64
  push   %r15
  mov    $0x4,%edx
  xor    %esi,%esi
  push   %r14
  push   %r13
  push   %r12
  xor    %r12d,%r12d
  push   %rbp
  push   %rbx
  mov    %rdi,%rbx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  lea    0x10(%rsp),%r13
  lea    0x14(%rsp),%r14
  mov    %r13,%rdi
  call   <memset@plt>
  nopl   0x0(%rax)
L41:
  mov    D6(%rip),%rax
  mov    %r13,%rcx
  mov    %rbx,%rsi
  mov    %r14,%rdi
  mov    (%rax),%edx
  call   <mbrtowc@plt>
  mov    %rax,%r15
  test   %rax,%rax
  je     L70
  cmp    $0xffffffffffffffff,%r15
  je     L53
  cmp    $0xfffffffffffffffe,%r15
  je     L19
  mov    0x14(%rsp),%edi
  mov    %edi,0xc(%rsp)
  call   <iswprint@plt>
  lea    (%rbx,%r15,1),%rcx
  mov    %rcx,(%rsp)
  test   %eax,%eax
  je     L38
  test   %r15d,%r15d
  mov    0xc(%rsp),%edi
  jle    L17
  lea    -0x1(%r15),%eax
  mov    %rbx,%rbp
  lea    0x1(%rbx,%rax,1),%rbx
  nopl   (%rax)
L22:
  movzbl 0x0(%rbp),%edi
  add    $0x1,%rbp
  call   <putchar@plt>
  cmp    %rbx,%rbp
  jne    L22
  mov    0x14(%rsp),%edi
L17:
  call   <wcwidth@plt>
  mov    (%rsp),%rbx
  add    %eax,%r12d
  jmp    L41
  nopw   0x0(%rax,%rax,1)
L38:
  mov    $0x3f,%edi
  add    $0x1,%r12d
  call   <putchar@plt>
  mov    (%rsp),%rbx
  jmp    L41
  nopw   0x0(%rax,%rax,1)
L53:
  mov    $0x3f,%edi
  add    $0x1,%rbx
  add    $0x1,%r12d
  call   <putchar@plt>
  mov    $0x4,%edx
  xor    %esi,%esi
  mov    %r13,%rdi
  call   <memset@plt>
  jmp    L41
  cs nopw 0x0(%rax,%rax,1)
L19:
  mov    $0x3f,%edi
  add    $0x1,%r12d
  call   <putchar@plt>
L70:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L59
  add    $0x28,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L59:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int prn_printable(const char *s) {
  mbstate_t mbs;
  wchar_t wc;
  int i, n;
  size_t clen;
  memset(&mbs, 0, sizeof(mbs));
  n = 0;
  while ((clen = mbrtowc(&wc, s, MB_LEN_MAX, &mbs)) != 0) {
    if (clen == (size_t)-1) {
      putchar('?');
      s++;
      n++;
      memset(&mbs, 0, sizeof(mbs));
      continue;
    }
    if (clen == (size_t)-2) {
      putchar('?');
      n++;
      break;
    }
    if (!iswprint(wc)) {
      putchar('?');
      s += clen;
      n++;
      continue;
    }
    for (i = 0; i < (int)clen; i++)
      putchar((unsigned char)s[i]);
    s += clen;
    n += wcwidth(wc);
  }
  return (n);
}
```