user: What would the C source look like for the assembly code provided here?

```asm
<confctl_save_atomic>:
  endbr64
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%r13
  mov    %rsi,%rbp
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  movq   $0x0,(%rsp)
  mov    %rsp,%rdi
  mov    %rsi,%rdx
  lea    D31(%rip),%rsi
  call   <asprintf@plt>
  test   %eax,%eax
  js     L57
L141:
  mov    (%rsp),%rdi
  call   <mkstemp@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  js     L34
L6:
  lea    D65(%rip),%rsi
  mov    %r12d,%edi
  call   <fdopen@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L24
L100:
  mov    %rbx,%rsi
  mov    %r13,%rdi
  call   <confctl_write@plt>
  mov    %rbx,%rdi
  call   <fflush@plt>
  test   %eax,%eax
  jne    L84
L109:
  mov    %r12d,%edi
  call   <fsync@plt>
  test   %eax,%eax
  jne    L105
L114:
  mov    %rbx,%rdi
  call   <fclose@plt>
  test   %eax,%eax
  jne    L28
L40:
  mov    %rbp,%rsi
  mov    (%rsp),%rdi
  call   <rename@plt>
  test   %eax,%eax
  jne    L23
L122:
  mov    0x8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L25
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L57:
  lea    D33(%rip),%rsi
  mov    $0x1,%edi
  mov    $0x0,%eax
  call   <err@plt>
  jmp    L141
L34:
  mov    (%rsp),%rdx
  lea    D51(%rip),%rsi
  mov    $0x1,%edi
  mov    $0x0,%eax
  call   <err@plt>
  jmp    L6
L24:
  mov    (%rsp),%rdi
  call   <remove_tmpfile@plt>
  lea    D22(%rip),%rsi
  mov    $0x1,%edi
  mov    $0x0,%eax
  call   <err@plt>
  jmp    L100
L84:
  mov    (%rsp),%rdi
  call   <remove_tmpfile@plt>
  lea    D1(%rip),%rsi
  mov    $0x1,%edi
  mov    $0x0,%eax
  call   <err@plt>
  jmp    L109
L105:
  mov    (%rsp),%rdi
  call   <remove_tmpfile@plt>
  lea    D58(%rip),%rsi
  mov    $0x1,%edi
  mov    $0x0,%eax
  call   <err@plt>
  jmp    L114
L28:
  mov    (%rsp),%rdi
  call   <remove_tmpfile@plt>
  lea    D11(%rip),%rsi
  mov    $0x1,%edi
  mov    $0x0,%eax
  call   <err@plt>
  jmp    L40
L23:
  mov    (%rsp),%rdi
  call   <remove_tmpfile@plt>
  mov    %rbp,%rdx
  lea    D44(%rip),%rsi
  mov    $0x1,%edi
  mov    $0x0,%eax
  call   <err@plt>
  jmp    L122
L25:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: label: D31
type: string
name: retrieve_data
arguments: label: D65
type: string
name: retrieve_data
arguments: label: D33
type: string
name: retrieve_data
arguments: label: D51
type: string
name: retrieve_data
arguments: label: D22
type: string
name: retrieve_data
arguments: label: D1
type: string
name: retrieve_data
arguments: label: D58
type: string
name: retrieve_data
arguments: label: D11
type: string
name: retrieve_data
arguments: label: D44
type: string

tool: D31: %s.XXXXXXXXX

tool: D65: w

tool: D33: asprintf

tool: D51: cannot create temporary file %s; use -I to rewrite file in place

tool: D22: fdopen

tool: D1: fflush

tool: D58: fsync

tool: D11: fclose

tool: D44: cannot replace %s; use -I to rewrite file in place

assistant: ```c
void confctl_save_atomic(struct confctl *cc, const char *path) {
  FILE *fp;
  int error, fd, written;
  char *tmppath = NULL;
  written = asprintf(&tmppath, "%s.XXXXXXXXX", path);
  if (written < 0)
    err(1, "asprintf");
  fd = mkstemp(tmppath);
  if (fd < 0)
    err(1, "cannot create temporary file %s; use -I to rewrite file in place", tmppath);
  fp = fdopen(fd, "w");
  if (fp == NULL) {
    remove_tmpfile(tmppath);
    err(1, "fdopen");
  }
  confctl_write(cc, fp);
  error = fflush(fp);
  if (error != 0) {
    remove_tmpfile(tmppath);
    err(1, "fflush");
  }
  error = fsync(fd);
  if (error != 0) {
    remove_tmpfile(tmppath);
    err(1, "fsync");
  }
  error = fclose(fp);
  if (error != 0) {
    remove_tmpfile(tmppath);
    err(1, "fclose");
  }
  error = rename(tmppath, path);
  if (error != 0) {
    remove_tmpfile(tmppath);
    err(1, "cannot replace %s; use -I to rewrite file in place", path);
  }
}
```