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

```asm
<Find_Shortest_Route>:
  endbr64
  btr    %esi,%edx
  push   %r14
  push   %r13
  push   %r12
  xor    %r12d,%r12d
  push   %rbp
  push   %rbx
  test   %edx,%edx
  je     L42
  mov    D3(%rip),%rax
  movslq %esi,%rsi
  mov    %rdi,%r13
  mov    %edx,%ebp
  lea    (%rdi,%rsi,8),%r14
  xor    %ebx,%ebx
  mov    (%rax),%r12d
  jmp    L17
L5:
  add    $0x1,%rbx
  cmp    $0x10,%rbx
  je     L42
L17:
  bt     %ebx,%ebp
  mov    %ebx,%esi
  jae    L5
  mov    %ebp,%edx
  mov    %r13,%rdi
  call   <Find_Shortest_Route>
  mov    (%r14),%rdx
  add    (%rdx,%rbx,4),%eax
  cmp    %eax,%r12d
  cmovg  %eax,%r12d
  add    $0x1,%rbx
  cmp    $0x10,%rbx
  jne    L17
L42:
  pop    %rbx
  mov    %r12d,%eax
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
```

assistant: ```c
int Find_Shortest_Route(int **distances, int startNode, uint16_t unvisitedMask) {
  int n, minDist, nextDist;
  unvisitedMask &= ~(1 << startNode);
  if (unvisitedMask == 0x0000)
    return 0;
  minDist = INT_MAX;
  for (n = 0; n < 16; n++) {
    if (unvisitedMask & (1 << n)) {
      nextDist = distances[startNode][n] + Find_Shortest_Route(distances, n, unvisitedMask);
      if (nextDist < minDist)
        minDist = nextDist;
    }
  }
  return minDist;
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<add_field_list>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x20,%rsp
  mov    %rdi,-0x18(%rbp)
  movl   $0x0,-0x10(%rbp)
  movl   $0xffffffff,-0xc(%rbp)
  movl   $0xffffffff,-0x8(%rbp)
  movl   $0x0,-0x4(%rbp)
  jmp    L137
L118:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2c,%al
  je     L43
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x20,%al
  je     L43
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x9,%al
  jne    L65
L43:
  mov    -0x8(%rbp),%edx
  mov    -0xc(%rbp),%eax
  mov    %edx,%esi
  mov    %eax,%edi
  call   <add_field@plt>
  mov    %eax,%edx
  mov    -0x10(%rbp),%eax
  add    %edx,%eax
  mov    %eax,-0x10(%rbp)
  movl   $0xffffffff,-0x8(%rbp)
  mov    -0x8(%rbp),%eax
  mov    %eax,-0xc(%rbp)
  movl   $0x0,-0x4(%rbp)
  jmp    L32
L65:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2e,%al
  jne    L19
  movl   $0x1,-0x4(%rbp)
  jmp    L32
L19:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  mov    %eax,%edi
  call   <isdigit@plt>
  test   %rax,%rax
  je     L84
  cmpl   $0x0,-0x4(%rbp)
  jne    L28
  cmpl   $0xffffffff,-0xc(%rbp)
  jne    L21
  movl   $0x0,-0xc(%rbp)
L21:
  mov    -0xc(%rbp),%edx
  mov    %edx,%eax
  shl    $0x2,%eax
  add    %edx,%eax
  add    %eax,%eax
  mov    %eax,%edx
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  add    %edx,%eax
  sub    $0x30,%eax
  mov    %eax,-0xc(%rbp)
  jmp    L32
L28:
  cmpl   $0xffffffff,-0x8(%rbp)
  jne    L133
  movl   $0x0,-0x8(%rbp)
L133:
  mov    -0x8(%rbp),%edx
  mov    %edx,%eax
  shl    $0x2,%eax
  add    %edx,%eax
  add    %eax,%eax
  mov    %eax,%edx
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  add    %edx,%eax
  sub    $0x30,%eax
  mov    %eax,-0x8(%rbp)
  jmp    L32
L84:
  mov    $0x0,%eax
  jmp    L51
L32:
  addq   $0x1,-0x18(%rbp)
L137:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L118
  mov    -0x8(%rbp),%edx
  mov    -0xc(%rbp),%eax
  mov    %edx,%esi
  mov    %eax,%edi
  call   <add_field@plt>
  mov    %eax,%edx
  mov    -0x10(%rbp),%eax
  add    %edx,%eax
  mov    %eax,-0x10(%rbp)
  mov    -0x10(%rbp),%eax
L51:
  leave
  ret
```

