ylfeng/ReF-Decompile-dataset huggingface dataset:
user: 请显示与下面列出的汇编代码相匹配的C语言实现:

```asm
<linexp>:
  endbr64
  push   %rbx
  movq   %xmm3,%rbx
  comisd %xmm0,%xmm1
  jae    L19
  movapd %xmm4,%xmm3
  comisd %xmm2,%xmm0
  jb     L10
L19:
  movapd %xmm3,%xmm0
  pop    %rbx
  ret
L10:
  subsd  %xmm1,%xmm0
  subsd  %xmm1,%xmm2
  movq   %rbx,%xmm5
  divsd  %xmm5,%xmm4
  movapd %xmm0,%xmm1
  divsd  %xmm2,%xmm1
  movapd %xmm4,%xmm0
  call   <pow@plt>
  movq   %rbx,%xmm3
  mulsd  %xmm0,%xmm3
  jmp    L19
```

assistant: ```c
double linexp(double x, double a, double b, double c, double d) {
  if (x <= a)
    return c;
  if (x >= b)
    return d;
  return pow(d / c, (x - a) / (b - a)) * c;
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<linexp>:
  endbr64
  comisd %xmm0,%xmm1
  movapd %xmm0,%xmm5
  jae    L3
  comisd %xmm2,%xmm5
  movapd %xmm4,%xmm0
  jb     L6
  ret
  nopl   0x0(%rax)
L6:
  subsd  %xmm1,%xmm2
  subsd  %xmm1,%xmm5
  divsd  %xmm3,%xmm0
  sub    $0x18,%rsp
  movsd  %xmm3,0x8(%rsp)
  divsd  %xmm2,%xmm5
  movapd %xmm5,%xmm1
  call   <pow@plt>
  movsd  0x8(%rsp),%xmm3
  add    $0x18,%rsp
  mulsd  %xmm3,%xmm0
  ret
  nopw   0x0(%rax,%rax,1)
L3:
  movapd %xmm3,%xmm0
  ret
```

assistant: ```c
double linexp(double x, double a, double b, double c, double d) {
  if (x <= a)
    return c;
  if (x >= b)
    return d;
  return pow(d / c, (x - a) / (b - a)) * c;
}
```
user: 提供的汇编代码用C语言表示会是什么样子:

```asm
<linexp>:
  endbr64
  comisd %xmm0,%xmm1
  movapd %xmm0,%xmm5
  jae    L3
  comisd %xmm2,%xmm5
  movapd %xmm4,%xmm0
  jb     L9
  ret
  nopl   0x0(%rax)
L9:
  subsd  %xmm1,%xmm2
  subsd  %xmm1,%xmm5
  divsd  %xmm3,%xmm0
  sub    $0x18,%rsp
  movsd  %xmm3,0x8(%rsp)
  divsd  %xmm2,%xmm5
  movapd %xmm5,%xmm1
  call   <pow@plt>
  movsd  0x8(%rsp),%xmm3
  add    $0x18,%rsp
  mulsd  %xmm3,%xmm0
  ret
  nopw   0x0(%rax,%rax,1)
L3:
  movapd %xmm3,%xmm0
  ret
```

assistant: ```c
double linexp(double x, double a, double b, double c, double d) {
  if (x <= a)
    return c;
  if (x >= b)
    return d;
  return pow(d / c, (x - a) / (b - a)) * c;
}
```
user: 这段汇编代码用C语言表示是什么样的?

```asm
<quicksort>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x20,%rsp
  mov    %rdi,-0x18(%rbp)
  mov    %esi,-0x1c(%rbp)
  mov    %edx,-0x20(%rbp)
  mov    -0x1c(%rbp),%eax
  cmp    -0x20(%rbp),%eax
  jge    L0
  mov    -0x20(%rbp),%edx
  mov    -0x1c(%rbp),%ecx
  mov    -0x18(%rbp),%rax
  mov    %ecx,%esi
  mov    %rax,%rdi
  call   <partition@plt>
  mov    %eax,-0x4(%rbp)
  mov    -0x4(%rbp),%eax
  lea    -0x1(%rax),%edx
  mov    -0x1c(%rbp),%ecx
  mov    -0x18(%rbp),%rax
  mov    %ecx,%esi
  mov    %rax,%rdi
  call   <quicksort>
  mov    -0x4(%rbp),%eax
  lea    0x1(%rax),%ecx
  mov    -0x20(%rbp),%edx
  mov    -0x18(%rbp),%rax
  mov    %ecx,%esi
  mov    %rax,%rdi
  call   <quicksort>
  jmp    L1
L0:
  nop
L1:
  leave
  ret
```

