ylfeng/ReF-Decompile-dataset huggingface dataset:
user: Translate the below assembly code into C programming language:

```asm
<lcs>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdi,-0x18(%rbp)
  mov    %rsi,-0x20(%rbp)
  mov    %edx,-0x24(%rbp)
  mov    %ecx,-0x28(%rbp)
  cmpl   $0x0,-0x24(%rbp)
  je     L47
  cmpl   $0x0,-0x28(%rbp)
  jne    L42
L47:
  mov    $0x0,%eax
  jmp    L26
L42:
  mov    -0x24(%rbp),%eax
  cltq
  lea    -0x1(%rax),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%edx
  mov    -0x28(%rbp),%eax
  cltq
  lea    -0x1(%rax),%rcx
  mov    -0x20(%rbp),%rax
  add    %rcx,%rax
  movzbl (%rax),%eax
  cmp    %al,%dl
  jne    L13
  mov    -0x28(%rbp),%eax
  lea    -0x1(%rax),%ecx
  mov    -0x24(%rbp),%eax
  lea    -0x1(%rax),%edx
  mov    -0x20(%rbp),%rsi
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <lcs>
  add    $0x1,%eax
  jmp    L26
L13:
  mov    -0x24(%rbp),%eax
  lea    -0x1(%rax),%edi
  mov    -0x28(%rbp),%edx
  mov    -0x20(%rbp),%rsi
  mov    -0x18(%rbp),%rax
  mov    %edx,%ecx
  mov    %edi,%edx
  mov    %rax,%rdi
  call   <lcs>
  mov    %eax,%ebx
  mov    -0x28(%rbp),%eax
  lea    -0x1(%rax),%ecx
  mov    -0x24(%rbp),%edx
  mov    -0x20(%rbp),%rsi
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <lcs>
  mov    %ebx,%esi
  mov    %eax,%edi
  call   <max@plt>
L26:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

assistant: ```c
int lcs(char *a, char *b, int m, int n) {
  if (m == 0 || n == 0)
    return 0;
  if (a[m - 1] == b[n - 1])
    return 1 + lcs(a, b, m - 1, n - 1);
  else
    return max(lcs(a, b, m, n - 1), lcs(a, b, m - 1, n));
}
```
user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<lcs>:
  endbr64
  test   %edx,%edx
  je     L21
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdi,%r12
  mov    %rsi,%r13
  mov    %edx,%ebp
  mov    %ecx,%ebx
  test   %ecx,%ecx
  je     L23
  movslq %edx,%rax
  movslq %ecx,%rdx
  movzbl -0x1(%rsi,%rdx,1),%esi
  cmp    %sil,-0x1(%rdi,%rax,1)
  je     L30
  lea    -0x1(%rbp),%edx
  mov    %r13,%rsi
  call   <lcs>
  mov    %eax,%r14d
  lea    -0x1(%rbx),%ecx
  mov    %ebp,%edx
  mov    %r13,%rsi
  mov    %r12,%rdi
  call   <lcs>
  mov    %eax,%edi
  mov    %r14d,%esi
  call   <max@plt>
L42:
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
L30:
  lea    -0x1(%rcx),%ecx
  lea    -0x1(%rbp),%edx
  mov    %r13,%rsi
  call   <lcs>
  add    $0x1,%eax
  jmp    L42
L23:
  mov    $0x0,%eax
  jmp    L42
L21:
  mov    $0x0,%eax
  ret
```

assistant: ```c
int lcs(char *a, char *b, int m, int n) {
  if (m == 0 || n == 0)
    return 0;
  if (a[m - 1] == b[n - 1])
    return 1 + lcs(a, b, m - 1, n - 1);
  else
    return max(lcs(a, b, m, n - 1), lcs(a, b, m - 1, n));
}
```
user: 请将这段汇编代码片段转换成等效的C代码:

```asm
<lcs>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x8,%rsp
  test   %edx,%edx
  je     L38
  test   %ecx,%ecx
  je     L38
  mov    %rdi,%r13
  lea    -0x1(%rcx),%eax
  movslq %edx,%rdi
  movslq %ecx,%rcx
  sub    %rcx,%rdi
  mov    %rsi,%rbp
  cltq
  xor    %r12d,%r12d
  add    %r13,%rdi
  jmp    L52
  xchg   %ax,%ax
L56:
  add    $0x1,%r12d
  test   %edx,%edx
  sete   %cl
  test   %eax,%eax
  sete   %sil
  sub    $0x1,%rax
  or     %sil,%cl
  jne    L34
L52:
  mov    %edx,%r14d
  movzbl 0x0(%rbp,%rax,1),%ebx
  lea    0x1(%rax),%ecx
  mov    %eax,%r15d
  sub    $0x1,%edx
  cmp    %bl,(%rdi,%rax,1)
  je     L56
  mov    %rbp,%rsi
  mov    %r13,%rdi
  call   <lcs>
  mov    %r15d,%ecx
  mov    %r14d,%edx
  mov    %rbp,%rsi
  mov    %r13,%rdi
  mov    %eax,%ebx
  call   <lcs>
  mov    %ebx,%esi
  mov    %eax,%edi
  call   <max@plt>
  add    %eax,%r12d
L34:
  add    $0x8,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L38:
  xor    %r12d,%r12d
  jmp    L34
```

assistant: ```c
int lcs(char *a, char *b, int m, int n) {
  if (m == 0 || n == 0)
    return 0;
  if (a[m - 1] == b[n - 1])
    return 1 + lcs(a, b, m - 1, n - 1);
  else
    return max(lcs(a, b, m, n - 1), lcs(a, b, m - 1, n));
}
```
user: Demonstrate the C code that generates the assembly output below:

```asm
<hostname2ip>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %rdi,-0x28(%rbp)
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <gethostbyname@plt>
  mov    %rax,-0x10(%rbp)
  cmpq   $0x0,-0x10(%rbp)
  jne    L9
  mov    $0x0,%eax
  jmp    L5
L9:
  mov    -0x10(%rbp),%rax
  mov    (%rax),%rax
  mov    (%rax),%rax
  mov    %rax,-0x8(%rbp)
  mov    -0x8(%rbp),%rax
  mov    (%rax),%eax
  mov    %eax,-0x14(%rbp)
  mov    -0x14(%rbp),%eax
L5:
  leave
  ret
```

assistant: ```c
uint32_t hostname2ip(char *hostname) {
  struct hostent *phostent;
  unsigned int hostaddr;
  unsigned char *temp;
  phostent = gethostbyname(hostname);
  if (phostent == NULL) {
    return 0;
  }
  temp = ((unsigned char *)phostent->h_addr_list[0]);
  hostaddr = *(unsigned int *)temp;
  return hostaddr;
}
```
user: What is the c source code of the assembly code below?

```asm
<hostname2ip>:
  endbr64
  sub    $0x8,%rsp
  call   <gethostbyname@plt>
  test   %rax,%rax
  je     L9
  mov    (%rax),%rax
  mov    (%rax),%rax
  mov    (%rax),%eax
L16:
  add    $0x8,%rsp
  ret
L9:
  mov    $0x0,%eax
  jmp    L16
```

assistant: ```c
uint32_t hostname2ip(char *hostname) {
  struct hostent *phostent;
  unsigned int hostaddr;
  unsigned char *temp;
  phostent = gethostbyname(hostname);
  if (phostent == NULL) {
    return 0;
  }
  temp = ((unsigned char *)phostent->h_addr_list[0]);
  hostaddr = *(unsigned int *)temp;
  return hostaddr;
}
```
user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<hostname2ip>:
  endbr64
  sub    $0x8,%rsp
  call   <gethostbyname@plt>
  test   %rax,%rax
  je     L4
  mov    (%rax),%rax
  mov    (%rax),%rax
  mov    (%rax),%eax
  add    $0x8,%rsp
  ret
  nop