assistant: ```c
int add_field_list(char *str) {
  int added = 0;
  int file = -1, field = -1;
  int dot_found = 0;
  for (; *str; str++) {
    if (*str == ',' || ((*str) == ' ' || (*str) == '\t')) {
      added += add_field(file, field);
      file = field = -1;
      dot_found = 0;
    } else if (*str == '.')
      dot_found = 1;
    else if (isdigit(*str)) {
      if (!dot_found) {
        if (file == -1)
          file = 0;
        file = file * 10 + *str - '0';
      } else {
        if (field == -1)
          field = 0;
        field = field * 10 + *str - '0';
      }
    } else
      return 0;
  }
  added += add_field(file, field);
  return added;
}
```
user: Translate the below assembly code into C programming language:

```asm
<add_field_list>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x8,%rsp
  mov    %rdi,%rbx
  movzbl (%rdi),%edi
  test   %dil,%dil
  je     L67
  mov    $0x0,%r14d
  mov    $0xffffffff,%r12d
  mov    $0xffffffff,%ebp
  mov    $0x0,%r13d
  movabs $0x100100000200,%r15
  jmp    L109
L49:
  mov    %r12d,%esi
  mov    %ebp,%edi
  call   <add_field@plt>
  add    %eax,%r13d
  mov    $0x0,%r14d
  mov    $0xffffffff,%r12d
  mov    $0xffffffff,%ebp
L72:
  add    $0x1,%rbx
  movzbl (%rbx),%edi
  test   %dil,%dil
  je     L39
L109:
  cmp    $0x2c,%dil
  ja     L24
  bt     %rdi,%r15
  jb     L49
L61:
  movsbl %dil,%edi
  call   <isdigit@plt>
  test   %rax,%rax
  je     L74
  test   %r14d,%r14d
  jne    L18
  cmp    $0xffffffff,%ebp
  cmove  %r14d,%ebp
  lea    0x0(%rbp,%rbp,4),%edx
  movsbl (%rbx),%eax
  lea    -0x30(%rax,%rdx,2),%ebp
  jmp    L72
L18:
  cmp    $0xffffffff,%r12d
  mov    $0x0,%eax
  cmove  %eax,%r12d
  lea    (%r12,%r12,4),%edx
  movsbl (%rbx),%eax
  lea    -0x30(%rax,%rdx,2),%r12d
  jmp    L72
L67:
  mov    $0xffffffff,%r12d
  mov    $0xffffffff,%ebp
  mov    $0x0,%r13d
L39:
  mov    %r12d,%esi
  mov    %ebp,%edi
  call   <add_field@plt>
  add    %r13d,%eax
L99:
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L74:
  mov    $0x0,%eax
  jmp    L99
L24:
  cmp    $0x2e,%dil
  jne    L61
  mov    $0x1,%r14d
  jmp    L72
```