assistant: ```c
void quicksort(int *l, int low, int high) {
  if (low >= high)
    return;
  int middle;
  middle = partition(l, low, high);
  quicksort(l, low, middle - 1);
  quicksort(l, middle + 1, high);
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<quicksort>:
  endbr64
  cmp    %edx,%esi
  jl     L5
  ret
L5:
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x8,%rsp
  mov    %rdi,%r12
  mov    %esi,%r13d
  mov    %edx,%ebx
  call   <partition@plt>
  mov    %eax,%ebp
  lea    -0x1(%rax),%edx
  mov    %r13d,%esi
  mov    %r12,%rdi
  call   <quicksort>
  lea    0x1(%rbp),%esi
  mov    %ebx,%edx
  mov    %r12,%rdi
  call   <quicksort>
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
```

assistant: ```c
void quicksort(int *l, int low, int high) {
  if (low >= high)
    return;
  int middle;
  middle = partition(l, low, high);
  quicksort(l, low, middle - 1);
  quicksort(l, middle + 1, high);
}
```
user: Converte this assembly snippet into its equivalent C code:

```asm
<copyStringN>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %rdi,-0x18(%rbp)
  mov    %rsi,-0x20(%rbp)
  mov    %edx,-0x24(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  je     L43
  cmpq   $0x0,-0x20(%rbp)
  jne    L63
L43:
  mov    $0xffffffff,%eax
  jmp    L37
L63:
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cmp    %eax,-0x24(%rbp)
  jle    L31
  mov    $0xfffffffe,%eax
  jmp    L37
L31:
  movl   $0x0,-0x4(%rbp)
  jmp    L3
L22:
  mov    -0x18(%rbp),%rdx
  lea    0x1(%rdx),%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x20(%rbp),%rax
  lea    0x1(%rax),%rcx
  mov    %rcx,-0x20(%rbp)
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
  addl   $0x1,-0x4(%rbp)
L3:
  mov    -0x4(%rbp),%eax
  cmp    -0x24(%rbp),%eax
  jl     L22
  mov    -0x20(%rbp),%rax
  movb   $0x0,(%rax)
  mov    $0x0,%eax
L37:
  leave
  ret
```

assistant: ```c
int copyStringN(char *str1, char *str2, int n) {
  if (!str1 || !str2) {
    return -1;
  }
  int i;
  if (n > strlen(str1)) {
    return -2;
  }
  for (i = 0; i < n; i++) {
    *str2++ = *str1++;
  }
  *str2 = '\0';
  return 0;
}
```
user: 请从给定的汇编指令推导出C源代码：

```asm
<copyStringN>:
  endbr64
  test   %rdi,%rdi
  je     L52
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdi,%rbp
  mov    %rsi,%rbx
  mov    %edx,%r12d
  test   %rsi,%rsi
  je     L51
  call   <strlen@plt>
  cmp    %r12d,%eax
  jl     L1
  test   %r12d,%r12d
  jle    L68
  lea    -0x1(%r12),%ecx
  lea    0x1(%rcx),%rsi
  mov    $0x0,%eax
L23:
  movzbl 0x0(%rbp,%rax,1),%edx
  mov    %dl,(%rbx,%rax,1)
  mov    %rax,%rdx
  add    $0x1,%rax
  cmp    %rcx,%rdx
  jne    L23
  add    %rsi,%rbx
L68:
  movb   $0x0,(%rbx)
  mov    $0x0,%eax
L35:
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L51:
  mov    $0xffffffff,%eax
  jmp    L35
L1:
  mov    $0xfffffffe,%eax
  jmp    L35
L52:
  mov    $0xffffffff,%eax
  ret
```

assistant: ```c
int copyStringN(char *str1, char *str2, int n) {
  if (!str1 || !str2) {
    return -1;
  }
  int i;
  if (n > strlen(str1)) {
    return -2;
  }
  for (i = 0; i < n; i++) {
    *str2++ = *str1++;
  }
  *str2 = '\0';
  return 0;
}
```
user: 请将以下的汇编代码转换成C语言代码：

