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

```asm
<os_server_start_2>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  mov    %rdi,%r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  test   %esi,%esi
  je     L78
  mov    D69(%rip),%rbx
  mov    (%rbx),%rdi
  test   %rdi,%rdi
  jne    L104
  mov    $0x2,%edi
  call   <fsync@plt>
  mov    $0x2,%edi
  call   <close@plt>
  mov    D15(%rip),%rbx
  mov    (%rbx),%rdi
  test   %rdi,%rdi
  je     L68
L37:
  call   <fflush@plt>
  mov    (%rbx),%rdi
  call   <fclose@plt>
  mov    D63(%rip),%rax
  mov    (%rax),%rdi
  test   %rdi,%rdi
  je     L70
L95:
  call   <fclose@plt>
L149:
  mov    $0x14,%esi
  mov    $0x3,%edi
  call   <os_close_files@plt>
L78:
  test   %r12,%r12
  je     L84
  cmpb   $0x0,(%r12)
  jne    L105
L84:
  xor    %eax,%eax
L114:
  mov    0x8(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L152
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L104:
  call   <fflush@plt>
  mov    (%rbx),%rdi
  call   <fclose@plt>
  mov    D15(%rip),%rbx
  mov    (%rbx),%rdi
  test   %rdi,%rdi
  jne    L37
L68:
  mov    $0x1,%edi
  call   <fsync@plt>
  mov    $0x1,%edi
  call   <close@plt>
  mov    D63(%rip),%rax
  mov    (%rax),%rdi
  test   %rdi,%rdi
  jne    L95
L70:
  xor    %edi,%edi
  call   <close@plt>
  jmp    L149
  nopl   0x0(%rax,%rax,1)
L105:
  mov    %rsp,%rsi
  lea    0x4(%rsp),%rdi
  mov    %r12,%rdx
  call   <os_uinfo@plt>
  test   %rax,%rax
  jne    L87
  call   <geteuid@plt>
  mov    %eax,%ebp
  xor    %eax,%eax
  call   <getuid@plt>
  xor    %eax,%eax
  call   <getegid@plt>
  mov    %eax,%r15d
  xor    %eax,%eax
  call   <getgid@plt>
  xor    %edi,%edi
  mov    %eax,%r12d
  call   <seteuid@plt>
  mov    (%rsp),%edi
  call   <setgid@plt>
  test   %rax,%rax
  jne    L136
  mov    0x4(%rsp),%edi
  call   <setuid@plt>
  test   %rax,%rax
  je     L84
  mov    D41(%rip),%r14
  mov    %ebp,%edi
  mov    (%r14),%r13d
  call   <seteuid@plt>
  mov    %r12d,%edi
  call   <setgid@plt>
  mov    %r15d,%edi
  call   <setegid@plt>
  mov    %r13d,(%r14)
  mov    $0xffffffff,%eax
  jmp    L114
L87:
  mov    $0xffffffff,%eax
  jmp    L114
L136:
  mov    D41(%rip),%rbx
  mov    %ebp,%edi
  mov    (%rbx),%r12d
  call   <seteuid@plt>
  mov    $0xffffffff,%eax
  mov    %r12d,(%rbx)
  jmp    L114
L152:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int os_server_start_2(const char *user, int close_stdfiles) {
  int istat;
  gid_t gid, old_egid, old_gid;
  uid_t uid, old_euid, old_uid;
  if (close_stdfiles) {
    if (stderr) {
      fflush(stderr);
      fclose(stderr);
    } else {
      fsync(2);
      close(2);
    }
    if (stdout) {
      fflush(stdout);
      fclose(stdout);
    } else {
      fsync(1);
      close(1);
    }
    if (stdin)
      fclose(stdin);
    else
      close(0);
    os_close_files(3, 20);
  }
  if (user && *user) {
    if (os_uinfo(&uid, &gid, user))
      return (-1);
    old_euid = geteuid();
    old_uid = getuid();
    old_egid = getegid();
    old_gid = getgid();
    seteuid(0);
    if (setgid(gid)) {
      int save_errno = errno;
      seteuid(old_euid);
      errno = save_errno;
      return (-1);
    }
    if (setuid(uid)) {
      int save_errno = errno;
      seteuid(old_euid);
      setgid(old_gid);
      setegid(old_egid);
      errno = save_errno;
      return (-1);
    }
  }
  return (0);
}
```