L4:
  xor    %eax,%eax
  add    $0x8,%rsp
  ret
```

assistant: ```c
uint32_t hostname2ip(char *hostname) {
  struct hostent *phostent;
  unsigned int hostaddr;
  unsigned char *temp;
  phostent = gethostbyname(hostname);
  if (phostent == NULL) {
    return 0;
  }
  temp = ((unsigned char *)phostent->h_addr_list[0]);
  hostaddr = *(unsigned int *)temp;
  return hostaddr;
}
```
user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<hostname2ip>:
  endbr64
  sub    $0x8,%rsp
  call   <gethostbyname@plt>
  test   %rax,%rax
  je     L8
  mov    (%rax),%rax
  mov    (%rax),%rax
  mov    (%rax),%eax
  add    $0x8,%rsp
  ret
  nop
L8:
  xor    %eax,%eax
  add    $0x8,%rsp
  ret
```

assistant: ```c
uint32_t hostname2ip(char *hostname) {
  struct hostent *phostent;
  unsigned int hostaddr;
  unsigned char *temp;
  phostent = gethostbyname(hostname);
  if (phostent == NULL) {
    return 0;
  }
  temp = ((unsigned char *)phostent->h_addr_list[0]);
  hostaddr = *(unsigned int *)temp;
  return hostaddr;
}
```
user: 提供的汇编代码用C语言表示会是什么样子:

```asm
<calc_total_distance>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %edi,-0x14(%rbp)
  mov    %esi,-0x18(%rbp)
  mov    %edx,-0x1c(%rbp)
  mov    %rcx,-0x28(%rbp)
  mov    %r8,-0x30(%rbp)
  mov    %r9,-0x38(%rbp)
  pxor   %xmm0,%xmm0
  movsd  %xmm0,-0x8(%rbp)
  movl   $0x0,-0x10(%rbp)
  jmp    L16
L23:
  mov    -0x10(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  mov    %eax,-0xc(%rbp)
  cmpl   $0xffffffff,-0xc(%rbp)
  je     L5
  mov    -0xc(%rbp),%eax
  imul   -0x14(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x30(%rbp),%rax
  add    %rax,%rdx
  mov    -0x10(%rbp),%eax
  imul   -0x14(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rcx
  mov    -0x28(%rbp),%rax
  add    %rax,%rcx
  mov    -0x14(%rbp),%eax
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <calc_distance@plt>
  pxor   %xmm0,%xmm0
  cvtsi2sd %rax,%xmm0
  movsd  -0x8(%rbp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x8(%rbp)
L5:
  addl   $0x1,-0x10(%rbp)
L16:
  mov    -0x10(%rbp),%eax
  cmp    -0x18(%rbp),%eax
  jl     L23
  movsd  -0x8(%rbp),%xmm0
  movq   %xmm0,%rax
  movq   %rax,%xmm0
  leave
  ret
```

assistant: ```c
double calc_total_distance(int dim, int n, int k, double *X, double *centroids, int *cluster_assignment_index) {
  double tot_D = 0;
  for (int ii = 0; ii < n; ii++) {
    int active_cluster = cluster_assignment_index[ii];
    if (active_cluster != -1)
      tot_D += calc_distance(dim, &X[ii * dim], &centroids[active_cluster * dim]);
  }
  return tot_D;
}
```
user: Demonstrate the C code that generates the assembly output below:

```asm
<calc_total_distance>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  test   %esi,%esi
  jle    L11
  mov    %edi,%r12d
  mov    %rcx,%r14
  mov    %r8,%r15
  mov    %r9,%rbx
  lea    -0x1(%rsi),%eax
  lea    0x4(%r9,%rax,4),%r13
  mov    $0x0,%ebp
  pxor   %xmm2,%xmm2
  movsd  %xmm2,0x8(%rsp)
  jmp    L34
L3:
  add    $0x4,%rbx
  add    %r12d,%ebp
  cmp    %r13,%rbx
  je     L31
L34:
  mov    (%rbx),%eax
  cmp    $0xffffffff,%eax
  je     L3
  imul   %r12d,%eax
  cltq
  lea    (%r15,%rax,8),%rdx
  movslq %ebp,%rax
  lea    (%r14,%rax,8),%rsi
  mov    %r12d,%edi
  call   <calc_distance@plt>
  pxor   %xmm0,%xmm0
  cvtsi2sd %rax,%xmm0
  addsd  0x8(%rsp),%xmm0
  movsd  %xmm0,0x8(%rsp)
  jmp    L3
L11:
  pxor   %xmm3,%xmm3
  movsd  %xmm3,0x8(%rsp)
L31:
  movsd  0x8(%rsp),%xmm0
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

assistant: ```c
double calc_total_distance(int dim, int n, int k, double *X, double *centroids, int *cluster_assignment_index) {
  double tot_D = 0;
  for (int ii = 0; ii < n; ii++) {
    int active_cluster = cluster_assignment_index[ii];
    if (active_cluster != -1)
      tot_D += calc_distance(dim, &X[ii * dim], &centroids[active_cluster * dim]);
  }
  return tot_D;
}
```
user: What would the C source look like for the assembly code provided here?

```asm
<calc_total_distance>:
  endbr64
  test   %esi,%esi
  jle    L5
  push   %r15
  lea    -0x1(%rsi),%eax
  mov    %edi,%r15d
  pxor   %xmm0,%xmm0
  push   %r14
  xor    %r14d,%r14d
  push   %r13
  mov    %r8,%r13
  push   %r12
  mov    %rcx,%r12
  push   %rbp
  lea    0x4(%r9,%rax,4),%rbp
  push   %rbx
  mov    %r9,%rbx
  sub    $0x18,%rsp
  nopl   (%rax)
L11:
  mov    (%rbx),%eax
  cmp    $0xffffffff,%eax
  je     L1
  imul   %r15d,%eax
  mov    %r15d,%edi
  movsd  %xmm0,0x8(%rsp)
  cltq
  lea    0x0(%r13,%rax,8),%rdx
  movslq %r14d,%rax
  lea    (%r12,%rax,8),%rsi
  call   <calc_distance@plt>
  pxor   %xmm1,%xmm1
  movsd  0x8(%rsp),%xmm0
  cvtsi2sd %rax,%xmm1
  addsd  %xmm1,%xmm0
L1:
  add    $0x4,%rbx
  add    %r15d,%r14d
  cmp    %rbp,%rbx
  jne    L11
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L5:
  pxor   %xmm0,%xmm0
  ret