```asm
<copyStringN>:
  endbr64
  test   %rdi,%rdi
  je     L35
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rsi,%rbx
  test   %rsi,%rsi
  je     L18
  mov    %edx,%ebp
  mov    %rdi,%r12
  call   <strlen@plt>
  cmp    %ebp,%eax
  jl     L39
  test   %ebp,%ebp
  jle    L29
  movslq %ebp,%rdx
  xor    %eax,%eax
  nopl   0x0(%rax)
L58:
  movzbl (%r12,%rax,1),%ecx
  mov    %cl,(%rbx,%rax,1)
  add    $0x1,%rax
  cmp    %rdx,%rax
  jne    L58
  add    %rax,%rbx
L29:
  movb   $0x0,(%rbx)
  xor    %eax,%eax
L34:
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L18:
  mov    $0xffffffff,%eax
  jmp    L34
L39:
  mov    $0xfffffffe,%eax
  jmp    L34
L35:
  or     $0xffffffff,%eax
  ret
```

assistant: ```c
int copyStringN(char *str1, char *str2, int n) {
  if (!str1 || !str2) {
    return -1;
  }
  int i;
  if (n > strlen(str1)) {
    return -2;
  }
  for (i = 0; i < n; i++) {
    *str2++ = *str1++;
  }
  *str2 = '\0';
  return 0;
}
```
user: 请从给定的汇编指令推导出C源代码：

```asm
<copyStringN>:
  endbr64
  test   %rdi,%rdi
  je     L208
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rsi,%rbx
  test   %rsi,%rsi
  je     L178
  mov    %edx,%ebp
  mov    %rdi,%r12
  call   <strlen@plt>
  cmp    %ebp,%eax
  jl     L75
  test   %ebp,%ebp
  jle    L97
  lea    0x1(%r12),%rcx
  mov    %rbx,%rdx
  lea    -0x1(%rbp),%eax
  sub    %rcx,%rdx
  cmp    $0xe,%rdx
  jbe    L210
  cmp    $0x6,%eax
  jbe    L210
  cmp    $0xe,%eax
  jbe    L172
  mov    %ebp,%edx
  xor    %eax,%eax
  shr    $0x4,%edx
  shl    $0x4,%rdx
  nopl   0x0(%rax)
L9:
  movdqu (%r12,%rax,1),%xmm0
  movups %xmm0,(%rbx,%rax,1)
  add    $0x10,%rax
  cmp    %rax,%rdx
  jne    L9
  mov    %ebp,%eax
  mov    %ebp,%edx
  and    $0xfffffff0,%eax
  mov    %eax,%ecx
  lea    (%r12,%rcx,1),%r8
  lea    (%rbx,%rcx,1),%rdi
  cmp    %eax,%ebp
  je     L40
  mov    %ebp,%esi
  sub    %eax,%esi
  lea    -0x1(%rsi),%edx
  cmp    $0x6,%edx
  jbe    L48
L77:
  mov    (%r12,%rcx,1),%rdx
  mov    %rdx,(%rbx,%rcx,1)
  mov    %esi,%ecx
  and    $0xfffffff8,%ecx
  mov    %ecx,%edx
  add    %ecx,%eax
  add    %rdx,%r8
  add    %rdx,%rdi
  mov    %ebp,%edx
  cmp    %ecx,%esi
  je     L40
L48:
  movzbl (%r8),%edx
  lea    0x1(%rax),%ecx
  mov    %dl,(%rdi)
  mov    %ebp,%edx
  cmp    %ecx,%ebp
  jle    L40
  movzbl 0x1(%r8),%ecx
  mov    %cl,0x1(%rdi)
  lea    0x2(%rax),%ecx
  cmp    %ecx,%ebp
  jle    L40
  movzbl 0x2(%r8),%ecx
  mov    %cl,0x2(%rdi)
  lea    0x3(%rax),%ecx
  cmp    %ecx,%ebp
  jle    L40
  movzbl 0x3(%r8),%ecx
  mov    %cl,0x3(%rdi)
  lea    0x4(%rax),%ecx
  cmp    %ecx,%ebp
  jle    L40
  movzbl 0x4(%r8),%ecx
  mov    %cl,0x4(%rdi)
  lea    0x5(%rax),%ecx
  cmp    %ecx,%ebp
  jle    L40
  movzbl 0x5(%r8),%ecx
  add    $0x6,%eax
  mov    %cl,0x5(%rdi)
  cmp    %eax,%ebp
  jle    L40
  movzbl 0x6(%r8),%eax
  mov    %al,0x6(%rdi)
L40:
  add    %rdx,%rbx
L97:
  movb   $0x0,(%rbx)
  xor    %eax,%eax
L127:
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
  nopl   0x0(%rax)
L210:
  mov    %ebp,%edx
  xor    %eax,%eax
  nopl   0x0(%rax)
L68:
  movzbl (%r12,%rax,1),%ecx
  mov    %cl,(%rbx,%rax,1)
  add    $0x1,%rax
  cmp    %rdx,%rax
  jne    L68
  jmp    L40
L172:
  mov    %ebp,%esi
  mov    %rbx,%rdi
  mov    %r12,%r8
  xor    %eax,%eax
  xor    %ecx,%ecx
  jmp    L77
L178:
  mov    $0xffffffff,%eax
  jmp    L127
L75:
  mov    $0xfffffffe,%eax
  jmp    L127
L208:
  or     $0xffffffff,%eax
  ret
```