assistant: ```c
int add_field_list(char *str) {
  int added = 0;
  int file = -1, field = -1;
  int dot_found = 0;
  for (; *str; str++) {
    if (*str == ',' || ((*str) == ' ' || (*str) == '\t')) {
      added += add_field(file, field);
      file = field = -1;
      dot_found = 0;
    } else if (*str == '.')
      dot_found = 1;
    else if (isdigit(*str)) {
      if (!dot_found) {
        if (file == -1)
          file = 0;
        file = file * 10 + *str - '0';
      } else {
        if (field == -1)
          field = 0;
        field = field * 10 + *str - '0';
      }
    } else
      return 0;
  }
  added += add_field(file, field);
  return added;
}
```
user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<add_field_list>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdi,%rbx
  sub    $0x8,%rsp
  movsbl (%rdi),%edi
  test   %dil,%dil
  je     L19
  xor    %r15d,%r15d
  mov    $0xffffffff,%r14d
  mov    $0xffffffff,%ebp
  xor    %r12d,%r12d
  movabs $0xffffeffefffffdff,%r13
  jmp    L50
  xchg   %ax,%ax
L43:
  bt     %rdi,%r13
  jb     L29
  mov    %r14d,%esi
  mov    %ebp,%edi
  xor    %r15d,%r15d
  mov    $0xffffffff,%r14d
  call   <add_field@plt>
  mov    $0xffffffff,%ebp
  add    %eax,%r12d
L0:
  movsbl 0x1(%rbx),%edi
  add    $0x1,%rbx
  test   %dil,%dil
  je     L3
L50:
  cmp    $0x2c,%dil
  jbe    L43
  cmp    $0x2e,%dil
  jne    L29
  movsbl 0x1(%rbx),%edi
  add    $0x1,%rbx
  mov    $0x1,%r15d
  test   %dil,%dil
  jne    L50
L3:
  mov    %r14d,%esi
  mov    %ebp,%edi
  call   <add_field@plt>
  add    %r12d,%eax
L73:
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L29:
  call   <isdigit@plt>
  test   %rax,%rax
  mov    $0x0,%eax
  je     L73
  test   %r15d,%r15d
  jne    L112
  cmp    $0xffffffff,%ebp
  je     L134
  lea    0x0(%rbp,%rbp,4),%eax
  add    %eax,%eax
L134:
  movsbl (%rbx),%edx
  lea    -0x30(%rax,%rdx,1),%ebp
  jmp    L0
  nopl   0x0(%rax,%rax,1)
L112:
  cmp    $0xffffffff,%r14d
  je     L129
  lea    (%r14,%r14,4),%eax
  add    %eax,%eax
L129:
  movsbl (%rbx),%edx
  lea    -0x30(%rax,%rdx,1),%r14d
  jmp    L0
L19:
  xor    %r12d,%r12d
  mov    $0xffffffff,%r14d
  mov    $0xffffffff,%ebp
  jmp    L3
```

assistant: ```c
int add_field_list(char *str) {
  int added = 0;
  int file = -1, field = -1;
  int dot_found = 0;
  for (; *str; str++) {
    if (*str == ',' || ((*str) == ' ' || (*str) == '\t')) {
      added += add_field(file, field);
      file = field = -1;
      dot_found = 0;
    } else if (*str == '.')
      dot_found = 1;
    else if (isdigit(*str)) {
      if (!dot_found) {
        if (file == -1)
          file = 0;
        file = file * 10 + *str - '0';
      } else {
        if (field == -1)
          field = 0;
        field = field * 10 + *str - '0';
      }
    } else
      return 0;
  }
  added += add_field(file, field);
  return added;
}
```
user: 请从给定的汇编指令推导出C源代码:

```asm
<add_field_list>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdi,%rbx
  sub    $0x8,%rsp
  movsbl (%rdi),%edi
  test   %dil,%dil
  je     L104
  xor    %r15d,%r15d
  mov    $0xffffffff,%r14d
  mov    $0xffffffff,%ebp
  xor    %r12d,%r12d
  movabs $0xffffeffefffffdff,%r13
  jmp    L74
  xchg   %ax,%ax
L135:
  bt     %rdi,%r13
  jb     L85
  mov    %r14d,%esi
  mov    %ebp,%edi
  xor    %r15d,%r15d
  mov    $0xffffffff,%r14d
  call   <add_field@plt>
  mov    $0xffffffff,%ebp
  add    %eax,%r12d
