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

```asm
<insert_str_in_file>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x440,%rsp
  mov    %rdi,-0x438(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movl   $0x0,-0x424(%rbp)
  lea    D17(%rip),%rax
  mov    %rax,%rsi
  lea    D118(%rip),%rax
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x420(%rbp)
  cmpq   $0x0,-0x420(%rbp)
  jne    L45
  lea    D58(%rip),%rax
  mov    %rax,%rsi
  lea    D118(%rip),%rax
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x418(%rbp)
  cmpq   $0x0,-0x418(%rbp)
  jne    L62
  lea    D139(%rip),%rax
  mov    %rax,%rdi
  call   <perror@plt>
  jmp    L39
L62:
  mov    -0x438(%rbp),%rdx
  mov    -0x418(%rbp),%rax
  lea    D128(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <fprintf@plt>
  mov    -0x418(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  jmp    L39
L45:
  lea    D118(%rip),%rax
  mov    %rax,%rdi
  call   <remove@plt>
  lea    D58(%rip),%rax
  mov    %rax,%rsi
  lea    D125(%rip),%rax
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x418(%rbp)
  cmpq   $0x0,-0x418(%rbp)
  jne    L46
  lea    D139(%rip),%rax
  mov    %rax,%rdi
  call   <perror@plt>
  mov    -0x420(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  jmp    L39
L87:
  lea    -0x410(%rbp),%rax
  mov    %rax,%rdi
  call   <strchomp@plt>
  cmpl   $0x1,-0x424(%rbp)
  je     L101
  mov    -0x438(%rbp),%rdx
  lea    -0x410(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jle    L101
  mov    -0x438(%rbp),%rdx
  mov    -0x418(%rbp),%rax
  lea    D128(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <fprintf@plt>
  movl   $0x1,-0x424(%rbp)
L101:
  lea    -0x410(%rbp),%rdx
  mov    -0x418(%rbp),%rax
  lea    D128(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <fprintf@plt>
L46:
  mov    -0x420(%rbp),%rdx
  lea    -0x410(%rbp),%rax
  mov    $0x400,%esi
  mov    %rax,%rdi
  call   <fgets@plt>
  test   %rax,%rax
  jne    L87
  cmpl   $0x1,-0x424(%rbp)
  je     L93
  mov    -0x438(%rbp),%rdx
  mov    -0x418(%rbp),%rax
  lea    D128(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <fprintf@plt>
L93:
  mov    -0x420(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  mov    -0x418(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  lea    D118(%rip),%rax
  mov    %rax,%rsi
  lea    D125(%rip),%rax
  mov    %rax,%rdi
  call   <rename@plt>
L39:
  mov    -0x8(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L3
  call   <__stack_chk_fail@plt>
L3:
  leave
  ret
```

tool_calls: name: unpack_data
arguments: label: D17
type_guessed: string
name: unpack_data
arguments: label: D118
type_guessed: string
name: unpack_data
arguments: label: D58
type_guessed: string
name: unpack_data
arguments: label: D139
type_guessed: string
name: unpack_data
arguments: label: D128
type_guessed: string
name: unpack_data
arguments: label: D125
type_guessed: string

tool: D17: r

tool: D118: names.txt

tool: D58: w

tool: D139: Could not open for write

tool: D128: %s


tool: D125: names.txt.new

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");
}
```