assistant: ```c
int copyStringN(char *str1, char *str2, int n) {
  if (!str1 || !str2) {
    return -1;
  }
  int i;
  if (n > strlen(str1)) {
    return -2;
  }
  for (i = 0; i < n; i++) {
    *str2++ = *str1++;
  }
  *str2 = '\0';
  return 0;
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<find_file>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %rdi,-0x18(%rbp)
  mov    %rsi,-0x20(%rbp)
  mov    %rdx,-0x28(%rbp)
  mov    %rcx,-0x30(%rbp)
  movl   $0x0,-0x8(%rbp)
  jmp    L23
L46:
  mov    -0x8(%rbp),%eax
  cltq
  shl    $0x9,%rax
  mov    %rax,%rdx
  mov    D4(%rip),%rax
  lea    (%rdx,%rax,1),%rdi
  mov    -0x30(%rbp),%rcx
  mov    -0x28(%rbp),%rdx
  mov    -0x20(%rbp),%rsi
  mov    -0x18(%rbp),%rax
  mov    %rcx,%r8
  mov    %rdx,%rcx
  mov    %rdi,%rdx
  mov    %rax,%rdi
  call   <find_file_helper@plt>
  mov    %eax,-0x4(%rbp)
  cmpl   $0x2,-0x4(%rbp)
  je     L33
  mov    -0x4(%rbp),%eax
  jmp    L11
L33:
  addl   $0x1,-0x8(%rbp)
L23:
  cmpl   $0x1f,-0x8(%rbp)
  jg     L32
  mov    D4(%rip),%rdx
  mov    -0x8(%rbp),%eax
  cltq
  shl    $0x9,%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L46
L32:
  mov    $0x2,%eax
L11:
  leave
  ret
```

assistant: ```c
int find_file(char *includepath, char *origin, char *actualpath, char *cwd) {
  int i;
  int success;
  extern char include_folders[32][512];
  for (i = 0; i < 32 && include_folders[i][0] != 0; i++) {
    success = find_file_helper(includepath, origin, include_folders[i], actualpath, cwd);
    if (success != 2)
      return success;
  }
  return 2;
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<find_file>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x8,%rsp
  mov    %rdi,%r14
  mov    %rsi,%r13
  mov    %rdx,%r12
  mov    %rcx,%rbp
  mov    D0(%rip),%rbx
  lea    0x4000(%rbx),%r15
L22:
  cmpb   $0x0,(%rbx)
  je     L3
  mov    %rbp,%r8
  mov    %r12,%rcx
  mov    %rbx,%rdx
  mov    %r13,%rsi
  mov    %r14,%rdi
  call   <find_file_helper@plt>
  cmp    $0x2,%eax
  jne    L30
  add    $0x200,%rbx
  cmp    %r15,%rbx
  jne    L22
  jmp    L30
L3:
  mov    $0x2,%eax
L30:
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

assistant: ```c
int find_file(char *includepath, char *origin, char *actualpath, char *cwd) {
  int i;
  int success;
  extern char include_folders[32][512];
  for (i = 0; i < 32 && include_folders[i][0] != 0; i++) {
    success = find_file_helper(includepath, origin, include_folders[i], actualpath, cwd);
    if (success != 2)
      return success;
  }
  return 2;
}
```
user: 请显示与下面列出的汇编代码相匹配的C语言实现:

```asm
<find_file>:
  endbr64
  push   %r15
  mov    %rcx,%r15
  push   %r14
  push   %r13
  mov    %rdi,%r13
  push   %r12
  mov    %rsi,%r12
  push   %rbp
  mov    %rdx,%rbp
  push   %rbx
  sub    $0x8,%rsp
  mov    D8(%rip),%rbx
  lea    0x4000(%rbx),%r14
  jmp    L13
  xchg   %ax,%ax