L91:
  movsbl 0x1(%rbx),%edi
  add    $0x1,%rbx
  test   %dil,%dil
  je     L16
L74:
  cmp    $0x2c,%dil
  jbe    L135
  cmp    $0x2e,%dil
  jne    L85
  movsbl 0x1(%rbx),%edi
  add    $0x1,%rbx
  mov    $0x1,%r15d
  test   %dil,%dil
  jne    L74
L16:
  mov    %r14d,%esi
  mov    %ebp,%edi
  call   <add_field@plt>
  add    %r12d,%eax
L103:
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L85:
  call   <isdigit@plt>
  test   %rax,%rax
  mov    $0x0,%eax
  je     L103
  test   %r15d,%r15d
  jne    L139
  cmp    $0xffffffff,%ebp
  je     L27
  lea    0x0(%rbp,%rbp,4),%eax
  add    %eax,%eax
L27:
  movsbl (%rbx),%edx
  lea    -0x30(%rax,%rdx,1),%ebp
  jmp    L91
  nopl   0x0(%rax,%rax,1)
L139:
  cmp    $0xffffffff,%r14d
  je     L113
  lea    (%r14,%r14,4),%eax
  add    %eax,%eax
L113:
  movsbl (%rbx),%edx
  lea    -0x30(%rax,%rdx,1),%r14d
  jmp    L91
L104:
  xor    %r12d,%r12d
  mov    $0xffffffff,%r14d
  mov    $0xffffffff,%ebp
  jmp    L16
```

assistant: ```c
int add_field_list(char *str) {
  int added = 0;
  int file = -1, field = -1;
  int dot_found = 0;
  for (; *str; str++) {
    if (*str == ',' || ((*str) == ' ' || (*str) == '\t')) {
      added += add_field(file, field);
      file = field = -1;
      dot_found = 0;
    } else if (*str == '.')
      dot_found = 1;
    else if (isdigit(*str)) {
      if (!dot_found) {
        if (file == -1)
          file = 0;
        file = file * 10 + *str - '0';
      } else {
        if (field == -1)
          field = 0;
        field = field * 10 + *str - '0';
      }
    } else
      return 0;
  }
  added += add_field(file, field);
  return added;
}
```
user: 请将以下的汇编代码转换成C语言代码：

```asm
<run_all_tests>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    $0x0,%eax
  call   <test_file_open_success@plt>
  mov    $0x0,%eax
  call   <test_file_open_error@plt>
  mov    $0x0,%eax
  call   <test_randomize_length@plt>
  mov    $0x0,%eax
  call   <test_quick_sort@plt>
  mov    $0x0,%eax
  call   <test_file_read_line_success@plt>
  mov    $0x0,%eax
  call   <test_file_read_line_error@plt>
  nop
  pop    %rbp
  ret
```

assistant: ```c
void run_all_tests() {
  test_file_open_success();
  test_file_open_error();
  test_randomize_length();
  test_quick_sort();
  test_file_read_line_success();
  test_file_read_line_error();
}
```
user: Please show me the C implementation that matches the assembly code listed below:

```asm
<run_all_tests>:
  endbr64
  sub    $0x8,%rsp
  mov    $0x0,%eax
  call   <test_file_open_success@plt>
  mov    $0x0,%eax
  call   <test_file_open_error@plt>
  mov    $0x0,%eax
  call   <test_randomize_length@plt>
  mov    $0x0,%eax
  call   <test_quick_sort@plt>
  mov    $0x0,%eax
  call   <test_file_read_line_success@plt>
  mov    $0x0,%eax
  call   <test_file_read_line_error@plt>
  add    $0x8,%rsp
  ret
