user: 请将这段汇编代码片段转换成等效的C代码:

```asm
<insert_str_in_file>:
  endbr64
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x410,%rsp
  mov    %rdi,%r13
  mov    %fs:0x28,%rax
  mov    %rax,0x408(%rsp)
  xor    %eax,%eax
  lea    D111(%rip),%rsi
  lea    D57(%rip),%rdi
  call   <fopen@plt>
  test   %rax,%rax
  je     L1
  mov    %rax,%rbx
  lea    D57(%rip),%rdi
  call   <remove@plt>
  lea    D82(%rip),%rsi
  lea    D2(%rip),%rdi
  call   <fopen@plt>
  mov    %rax,%rbp
  mov    $0x0,%r12d
  lea    D13(%rip),%r14
  test   %rax,%rax
  jne    L50
  lea    D138(%rip),%rdi
  call   <perror@plt>
  mov    %rbx,%rdi
  call   <fclose@plt>
  jmp    L28
L1:
  lea    D82(%rip),%rsi
  lea    D57(%rip),%rdi
  call   <fopen@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L81
  mov    %r13,%rdx
  lea    D13(%rip),%rsi
  mov    %rax,%rdi
  call   <fprintf@plt>
  mov    %rbx,%rdi
  call   <fclose@plt>
  jmp    L28
L81:
  lea    D138(%rip),%rdi
  call   <perror@plt>
  jmp    L28
L21:
  mov    %rsp,%rdx
  mov    %r14,%rsi
  mov    %rbp,%rdi
  call   <fprintf@plt>
L50:
  mov    %rsp,%rdi
  mov    %rbx,%rdx
  mov    $0x400,%esi
  call   <fgets@plt>
  test   %rax,%rax
  je     L65
  mov    %rsp,%rdi
  call   <strchomp@plt>
  cmp    $0x1,%r12d
  je     L21
  mov    %rsp,%rdi
  mov    %r13,%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jle    L21
  mov    %r13,%rdx
  mov    %r14,%rsi
  mov    %rbp,%rdi
  call   <fprintf@plt>
  mov    $0x1,%r12d
  jmp    L21
L65:
  cmp    $0x1,%r12d
  jne    L62
L83:
  mov    %rbx,%rdi
  call   <fclose@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
  lea    D57(%rip),%rsi
  lea    D2(%rip),%rdi
  call   <rename@plt>
L28:
  mov    0x408(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L105
  add    $0x410,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
L62:
  mov    %r13,%rdx
  lea    D13(%rip),%rsi
  mov    %rbp,%rdi
  call   <fprintf@plt>
  jmp    L83
L105:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: label: D111
type: string
name: parse_data
arguments: label: D57
type: string
name: parse_data
arguments: label: D82
type: string
name: parse_data
arguments: label: D2
type: string
name: parse_data
arguments: label: D13
type: string
name: parse_data
arguments: label: D138
type: string

tool: D111: r

tool: D57: names.txt

tool: D82: w

tool: D2: names.txt.new

tool: D13: %s


tool: D138: Could not open for write

assistant: ```c
void insert_str_in_file(const char *str) {
  FILE *fpr;
  FILE *fpw;
  char buffer[1024];
  int printed = 0;
  fpr = fopen("names.txt", "r");
  if (fpr == NULL) {
    fpw = fopen("names.txt", "w");
    if (fpw == NULL) {
      perror("Could not open for write");
      return;
    }
    fprintf(fpw, "%s\n", str);
    fclose(fpw);
    return;
  }
  remove("names.txt");
  fpw = fopen("names.txt"
              ".new",
              "w");
  if (fpw == NULL) {
    perror("Could not open for write");
    fclose(fpr);
    return;
  }
  while (fgets(buffer, 1024, fpr) != NULL) {
    strchomp(buffer);
    if (printed != 1 && strcmp(buffer, str) > 0) {
      fprintf(fpw, "%s\n", str);
      printed = 1;
    }
    fprintf(fpw, "%s\n", buffer);
  }
  if (printed != 1) {
    fprintf(fpw, "%s\n", str);
  }
  fclose(fpr);
  fclose(fpw);
  rename("names.txt"
         ".new",
         "names.txt");
}
```