ylfeng/ReF-Decompile-dataset huggingface dataset:
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<length_sort>:
  endbr64
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdi,%rbp
  mov    %rsi,%r12
  call   <strlen@plt>
  mov    %eax,%ebx
  mov    %r12,%rdi
  call   <strlen@plt>
  mov    $0x1,%edx
  cmp    %eax,%ebx
  jl     L3
  jg     L5
  mov    %r12,%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  mov    %eax,%edx
L3:
  mov    %edx,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L5:
  mov    $0xffffffff,%edx
  jmp    L3
```

assistant: ```c
int length_sort(const char *a, const char *b) {
  int alen = strlen(a), blen = strlen(b);
  if (alen < blen)
    return 1;
  if (blen < alen)
    return -1;
  return strcmp(a, b);
}
```
user: 下面的汇编指令对应的C源代码是什么:

```asm
<length_sort>:
  endbr64
  push   %r12
  mov    %rsi,%r12
  push   %rbp
  mov    %rdi,%rbp
  push   %rbx
  call   <strlen@plt>
  mov    %r12,%rdi
  mov    %eax,%ebx
  call   <strlen@plt>
  cmp    %eax,%ebx
  jl     L15
  jg     L17
  pop    %rbx
  mov    %r12,%rsi
  mov    %rbp,%rdi
  pop    %rbp
  pop    %r12
  jmp    1070 <strcmp@plt>
  nopw   0x0(%rax,%rax,1)
L15:
  mov    $0x1,%eax
L1:
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L17:
  mov    $0xffffffff,%eax
  jmp    L1
```

assistant: ```c
int length_sort(const char *a, const char *b) {
  int alen = strlen(a), blen = strlen(b);
  if (alen < blen)
    return 1;
  if (blen < alen)
    return -1;
  return strcmp(a, b);
}
```
user: Demonstrate the C code that generates the assembly output below:

```asm
<length_sort>:
  endbr64
  push   %r12
  mov    %rsi,%r12
  push   %rbp
  mov    %rdi,%rbp
  push   %rbx
  call   <strlen@plt>
  mov    %r12,%rdi
  mov    %eax,%ebx
  call   <strlen@plt>
  cmp    %eax,%ebx
  jl     L17
  jg     L16
  pop    %rbx
  mov    %r12,%rsi
  mov    %rbp,%rdi
  pop    %rbp
  pop    %r12
  jmp    1070 <strcmp@plt>
  nopw   0x0(%rax,%rax,1)
L17:
  mov    $0x1,%eax
L9:
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L16:
  mov    $0xffffffff,%eax
  jmp    L9
```

assistant: ```c
int length_sort(const char *a, const char *b) {
  int alen = strlen(a), blen = strlen(b);
  if (alen < blen)
    return 1;
  if (blen < alen)
    return -1;
  return strcmp(a, b);
}
```
user: What would the C source look like for the assembly code provided here:

```asm
<diff_tree>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %rdi,-0x8(%rbp)
  mov    %rsi,-0x10(%rbp)
  mov    %rdx,-0x18(%rbp)
  mov    %rcx,-0x20(%rbp)
  mov    %r8,-0x28(%rbp)
  jmp    L6