```

assistant: ```c
void run_all_tests() {
  test_file_open_success();
  test_file_open_error();
  test_randomize_length();
  test_quick_sort();
  test_file_read_line_success();
  test_file_read_line_error();
}
```
user: What is the c source code of the assembly code below:

```asm
<run_all_tests>:
  endbr64
  sub    $0x8,%rsp
  xor    %eax,%eax
  call   <test_file_open_success@plt>
  xor    %eax,%eax
  call   <test_file_open_error@plt>
  xor    %eax,%eax
  call   <test_randomize_length@plt>
  xor    %eax,%eax
  call   <test_quick_sort@plt>
  xor    %eax,%eax
  call   <test_file_read_line_success@plt>
  xor    %eax,%eax
  add    $0x8,%rsp
  jmp    10a0 <test_file_read_line_error@plt>
```

assistant: ```c
void run_all_tests() {
  test_file_open_success();
  test_file_open_error();
  test_randomize_length();
  test_quick_sort();
  test_file_read_line_success();
  test_file_read_line_error();
}
```
user: 提供的汇编代码用C语言表示会是什么样子：

```asm
<run_all_tests>:
  endbr64
  sub    $0x8,%rsp
  xor    %eax,%eax
  call   <test_file_open_success@plt>
  xor    %eax,%eax
  call   <test_file_open_error@plt>
  xor    %eax,%eax
  call   <test_randomize_length@plt>
  xor    %eax,%eax
  call   <test_quick_sort@plt>
  xor    %eax,%eax
  call   <test_file_read_line_success@plt>
  xor    %eax,%eax
  add    $0x8,%rsp
  jmp    10a0 <test_file_read_line_error@plt>
```

assistant: ```c
void run_all_tests() {
  test_file_open_success();
  test_file_open_error();
  test_randomize_length();
  test_quick_sort();
  test_file_read_line_success();
  test_file_read_line_error();
}
```
user: Translate the below assembly code into C programming language:

```asm
<get_phase>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %edi,-0x24(%rbp)
  mov    %esi,-0x28(%rbp)
  mov    %edx,-0x2c(%rbp)
  mov    %ecx,-0x30(%rbp)
  movl   $0x1,-0x18(%rbp)
  movl   $0x1,-0x14(%rbp)
  movl   $0x2,-0x10(%rbp)
  movl   $0x4,-0xc(%rbp)
  mov    -0x18(%rbp),%edx
  mov    -0x14(%rbp),%eax
  add    %eax,%edx
  mov    -0x10(%rbp),%eax
  add    %edx,%eax
  lea    (%rax,%rax,1),%edx
  mov    -0xc(%rbp),%eax
  add    %edx,%eax
  add    %eax,%eax
  mov    %eax,-0x8(%rbp)
  mov    -0x8(%rbp),%eax
  mov    %eax,-0x4(%rbp)
  mov    -0x18(%rbp),%eax
  imul   -0x24(%rbp),%eax
  sub    %eax,-0x4(%rbp)
  mov    -0x14(%rbp),%eax
  imul   -0x28(%rbp),%eax
  sub    %eax,-0x4(%rbp)
  mov    -0x10(%rbp),%eax
  imul   -0x2c(%rbp),%eax
  sub    %eax,-0x4(%rbp)
  mov    -0xc(%rbp),%eax
  imul   -0x30(%rbp),%eax
  sub    %eax,-0x4(%rbp)
  mov    -0x4(%rbp),%eax
  shl    $0x8,%eax
  mov    %eax,%edx
  mov    -0x8(%rbp),%eax
  mov    %eax,%ecx
  shr    $0x1f,%ecx
  add    %ecx,%eax
  sar    %eax
  add    %edx,%eax
  cltd
  idivl  -0x8(%rbp)
  pop    %rbp
  ret