L29:
  mov    %r15,%r8
  mov    %rbp,%rcx
  mov    %rbx,%rdx
  mov    %r12,%rsi
  mov    %r13,%rdi
  call   <find_file_helper@plt>
  cmp    $0x2,%eax
  jne    L8
  add    $0x200,%rbx
  cmp    %r14,%rbx
  je     L37
L13:
  cmpb   $0x0,(%rbx)
  jne    L29
L37:
  mov    $0x2,%eax
L8:
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

assistant: ```c
int find_file(char *includepath, char *origin, char *actualpath, char *cwd) {
  int i;
  int success;
  extern char include_folders[32][512];
  for (i = 0; i < 32 && include_folders[i][0] != 0; i++) {
    success = find_file_helper(includepath, origin, include_folders[i], actualpath, cwd);
    if (success != 2)
      return success;
  }
  return 2;
}
```
user: Converte this assembly snippet into its equivalent C code:

```asm
<find_file>:
  endbr64
  push   %r15
  mov    %rcx,%r15
  push   %r14
  push   %r13
  mov    %rdi,%r13
  push   %r12
  mov    %rsi,%r12
  push   %rbp
  mov    %rdx,%rbp
  push   %rbx
  sub    $0x8,%rsp
  mov    D5(%rip),%rbx
  lea    0x4000(%rbx),%r14
  jmp    L37
  xchg   %ax,%ax
L10:
  mov    %r15,%r8
  mov    %rbp,%rcx
  mov    %rbx,%rdx
  mov    %r12,%rsi
  mov    %r13,%rdi
  call   <find_file_helper@plt>
  cmp    $0x2,%eax
  jne    L28
  add    $0x200,%rbx
  cmp    %r14,%rbx
  je     L23
L37:
  cmpb   $0x0,(%rbx)
  jne    L10
L23:
  mov    $0x2,%eax
L28:
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

assistant: ```c
int find_file(char *includepath, char *origin, char *actualpath, char *cwd) {
  int i;
  int success;
  extern char include_folders[32][512];
  for (i = 0; i < 32 && include_folders[i][0] != 0; i++) {
    success = find_file_helper(includepath, origin, include_folders[i], actualpath, cwd);
    if (success != 2)
      return success;
  }
  return 2;
}
```
user: What would the C source look like for the assembly code provided here:

```asm
<safe_write>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %edi,-0x14(%rbp)
  mov    %rsi,-0x20(%rbp)
  mov    %rdx,-0x28(%rbp)
