#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct passwd {
  scalar_t__ pw_uid;
};
struct group {
  scalar_t__ gr_gid;
};
struct flock {
  scalar_t__ l_len;
  scalar_t__ l_start;
  int /*<<< orphan*/ l_whence;
  int /*<<< orphan*/ l_type;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ EACCES;
scalar_t__ EAGAIN;
int /*<<< orphan*/ F_SETLK;
int /*<<< orphan*/ F_WRLCK;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int S_IRUSR;
int S_IWUSR;
int chdir(char *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int fchown(int, scalar_t__, scalar_t__);
int fcntl(int, int /*<<< orphan*/, struct flock *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fsync(int);
scalar_t__ getgid();
struct group *getgrnam(char const *);
int getpid();
struct passwd *getpwnam(char const *);
scalar_t__ getuid();
int /*<<< orphan*/ inform_parent(int, char *, char const *, ...);
int open(char const *, int, int);
int /*<<< orphan*/ perror(char const *);
int pipe(int *);
size_t read(int, char *, int);
int setgid(scalar_t__);
scalar_t__ setsid();
int setuid(scalar_t__);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *strerror(scalar_t__);
size_t strlen(char *);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char const *);
size_t write(int, char *, size_t);
void daemonize(const char *pidfile, const char *user, const char *group) {
  int rc, fd = -1;
  size_t n;
  umask(0);
  if (pidfile) {
    fd = open(pidfile, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
    if (fd == -1) {
      perror(pidfile);
      exit(2);
    }
  }
  errno = 0;
  struct passwd *pw = getpwnam(user);
  if (!pw) {
    fprintf(stderr, "Failed to look up user '%s': %s\n", user,
            (errno == 0 ? "user not found" : strerror(errno)));
    exit(2);
  }
  errno = 0;
  struct group *gr = getgrnam(group);
  if (!gr) {
    fprintf(stderr, "Failed to look up group '%s': %s\n", group,
            (errno == 0 ? "group not found" : strerror(errno)));
    exit(2);
  }
  rc = chdir("/");
  if (rc != 0) {
    fprintf(stderr, "Failed to change directory to /: %s\n", strerror(errno));
    exit(2);
  }
  int pfds[2];
  rc = pipe(pfds);
  if (rc != 0) {
    fprintf(stderr, "Failed to create communication pipe: %s\n",
            strerror(errno));
    exit(2);
  }
  pid_t pid = fork();
  if (pid < 0) {
    fprintf(stderr, "Failed to fork child process: %s\n", strerror(errno));
    exit(2);
  }
  if (pid > 0) {
    close(pfds[1]);
    char buf[8192];
    while ((n = read(pfds[0], buf, 8192)) > 0) {
      buf[n] = '\0';
      fprintf(stderr, "%s", buf);
    }
    exit(0);
  }
  close(pfds[0]);
  char error[8192];
  if (pidfile) {
    struct flock lock;
    size_t n;
    lock.l_type = F_WRLCK;
    lock.l_whence = SEEK_SET;
    lock.l_start = 0;
    lock.l_len = 0;
    rc = fcntl(fd, F_SETLK, &lock);
    if (rc == -1) {
      snprintf(error, 8192, "Failed to acquire lock on %s.%s\n", pidfile,
               (errno == EACCES || errno == EAGAIN
                    ? "  Is another copy running?"
                    : strerror(errno)));
      n = write(pfds[1], error, strlen(error));
      if (n < 0)
        perror("failed to inform parent of our error condition");
      if (n < strlen(error))
        fprintf(stderr, "child->parent inform - only wrote %li of %li bytes\n",
                (long)n, (long)strlen(error));
      exit(2);
    }
  }
  rc = (int)setsid();
  if (rc == -1) {
    inform_parent(pfds[1], "Failed to drop controlling terminal: %s\n",
                  strerror(errno));
    exit(2);
  }
  if (pidfile) {
    char buf[8];
    snprintf(buf, 8, "%i\n", getpid());
    n = write(fd, buf, strlen(buf));
    if (n < 0)
      perror("failed to write PID to pidfile");
    if (n < strlen(buf))
      fprintf(stderr, "only wrote %li of %li bytes to pidfile\n", (long)n,
              (long)strlen(error));
    fsync(fd);
    if (getuid() == 0) {
      rc = fchown(fd, pw->pw_uid, gr->gr_gid);
      if (rc != 0) {
        inform_parent(
            pfds[1],
            "Failed to change user/groupd ownership of pidfile %s: %s\n",
            pidfile, strerror(errno));
        unlink(pidfile);
        exit(2);
      }
    }
  }
  if (getuid() == 0) {
    if (gr->gr_gid != getgid()) {
      rc = setgid(gr->gr_gid);
      if (rc != 0) {
        inform_parent(pfds[1], "Failed to switch to group '%s': %s\n", group,
                      strerror(errno));
        unlink(pidfile);
        exit(2);
      }
    }
    if (pw->pw_uid != getuid()) {
      rc = setuid(pw->pw_uid);
      if (rc != 0) {
        inform_parent(pfds[1], "Failed to switch to user '%s': %s\n", user,
                      strerror(errno));
        unlink(pidfile);
        exit(2);
      }
    }
  }
  if (!freopen("/dev/null", "r", stdin))
    perror("Failed to reopen stdin </dev/null");
  if (!freopen("/dev/null", "w", stdout))
    perror("Failed to reopen stdout >/dev/null");
  if (!freopen("/dev/null", "w", stderr))
    perror("Failed to reopen stderr >/dev/null");
  close(pfds[1]);
}


x86 assembly (clang, -O0):
<daemonize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4170,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x20(%rbp)
xor    %edi,%edi
call   1120 <umask@plt>
cmpq   $0x0,-0x8(%rbp)
je     1342 <daemonize+0x82>
mov    -0x8(%rbp),%rdi
mov    0x2ce5(%rip),%rax
mov    (%rax),%esi
mov    0x2cf4(%rip),%rax
or     (%rax),%esi
mov    0x2c8b(%rip),%rax
mov    (%rax),%edx
mov    0x2cb2(%rip),%rax
or     (%rax),%edx
call   1170 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    133d <daemonize+0x7d>
mov    -0x8(%rbp),%rdi
call   1190 <perror@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
jmp    1342 <daemonize+0x82>
mov    0x2c5f(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1100 <getpwnam@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    13e8 <daemonize+0x128>
mov    0x2c41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4084(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x4080(%rbp)
mov    0x2c1f(%rip),%rax
cmpq   $0x0,(%rax)
jne    13a6 <daemonize+0xe6>
lea    0xc87(%rip),%rax
mov    %rax,-0x4090(%rbp)
jmp    13bc <daemonize+0xfc>
mov    0x2bfb(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
mov    %rax,-0x4090(%rbp)
mov    -0x4080(%rbp),%rdx
mov    -0x4084(%rbp),%edi
mov    -0x4090(%rbp),%rcx
lea    0xc29(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
mov    0x2bb9(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1130 <getgrnam@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    148e <daemonize+0x1ce>
mov    0x2b9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x409c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x4098(%rbp)
mov    0x2b79(%rip),%rax
cmpq   $0x0,(%rax)
jne    144c <daemonize+0x18c>
lea    0xc12(%rip),%rax
mov    %rax,-0x40a8(%rbp)
jmp    1462 <daemonize+0x1a2>
mov    0x2b55(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
mov    %rax,-0x40a8(%rbp)
mov    -0x4098(%rbp),%rdx
mov    -0x409c(%rbp),%edi
mov    -0x40a8(%rbp),%rcx
lea    0xbb3(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
lea    0xbcd(%rip),%rdi
call   1080 <chdir@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     14e6 <daemonize+0x226>
mov    0x2b02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40ac(%rbp)
mov    0x2aeb(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
mov    -0x40ac(%rbp),%edi
mov    %rax,%rdx
lea    0xb8f(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
lea    -0x40(%rbp),%rdi
call   10d0 <pipe@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     153b <daemonize+0x27b>
mov    0x2aad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40b0(%rbp)
mov    0x2a96(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
mov    -0x40b0(%rbp),%edi
mov    %rax,%rdx
lea    0xb5f(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
mov    $0x0,%al
call   11e0 <fork@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jge    1590 <daemonize+0x2d0>
mov    0x2a58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40b4(%rbp)
mov    0x2a41(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
mov    -0x40b4(%rbp),%edi
mov    %rax,%rdx
lea    0xb33(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
cmpq   $0x0,-0x48(%rbp)
jle    15fb <daemonize+0x33b>
mov    -0x3c(%rbp),%edi
call   10c0 <close@plt>
mov    -0x40(%rbp),%edi
lea    -0x2050(%rbp),%rsi
mov    $0x2000,%edx
call   10f0 <read@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jbe    15f4 <daemonize+0x334>
mov    -0x28(%rbp),%rax
movb   $0x0,-0x2050(%rbp,%rax,1)
mov    0x29d8(%rip),%rax
mov    (%rax),%edi
lea    -0x2050(%rbp),%rdx
lea    0xaec(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
jmp    15a3 <daemonize+0x2e3>
xor    %edi,%edi
call   11a0 <exit@plt>
mov    -0x40(%rbp),%edi
call   10c0 <close@plt>
cmpq   $0x0,-0x8(%rbp)
je     17e1 <daemonize+0x521>
mov    0x2973(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4054(%rbp)
mov    0x297c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4058(%rbp)
movq   $0x0,-0x4060(%rbp)
movq   $0x0,-0x4068(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2984(%rip),%rax
mov    (%rax),%esi
lea    -0x4068(%rbp),%rdx
call   1040 <fcntl@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    17dc <daemonize+0x51c>
lea    -0x4050(%rbp),%rax
mov    %rax,-0x40c8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40c0(%rbp)
mov    0x2921(%rip),%rax
mov    (%rax),%rax
mov    0x292f(%rip),%rcx
cmp    (%rcx),%rax
je     16b4 <daemonize+0x3f4>
mov    0x2907(%rip),%rax
mov    (%rax),%rax
mov    0x28cd(%rip),%rcx
cmp    (%rcx),%rax
jne    16c7 <daemonize+0x407>
lea    0xa3d(%rip),%rax
mov    %rax,-0x40d0(%rbp)
jmp    16dd <daemonize+0x41d>
mov    0x28da(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
mov    %rax,-0x40d0(%rbp)
mov    -0x40c0(%rbp),%rcx
mov    -0x40c8(%rbp),%rdi
mov    -0x40d0(%rbp),%r8
mov    $0x2000,%esi
lea    0x9d9(%rip),%rdx
mov    $0x0,%al
call   10a0 <snprintf@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40dc(%rbp)
lea    -0x4050(%rbp),%rax
mov    %rax,-0x40d8(%rbp)
lea    -0x4050(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x40dc(%rbp),%edi
mov    -0x40d8(%rbp),%rsi
mov    %rax,%rdx
call   1050 <write@plt>
mov    %rax,-0x4070(%rbp)
cmpq   $0x0,-0x4070(%rbp)
jae    175e <daemonize+0x49e>
lea    0x9ba(%rip),%rdi
call   1190 <perror@plt>
mov    -0x4070(%rbp),%rax
mov    %rax,-0x40e8(%rbp)
lea    -0x4050(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rcx
mov    -0x40e8(%rbp),%rax
cmp    %rcx,%rax
jae    17d2 <daemonize+0x512>
mov    0x281e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40f4(%rbp)
mov    -0x4070(%rbp),%rax
mov    %rax,-0x40f0(%rbp)
lea    -0x4050(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x40f4(%rbp),%edi
mov    -0x40f0(%rbp),%rdx
mov    %rax,%rcx
lea    0x977(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
jmp    17e1 <daemonize+0x521>
mov    $0x0,%al
call   10e0 <setsid@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    182e <daemonize+0x56e>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40f8(%rbp)
mov    0x27a3(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
mov    -0x40f8(%rbp),%edi
mov    %rax,%rdx
lea    0x959(%rip),%rsi
mov    $0x0,%al
call   11d0 <inform_parent@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
cmpq   $0x0,-0x8(%rbp)
je     19c5 <daemonize+0x705>
lea    -0x4078(%rbp),%rax
mov    %rax,-0x4110(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x4110(%rbp),%rdi
mov    %eax,%ecx
mov    $0x8,%esi
lea    0x93c(%rip),%rdx
mov    $0x0,%al
call   10a0 <snprintf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4104(%rbp)
lea    -0x4078(%rbp),%rax
mov    %rax,-0x4100(%rbp)
lea    -0x4078(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x4104(%rbp),%edi
mov    -0x4100(%rbp),%rsi
mov    %rax,%rdx
call   1050 <write@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jae    18bd <daemonize+0x5fd>
lea    0x8eb(%rip),%rdi
call   1190 <perror@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x4118(%rbp)
lea    -0x4078(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rcx
mov    -0x4118(%rbp),%rax
cmp    %rcx,%rax
jae    192b <daemonize+0x66b>
mov    0x26c2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4124(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x4120(%rbp)
lea    -0x4050(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x4124(%rbp),%edi
mov    -0x4120(%rbp),%rdx
mov    %rax,%rcx
lea    0x89e(%rip),%rsi
mov    $0x0,%al
call   1110 <fprintf@plt>
mov    -0x20(%rbp),%edi
call   1150 <fsync@plt>
mov    $0x0,%al
call   1090 <getuid@plt>
cmp    $0x0,%rax
jne    19c0 <daemonize+0x700>
mov    -0x20(%rbp),%edi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
mov    -0x38(%rbp),%rax
mov    (%rax),%rdx
call   1180 <fchown@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     19bb <daemonize+0x6fb>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4134(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x4130(%rbp)
mov    0x2626(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
mov    -0x4134(%rbp),%edi
mov    -0x4130(%rbp),%rdx
mov    %rax,%rcx
lea    0x849(%rip),%rsi
mov    $0x0,%al
call   11d0 <inform_parent@plt>
mov    -0x8(%rbp),%rdi
call   1030 <unlink@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
jmp    19c0 <daemonize+0x700>
jmp    19c5 <daemonize+0x705>
mov    $0x0,%al
call   1090 <getuid@plt>
cmp    $0x0,%rax
jne    1b0f <daemonize+0x84f>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x4140(%rbp)
mov    $0x0,%al
call   1140 <getgid@plt>
mov    %rax,%rcx
mov    -0x4140(%rbp),%rax
cmp    %rcx,%rax
je     1a70 <daemonize+0x7b0>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1160 <setgid@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1a6b <daemonize+0x7ab>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x414c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x4148(%rbp)
mov    0x2576(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
mov    -0x414c(%rbp),%edi
mov    -0x4148(%rbp),%rdx
mov    %rax,%rcx
lea    0x7d3(%rip),%rsi
mov    $0x0,%al
call   11d0 <inform_parent@plt>
mov    -0x8(%rbp),%rdi
call   1030 <unlink@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
jmp    1a70 <daemonize+0x7b0>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x4158(%rbp)
mov    $0x0,%al
call   1090 <getuid@plt>
mov    %rax,%rcx
mov    -0x4158(%rbp),%rax
cmp    %rcx,%rax
je     1b0a <daemonize+0x84a>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
call   11b0 <setuid@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1b05 <daemonize+0x845>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4164(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x4160(%rbp)
mov    0x24dc(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
mov    -0x4164(%rbp),%edi
mov    -0x4160(%rbp),%rdx
mov    %rax,%rcx
lea    0x75d(%rip),%rsi
mov    $0x0,%al
call   11d0 <inform_parent@plt>
mov    -0x8(%rbp),%rdi
call   1030 <unlink@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
jmp    1b0a <daemonize+0x84a>
jmp    1b0f <daemonize+0x84f>
mov    0x24c2(%rip),%rax
mov    (%rax),%edx
lea    0x766(%rip),%rdi
lea    0x745(%rip),%rsi
call   10b0 <freopen@plt>
cmp    $0x0,%eax
jne    1b40 <daemonize+0x880>
lea    0x732(%rip),%rdi
call   1190 <perror@plt>
mov    0x2449(%rip),%rax
mov    (%rax),%edx
lea    0x735(%rip),%rdi
lea    0x738(%rip),%rsi
call   10b0 <freopen@plt>
cmp    $0x0,%eax
jne    1b71 <daemonize+0x8b1>
lea    0x725(%rip),%rdi
call   1190 <perror@plt>
mov    0x2438(%rip),%rax
mov    (%rax),%edx
lea    0x704(%rip),%rdi
lea    0x707(%rip),%rsi
call   10b0 <freopen@plt>
cmp    $0x0,%eax
jne    1ba2 <daemonize+0x8e2>
lea    0x717(%rip),%rdi
call   1190 <perror@plt>
mov    -0x3c(%rbp),%edi
call   10c0 <close@plt>
add    $0x4170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daemonize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2048,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
call   1120 <umask@plt>
test   %r14,%r14
je     132c <daemonize+0x6c>
mov    0x2cf3(%rip),%rax
mov    0x2d04(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2c99(%rip),%rax
mov    0x2cc2(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %r14,%rdi
call   1170 <open@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    1332 <daemonize+0x72>
mov    %r14,%rdi
call   1190 <perror@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
mov    $0xffffffff,%r13d
mov    0x2c6f(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    %rbx,0x18(%rsp)
mov    %rbx,%rdi
call   1100 <getpwnam@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     15cf <daemonize+0x30f>
movq   $0x0,0x0(%rbp)
mov    %r15,0x10(%rsp)
mov    %r15,%rdi
call   1130 <getgrnam@plt>
test   %rax,%rax
je     15f1 <daemonize+0x331>
mov    %rax,%r12
lea    0xcde(%rip),%rdi
call   1080 <chdir@plt>
test   %eax,%eax
jne    1619 <daemonize+0x359>
mov    %rsp,%rdi
call   10d0 <pipe@plt>
test   %eax,%eax
jne    163a <daemonize+0x37a>
xor    %eax,%eax
call   11e0 <fork@plt>
test   %rax,%rax
js     165b <daemonize+0x39b>
jne    1690 <daemonize+0x3d0>
mov    (%rsp),%edi
call   10c0 <close@plt>
test   %r14,%r14
je     14c4 <daemonize+0x204>
mov    0x2bb9(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
mov    0x2bc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
mov    0x2bdf(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rdx
mov    %r13d,%edi
call   1040 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1731 <daemonize+0x471>
xor    %eax,%eax
call   10e0 <setsid@plt>
cmp    $0xffffffff,%eax
je     1701 <daemonize+0x441>
mov    %r14,%rbp
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xd46(%rip),%rdx
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    $0x8,%esi
mov    %eax,%ecx
xor    %eax,%eax
call   10a0 <snprintf@plt>
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    %rax,%rdx
call   1050 <write@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1070 <strlen@plt>
cmp    %rax,%r14
jae    148f <daemonize+0x1cf>
mov    0x2b43(%rip),%rax
mov    (%rax),%ebx
lea    0x40(%rsp),%rdi
call   1070 <strlen@plt>
lea    0xcf4(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1110 <fprintf@plt>
mov    %r13d,%edi
call   1150 <fsync@plt>
xor    %eax,%eax
call   1090 <getuid@plt>
test   %rax,%rax
jne    14bf <daemonize+0x1ff>
mov    0x8(%rsp),%rax
mov    (%rax),%rsi
mov    (%r12),%rdx
mov    %r13d,%edi
call   1180 <fchown@plt>
test   %eax,%eax
jne    180f <daemonize+0x54f>
mov    %rbp,%r14
jmp    14d4 <daemonize+0x214>
xor    %eax,%eax
call   10e0 <setsid@plt>
cmp    $0xffffffff,%eax
je     1701 <daemonize+0x441>
xor    %eax,%eax
call   1090 <getuid@plt>
test   %rax,%rax
jne    152a <daemonize+0x26a>
mov    (%r12),%rbx
xor    %eax,%eax
call   1140 <getgid@plt>
cmp    %rax,%rbx
je     1501 <daemonize+0x241>
mov    (%r12),%rdi
call   1160 <setgid@plt>
test   %eax,%eax
jne    183d <daemonize+0x57d>
mov    0x8(%rsp),%rax
mov    (%rax),%rbx
xor    %eax,%eax
call   1090 <getuid@plt>
cmp    %rax,%rbx
je     152a <daemonize+0x26a>
mov    0x8(%rsp),%rax
mov    (%rax),%rdi
call   11b0 <setuid@plt>
test   %eax,%eax
jne    1860 <daemonize+0x5a0>
mov    0x2aa7(%rip),%rax
mov    (%rax),%edx
lea    0xcfd(%rip),%rdi
lea    0xcdc(%rip),%rsi
call   10b0 <freopen@plt>
test   %eax,%eax
je     15a5 <daemonize+0x2e5>
mov    0x2a3f(%rip),%rax
mov    (%rax),%edx
lea    0xcdd(%rip),%rdi
lea    0xce0(%rip),%rsi
call   10b0 <freopen@plt>
test   %eax,%eax
je     15b3 <daemonize+0x2f3>
mov    0x2a3f(%rip),%rax
mov    (%rax),%edx
lea    0xcbd(%rip),%rdi
lea    0xcc0(%rip),%rsi
call   10b0 <freopen@plt>
test   %eax,%eax
je     15c1 <daemonize+0x301>
mov    0x4(%rsp),%edi
call   10c0 <close@plt>
add    $0x2048,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc73(%rip),%rdi
call   1190 <perror@plt>
jmp    154a <daemonize+0x28a>
lea    0xc89(%rip),%rdi
call   1190 <perror@plt>
jmp    156a <daemonize+0x2aa>
lea    0xc9e(%rip),%rdi
call   1190 <perror@plt>
jmp    158a <daemonize+0x2ca>
mov    0x29da(%rip),%rax
mov    (%rax),%ebx
mov    0x0(%rbp),%rdi
test   %rdi,%rdi
jne    17d0 <daemonize+0x510>
lea    0xa35(%rip),%rcx
jmp    17d8 <daemonize+0x518>
mov    0x29b8(%rip),%rax
mov    (%rax),%ebx
mov    0x29a7(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
jne    17e8 <daemonize+0x528>
lea    0xa3e(%rip),%rcx
jmp    17f0 <daemonize+0x530>
mov    0x2990(%rip),%rax
mov    (%rax),%ebx
mov    0x297f(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
lea    0xa2c(%rip),%rsi
jmp    167a <daemonize+0x3ba>
mov    0x296f(%rip),%rax
mov    (%rax),%ebx
mov    0x295e(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
lea    0xa30(%rip),%rsi
jmp    167a <daemonize+0x3ba>
mov    0x294e(%rip),%rax
mov    (%rax),%ebx
mov    0x293d(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
lea    0xa38(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
mov    0x4(%rsp),%edi
call   10c0 <close@plt>
mov    (%rsp),%edi
lea    0x40(%rsp),%rsi
mov    $0x2000,%edx
call   10f0 <read@plt>
test   %rax,%rax
je     16fa <daemonize+0x43a>
mov    0x28f9(%rip),%r14
lea    0xa16(%rip),%rbx
lea    0x40(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x0,0x40(%rsp,%rax,1)
mov    (%r14),%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
mov    (%rsp),%edi
mov    %rbp,%rsi
mov    $0x2000,%edx
call   10f0 <read@plt>
test   %rax,%rax
jne    16d0 <daemonize+0x410>
xor    %edi,%edi
call   11a0 <exit@plt>
mov    0x4(%rsp),%ebx
mov    0x289c(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
lea    0xa2c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   11d0 <inform_parent@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
mov    0x2870(%rip),%rax
mov    (%rax),%rdi
mov    0x287e(%rip),%rax
lea    0x9af(%rip),%r8
cmp    (%rax),%rdi
je     1762 <daemonize+0x4a2>
mov    0x2823(%rip),%rax
cmp    (%rax),%rdi
je     1762 <daemonize+0x4a2>
call   11c0 <strerror@plt>
mov    %rax,%r8
lea    0x96e(%rip),%rdx
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x2000,%esi
mov    %r14,%rcx
xor    %eax,%eax
call   10a0 <snprintf@plt>
mov    0x4(%rsp),%ebx
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1050 <write@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1070 <strlen@plt>
cmp    %rax,%rbx
jae    17c6 <daemonize+0x506>
mov    0x2800(%rip),%rcx
mov    (%rcx),%edi
lea    0x95a(%rip),%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1110 <fprintf@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
call   11c0 <strerror@plt>
mov    %rax,%rcx
lea    0x821(%rip),%rsi
mov    %ebx,%edi
mov    0x18(%rsp),%rdx
jmp    17fe <daemonize+0x53e>
call   11c0 <strerror@plt>
mov    %rax,%rcx
lea    0x839(%rip),%rsi
mov    %ebx,%edi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   1110 <fprintf@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
mov    0x4(%rsp),%ebx
mov    0x278e(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
lea    0x973(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   11d0 <inform_parent@plt>
mov    %rbp,%rdi
jmp    188e <daemonize+0x5ce>
mov    0x4(%rsp),%ebx
mov    0x2760(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
lea    0x97f(%rip),%rsi
mov    %ebx,%edi
mov    0x10(%rsp),%rdx
jmp    1881 <daemonize+0x5c1>
mov    0x4(%rsp),%ebx
mov    0x273d(%rip),%rax
mov    (%rax),%rdi
call   11c0 <strerror@plt>
lea    0x980(%rip),%rsi
mov    %ebx,%edi
mov    0x18(%rsp),%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   11d0 <inform_parent@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i64 }
%struct.group = type { i64 }
%struct.flock = type { i64, i64, i32, i32 }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@errno = global i64 0
@stderr = global i32 0
@.str = [33 x i8] c"Failed to look up user '%s': %s\0A\00"
@.str.1 = [15 x i8] c"user not found\00"
@.str.2 = [34 x i8] c"Failed to look up group '%s': %s\0A\00"
@.str.3 = [16 x i8] c"group not found\00"
@.str.4 = [2 x i8] c"/\00"
@.str.5 = [37 x i8] c"Failed to change directory to /: %s\0A\00"
@.str.6 = [41 x i8] c"Failed to create communication pipe: %s\0A\00"
@.str.7 = [34 x i8] c"Failed to fork child process: %s\0A\00"
@.str.8 = [3 x i8] c"%s\00"
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str.9 = [33 x i8] c"Failed to acquire lock on %s.%s\0A\00"
@EACCES = global i64 0
@EAGAIN = global i64 0
@.str.10 = [27 x i8] c" Is another copy running?\00"
@.str.11 = [47 x i8] c"failed to inform parent of our error condition\00"
@.str.12 = [52 x i8] c"child->parent inform - only wrote %li of %li bytes\0A\00"
@.str.13 = [41 x i8] c"Failed to drop controlling terminal: %s\0A\00"
@.str.14 = [4 x i8] c"%i\0A\00"
@.str.15 = [31 x i8] c"failed to write PID to pidfile\00"
@.str.16 = [40 x i8] c"only wrote %li of %li bytes to pidfile\0A\00"
@.str.17 = [58 x i8] c"Failed to change user/groupd ownership of pidfile %s: %s\0A\00"
@.str.18 = [36 x i8] c"Failed to switch to group '%s': %s\0A\00"
@.str.19 = [35 x i8] c"Failed to switch to user '%s': %s\0A\00"
@.str.20 = [10 x i8] c"/dev/null\00"
@.str.21 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.22 = [34 x i8] c"Failed to reopen stdin </dev/null\00"
@.str.23 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.24 = [35 x i8] c"Failed to reopen stdout >/dev/null\00"
@.str.25 = [35 x i8] c"Failed to reopen stderr >/dev/null\00"
define void @daemonize(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca %struct.passwd*
%11 = alloca %struct.group*
%12 = alloca [2 x i32]
%13 = alloca i64
%14 = alloca [8192 x i8]
%15 = alloca [8192 x i8]
%16 = alloca %struct.flock
%17 = alloca i64
%18 = alloca [8 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 -1, i32* %8
%19 = call i32 @umask(i32 0)
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %38
22: ; preds = %3
%23 = load i8*, i8** %4
%24 = load i32, i32* @O_RDWR
%25 = load i32, i32* @O_CREAT
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IRUSR
%28 = load i32, i32* @S_IWUSR
%29 = or i32 %27, %28
%30 = call i32 @open(i8* %23, i32 %26, i32 %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %22
%34 = load i8*, i8** %4
%35 = call i32 @perror(i8* %34)
%36 = call i32 @exit(i32 2)
unreachable
37: ; preds = %22
br label %38
38: ; preds = %37, %3
store i64 0, i64* @errno
%39 = load i8*, i8** %5
%40 = call %struct.passwd* @getpwnam(i8* %39)
store %struct.passwd* %40, %struct.passwd** %10
%41 = load %struct.passwd*, %struct.passwd** %10
%42 = icmp ne %struct.passwd* %41, null
br i1 %42, label %56, label %43
43: ; preds = %38
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %5
%46 = load i64, i64* @errno
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %43
br label %52
49: ; preds = %43
%50 = load i64, i64* @errno
%51 = call i8* @strerror(i64 %50)
br label %52
52: ; preds = %49, %48
%53 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %48 ], [ %51, %49 ]
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %45, i8* %53)
%55 = call i32 @exit(i32 2)
unreachable
56: ; preds = %38
store i64 0, i64* @errno
%57 = load i8*, i8** %6
%58 = call %struct.group* @getgrnam(i8* %57)
store %struct.group* %58, %struct.group** %11
%59 = load %struct.group*, %struct.group** %11
%60 = icmp ne %struct.group* %59, null
br i1 %60, label %74, label %61
61: ; preds = %56
%62 = load i32, i32* @stderr
%63 = load i8*, i8** %6
%64 = load i64, i64* @errno
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %61
br label %70
67: ; preds = %61
%68 = load i64, i64* @errno
%69 = call i8* @strerror(i64 %68)
br label %70
70: ; preds = %67, %66
%71 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), %66 ], [ %69, %67 ]
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %63, i8* %71)
%73 = call i32 @exit(i32 2)
unreachable
74: ; preds = %56
%75 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 %75, i32* %7
%76 = load i32, i32* %7
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %84
78: ; preds = %74
%79 = load i32, i32* @stderr
%80 = load i64, i64* @errno
%81 = call i8* @strerror(i64 %80)
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %81)
%83 = call i32 @exit(i32 2)
unreachable
84: ; preds = %74
%85 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%86 = call i32 @pipe(i32* %85)
store i32 %86, i32* %7
%87 = load i32, i32* %7
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %95
89: ; preds = %84
%90 = load i32, i32* @stderr
%91 = load i64, i64* @errno
%92 = call i8* @strerror(i64 %91)
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i8* %92)
%94 = call i32 @exit(i32 2)
unreachable
95: ; preds = %84
%96 = call i64 (...) @fork()
store i64 %96, i64* %13
%97 = load i64, i64* %13
%98 = icmp slt i64 %97, 0
br i1 %98, label %99, label %105
99: ; preds = %95
%100 = load i32, i32* @stderr
%101 = load i64, i64* @errno
%102 = call i8* @strerror(i64 %101)
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %102)
%104 = call i32 @exit(i32 2)
unreachable
105: ; preds = %95
%106 = load i64, i64* %13
%107 = icmp sgt i64 %106, 0
br i1 %107, label %108, label %126
108: ; preds = %105
%109 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%110 = load i32, i32* %109
%111 = call i32 @close(i32 %110)
br label %112
112: ; preds = %118, %108
%113 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%114 = load i32, i32* %113
%115 = getelementptr inbounds [8192 x i8], [8192 x i8]* %14, i64 0, i64 0
%116 = call i64 @read(i32 %114, i8* %115, i32 8192)
store i64 %116, i64* %9
%117 = icmp ugt i64 %116, 0
br i1 %117, label %118, label %124
118: ; preds = %112
%119 = load i64, i64* %9
%120 = getelementptr inbounds [8192 x i8], [8192 x i8]* %14, i64 0, i64 %119
store i8 0, i8* %120
%121 = load i32, i32* @stderr
%122 = getelementptr inbounds [8192 x i8], [8192 x i8]* %14, i64 0, i64 0
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %122)
br label %112
124: ; preds = %112
%125 = call i32 @exit(i32 0)
unreachable
126: ; preds = %105
%127 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%128 = load i32, i32* %127
%129 = call i32 @close(i32 %128)
%130 = load i8*, i8** %4
%131 = icmp ne i8* %130, null
br i1 %131, label %132, label %185
132: ; preds = %126
%133 = load i32, i32* @F_WRLCK
%134 = getelementptr inbounds %struct.flock, %struct.flock* %16, i32 0, i32 3
store i32 %133, i32* %134
%135 = load i32, i32* @SEEK_SET
%136 = getelementptr inbounds %struct.flock, %struct.flock* %16, i32 0, i32 2
store i32 %135, i32* %136
%137 = getelementptr inbounds %struct.flock, %struct.flock* %16, i32 0, i32 1
store i64 0, i64* %137
%138 = getelementptr inbounds %struct.flock, %struct.flock* %16, i32 0, i32 0
store i64 0, i64* %138
%139 = load i32, i32* %8
%140 = load i32, i32* @F_SETLK
%141 = call i32 @fcntl(i32 %139, i32 %140, %struct.flock* %16)
store i32 %141, i32* %7
%142 = load i32, i32* %7
%143 = icmp eq i32 %142, -1
br i1 %143, label %144, label %184
144: ; preds = %132
%145 = getelementptr inbounds [8192 x i8], [8192 x i8]* %15, i64 0, i64 0
%146 = load i8*, i8** %4
%147 = load i64, i64* @errno
%148 = load i64, i64* @EACCES
%149 = icmp eq i64 %147, %148
br i1 %149, label %154, label %150
150: ; preds = %144
%151 = load i64, i64* @errno
%152 = load i64, i64* @EAGAIN
%153 = icmp eq i64 %151, %152
br i1 %153, label %154, label %155
154: ; preds = %150, %144
br label %158
155: ; preds = %150
%156 = load i64, i64* @errno
%157 = call i8* @strerror(i64 %156)
br label %158
158: ; preds = %155, %154
%159 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), %154 ], [ %157, %155 ]
%160 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %145, i32 8192, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i8* %146, i8* %159)
%161 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%162 = load i32, i32* %161
%163 = getelementptr inbounds [8192 x i8], [8192 x i8]* %15, i64 0, i64 0
%164 = getelementptr inbounds [8192 x i8], [8192 x i8]* %15, i64 0, i64 0
%165 = call i64 @strlen(i8* %164)
%166 = call i64 @write(i32 %162, i8* %163, i64 %165)
store i64 %166, i64* %17
%167 = load i64, i64* %17
%168 = icmp ult i64 %167, 0
br i1 %168, label %169, label %171
169: ; preds = %158
%170 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.11, i64 0, i64 0))
br label %171
171: ; preds = %169, %158
%172 = load i64, i64* %17
%173 = getelementptr inbounds [8192 x i8], [8192 x i8]* %15, i64 0, i64 0
%174 = call i64 @strlen(i8* %173)
%175 = icmp ult i64 %172, %174
br i1 %175, label %176, label %182
176: ; preds = %171
%177 = load i32, i32* @stderr
%178 = load i64, i64* %17
%179 = getelementptr inbounds [8192 x i8], [8192 x i8]* %15, i64 0, i64 0
%180 = call i64 @strlen(i8* %179)
%181 = call i32 (i32, i8*, ...) @fprintf(i32 %177, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.12, i64 0, i64 0), i64 %178, i64 %180)
br label %182
182: ; preds = %176, %171
%183 = call i32 @exit(i32 2)
unreachable
184: ; preds = %132
br label %185
185: ; preds = %184, %126
%186 = call i64 (...) @setsid()
%187 = trunc i64 %186 to i32
store i32 %187, i32* %7
%188 = load i32, i32* %7
%189 = icmp eq i32 %188, -1
br i1 %189, label %190, label %197
190: ; preds = %185
%191 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%192 = load i32, i32* %191
%193 = load i64, i64* @errno
%194 = call i8* @strerror(i64 %193)
%195 = call i32 (i32, i8*, i8*, ...) @inform_parent(i32 %192, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.13, i64 0, i64 0), i8* %194)
%196 = call i32 @exit(i32 2)
unreachable
197: ; preds = %185
%198 = load i8*, i8** %4
%199 = icmp ne i8* %198, null
br i1 %199, label %200, label %252
200: ; preds = %197
%201 = getelementptr inbounds [8 x i8], [8 x i8]* %18, i64 0, i64 0
%202 = call i32 (...) @getpid()
%203 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %201, i32 8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i32 %202)
%204 = load i32, i32* %8
%205 = getelementptr inbounds [8 x i8], [8 x i8]* %18, i64 0, i64 0
%206 = getelementptr inbounds [8 x i8], [8 x i8]* %18, i64 0, i64 0
%207 = call i64 @strlen(i8* %206)
%208 = call i64 @write(i32 %204, i8* %205, i64 %207)
store i64 %208, i64* %9
%209 = load i64, i64* %9
%210 = icmp ult i64 %209, 0
br i1 %210, label %211, label %213
211: ; preds = %200
%212 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.15, i64 0, i64 0))
br label %213
213: ; preds = %211, %200
%214 = load i64, i64* %9
%215 = getelementptr inbounds [8 x i8], [8 x i8]* %18, i64 0, i64 0
%216 = call i64 @strlen(i8* %215)
%217 = icmp ult i64 %214, %216
br i1 %217, label %218, label %224
218: ; preds = %213
%219 = load i32, i32* @stderr
%220 = load i64, i64* %9
%221 = getelementptr inbounds [8192 x i8], [8192 x i8]* %15, i64 0, i64 0
%222 = call i64 @strlen(i8* %221)
%223 = call i32 (i32, i8*, ...) @fprintf(i32 %219, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.16, i64 0, i64 0), i64 %220, i64 %222)
br label %224
224: ; preds = %218, %213
%225 = load i32, i32* %8
%226 = call i32 @fsync(i32 %225)
%227 = call i64 (...) @getuid()
%228 = icmp eq i64 %227, 0
br i1 %228, label %229, label %251
229: ; preds = %224
%230 = load i32, i32* %8
%231 = load %struct.passwd*, %struct.passwd** %10
%232 = getelementptr inbounds %struct.passwd, %struct.passwd* %231, i32 0, i32 0
%233 = load i64, i64* %232
%234 = load %struct.group*, %struct.group** %11
%235 = getelementptr inbounds %struct.group, %struct.group* %234, i32 0, i32 0
%236 = load i64, i64* %235
%237 = call i32 @fchown(i32 %230, i64 %233, i64 %236)
store i32 %237, i32* %7
%238 = load i32, i32* %7
%239 = icmp ne i32 %238, 0
br i1 %239, label %240, label %250
240: ; preds = %229
%241 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%242 = load i32, i32* %241
%243 = load i8*, i8** %4
%244 = load i64, i64* @errno
%245 = call i8* @strerror(i64 %244)
%246 = call i32 (i32, i8*, i8*, ...) @inform_parent(i32 %242, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.17, i64 0, i64 0), i8* %243, i8* %245)
%247 = load i8*, i8** %4
%248 = call i32 @unlink(i8* %247)
%249 = call i32 @exit(i32 2)
unreachable
250: ; preds = %229
br label %251
251: ; preds = %250, %224
br label %252
252: ; preds = %251, %197
%253 = call i64 (...) @getuid()
%254 = icmp eq i64 %253, 0
br i1 %254, label %255, label %304
255: ; preds = %252
%256 = load %struct.group*, %struct.group** %11
%257 = getelementptr inbounds %struct.group, %struct.group* %256, i32 0, i32 0
%258 = load i64, i64* %257
%259 = call i64 (...) @getgid()
%260 = icmp ne i64 %258, %259
br i1 %260, label %261, label %279
261: ; preds = %255
%262 = load %struct.group*, %struct.group** %11
%263 = getelementptr inbounds %struct.group, %struct.group* %262, i32 0, i32 0
%264 = load i64, i64* %263
%265 = call i32 @setgid(i64 %264)
store i32 %265, i32* %7
%266 = load i32, i32* %7
%267 = icmp ne i32 %266, 0
br i1 %267, label %268, label %278
268: ; preds = %261
%269 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%270 = load i32, i32* %269
%271 = load i8*, i8** %6
%272 = load i64, i64* @errno
%273 = call i8* @strerror(i64 %272)
%274 = call i32 (i32, i8*, i8*, ...) @inform_parent(i32 %270, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.18, i64 0, i64 0), i8* %271, i8* %273)
%275 = load i8*, i8** %4
%276 = call i32 @unlink(i8* %275)
%277 = call i32 @exit(i32 2)
unreachable
278: ; preds = %261
br label %279
279: ; preds = %278, %255
%280 = load %struct.passwd*, %struct.passwd** %10
%281 = getelementptr inbounds %struct.passwd, %struct.passwd* %280, i32 0, i32 0
%282 = load i64, i64* %281
%283 = call i64 (...) @getuid()
%284 = icmp ne i64 %282, %283
br i1 %284, label %285, label %303
285: ; preds = %279
%286 = load %struct.passwd*, %struct.passwd** %10
%287 = getelementptr inbounds %struct.passwd, %struct.passwd* %286, i32 0, i32 0
%288 = load i64, i64* %287
%289 = call i32 @setuid(i64 %288)
store i32 %289, i32* %7
%290 = load i32, i32* %7
%291 = icmp ne i32 %290, 0
br i1 %291, label %292, label %302
292: ; preds = %285
%293 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%294 = load i32, i32* %293
%295 = load i8*, i8** %5
%296 = load i64, i64* @errno
%297 = call i8* @strerror(i64 %296)
%298 = call i32 (i32, i8*, i8*, ...) @inform_parent(i32 %294, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.19, i64 0, i64 0), i8* %295, i8* %297)
%299 = load i8*, i8** %4
%300 = call i32 @unlink(i8* %299)
%301 = call i32 @exit(i32 2)
unreachable
302: ; preds = %285
br label %303
303: ; preds = %302, %279
br label %304
304: ; preds = %303, %252
%305 = load i32, i32* @stdin
%306 = call i32 @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.21, i64 0, i64 0), i32 %305)
%307 = icmp ne i32 %306, 0
br i1 %307, label %310, label %308
308: ; preds = %304
%309 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.22, i64 0, i64 0))
br label %310
310: ; preds = %308, %304
%311 = load i32, i32* @stdout
%312 = call i32 @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.23, i64 0, i64 0), i32 %311)
%313 = icmp ne i32 %312, 0
br i1 %313, label %316, label %314
314: ; preds = %310
%315 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.24, i64 0, i64 0))
br label %316
316: ; preds = %314, %310
%317 = load i32, i32* @stderr
%318 = call i32 @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.23, i64 0, i64 0), i32 %317)
%319 = icmp ne i32 %318, 0
br i1 %319, label %322, label %320
320: ; preds = %316
%321 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.25, i64 0, i64 0))
br label %322
322: ; preds = %320, %316
%323 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
%324 = load i32, i32* %323
%325 = call i32 @close(i32 %324)
ret void
}

LLVM IR (-O2):
%struct.flock = type { i64, i64, i32, i32 }
%struct.passwd = type { i64 }
%struct.group = type { i64 }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@errno = global i64 0
@stderr = global i32 0
@.str = [33 x i8] c"Failed to look up user '%s': %s\0A\00"
@.str.1 = [15 x i8] c"user not found\00"
@.str.2 = [34 x i8] c"Failed to look up group '%s': %s\0A\00"
@.str.3 = [16 x i8] c"group not found\00"
@.str.4 = [2 x i8] c"/\00"
@.str.5 = [37 x i8] c"Failed to change directory to /: %s\0A\00"
@.str.6 = [41 x i8] c"Failed to create communication pipe: %s\0A\00"
@.str.7 = [34 x i8] c"Failed to fork child process: %s\0A\00"
@.str.8 = [3 x i8] c"%s\00"
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str.9 = [33 x i8] c"Failed to acquire lock on %s.%s\0A\00"
@EACCES = global i64 0
@EAGAIN = global i64 0
@.str.10 = [27 x i8] c" Is another copy running?\00"
@.str.12 = [52 x i8] c"child->parent inform - only wrote %li of %li bytes\0A\00"
@.str.13 = [41 x i8] c"Failed to drop controlling terminal: %s\0A\00"
@.str.14 = [4 x i8] c"%i\0A\00"
@.str.16 = [40 x i8] c"only wrote %li of %li bytes to pidfile\0A\00"
@.str.17 = [58 x i8] c"Failed to change user/groupd ownership of pidfile %s: %s\0A\00"
@.str.18 = [36 x i8] c"Failed to switch to group '%s': %s\0A\00"
@.str.19 = [35 x i8] c"Failed to switch to user '%s': %s\0A\00"
@.str.20 = [10 x i8] c"/dev/null\00"
@.str.21 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.22 = [34 x i8] c"Failed to reopen stdin </dev/null\00"
@.str.23 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.24 = [35 x i8] c"Failed to reopen stdout >/dev/null\00"
@.str.25 = [35 x i8] c"Failed to reopen stderr >/dev/null\00"
define void @daemonize(i8* %0, i8* %1, i8* %2) {
%4 = alloca [2 x i32]
%5 = alloca [8192 x i8]
%6 = alloca [8192 x i8]
%7 = alloca %struct.flock
%8 = alloca [8 x i8]
%9 = tail call i32 @umask(i32 0)
%10 = icmp eq i8* %0, null
br i1 %10, label %23, label %11
11: ; preds = %3
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_CREAT
%14 = or i32 %13, %12
%15 = load i32, i32* @S_IRUSR
%16 = load i32, i32* @S_IWUSR
%17 = or i32 %16, %15
%18 = tail call i32 @open(i8* %0, i32 %14, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %11
%21 = tail call i32 @perror(i8* %0)
%22 = tail call i32 @exit(i32 2)
unreachable
23: ; preds = %11, %3
%24 = phi i32 [ %18, %11 ], [ -1, %3 ]
store i64 0, i64* @errno
%25 = tail call %struct.passwd* @getpwnam(i8* %1)
%26 = icmp eq %struct.passwd* %25, null
br i1 %26, label %27, label %37
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i64, i64* @errno
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %27
%32 = tail call i8* @strerror(i64 %29)
br label %33
33: ; preds = %27, %31
%34 = phi i8* [ %32, %31 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %27 ]
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %34)
%36 = tail call i32 @exit(i32 2)
unreachable
37: ; preds = %23
store i64 0, i64* @errno
%38 = tail call %struct.group* @getgrnam(i8* %2)
%39 = icmp eq %struct.group* %38, null
br i1 %39, label %40, label %50
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = load i64, i64* @errno
%43 = icmp eq i64 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %40
%45 = tail call i8* @strerror(i64 %42)
br label %46
46: ; preds = %40, %44
%47 = phi i8* [ %45, %44 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), %40 ]
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %2, i8* %47)
%49 = tail call i32 @exit(i32 2)
unreachable
50: ; preds = %37
%51 = tail call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%52 = icmp eq i32 %51, 0
br i1 %52, label %59, label %53
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = load i64, i64* @errno
%56 = tail call i8* @strerror(i64 %55)
%57 = tail call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %56)
%58 = tail call i32 @exit(i32 2)
unreachable
59: ; preds = %50
%60 = bitcast [2 x i32]* %4 to i8*
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%62 = call i32 @pipe(i32* %61)
%63 = icmp eq i32 %62, 0
br i1 %63, label %70, label %64
64: ; preds = %59
%65 = load i32, i32* @stderr
%66 = load i64, i64* @errno
%67 = call i8* @strerror(i64 %66)
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i8* %67)
%69 = call i32 @exit(i32 2)
unreachable
70: ; preds = %59
%71 = call i64 (...) @fork()
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %79
73: ; preds = %70
%74 = load i32, i32* @stderr
%75 = load i64, i64* @errno
%76 = call i8* @strerror(i64 %75)
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %76)
%78 = call i32 @exit(i32 2)
unreachable
79: ; preds = %70
%80 = icmp eq i64 %71, 0
br i1 %80, label %99, label %81
81: ; preds = %79
%82 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%83 = load i32, i32* %82
%84 = call i32 @close(i32 %83)
%85 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%86 = load i32, i32* %61
%87 = call i64 @read(i32 %86, i8* %85, i32 8192)
%88 = icmp eq i64 %87, 0
br i1 %88, label %97, label %89
89: ; preds = %81, %89
%90 = phi i64 [ %95, %89 ], [ %87, %81 ]
%91 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 %90
store i8 0, i8* %91
%92 = load i32, i32* @stderr
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %85)
%94 = load i32, i32* %61
%95 = call i64 @read(i32 %94, i8* %85, i32 8192)
%96 = icmp eq i64 %95, 0
br i1 %96, label %97, label %89
97: ; preds = %89, %81
%98 = call i32 @exit(i32 0)
unreachable
99: ; preds = %79
%100 = load i32, i32* %61
%101 = call i32 @close(i32 %100)
%102 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 0
br i1 %10, label %136, label %103
103: ; preds = %99
%104 = bitcast %struct.flock* %7 to i8*
%105 = load i32, i32* @F_WRLCK
%106 = getelementptr inbounds %struct.flock, %struct.flock* %7, i64 0, i32 3
store i32 %105, i32* %106
%107 = load i32, i32* @SEEK_SET
%108 = getelementptr inbounds %struct.flock, %struct.flock* %7, i64 0, i32 2
store i32 %107, i32* %108
%109 = bitcast %struct.flock* %7 to i8*
%110 = load i32, i32* @F_SETLK
%111 = call i32 @fcntl(i32 %24, i32 %110, %struct.flock* %7)
%112 = icmp eq i32 %111, -1
br i1 %112, label %113, label %140
113: ; preds = %103
%114 = load i64, i64* @errno
%115 = load i64, i64* @EACCES
%116 = icmp eq i64 %114, %115
%117 = load i64, i64* @EAGAIN
%118 = icmp eq i64 %114, %117
%119 = select i1 %116, i1 true, i1 %118
br i1 %119, label %122, label %120
120: ; preds = %113
%121 = call i8* @strerror(i64 %114)
br label %122
122: ; preds = %113, %120
%123 = phi i8* [ %121, %120 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), %113 ]
%124 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %102, i32 8192, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i8* %0, i8* %123)
%125 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%126 = load i32, i32* %125
%127 = call i64 @strlen(i8* %102)
%128 = call i64 @write(i32 %126, i8* %102, i64 %127)
%129 = call i64 @strlen(i8* %102)
%130 = icmp ult i64 %128, %129
br i1 %130, label %131, label %134
131: ; preds = %122
%132 = load i32, i32* @stderr
%133 = call i32 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.12, i64 0, i64 0), i64 %128, i64 %129)
br label %134
134: ; preds = %131, %122
%135 = call i32 @exit(i32 2)
unreachable
136: ; preds = %99
%137 = call i64 (...) @setsid()
%138 = trunc i64 %137 to i32
%139 = icmp eq i32 %138, -1
br i1 %139, label %144, label %183
140: ; preds = %103
%141 = call i64 (...) @setsid()
%142 = trunc i64 %141 to i32
%143 = icmp eq i32 %142, -1
br i1 %143, label %144, label %151
144: ; preds = %140, %136
%145 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%146 = load i32, i32* %145
%147 = load i64, i64* @errno
%148 = call i8* @strerror(i64 %147)
%149 = call i32 (i32, i8*, i8*, ...) @inform_parent(i32 %146, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.13, i64 0, i64 0), i8* %148)
%150 = call i32 @exit(i32 2)
unreachable
151: ; preds = %140
%152 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%153 = call i32 (...) @getpid()
%154 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %152, i32 8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i32 %153)
%155 = call i64 @strlen(i8* %152)
%156 = call i64 @write(i32 %24, i8* %152, i64 %155)
%157 = call i64 @strlen(i8* %152)
%158 = icmp ult i64 %156, %157
br i1 %158, label %159, label %163
159: ; preds = %151
%160 = load i32, i32* @stderr
%161 = call i64 @strlen(i8* %102)
%162 = call i32 (i32, i8*, ...) @fprintf(i32 %160, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.16, i64 0, i64 0), i64 %156, i64 %161)
br label %163
163: ; preds = %159, %151
%164 = call i32 @fsync(i32 %24)
%165 = call i64 (...) @getuid()
%166 = icmp eq i64 %165, 0
br i1 %166, label %167, label %182
167: ; preds = %163
%168 = getelementptr inbounds %struct.passwd, %struct.passwd* %25, i64 0, i32 0
%169 = load i64, i64* %168
%170 = getelementptr inbounds %struct.group, %struct.group* %38, i64 0, i32 0
%171 = load i64, i64* %170
%172 = call i32 @fchown(i32 %24, i64 %169, i64 %171)
%173 = icmp eq i32 %172, 0
br i1 %173, label %182, label %174
174: ; preds = %167
%175 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%176 = load i32, i32* %175
%177 = load i64, i64* @errno
%178 = call i8* @strerror(i64 %177)
%179 = call i32 (i32, i8*, i8*, ...) @inform_parent(i32 %176, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.17, i64 0, i64 0), i8* %0, i8* %178)
%180 = call i32 @unlink(i8* %0)
%181 = call i32 @exit(i32 2)
unreachable
182: ; preds = %167, %163
br label %183
183: ; preds = %136, %182
%184 = call i64 (...) @getuid()
%185 = icmp eq i64 %184, 0
br i1 %185, label %186, label %220
186: ; preds = %183
%187 = getelementptr inbounds %struct.group, %struct.group* %38, i64 0, i32 0
%188 = load i64, i64* %187
%189 = call i64 (...) @getgid()
%190 = icmp eq i64 %188, %189
br i1 %190, label %203, label %191
191: ; preds = %186
%192 = load i64, i64* %187
%193 = call i32 @setgid(i64 %192)
%194 = icmp eq i32 %193, 0
br i1 %194, label %203, label %195
195: ; preds = %191
%196 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%197 = load i32, i32* %196
%198 = load i64, i64* @errno
%199 = call i8* @strerror(i64 %198)
%200 = call i32 (i32, i8*, i8*, ...) @inform_parent(i32 %197, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.18, i64 0, i64 0), i8* %2, i8* %199)
%201 = call i32 @unlink(i8* %0)
%202 = call i32 @exit(i32 2)
unreachable
203: ; preds = %191, %186
%204 = getelementptr inbounds %struct.passwd, %struct.passwd* %25, i64 0, i32 0
%205 = load i64, i64* %204
%206 = call i64 (...) @getuid()
%207 = icmp eq i64 %205, %206
br i1 %207, label %220, label %208
208: ; preds = %203
%209 = load i64, i64* %204
%210 = call i32 @setuid(i64 %209)
%211 = icmp eq i32 %210, 0
br i1 %211, label %220, label %212
212: ; preds = %208
%213 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%214 = load i32, i32* %213
%215 = load i64, i64* @errno
%216 = call i8* @strerror(i64 %215)
%217 = call i32 (i32, i8*, i8*, ...) @inform_parent(i32 %214, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.19, i64 0, i64 0), i8* %1, i8* %216)
%218 = call i32 @unlink(i8* %0)
%219 = call i32 @exit(i32 2)
unreachable
220: ; preds = %203, %208, %183
%221 = load i32, i32* @stdin
%222 = call i32 @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.21, i64 0, i64 0), i32 %221)
%223 = icmp eq i32 %222, 0
br i1 %223, label %224, label %226
224: ; preds = %220
%225 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.22, i64 0, i64 0))
br label %226
226: ; preds = %224, %220
%227 = load i32, i32* @stdout
%228 = call i32 @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.23, i64 0, i64 0), i32 %227)
%229 = icmp eq i32 %228, 0
br i1 %229, label %230, label %232
230: ; preds = %226
%231 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.24, i64 0, i64 0))
br label %232
232: ; preds = %230, %226
%233 = load i32, i32* @stderr
%234 = call i32 @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.23, i64 0, i64 0), i32 %233)
%235 = icmp eq i32 %234, 0
br i1 %235, label %236, label %238
236: ; preds = %232
%237 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.25, i64 0, i64 0))
br label %238
238: ; preds = %236, %232
%239 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%240 = load i32, i32* %239
%241 = call i32 @close(i32 %240)
ret void
}