```

assistant: ```c
int get_phase(const int num_knights, const int num_bishops, const int num_rooks, const int num_queens) {
  const int knight_phase = 1;
  const int bishop_phase = 1;
  const int rook_phase = 2;
  const int queen_phase = 4;
  const int total_phase = knight_phase * 4 + bishop_phase * 4 + rook_phase * 4 + queen_phase * 2;
  int phase = total_phase;
  phase -= knight_phase * num_knights;
  phase -= bishop_phase * num_bishops;
  phase -= rook_phase * num_rooks;
  phase -= queen_phase * num_queens;
  return (phase * 256 + (total_phase / 2)) / total_phase;
}
```
user: Demonstrate the C code that generates the assembly output below:

```asm
<get_phase>:
  endbr64
  mov    %edx,%eax
  mov    $0x18,%edx
  sub    %edi,%edx
  sub    %esi,%edx
  add    %eax,%eax
  sub    %eax,%edx
  shl    $0x2,%ecx
  sub    %ecx,%edx
  shl    $0x8,%edx
  add    $0xc,%edx
  movslq %edx,%rax
  imul   $0x2aaaaaab,%rax,%rax
  sar    $0x22,%rax
  sar    $0x1f,%edx
  sub    %edx,%eax
  ret
```

assistant: ```c
int get_phase(const int num_knights, const int num_bishops, const int num_rooks, const int num_queens) {
  const int knight_phase = 1;
  const int bishop_phase = 1;
  const int rook_phase = 2;
  const int queen_phase = 4;
  const int total_phase = knight_phase * 4 + bishop_phase * 4 + rook_phase * 4 + queen_phase * 2;
  int phase = total_phase;
  phase -= knight_phase * num_knights;
  phase -= bishop_phase * num_bishops;
  phase -= rook_phase * num_rooks;
  phase -= queen_phase * num_queens;
  return (phase * 256 + (total_phase / 2)) / total_phase;
}
```
user: What would the C source look like for the assembly code provided here?

```asm
<get_phase>:
  endbr64
  mov    %edx,%r8d
  mov    $0x18,%edx
  shl    $0x2,%ecx
  sub    %edi,%edx
  add    %r8d,%r8d
  sub    %esi,%edx
  sub    %r8d,%edx
  sub    %ecx,%edx
  shl    $0x8,%edx
  add    $0xc,%edx
  movslq %edx,%rax
  sar    $0x1f,%edx
  imul   $0x2aaaaaab,%rax,%rax
  sar    $0x22,%rax
  sub    %edx,%eax
  ret
```

assistant: ```c
int get_phase(const int num_knights, const int num_bishops, const int num_rooks, const int num_queens) {
  const int knight_phase = 1;
  const int bishop_phase = 1;
  const int rook_phase = 2;
  const int queen_phase = 4;
  const int total_phase = knight_phase * 4 + bishop_phase * 4 + rook_phase * 4 + queen_phase * 2;
  int phase = total_phase;
  phase -= knight_phase * num_knights;
  phase -= bishop_phase * num_bishops;
  phase -= rook_phase * num_rooks;
  phase -= queen_phase * num_queens;
  return (phase * 256 + (total_phase / 2)) / total_phase;
}
```
user: 这段汇编代码用C语言表示是什么样的?

```asm
<get_phase>:
  endbr64
  mov    %edx,%r8d
  mov    $0x18,%edx
  shl    $0x2,%ecx
  sub    %edi,%edx
  add    %r8d,%r8d
  sub    %esi,%edx
  sub    %r8d,%edx
  sub    %ecx,%edx
  shl    $0x8,%edx
  add    $0xc,%edx
  movslq %edx,%rax
  sar    $0x1f,%edx
  imul   $0x2aaaaaab,%rax,%rax
  sar    $0x22,%rax
  sub    %edx,%eax
  ret