```

assistant: ```c
double calc_total_distance(int dim, int n, int k, double *X, double *centroids, int *cluster_assignment_index) {
  double tot_D = 0;
  for (int ii = 0; ii < n; ii++) {
    int active_cluster = cluster_assignment_index[ii];
    if (active_cluster != -1)
      tot_D += calc_distance(dim, &X[ii * dim], &centroids[active_cluster * dim]);
  }
  return tot_D;
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<calc_total_distance>:
  endbr64
  test   %esi,%esi
  jle    L21
  push   %r15
  lea    -0x1(%rsi),%eax
  mov    %edi,%r15d
  pxor   %xmm0,%xmm0
  push   %r14
  xor    %r14d,%r14d
  push   %r13
  mov    %r8,%r13
  push   %r12
  mov    %rcx,%r12
  push   %rbp
  lea    0x4(%r9,%rax,4),%rbp
  push   %rbx
  mov    %r9,%rbx
  sub    $0x18,%rsp
  nopl   (%rax)
L11:
  mov    (%rbx),%eax
  cmp    $0xffffffff,%eax
  je     L28
  imul   %r15d,%eax
  mov    %r15d,%edi
  movsd  %xmm0,0x8(%rsp)
  cltq
  lea    0x0(%r13,%rax,8),%rdx
  movslq %r14d,%rax
  lea    (%r12,%rax,8),%rsi
  call   <calc_distance@plt>
  pxor   %xmm1,%xmm1
  movsd  0x8(%rsp),%xmm0
  cvtsi2sd %rax,%xmm1
  addsd  %xmm1,%xmm0
L28:
  add    $0x4,%rbx
  add    %r15d,%r14d
  cmp    %rbp,%rbx
  jne    L11
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L21:
  pxor   %xmm0,%xmm0
  ret
```

assistant: ```c
double calc_total_distance(int dim, int n, int k, double *X, double *centroids, int *cluster_assignment_index) {
  double tot_D = 0;
  for (int ii = 0; ii < n; ii++) {
    int active_cluster = cluster_assignment_index[ii];
    if (active_cluster != -1)
      tot_D += calc_distance(dim, &X[ii * dim], &centroids[active_cluster * dim]);
  }
  return tot_D;
}
```
user: What would the C source look like for the assembly code provided here:

```asm
<checksum>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %rdi,-0x18(%rbp)
  mov    %esi,-0x1c(%rbp)
  movl   $0x0,-0x4(%rbp)
  cmpl   $0x0,-0x1c(%rbp)
  je     L8
L19:
  mov    -0x18(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x18(%rbp)
  movzbl (%rax),%eax
  movsbl %al,%eax
  add    %eax,-0x4(%rbp)
  subl   $0x1,-0x1c(%rbp)
  cmpl   $0x0,-0x1c(%rbp)
  jne    L19
L8:
  mov    -0x4(%rbp),%eax
  pop    %rbp
  ret
```

assistant: ```c
int checksum(char *str, int len) {
  int check = 0;
  if (len)
    do
      check += *str++;
    while (--len);
  return (check);
}
```
user: 提供的汇编代码用C语言表示会是什么样子：

```asm
<checksum>:
  endbr64
  mov    %esi,%eax
  test   %esi,%esi
  je     L3
  mov    %esi,%eax
  lea    (%rdi,%rax,1),%rcx
  mov    $0x0,%eax
L6:
  add    $0x1,%rdi
  movsbl -0x1(%rdi),%edx
  add    %edx,%eax
  cmp    %rcx,%rdi
  jne    L6
L3:
  ret
```

assistant: ```c
int checksum(char *str, int len) {
  int check = 0;
  if (len)
    do
      check += *str++;
    while (--len);
  return (check);
}
```
user: Demonstrate the C code that generates the assembly output below:

```asm
<checksum>:
  endbr64
  mov    %esi,%eax
  test   %eax,%eax
  je     L10
  lea    (%rdi,%rax,1),%rcx
  xor    %eax,%eax
L0:
  movsbl (%rdi),%edx
  add    $0x1,%rdi
  add    %edx,%eax
  cmp    %rcx,%rdi
  jne    L0
L10:
  ret
```

assistant: ```c
int checksum(char *str, int len) {
  int check = 0;
  if (len)
    do
      check += *str++;
    while (--len);
  return (check);
}
```
user: 请从给定的汇编指令推导出C源代码：

```asm
<checksum>:
  endbr64
  mov    %esi,%edx
  xor    %eax,%eax
  test   %esi,%esi
  je     L2
  lea    -0x1(%rsi),%ecx
  cmp    $0xe,%ecx
  jbe    L168
  mov    %esi,%ecx
  pxor   %xmm1,%xmm1
  pxor   %xmm6,%xmm6
  mov    %rdi,%rax
  shr    $0x4,%ecx
  pxor   %xmm4,%xmm4
  sub    $0x1,%ecx
  shl    $0x4,%rcx
  lea    0x10(%rdi,%rcx,1),%rcx
  nopl   0x0(%rax)
L28:
  movdqu (%rax),%xmm0
  movdqa %xmm6,%xmm3
  add    $0x10,%rax
  pcmpgtb %xmm0,%xmm3
  movdqa %xmm0,%xmm2
  punpcklbw %xmm3,%xmm2
  punpckhbw %xmm3,%xmm0
  movdqa %xmm4,%xmm3
  pcmpgtw %xmm2,%xmm3
  movdqa %xmm2,%xmm5
  punpcklwd %xmm3,%xmm5
  punpckhwd %xmm3,%xmm2
  movdqa %xmm0,%xmm3
  paddd  %xmm5,%xmm1
  paddd  %xmm2,%xmm1
  movdqa %xmm4,%xmm2
  pcmpgtw %xmm0,%xmm2
  punpcklwd %xmm2,%xmm3
  punpckhwd %xmm2,%xmm0
  paddd  %xmm3,%xmm1
  paddd  %xmm0,%xmm1
  cmp    %rcx,%rax
  jne    L28
  movdqa %xmm1,%xmm0
  mov    %edx,%ecx
  psrldq $0x8,%xmm0
  and    $0xfffffff0,%ecx
  paddd  %xmm0,%xmm1
  mov    %ecx,%r8d
  sub    %ecx,%edx
  movdqa %xmm1,%xmm0
  add    %r8,%rdi
  psrldq $0x4,%xmm0
  paddd  %xmm0,%xmm1
  movd   %xmm1,%eax
  cmp    %ecx,%esi
  je     L2
  lea    -0x1(%rdx),%ecx
L168:
  movsbl (%rdi),%esi
  add    %esi,%eax
  test   %ecx,%ecx
  je     L2
  movsbl 0x1(%rdi),%ecx
  add    %ecx,%eax
  cmp    $0x2,%edx
  je     L2
  movsbl 0x2(%rdi),%ecx
  add    %ecx,%eax
  cmp    $0x3,%edx
  je     L2
  movsbl 0x3(%rdi),%ecx
  add    %ecx,%eax
  cmp    $0x4,%edx
  je     L2
  movsbl 0x4(%rdi),%ecx
  add    %ecx,%eax
  cmp    $0x5,%edx
  je     L2
  movsbl 0x5(%rdi),%ecx
  add    %ecx,%eax
  cmp    $0x6,%edx
  je     L2
  movsbl 0x6(%rdi),%ecx
  add    %ecx,%eax
  cmp    $0x7,%edx
  je     L2
  movsbl 0x7(%rdi),%ecx
  add    %ecx,%eax
  cmp    $0x8,%edx
  je     L2
  movsbl 0x8(%rdi),%ecx
  add    %ecx,%eax
  cmp    $0x9,%edx
  je     L2
  movsbl 0x9(%rdi),%ecx
  add    %ecx,%eax
  cmp    $0xa,%edx
  je     L2
  movsbl 0xa(%rdi),%ecx
  add    %ecx,%eax
  cmp    $0xb,%edx
  je     L2
  movsbl 0xb(%rdi),%ecx
  add    %ecx,%eax
  cmp    $0xc,%edx
  je     L2
  movsbl 0xc(%rdi),%ecx
  add    %ecx,%eax
  cmp    $0xd,%edx
  je     L2
  movsbl 0xd(%rdi),%ecx
  add    %ecx,%eax
  cmp    $0xe,%edx
  je     L2
  movsbl 0xe(%rdi),%edx
  add    %edx,%eax
L2:
  ret
```

assistant: ```c
int checksum(char *str, int len) {
  int check = 0;
  if (len)
    do
      check += *str++;
    while (--len);
  return (check);
}
```
user: 请将这段汇编代码片段转换成等效的C代码:

```asm
<setSaneCfgAddPath>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %rdx,-0x48(%rbp)
  mov    %ecx,-0x4c(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x18(%rbp)
  xor    %eax,%eax
  mov    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <PHYSFS_getRealDir@plt>
  mov    %rax,-0x30(%rbp)
  mov    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %rax,%rbx
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  lea    (%rbx,%rax,1),%rdx
  mov    -0x40(%rbp),%rax
  add    %rdx,%rax
  add    $0x1,%rax
  mov    %rax,-0x28(%rbp)
  cmpq   $0x7f,-0x28(%rbp)
  ja     L19
  mov    -0x28(%rbp),%rax
  add    $0x1,%rax
  lea    0x8(%rax),%rdx
  mov    $0x10,%eax
  sub    $0x1,%rax
  add    %rdx,%rax
  mov    $0x10,%ebx
  mov    $0x0,%edx
  div    %rbx
  imul   $0x10,%rax,%rax
  mov    %rax,%rcx
  and    $0xfffffffffffff000,%rcx
  mov    %rsp,%rdx
  sub    %rcx,%rdx
L4:
  cmp    %rdx,%rsp
  je     L25
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L4
L25:
  mov    %rax,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  mov    %rax,%rdx
  and    $0xfff,%edx
  test   %rdx,%rdx
  je     L49
  and    $0xfff,%eax
  sub    $0x8,%rax
  add    %rsp,%rax
  orq    $0x0,(%rax)
L49:
  mov    %rsp,%rax
  add    $0xf,%rax
  shr    $0x4,%rax
  shl    $0x4,%rax
  mov    %rax,%rdx
  jmp    L50
L19:
  mov    $0x0,%edx
L50:
  mov    -0x28(%rbp),%rax
  mov    %rax,%rsi
  mov    %rdx,%rdi
  call   <__PHYSFS_initSmallAlloc@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  je     L57
  mov    -0x38(%rbp),%rsi
  mov    -0x48(%rbp),%rcx
  mov    -0x30(%rbp),%rdx
  mov    -0x20(%rbp),%rax
  mov    %rsi,%r8
  lea    D8(%rip),%rsi
  mov    %rax,%rdi
  call   <sprintf@plt>
  cmpl   $0x0,-0x4c(%rbp)
  sete   %al
  movzbl %al,%edx
  mov    -0x20(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <PHYSFS_addToSearchPath@plt>
  mov    -0x20(%rbp),%rax
  mov    %rax,%rdi
  call   <__PHYSFS_smallFree@plt>
L57:
  nop
  mov    -0x18(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L31
  call   <__stack_chk_fail@plt>
L31:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

tool_calls: name: unpack_data
arguments: tag: D8
type_infered: string

tool: D8: %s%s%s

assistant: ```c
void setSaneCfgAddPath(const char *i, const size_t l, const char *dirsep, int archivesFirst) {
  const char *d = PHYSFS_getRealDir(i);
  const size_t allocsize = strlen(d) + strlen(dirsep) + l + 1;
  char *str = (char *)(__PHYSFS_initSmallAlloc((((allocsize) < 128) ? alloca((size_t)((allocsize) + 1)) : NULL), (allocsize)));
  if (str != NULL) {
    sprintf(str, "%s%s%s", d, dirsep, i);
    PHYSFS_addToSearchPath(str, archivesFirst == 0);
    __PHYSFS_smallFree(str);
  }
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<setSaneCfgAddPath>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdi,%r14
  mov    %rsi,-0x48(%rbp)
  mov    %rdx,%r13
  mov    %ecx,%r15d
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  call   <PHYSFS_getRealDir@plt>
  mov    %rax,%r12
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %rax,%rbx
  mov    %r13,%rdi
  call   <strlen@plt>
  add    %rax,%rbx
  add    -0x48(%rbp),%rbx
  lea    0x1(%rbx),%rsi
  mov    $0x0,%edi
  cmp    $0x7f,%rsi
  ja     L10
  add    $0x19,%rbx
  mov    %rbx,%rdx
  and    $0xfffffffffffffff0,%rdx
  and    $0xfffffffffffff000,%rbx
  mov    %rsp,%rax
  sub    %rbx,%rax
L28:
  cmp    %rax,%rsp
  je     L41
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L28
L41:
  mov    %rdx,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L6
  orq    $0x0,-0x8(%rsp,%rax,1)
L6:
  lea    0xf(%rsp),%rdi
  and    $0xfffffffffffffff0,%rdi
L10:
  call   <__PHYSFS_initSmallAlloc@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  jne    L33
L65:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L51
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L33:
  mov    %r14,%r8
  mov    %r13,%rcx
  mov    %r12,%rdx
  lea    D3(%rip),%rsi
  mov    %rax,%rdi
  call   <sprintf@plt>
  test   %r15d,%r15d
  sete   %sil
  movzbl %sil,%esi
  mov    %rbx,%rdi
  call   <PHYSFS_addToSearchPath@plt>
  mov    %rbx,%rdi
  call   <__PHYSFS_smallFree@plt>
  jmp    L65
L51:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: data_label: D3
data_type: string

tool: D3: %s%s%s

assistant: ```c
void setSaneCfgAddPath(const char *i, const size_t l, const char *dirsep, int archivesFirst) {
  const char *d = PHYSFS_getRealDir(i);
  const size_t allocsize = strlen(d) + strlen(dirsep) + l + 1;
  char *str = (char *)(__PHYSFS_initSmallAlloc((((allocsize) < 128) ? alloca((size_t)((allocsize) + 1)) : NULL), (allocsize)));
  if (str != NULL) {
    sprintf(str, "%s%s%s", d, dirsep, i);
    PHYSFS_addToSearchPath(str, archivesFirst == 0);
    __PHYSFS_smallFree(str);
  }
}
```
user: What is the c source code of the assembly code below?

```asm
<setSaneCfgAddPath>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  mov    %rsi,%r15
  push   %r14
  mov    %rdi,%r14
  push   %r13
  mov    %rdx,%r13
  push   %r12
  push   %rbx
  sub    $0x28,%rsp
  mov    %ecx,-0x44(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  call   <PHYSFS_getRealDir@plt>
  mov    %rax,%rdi
  mov    %rax,%r12
  call   <strlen@plt>
  mov    %r13,%rdi
  mov    %rax,%rbx
  call   <strlen@plt>
  xor    %edi,%edi
  add    %rax,%rbx
  add    %r15,%rbx
  lea    0x1(%rbx),%rsi
  cmp    $0x7f,%rsi
  ja     L56
  add    $0x19,%rbx
  mov    %rsp,%rdx
  mov    %rbx,%rax
  and    $0xfffffffffffff000,%rbx
  sub    %rbx,%rdx
  and    $0xfffffffffffffff0,%rax
  cmp    %rdx,%rsp
  je     L50
L38:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rdx,%rsp
  jne    L38
L50:
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L68
  orq    $0x0,-0x8(%rsp,%rax,1)
L68:
  lea    0xf(%rsp),%rdi
  and    $0xfffffffffffffff0,%rdi
L56:
  call   <__PHYSFS_initSmallAlloc@plt>
  mov    %rax,%r15
  test   %rax,%rax
  jne    L43
L59:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L42
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
  cs nopw 0x0(%rax,%rax,1)
L43:
  mov    %r14,%r8
  mov    %r13,%rcx
  mov    %r12,%rdx
  mov    %rax,%rdi
  lea    D0(%rip),%rsi
  call   <sprintf@plt>
  mov    -0x44(%rbp),%eax
  xor    %esi,%esi
  mov    %r15,%rdi
  test   %eax,%eax
  sete   %sil
  call   <PHYSFS_addToSearchPath@plt>
  mov    %r15,%rdi
  call   <__PHYSFS_smallFree@plt>
  jmp    L59
L42:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: data_tag: D0
type: string

tool: D0: %s%s%s

assistant: ```c
void setSaneCfgAddPath(const char *i, const size_t l, const char *dirsep, int archivesFirst) {
  const char *d = PHYSFS_getRealDir(i);
  const size_t allocsize = strlen(d) + strlen(dirsep) + l + 1;
  char *str = (char *)(__PHYSFS_initSmallAlloc((((allocsize) < 128) ? alloca((size_t)((allocsize) + 1)) : NULL), (allocsize)));
  if (str != NULL) {
    sprintf(str, "%s%s%s", d, dirsep, i);
    PHYSFS_addToSearchPath(str, archivesFirst == 0);
    __PHYSFS_smallFree(str);
  }
}
```