L33:
  mov    -0x28(%rbp),%rdx
  mov    -0x20(%rbp),%rcx
  mov    -0x14(%rbp),%eax
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <write@plt>
  mov    %rax,-0x8(%rbp)
  cmpq   $0x0,-0x8(%rbp)
  jns    L21
  mov    D9(%rip),%rax
  mov    (%rax),%rdx
  mov    D2(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,%rdx
  je     L45
  mov    D9(%rip),%rax
  mov    (%rax),%rdx
  mov    D11(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,%rdx
  je     L45
L21:
  mov    -0x8(%rbp),%rax
  jmp    L48
L45:
  nop
  jmp    L33
L48:
  leave
  ret
```

assistant: ```c
ssize_t safe_write(int fd, const void *buf, size_t len) {
  ssize_t written;
  do {
    written = write(fd, buf, len);
    if ((written < 0) && (errno == EAGAIN || errno == EINTR))
      continue;
    return written;
  } while (1);
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<safe_write>:
  endbr64
  push   %r12
  push   %rbp
  push   %rbx
  mov    %edi,%r12d
  mov    %rsi,%rbp
  mov    %rdx,%rbx
L1:
  mov    %rbx,%rdx
  mov    %rbp,%rsi
  mov    %r12d,%edi
  call   <write@plt>
  test   %rax,%rax
  jns    L0
  mov    D12(%rip),%rdx
  mov    (%rdx),%rdx
  mov    D10(%rip),%rcx
  cmp    (%rcx),%rdx
  je     L1
  mov    D19(%rip),%rcx
  cmp    (%rcx),%rdx
  je     L1
L0:
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
```

assistant: ```c
ssize_t safe_write(int fd, const void *buf, size_t len) {
  ssize_t written;
  do {
    written = write(fd, buf, len);
    if ((written < 0) && (errno == EAGAIN || errno == EINTR))
      continue;
    return written;
  } while (1);
}
```
user: 请从给定的汇编指令推导出C源代码：

```asm
<safe_write>:
  endbr64
  push   %r12
  mov    %edi,%r12d
  push   %rbp
  mov    %rsi,%rbp
  push   %rbx
  mov    %rdx,%rbx
L24:
  mov    %rbx,%rdx
  mov    %rbp,%rsi
  mov    %r12d,%edi
  call   <write@plt>
  test   %rax,%rax
  jns    L28
  mov    D27(%rip),%rdx
  mov    D8(%rip),%rcx
  mov    (%rdx),%rdx
  cmp    (%rcx),%rdx
  je     L24
  mov    D28(%rip),%rcx
  cmp    (%rcx),%rdx
  je     L24
L28:
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
```

assistant: ```c
ssize_t safe_write(int fd, const void *buf, size_t len) {
  ssize_t written;
  do {
    written = write(fd, buf, len);
    if ((written < 0) && (errno == EAGAIN || errno == EINTR))
      continue;
    return written;
  } while (1);
}
```
user: 请显示与下面列出的汇编代码相匹配的C语言实现:

```asm
<safe_write>:
  endbr64
  push   %r12
  mov    %edi,%r12d
  push   %rbp
  mov    %rsi,%rbp
  push   %rbx
  mov    %rdx,%rbx
L4:
  mov    %rbx,%rdx
  mov    %rbp,%rsi
  mov    %r12d,%edi
  call   <write@plt>
  test   %rax,%rax
  jns    L9
  mov    D6(%rip),%rdx
  mov    D9(%rip),%rcx
  mov    (%rdx),%rdx
  cmp    (%rcx),%rdx
  je     L4
  mov    D20(%rip),%rcx
  cmp    (%rcx),%rdx
  je     L4
L9:
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
```

assistant: ```c
ssize_t safe_write(int fd, const void *buf, size_t len) {
  ssize_t written;
  do {
    written = write(fd, buf, len);
    if ((written < 0) && (errno == EAGAIN || errno == EINTR))
      continue;
    return written;
  } while (1);
}
```
user: What is the c source code of the assembly code below:

```asm
<xchg>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %rdx,-0x48(%rbp)
  mov    %rcx,-0x50(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x18(%rbp)
  xor    %eax,%eax
  mov    -0x48(%rbp),%rax
  cmp    -0x50(%rbp),%rax
  je     L15
  mov    %rsp,%rax
  mov    %rax,%rbx
  mov    -0x40(%rbp),%rax
  mov    %rax,%rdx
  sub    $0x1,%rdx
  mov    %rdx,-0x28(%rbp)
  mov    %rax,%r10
  mov    $0x0,%r11d
  mov    %rax,%r8
  mov    $0x0,%r9d
  mov    $0x10,%edx
  sub    $0x1,%rdx
  add    %rdx,%rax
  mov    $0x10,%edi
  mov    $0x0,%edx
  div    %rdi
  imul   $0x10,%rax,%rax
  mov    %rax,%rcx
  and    $0xfffffffffffff000,%rcx
  mov    %rsp,%rdx
  sub    %rcx,%rdx
L2:
  cmp    %rdx,%rsp
  je     L32
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L2
L32:
  mov    %rax,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  mov    %rax,%rdx
  and    $0xfff,%edx
  test   %rdx,%rdx
  je     L39
  and    $0xfff,%eax
  sub    $0x8,%rax
  add    %rsp,%rax
  orq    $0x0,(%rax)
L39:
  mov    %rsp,%rax
  add    $0x0,%rax
  mov    %rax,-0x20(%rbp)
  mov    -0x48(%rbp),%rax
  imul   -0x40(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x38(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x40(%rbp),%rdx
  mov    -0x20(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x50(%rbp),%rax
  imul   -0x40(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x38(%rbp),%rax
  lea    (%rdx,%rax,1),%rsi
  mov    -0x48(%rbp),%rax
  imul   -0x40(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x38(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x40(%rbp),%rax
  mov    %rax,%rdx
  mov    %rcx,%rdi
  call   <memcpy@plt>
  mov    -0x50(%rbp),%rax
  imul   -0x40(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x38(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x40(%rbp),%rdx
  mov    -0x20(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <memcpy@plt>
  mov    %rbx,%rsp
L15:
  nop
  mov    -0x18(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L4
  call   <__stack_chk_fail@plt>
L4:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

assistant: ```c
void xchg(char *base, size_t size, size_t a, size_t b) {
  if (a != b) {
    char buffer[size];
    memcpy(buffer, base + a * size, size);
    memcpy(base + a * size, base + b * size, size);
    memcpy(base + b * size, buffer, size);
  }
}
```
user: 下面的汇编指令对应的C源代码是什么:

```asm
<xchg>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x18,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  cmp    %rcx,%rdx
  jne    L24
L37:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L57
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L24:
  mov    %rdi,%r13
  mov    %rsi,%r12
  mov    %rcx,%rbx
  mov    %rsp,%r14
  lea    0xf(%rsi),%rax
  mov    %rax,%rsi
  and    $0xfffffffffffffff0,%rsi
  and    $0xfffffffffffff000,%rax
  mov    %rsp,%rcx
  sub    %rax,%rcx
L42:
  cmp    %rcx,%rsp
  je     L32
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L42
L32:
  mov    %rsi,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L18
  orq    $0x0,-0x8(%rsp,%rax,1)
L18:
  imul   %r12,%rdx
  lea    0x0(%r13,%rdx,1),%r15
  mov    %r12,%rdx
  mov    %r15,%rsi
  mov    %rsp,%rdi
  call   <memcpy@plt>
  imul   %r12,%rbx
  add    %rbx,%r13
  mov    %r12,%rdx
  mov    %r13,%rsi
  mov    %r15,%rdi
  call   <memcpy@plt>
  mov    %r12,%rdx
  mov    %rsp,%rsi
  mov    %r13,%rdi
  call   <memcpy@plt>
  mov    %r14,%rsp
  jmp    L37
L57:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void xchg(char *base, size_t size, size_t a, size_t b) {
  if (a != b) {
    char buffer[size];
    memcpy(buffer, base + a * size, size);
    memcpy(base + a * size, base + b * size, size);
    memcpy(base + b * size, buffer, size);
  }
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<xchg>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x18,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  cmp    %rcx,%rdx
  jne    L14
L0:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L35
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
  nopl   0x0(%rax,%rax,1)
L14:
  lea    0xf(%rsi),%rax
  mov    %rsi,%r13
  mov    %rcx,%rbx
  mov    %rsp,%rsi
  mov    %rax,%rcx
  and    $0xfffffffffffff000,%rax
  mov    %rdi,%r14
  mov    %rsp,%r15
  sub    %rax,%rsi
  and    $0xfffffffffffffff0,%rcx
  cmp    %rsi,%rsp
  je     L22
L20:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rsi,%rsp
  jne    L20
L22:
  and    $0xfff,%ecx
  sub    %rcx,%rsp
  test   %rcx,%rcx
  je     L37
  orq    $0x0,-0x8(%rsp,%rcx,1)
L37:
  imul   %r13,%rdx
  mov    %rsp,%rdi
  imul   %r13,%rbx
  lea    (%r14,%rdx,1),%r12
  mov    %r13,%rdx
  mov    %r12,%rsi
  add    %rbx,%r14
  call   <memcpy@plt>
  mov    %r13,%rdx
  mov    %r14,%rsi
  mov    %r12,%rdi
  call   <memcpy@plt>
  mov    %rsp,%rsi
  mov    %r13,%rdx
  mov    %r14,%rdi
  call   <memcpy@plt>
  mov    %r15,%rsp
  jmp    L0
L35:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void xchg(char *base, size_t size, size_t a, size_t b) {
  if (a != b) {
    char buffer[size];
    memcpy(buffer, base + a * size, size);
    memcpy(base + a * size, base + b * size, size);
    memcpy(base + b * size, buffer, size);
  }
}
```