L116:
  mov    -0x10(%rbp),%rax
  test   %rax,%rax
  jne    L58
  mov    -0x20(%rbp),%rdx
  mov    -0x18(%rbp),%rax
  mov    -0x28(%rbp),%rcx
  mov    %rax,%rsi
  lea    D26(%rip),%rax
  mov    %rax,%rdi
  call   <show_file@plt>
  lea    -0x20(%rbp),%rdx
  lea    -0x18(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <update_tree_entry@plt>
  jmp    L6
L58:
  mov    -0x20(%rbp),%rax
  test   %rax,%rax
  jne    L18
  mov    -0x10(%rbp),%rdx
  mov    -0x8(%rbp),%rax
  mov    -0x28(%rbp),%rcx
  mov    %rax,%rsi
  lea    D14(%rip),%rax
  mov    %rax,%rdi
  call   <show_file@plt>
  lea    -0x10(%rbp),%rdx
  lea    -0x8(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <update_tree_entry@plt>
  jmp    L6
L18:
  mov    -0x20(%rbp),%rcx
  mov    -0x18(%rbp),%rdx
  mov    -0x10(%rbp),%rsi
  mov    -0x8(%rbp),%rax
  mov    -0x28(%rbp),%rdi
  mov    %rdi,%r8
  mov    %rax,%rdi
  call   <compare_tree_entry@plt>
  cmp    $0x1,%eax
  je     L14
  cmp    $0x1,%eax
  jg     L122
  cmp    $0xffffffff,%eax
  je     L128
  test   %eax,%eax
  je     L31
  jmp    L122
L128:
  lea    -0x10(%rbp),%rdx
  lea    -0x8(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <update_tree_entry@plt>
  jmp    L6
L31:
  lea    -0x10(%rbp),%rdx
  lea    -0x8(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <update_tree_entry@plt>
L14:
  lea    -0x20(%rbp),%rdx
  lea    -0x18(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <update_tree_entry@plt>
  jmp    L6
L122:
  lea    D16(%rip),%rax
  mov    %rax,%rdi
  call   <usage@plt>
L6:
  mov    -0x10(%rbp),%rdx
  mov    -0x20(%rbp),%rax
  or     %rdx,%rax
  test   %rax,%rax
  jne    L116
  mov    $0x0,%eax
  leave
  ret
```

tool_calls: name: retrieve_data
arguments: data_label: D26
data_type: string
name: retrieve_data
arguments: data_label: D14
data_type: string
name: retrieve_data
arguments: data_label: D16
data_type: string

tool: D26: +

tool: D14: -

tool: D16: diff-tree: internal error

assistant: ```c
int diff_tree(void *tree1, unsigned long size1, void *tree2, unsigned long size2, const char *base) {
  while (size1 | size2) {
    if (!size1) {
      show_file("+", tree2, size2, base);
      update_tree_entry(&tree2, &size2);
      continue;
    }
    if (!size2) {
      show_file("-", tree1, size1, base);
      update_tree_entry(&tree1, &size1);
      continue;
    }
    switch (compare_tree_entry(tree1, size1, tree2, size2, base)) {
    case -1:
      update_tree_entry(&tree1, &size1);
      continue;
    case 0:
      update_tree_entry(&tree1, &size1);
    case 1:
      update_tree_entry(&tree2, &size2);
      continue;
    }
    usage("diff-tree: internal error");
  }
  return 0;
}
```
user: 请将以下的汇编代码转换成C语言代码:

```asm
<diff_tree>:
  endbr64
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x20,%rsp
  mov    %rdi,0x18(%rsp)
  mov    %rsi,0x10(%rsp)
  mov    %rdx,0x8(%rsp)
  mov    %rcx,(%rsp)
  mov    %rsi,%rax
  or     %rcx,%rax
  je     L59
  mov    %rcx,%rdx
  mov    %r8,%rbx
  mov    %rsp,%rbp
  lea    D3(%rip),%r14
  lea    D27(%rip),%r12
  lea    D17(%rip),%r13
  jmp    L115
L43:
  mov    %rbx,%rcx
  mov    0x8(%rsp),%rsi
  mov    %r13,%rdi
  call   <show_file@plt>
  lea    0x8(%rsp),%rdi
  mov    %rbp,%rsi
  call   <update_tree_entry@plt>
  jmp    L18
L21:
  mov    %rbx,%rcx
  mov    %rsi,%rdx
  mov    0x18(%rsp),%rsi
  mov    %r12,%rdi
  call   <show_file@plt>
  lea    0x10(%rsp),%rsi
  lea    0x18(%rsp),%rdi
  call   <update_tree_entry@plt>
  jmp    L18
L91:
  lea    0x10(%rsp),%rsi
  lea    0x18(%rsp),%rdi
  call   <update_tree_entry@plt>
  jmp    L18
L10:
  lea    0x10(%rsp),%rsi
  lea    0x18(%rsp),%rdi
  call   <update_tree_entry@plt>
L53:
  lea    0x8(%rsp),%rdi
  mov    %rbp,%rsi
  call   <update_tree_entry@plt>
L18:
  mov    0x10(%rsp),%rsi
  mov    (%rsp),%rdx
  mov    %rsi,%rax
  or     %rdx,%rax
  je     L59
L115:
  test   %rsi,%rsi
  je     L43
  test   %rdx,%rdx
  je     L21
  mov    %rbx,%r8
  mov    %rdx,%rcx
  mov    0x8(%rsp),%rdx
  mov    0x18(%rsp),%rdi
  call   <compare_tree_entry@plt>
  test   %eax,%eax
  je     L10
  cmp    $0x1,%eax
  je     L53
  cmp    $0xffffffff,%eax
  je     L91
  mov    %r14,%rdi
  call   <usage@plt>
  jmp    L18
L59:
  mov    $0x0,%eax
  add    $0x20,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
```

tool_calls: name: disassemble_data
arguments: label: D3
type_infered: string
name: disassemble_data
arguments: label: D27
type_infered: string
name: disassemble_data
arguments: label: D17
type_infered: string

tool: D3: diff-tree: internal error

tool: D27: -

tool: D17: +

assistant: ```c
int diff_tree(void *tree1, unsigned long size1, void *tree2, unsigned long size2, const char *base) {
  while (size1 | size2) {
    if (!size1) {
      show_file("+", tree2, size2, base);
      update_tree_entry(&tree2, &size2);
      continue;
    }
    if (!size2) {
      show_file("-", tree1, size1, base);
      update_tree_entry(&tree1, &size1);
      continue;
    }
    switch (compare_tree_entry(tree1, size1, tree2, size2, base)) {
    case -1:
      update_tree_entry(&tree1, &size1);
      continue;
    case 0:
      update_tree_entry(&tree1, &size1);
    case 1:
      update_tree_entry(&tree2, &size2);
      continue;
    }
    usage("diff-tree: internal error");
  }
  return 0;
}
```
user: 请从给定的汇编指令推导出C源代码:

```asm
<diff_tree>:
  endbr64
  push   %r14
  mov    %rsi,%rax
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x20,%rsp
  or     %rcx,%rax
  mov    %rdi,0x18(%rsp)
  mov    %rsi,0x10(%rsp)
  mov    %rdx,0x8(%rsp)
  mov    %rcx,(%rsp)
  je     L9
  mov    %rcx,%r9
  mov    %r8,%rbx
  lea    D21(%rip),%r14
  mov    %rsp,%rbp
  lea    D25(%rip),%r12
  lea    D17(%rip),%r13
  jmp    L3
  nop
L56:
  mov    0x8(%rsp),%rdx
  mov    %rbx,%r8
  mov    %r9,%rcx
  call   <compare_tree_entry@plt>
  test   %eax,%eax
  je     L117
  cmp    $0x1,%eax
  je     L81
  cmp    $0xffffffff,%eax
  je     L96
  mov    %r14,%rdi
  call   <usage@plt>
  nopw   0x0(%rax,%rax,1)
L38:
  mov    0x10(%rsp),%rsi
  mov    (%rsp),%r9
  mov    %rsi,%rax
  or     %r9,%rax
  je     L9
L3:
  test   %rsi,%rsi
  je     L16
  mov    0x18(%rsp),%rdi
  test   %r9,%r9
  jne    L56
  mov    %rsi,%rdx
  mov    %rbx,%rcx
  mov    %rdi,%rsi
  mov    %r12,%rdi
  call   <show_file@plt>
  lea    0x10(%rsp),%rsi
  lea    0x18(%rsp),%rdi
  call   <update_tree_entry@plt>
  jmp    L38
  cs nopw 0x0(%rax,%rax,1)
L117:
  lea    0x10(%rsp),%rsi
  lea    0x18(%rsp),%rdi
  call   <update_tree_entry@plt>
L81:
  lea    0x8(%rsp),%rdi
  mov    %rbp,%rsi
  call   <update_tree_entry@plt>
  jmp    L38
  xchg   %ax,%ax
L16:
  mov    0x8(%rsp),%rsi
  mov    %r13,%rdi
  mov    %rbx,%rcx
  mov    %r9,%rdx
  call   <show_file@plt>
  lea    0x8(%rsp),%rdi
  mov    %rbp,%rsi
  call   <update_tree_entry@plt>
  jmp    L38
  nopl   (%rax)
L96:
  lea    0x10(%rsp),%rsi
  lea    0x18(%rsp),%rdi
  call   <update_tree_entry@plt>
  jmp    L38
  nopl   0x0(%rax)
L9:
  add    $0x20,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
```

tool_calls: name: parse_data
arguments: data_label: D21
type: string
name: parse_data
arguments: data_label: D25
type: string
name: parse_data
arguments: data_label: D17
type: string

tool: D21: diff-tree: internal error

tool: D25: -

tool: D17: +

assistant: ```c
int diff_tree(void *tree1, unsigned long size1, void *tree2, unsigned long size2, const char *base) {
  while (size1 | size2) {
    if (!size1) {
      show_file("+", tree2, size2, base);
      update_tree_entry(&tree2, &size2);
      continue;
    }
    if (!size2) {
      show_file("-", tree1, size1, base);
      update_tree_entry(&tree1, &size1);
      continue;
    }
    switch (compare_tree_entry(tree1, size1, tree2, size2, base)) {
    case -1:
      update_tree_entry(&tree1, &size1);
      continue;
    case 0:
      update_tree_entry(&tree1, &size1);
    case 1:
      update_tree_entry(&tree2, &size2);
      continue;
    }
    usage("diff-tree: internal error");
  }
  return 0;
}
```
user: What would the C source look like for the assembly code provided here?

```asm
<diff_tree>:
  endbr64
  push   %r14
  mov    %rsi,%rax
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x20,%rsp
  or     %rcx,%rax
  mov    %rdi,0x18(%rsp)
  mov    %rsi,0x10(%rsp)
  mov    %rdx,0x8(%rsp)
  mov    %rcx,(%rsp)
  je     L76
  mov    %rcx,%r9
  mov    %r8,%rbx
  lea    D21(%rip),%r14
  mov    %rsp,%rbp
  lea    D13(%rip),%r12
  lea    D18(%rip),%r13
  jmp    L73
  nop
L100:
  mov    0x8(%rsp),%rdx
  mov    %rbx,%r8
  mov    %r9,%rcx
  call   <compare_tree_entry@plt>
  test   %eax,%eax
  je     L75
  cmp    $0x1,%eax
  je     L66
  cmp    $0xffffffff,%eax
  je     L16
  mov    %r14,%rdi
  call   <usage@plt>
  nopw   0x0(%rax,%rax,1)
L10:
  mov    0x10(%rsp),%rsi
  mov    (%rsp),%r9
  mov    %rsi,%rax
  or     %r9,%rax
  je     L76
L73:
  test   %rsi,%rsi
  je     L118
  mov    0x18(%rsp),%rdi
  test   %r9,%r9
  jne    L100
  mov    %rsi,%rdx
  mov    %rbx,%rcx
  mov    %rdi,%rsi
  mov    %r12,%rdi
  call   <show_file@plt>
  lea    0x10(%rsp),%rsi
  lea    0x18(%rsp),%rdi
  call   <update_tree_entry@plt>
  jmp    L10
  cs nopw 0x0(%rax,%rax,1)
L75:
  lea    0x10(%rsp),%rsi
  lea    0x18(%rsp),%rdi
  call   <update_tree_entry@plt>
L66:
  lea    0x8(%rsp),%rdi
  mov    %rbp,%rsi
  call   <update_tree_entry@plt>
  jmp    L10
  xchg   %ax,%ax
L118:
  mov    0x8(%rsp),%rsi
  mov    %r13,%rdi
  mov    %rbx,%rcx
  mov    %r9,%rdx
  call   <show_file@plt>
  lea    0x8(%rsp),%rdi
  mov    %rbp,%rsi
  call   <update_tree_entry@plt>
  jmp    L10
  nopl   (%rax)
L16:
  lea    0x10(%rsp),%rsi
  lea    0x18(%rsp),%rdi
  call   <update_tree_entry@plt>
  jmp    L10
  nopl   0x0(%rax)
L76:
  add    $0x20,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
```

tool_calls: name: disassemble_data
arguments: label: D21
datatype: string
name: disassemble_data
arguments: label: D13
datatype: string
name: disassemble_data
arguments: label: D18
datatype: string

tool: D21: diff-tree: internal error

tool: D13: -

tool: D18: +

assistant: ```c
int diff_tree(void *tree1, unsigned long size1, void *tree2, unsigned long size2, const char *base) {
  while (size1 | size2) {
    if (!size1) {
      show_file("+", tree2, size2, base);
      update_tree_entry(&tree2, &size2);
      continue;
    }
    if (!size2) {
      show_file("-", tree1, size1, base);
      update_tree_entry(&tree1, &size1);
      continue;
    }
    switch (compare_tree_entry(tree1, size1, tree2, size2, base)) {
    case -1:
      update_tree_entry(&tree1, &size1);
      continue;
    case 0:
      update_tree_entry(&tree1, &size1);
    case 1:
      update_tree_entry(&tree2, &size2);
      continue;
    }
    usage("diff-tree: internal error");
  }
  return 0;
}
```
user: Converte this assembly snippet into its equivalent C code:

```asm
<xrop3_54_1_0>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %edi,%edx
  mov    %esi,%eax
  mov    %dl,-0x24(%rbp)
  mov    %al,-0x28(%rbp)
  movl   $0xff,-0x14(%rbp)
  movzbl -0x24(%rbp),%eax
  shl    $0x8,%eax
  mov    %eax,%edx
  movzbl -0x24(%rbp),%eax
  or     %edx,%eax
  mov    %eax,-0x10(%rbp)
  movzbl -0x28(%rbp),%eax
  shl    $0x8,%eax
  mov    %eax,%edx
  movzbl -0x28(%rbp),%eax
  or     %edx,%eax
  mov    %eax,-0xc(%rbp)
  mov    -0x14(%rbp),%eax
  or     -0xc(%rbp),%eax
  mov    %eax,-0x8(%rbp)
  mov    -0x10(%rbp),%eax
  xor    -0x8(%rbp),%eax
  mov    %eax,-0x4(%rbp)
  mov    -0x10(%rbp),%eax
  not    %eax
  and    -0x4(%rbp),%eax
  mov    %eax,%edx
  mov    -0x14(%rbp),%eax
  and    -0x10(%rbp),%eax
  or     %edx,%eax
  pop    %rbp
  ret
```

assistant: ```c
unsigned xrop3_54_1_0(unsigned char s, unsigned char t) {
  unsigned D = 0x00ff;
  unsigned S = ((unsigned)s << 8) | s;
  unsigned T = ((unsigned)t << 8) | t;
  unsigned stk1;
  unsigned stk2;
  stk2 = D | T;
  stk1 = S ^ stk2;
  return (stk1 & (~S)) | (D & S);
}
```
user: 请将以下的汇编代码转换成C语言代码：

```asm
<xrop3_54_1_0>:
  endbr64
  movzbl %dil,%eax
  mov    %eax,%edi
  shl    $0x8,%edi
  or     %eax,%edi
  movzbl %sil,%esi
  shl    $0x8,%esi
  or     $0xff,%sil
  xor    %edi,%esi
  mov    %esi,%eax
  xor    $0xff,%al
  and    %edi,%eax
  xor    %esi,%eax
  ret
```

assistant: ```c
unsigned xrop3_54_1_0(unsigned char s, unsigned char t) {
  unsigned D = 0x00ff;
  unsigned S = ((unsigned)s << 8) | s;
  unsigned T = ((unsigned)t << 8) | t;
  unsigned stk1;
  unsigned stk2;
  stk2 = D | T;
  stk1 = S ^ stk2;
  return (stk1 & (~S)) | (D & S);
}
```
user: 下面的汇编指令对应的C源代码是什么：

```asm
<xrop3_54_1_0>:
  endbr64
  movzbl %dil,%eax
  movzbl %sil,%esi
  mov    %eax,%edi
  shl    $0x8,%esi
  shl    $0x8,%edi
  or     $0xff,%sil
  or     %eax,%edi
  xor    %edi,%esi
  mov    %esi,%eax
  xor    $0xff,%al
  and    %edi,%eax
  xor    %esi,%eax
  ret
```

assistant: ```c
unsigned xrop3_54_1_0(unsigned char s, unsigned char t) {
  unsigned D = 0x00ff;
  unsigned S = ((unsigned)s << 8) | s;
  unsigned T = ((unsigned)t << 8) | t;
  unsigned stk1;
  unsigned stk2;
  stk2 = D | T;
  stk1 = S ^ stk2;
  return (stk1 & (~S)) | (D & S);
}
```
user: 这段汇编代码用C语言表示是什么样的？

```asm
<xgetgrgid>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdi,-0x28(%rbp)
  movl   $0x0,-0x1c(%rbp)
  jmp    L26
L44:
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  lea    D116(%rip),%rax
  mov    (%rdx,%rax,1),%rax
  cmp    %rax,-0x28(%rbp)
  jne    L18
  mov    -0x1c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  lea    D40(%rip),%rax
  mov    (%rdx,%rax,1),%rax
  jmp    L73
L18:
  addl   $0x1,-0x1c(%rbp)
L26:
  mov    -0x1c(%rbp),%edx
  mov    D163(%rip),%eax
  cmp    %eax,%edx
  jb     L44
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <getgrgid@plt>
  mov    %rax,-0x18(%rbp)
  mov    D194(%rip),%eax
  mov    %eax,%eax
  lea    0x0(,%rax,8),%rdx
  lea    D40(%rip),%rax
  mov    (%rdx,%rax,1),%rax
  test   %rax,%rax
  je     L63
  mov    D194(%rip),%eax
  mov    %eax,%eax
  lea    0x0(,%rax,8),%rdx
  lea    D40(%rip),%rax
  mov    (%rdx,%rax,1),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    D194(%rip),%eax
  mov    %eax,%eax
  lea    0x0(,%rax,8),%rdx
  lea    D40(%rip),%rax
  movq   $0x0,(%rdx,%rax,1)
L63:
  cmpq   $0x0,-0x18(%rbp)
  je     L0
  mov    -0x18(%rbp),%rax
  mov    (%rax),%rax
  mov    D194(%rip),%ebx
  mov    %rax,%rdi
  call   <strdup@plt>
  mov    %rax,%rcx
  mov    %ebx,%eax
  lea    0x0(,%rax,8),%rdx
  lea    D40(%rip),%rax
  mov    %rcx,(%rdx,%rax,1)
L0:
  mov    D194(%rip),%eax
  mov    %eax,%eax
  lea    0x0(,%rax,8),%rcx
  lea    D116(%rip),%rdx
  mov    -0x28(%rbp),%rax
  mov    %rax,(%rcx,%rdx,1)
  mov    D194(%rip),%eax
  add    $0x1,%eax
  mov    %eax,D122(%rip)
  mov    D122(%rip),%eax
  cmp    $0x20,%eax
  jne    L95
  movl   $0x0,D122(%rip)
L95:
  mov    D163(%rip),%eax
  cmp    $0x1f,%eax
  ja     L94
  mov    D163(%rip),%eax
  add    $0x1,%eax
  mov    %eax,D122(%rip)
L94:
  cmpq   $0x0,-0x18(%rbp)
  je     L53
  mov    -0x18(%rbp),%rax
  mov    (%rax),%rax
  jmp    L73
L53:
  mov    $0x0,%eax
L73:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

assistant: ```c
char *xgetgrgid(gid_t gid) {
  static char *cache[32];
  static gid_t gids[32];
  static unsigned int used, next;
  struct group *gr;
  int i;
  for (i = 0; i < used; i++) {
    if (gids[i] == gid) {
      return cache[i];
    }
  }
  gr = getgrgid(gid);
  if (NULL != cache[next]) {
    free(cache[next]);
    cache[next] = NULL;
  }
  if (NULL != gr) {
    cache[next] = strdup(gr->gr_name);
  }
  gids[next] = gid;
  next++;
  if (32 == next) {
    next = 0;
  }
  if (used < 32) {
    used++;
  }
  return gr ? gr->gr_name : NULL;
}
```
user: 请将这段汇编代码片段转换成等效的C代码:

```asm
<xgetgrgid>:
  endbr64
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdi,%rbx
  mov    D18(%rip),%edx
  test   %edx,%edx
  je     L39
  mov    %edx,%edx
  mov    $0x0,%eax
  lea    D42(%rip),%rsi
L63:
  cmp    %rbx,(%rsi,%rax,8)
  je     L25
  add    $0x1,%rax
  cmp    %rdx,%rax
  jne    L63
L39:
  mov    %rbx,%rdi
  call   <getgrgid@plt>
  mov    %rax,%rbp
  mov    D114(%rip),%edx
  lea    D20(%rip),%rax
  mov    (%rax,%rdx,8),%rdi
  test   %rdi,%rdi
  je     L71
  call   <free@plt>
  mov    D114(%rip),%edx
  lea    D20(%rip),%rax
  movq   $0x0,(%rax,%rdx,8)
L71:
  test   %rbp,%rbp
  je     L66
  mov    D114(%rip),%r12d
  mov    0x0(%rbp),%rdi
  call   <strdup@plt>
  mov    %rax,%rdx
  mov    %r12d,%r12d
  lea    D20(%rip),%rax
  mov    %rdx,(%rax,%r12,8)
L66:
  mov    D114(%rip),%edx
  mov    %edx,%ecx
  lea    D42(%rip),%rax
  mov    %rbx,(%rax,%rcx,8)
  lea    0x1(%rdx),%eax
  cmp    $0x1f,%edx
  mov    $0x0,%edx
  cmove  %edx,%eax
  mov    %eax,D130(%rip)
  mov    D18(%rip),%eax
  cmp    $0x1f,%eax
  ja     L60
  add    $0x1,%eax
  mov    %eax,D130(%rip)
L60:
  test   %rbp,%rbp
  je     L14
  mov    0x0(%rbp),%rbp
  jmp    L14
L25:
  movslq %eax,%rcx
  lea    D20(%rip),%rax
  mov    (%rax,%rcx,8),%rbp
L14:
  mov    %rbp,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
```

assistant: ```c
char *xgetgrgid(gid_t gid) {
  static char *cache[32];
  static gid_t gids[32];
  static unsigned int used, next;
  struct group *gr;
  int i;
  for (i = 0; i < used; i++) {
    if (gids[i] == gid) {
      return cache[i];
    }
  }
  gr = getgrgid(gid);
  if (NULL != cache[next]) {
    free(cache[next]);
    cache[next] = NULL;
  }
  if (NULL != gr) {
    cache[next] = strdup(gr->gr_name);
  }
  gids[next] = gid;
  next++;
  if (32 == next) {
    next = 0;
  }
  if (used < 32) {
    used++;
  }
  return gr ? gr->gr_name : NULL;
}
```
user: 提供的汇编代码用C语言表示会是什么样子：

```asm
<xgetgrgid>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  lea    D41(%rip),%rbp
  push   %rbx
  mov    %rdi,%rbx
  sub    $0x8,%rsp
  mov    D96(%rip),%edx
  test   %edx,%edx
  je     L58
  xor    %eax,%eax
  lea    D41(%rip),%rbp
  jmp    L39
  nopl   0x0(%rax)
L69:
  add    $0x1,%rax
  cmp    %rdx,%rax
  je     L58
L39:
  movslq %eax,%rcx
  cmp    %rbx,0x0(%rbp,%rax,8)
  jne    L69
  lea    D4(%rip),%rax
  mov    (%rax,%rcx,8),%r12
L46:
  add    $0x8,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L58:
  mov    %rbx,%rdi
  lea    D4(%rip),%r15
  call   <getgrgid@plt>
  mov    D14(%rip),%r14d
  mov    %rax,%r12
  mov    (%r15,%r14,8),%rdi
  mov    %r14,%r13
  test   %rdi,%rdi
  je     L80
  call   <free@plt>
  mov    D14(%rip),%r14d
  movq   $0x0,(%r15,%r14,8)
  mov    %r14,%r13
L80:
  test   %r12,%r12
  je     L25
  mov    (%r12),%rdi
  call   <strdup@plt>
  mov    %rax,(%r15,%r14,8)
L25:
  xor    %edx,%edx
  lea    0x1(%r13),%eax
  cmp    $0x1f,%r13d
  mov    %rbx,0x0(%rbp,%r14,8)
  cmove  %edx,%eax
  mov    %eax,D59(%rip)
  mov    D96(%rip),%eax
  cmp    $0x1f,%eax
  ja     L75
  add    $0x1,%eax
  mov    %eax,D59(%rip)
L75:
  test   %r12,%r12
  je     L46
  mov    (%r12),%r12
  jmp    L46
```

assistant: ```c
char *xgetgrgid(gid_t gid) {
  static char *cache[32];
  static gid_t gids[32];
  static unsigned int used, next;
  struct group *gr;
  int i;
  for (i = 0; i < used; i++) {
    if (gids[i] == gid) {
      return cache[i];
    }
  }
  gr = getgrgid(gid);
  if (NULL != cache[next]) {
    free(cache[next]);
    cache[next] = NULL;
  }
  if (NULL != gr) {
    cache[next] = strdup(gr->gr_name);
  }
  gids[next] = gid;
  next++;
  if (32 == next) {
    next = 0;
  }
  if (used < 32) {
    used++;
  }
  return gr ? gr->gr_name : NULL;
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<xgetgrgid>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  lea    D14(%rip),%rbp
  push   %rbx
  mov    %rdi,%rbx
  sub    $0x8,%rsp
  mov    D91(%rip),%edx
  test   %edx,%edx
  je     L63
  xor    %eax,%eax
  lea    D14(%rip),%rbp
  jmp    L19
  nopl   0x0(%rax)
L6:
  add    $0x1,%rax
  cmp    %rdx,%rax
  je     L63
L19:
  movslq %eax,%rcx
  cmp    %rbx,0x0(%rbp,%rax,8)
  jne    L6
  lea    D89(%rip),%rax
  mov    (%rax,%rcx,8),%r12
L44:
  add    $0x8,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L63:
  mov    %rbx,%rdi
  lea    D89(%rip),%r15
  call   <getgrgid@plt>
  mov    D40(%rip),%r14d
  mov    %rax,%r12
  mov    (%r15,%r14,8),%rdi
  mov    %r14,%r13
  test   %rdi,%rdi
  je     L46
  call   <free@plt>
  mov    D40(%rip),%r14d
  movq   $0x0,(%r15,%r14,8)
  mov    %r14,%r13
L46:
  test   %r12,%r12
  je     L16
  mov    (%r12),%rdi
  call   <strdup@plt>
  mov    %rax,(%r15,%r14,8)
L16:
  xor    %edx,%edx
  lea    0x1(%r13),%eax
  cmp    $0x1f,%r13d
  mov    %rbx,0x0(%rbp,%r14,8)
  cmove  %edx,%eax
  mov    %eax,D23(%rip)
  mov    D91(%rip),%eax
  cmp    $0x1f,%eax
  ja     L41
  add    $0x1,%eax
  mov    %eax,D23(%rip)
L41:
  test   %r12,%r12
  je     L44
  mov    (%r12),%r12
  jmp    L44
```

assistant: ```c
char *xgetgrgid(gid_t gid) {
  static char *cache[32];
  static gid_t gids[32];
  static unsigned int used, next;
  struct group *gr;
  int i;
  for (i = 0; i < used; i++) {
    if (gids[i] == gid) {
      return cache[i];
    }
  }
  gr = getgrgid(gid);
  if (NULL != cache[next]) {
    free(cache[next]);
    cache[next] = NULL;
  }
  if (NULL != gr) {
    cache[next] = strdup(gr->gr_name);
  }
  gids[next] = gid;
  next++;
  if (32 == next) {
    next = 0;
  }
  if (used < 32) {
    used++;
  }
  return gr ? gr->gr_name : NULL;
}
```