```

assistant: ```c
int get_phase(const int num_knights, const int num_bishops, const int num_rooks, const int num_queens) {
  const int knight_phase = 1;
  const int bishop_phase = 1;
  const int rook_phase = 2;
  const int queen_phase = 4;
  const int total_phase = knight_phase * 4 + bishop_phase * 4 + rook_phase * 4 + queen_phase * 2;
  int phase = total_phase;
  phase -= knight_phase * num_knights;
  phase -= bishop_phase * num_bishops;
  phase -= rook_phase * num_rooks;
  phase -= queen_phase * num_queens;
  return (phase * 256 + (total_phase / 2)) / total_phase;
}
```
user: What would the C source look like for the assembly code provided here?

```asm
<hash_function_inode>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x20,%rsp
  mov    %rdi,-0x18(%rbp)
  mov    -0x18(%rbp),%rax
  mov    %rax,-0x8(%rbp)
  mov    -0x8(%rbp),%rax
  mov    (%rax),%rax
  and    $0xffff,%eax
  mov    %eax,-0xc(%rbp)
  cmpl   $0x0,-0xc(%rbp)
  js     L16
  cmpl   $0xffff,-0xc(%rbp)
  jg     L16
  mov    $0x1,%eax
  jmp    L23
L16:
  mov    $0x0,%eax
L23:
  mov    %eax,%edi
  call   <assert@plt>
  mov    -0xc(%rbp),%eax
  leave
  ret
```

assistant: ```c
uint16_t hash_function_inode(void *key) {
  int ret;
  unsigned long long *real_key;
  real_key = (unsigned long long *)key;
  ret = (int)(*real_key & 0xFFFF);
  assert(ret >= 0 && ret <= 65535);
  return ret;
}
```
user: Converte this assembly snippet into its equivalent C code:

```asm
<hash_function_inode>:
  endbr64
  push   %rbx
  movzwl (%rdi),%ebx
  mov    $0x1,%edi
  call   <assert@plt>
  mov    %ebx,%eax
  pop    %rbx
  ret
```

assistant: ```c
uint16_t hash_function_inode(void *key) {
  int ret;
  unsigned long long *real_key;
  real_key = (unsigned long long *)key;
  ret = (int)(*real_key & 0xFFFF);
  assert(ret >= 0 && ret <= 65535);
  return ret;
}
```
user: Demonstrate the C code that generates the assembly output below:

```asm
<hash_function_inode>:
  endbr64
  push   %r12
  movzwl (%rdi),%r12d
  mov    $0x1,%edi
  call   <assert@plt>
  mov    %r12d,%eax
  pop    %r12
  ret
```

assistant: ```c
uint16_t hash_function_inode(void *key) {
  int ret;
  unsigned long long *real_key;
  real_key = (unsigned long long *)key;
  ret = (int)(*real_key & 0xFFFF);
  assert(ret >= 0 && ret <= 65535);
  return ret;
}
```
user: Converte this assembly snippet into its equivalent C code:

```asm
<hash_function_inode>:
  endbr64
  push   %r12
  movzwl (%rdi),%r12d
  mov    $0x1,%edi
  call   <assert@plt>
  mov    %r12d,%eax
  pop    %r12
  ret
```

assistant: ```c
uint16_t hash_function_inode(void *key) {
  int ret;
  unsigned long long *real_key;
  real_key = (unsigned long long *)key;
  ret = (int)(*real_key & 0xFFFF);
  assert(ret >= 0 && ret <= 65535);
  return ret;
}
```
user: Converte this assembly snippet into its equivalent C code:

```asm
<mat_add_scal_mult>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %edi,-0x14(%rbp)
  mov    %esi,-0x18(%rbp)
  mov    %rdx,-0x20(%rbp)
  mov    %rcx,-0x28(%rbp)
  movsd  %xmm0,-0x30(%rbp)
  mov    %r8,-0x38(%rbp)
  movl   $0x0,-0xc(%rbp)
  jmp    L16
L15:
  movl   $0x0,-0x8(%rbp)
  jmp    L7
