user: Converte this assembly snippet into its equivalent C code:

```asm
<confctl_save_atomic>:
  endbr64
  push   %r14
  mov    %rsi,%rdx
  mov    %rdi,%r14
  push   %r13
  push   %r12
  mov    %rsi,%r12
  lea    D49(%rip),%rsi
  push   %rbp
  sub    $0x18,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  mov    %rsp,%rdi
  movq   $0x0,(%rsp)
  call   <asprintf@plt>
  test   %eax,%eax
  js     L34
L67:
  mov    (%rsp),%rdi
  call   <mkstemp@plt>
  mov    %eax,%r13d
  test   %eax,%eax
  js     L84
L114:
  lea    D3(%rip),%rsi
  mov    %r13d,%edi
  call   <fdopen@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L137
L24:
  mov    %r14,%rdi
  mov    %rbp,%rsi
  call   <confctl_write@plt>
  mov    %rbp,%rdi
  call   <fflush@plt>
  test   %eax,%eax
  jne    L105
  mov    %r13d,%edi
  call   <fsync@plt>
  test   %eax,%eax
  jne    L78
L94:
  mov    %rbp,%rdi
  call   <fclose@plt>
  test   %eax,%eax
  jne    L140
L12:
  mov    (%rsp),%rdi
  mov    %r12,%rsi
  call   <rename@plt>
  test   %eax,%eax
  jne    L4
L99:
  mov    0x8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L14
  add    $0x18,%rsp
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
  nopl   (%rax)
L105:
  mov    (%rsp),%rdi
  call   <remove_tmpfile@plt>
  mov    $0x1,%edi
  xor    %eax,%eax
  lea    D60(%rip),%rsi
  call   <err@plt>
  mov    %r13d,%edi
  call   <fsync@plt>
  test   %eax,%eax
  je     L94
L78:
  mov    (%rsp),%rdi
  call   <remove_tmpfile@plt>
  mov    $0x1,%edi
  xor    %eax,%eax
  lea    D29(%rip),%rsi
  call   <err@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
  test   %eax,%eax
  je     L12
L140:
  mov    (%rsp),%rdi
  call   <remove_tmpfile@plt>
  lea    D41(%rip),%rsi
  mov    $0x1,%edi
  xor    %eax,%eax
  call   <err@plt>
  mov    (%rsp),%rdi
  mov    %r12,%rsi
  call   <rename@plt>
  test   %eax,%eax
  je     L99
L4:
  mov    (%rsp),%rdi
  call   <remove_tmpfile@plt>
  mov    %r12,%rdx
  mov    $0x1,%edi
  xor    %eax,%eax
  lea    D73(%rip),%rsi
  call   <err@plt>
  jmp    L99
  nopl   0x0(%rax,%rax,1)
L84:
  mov    (%rsp),%rdx
  lea    D6(%rip),%rsi
  mov    $0x1,%edi
  xor    %eax,%eax
  call   <err@plt>
  jmp    L114
  nopl   0x0(%rax)
L34:
  lea    D24(%rip),%rsi
  mov    $0x1,%edi
  xor    %eax,%eax
  call   <err@plt>
  jmp    L67
  nopl   0x0(%rax,%rax,1)
L137:
  mov    (%rsp),%rdi
  call   <remove_tmpfile@plt>
  lea    D39(%rip),%rsi
  mov    $0x1,%edi
  xor    %eax,%eax
  call   <err@plt>
  jmp    L24
L14:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: label: D49
type_infered: string
name: read_data
arguments: label: D3
type_infered: string
name: read_data
arguments: label: D60
type_infered: string
name: read_data
arguments: label: D29
type_infered: string
name: read_data
arguments: label: D41
type_infered: string
name: read_data
arguments: label: D73
type_infered: string
name: read_data
arguments: label: D6
type_infered: string
name: read_data
arguments: label: D24
type_infered: string
name: read_data
arguments: label: D39
type_infered: string

tool: D49: %s.XXXXXXXXX

tool: D3: w

tool: D60: fflush

tool: D29: fsync

tool: D41: fclose

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

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

tool: D24: asprintf

tool: D39: fdopen

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