L4:
  mov    -0xc(%rbp),%eax
  imul   -0x18(%rbp),%eax
  mov    %eax,%edx
  mov    -0x8(%rbp),%eax
  add    %edx,%eax
  mov    %eax,-0x4(%rbp)
  mov    -0x4(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  mov    -0x4(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  mulsd  -0x30(%rbp),%xmm0
  mov    -0x4(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  addsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
  addl   $0x1,-0x8(%rbp)
L7:
  mov    -0x8(%rbp),%eax
  cmp    -0x18(%rbp),%eax
  jl     L4
  addl   $0x1,-0xc(%rbp)
L16:
  mov    -0xc(%rbp),%eax
  cmp    -0x14(%rbp),%eax
  jl     L15
  nop
  nop
  pop    %rbp
  ret
```

assistant: ```c
void mat_add_scal_mult(int n_row, int n_col, double *r, double *a, double k, double *b) {
  int row, col;
  for (row = 0; row < n_row; row++) {
    for (col = 0; col < n_col; col++) {
      int ridx = row * n_col + col;
      r[ridx] = a[ridx] + k * b[ridx];
    }
  }
}
```
user: 请显示与下面列出的汇编代码相匹配的C语言实现:

```asm
<mat_add_scal_mult>:
  endbr64
  test   %edi,%edi
  jle    L59
  push   %rbx
  mov    %esi,%r9d
  mov    %rdx,%rsi
  mov    $0x0,%r11d
  mov    $0x0,%r10d
  mov    %r9d,%ebx
  jmp    L47
L44:
  movslq %r11d,%rdx
  lea    0x0(,%rdx,8),%rax
  add    %rbx,%rdx
  shl    $0x3,%rdx
L40:
  movapd %xmm0,%xmm1
  mulsd  (%r8,%rax,1),%xmm1
  addsd  (%rcx,%rax,1),%xmm1
  movsd  %xmm1,(%rsi,%rax,1)
  add    $0x8,%rax
  cmp    %rdx,%rax
  jne    L40
L21:
  add    $0x1,%r10d
  add    %r9d,%r11d
  cmp    %r10d,%edi
  je     L54
L47:
  test   %r9d,%r9d
  jg     L44
  jmp    L21
L54:
  pop    %rbx
  ret
L59:
  ret
```

assistant: ```c
void mat_add_scal_mult(int n_row, int n_col, double *r, double *a, double k, double *b) {
  int row, col;
  for (row = 0; row < n_row; row++) {
    for (col = 0; col < n_col; col++) {
      int ridx = row * n_col + col;
      r[ridx] = a[ridx] + k * b[ridx];
    }
  }
}
```
user: 这段汇编代码用C语言表示是什么样的:

```asm
<mat_add_scal_mult>:
  endbr64
  test   %edi,%edi
  jle    L14
  mov    %esi,%r9d
  push   %rbx
  mov    %rdx,%rsi
  xor    %r11d,%r11d
  lea    -0x1(%r9),%ebx
  xor    %r10d,%r10d
  add    $0x1,%rbx
  nopl   (%rax)
L31:
  test   %r9d,%r9d
  jle    L12
  movslq %r11d,%rdx
  lea    0x0(,%rdx,8),%rax
  add    %rbx,%rdx
  shl    $0x3,%rdx
  nopw   0x0(%rax,%rax,1)
L36:
  movsd  (%r8,%rax,1),%xmm1
  mulsd  %xmm0,%xmm1
  addsd  (%rcx,%rax,1),%xmm1
  movsd  %xmm1,(%rsi,%rax,1)
  add    $0x8,%rax
  cmp    %rax,%rdx
  jne    L36
L12:
  add    $0x1,%r10d
  add    %r9d,%r11d
  cmp    %r10d,%edi
  jne    L31
  pop    %rbx
  ret
L14:
  ret
```

assistant: ```c
void mat_add_scal_mult(int n_row, int n_col, double *r, double *a, double k, double *b) {
  int row, col;
  for (row = 0; row < n_row; row++) {
    for (col = 0; col < n_col; col++) {
      int ridx = row * n_col + col;
      r[ridx] = a[ridx] + k * b[ridx];
    }
  }
}
```