#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 {
  int /*<<< orphan*/ pw_uid;
  int /*<<< orphan*/ pw_gid;
};
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_WARNING;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIG_IGN;
scalar_t__ chdir(char *);
scalar_t__ chroot(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ freopen(char *, char *, int /*<<< orphan*/);
struct passwd *getpwnam(char *);
scalar_t__ setgid(int /*<<< orphan*/);
scalar_t__ setgroups(int, int /*<<< orphan*/ *);
scalar_t__ setsid();
scalar_t__ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int daemonize(char *pidfile, char *user, char *dir, char *path, char *outfile,
              char *errfile, char *infile) {
  int ret;
  pid_t child;
  struct passwd *pw;
  FILE *pidfd = NULL;
  if (!path) {
    path = "/";
  }
  if (!dir) {
    dir = "/";
  }
  if (!infile) {
    infile = "/dev/null";
  }
  if (!outfile) {
    outfile = "/dev/null";
  }
  if (!errfile) {
    errfile = "/dev/null";
  }
  if (!user) {
    user = "nobody";
  }
  if (pidfile) {
    if ((pidfd = fopen(pidfile, "w")) == NULL) {
      fprintf(stderr, "Failed to open pid file %s: %s\n", pidfile,
              strerror(errno));
    }
  }
  if ((pw = getpwnam(user)) == NULL) {
    fprintf(stderr, "getpwnam(%s) failed: %s\n", user, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((child = fork()) < 0) {
    fprintf(stderr, "error: failed fork\n");
    exit(EXIT_FAILURE);
  }
  if (child > 0) {
    exit(EXIT_SUCCESS);
  }
  if (setsid() < 0) {
    fprintf(stderr, "error: failed setsid\n");
    exit(EXIT_FAILURE);
  }
  signal(SIGCHLD, SIG_IGN);
  signal(SIGHUP, SIG_IGN);
  if ((child = fork()) < 0) {
    fprintf(stderr, "error: failed fork\n");
    exit(EXIT_FAILURE);
  }
  if (child > 0) {
    if (pidfd != NULL) {
      fprintf(pidfd, "%d\n", child);
      fclose(pidfd);
    }
    exit(EXIT_SUCCESS);
  }
  umask(0);
  if (!freopen(infile, "r", stdin) || freopen(outfile, "w+", stdout) ||
      freopen(errfile, "w+", stderr)) {
    syslog(LOG_WARNING, "close std fds %s failed: %s\n", dir, strerror(errno));
  }
  if (chroot(dir) < 0) {
    syslog(LOG_ERR, "chroot(%s) failed: %s\n", dir, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (chdir(path) < 0) {
    syslog(LOG_ERR, "chdir(\"/\") failed: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (setgroups(1, &pw->pw_gid) < 0) {
    syslog(LOG_ERR, "setgroups() failed: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (setgid(pw->pw_gid)) {
    syslog(LOG_ERR, "setgid %i (user=%s) failed: %s\n", pw->pw_gid, user,
           strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (setuid(pw->pw_uid)) {
    syslog(LOG_ERR, "setuid %i (user=%s) failed: %s\n", pw->pw_uid, user,
           strerror(errno));
    exit(EXIT_FAILURE);
  }
  ret = 1;
  return (ret);
}


x86 assembly (clang, -O0):
<daemonize>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movq   $0x0,-0x50(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1255 <daemonize+0x45>
lea    0xdaf(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    126b <daemonize+0x5b>
lea    0xd99(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,0x10(%rbp)
jne    1281 <daemonize+0x71>
lea    0xd85(%rip),%rax
mov    %rax,0x10(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1297 <daemonize+0x87>
lea    0xd6f(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12ad <daemonize+0x9d>
lea    0xd59(%rip),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    12c3 <daemonize+0xb3>
lea    0xd4d(%rip),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     132e <daemonize+0x11e>
mov    -0x8(%rbp),%rdi
lea    0xd3a(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    1329 <daemonize+0x119>
mov    0x2cc5(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xcf3(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    132e <daemonize+0x11e>
mov    -0x10(%rbp),%rdi
call   10a0 <getpwnam@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    1390 <daemonize+0x180>
mov    0x2c6c(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2c4e(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xcba(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    $0x0,%al
call   1130 <fork@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jge    13cb <daemonize+0x1bb>
mov    0x2c0c(%rip),%rax
movslq (%rax),%rdi
lea    0xc98(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2be4(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
cmpq   $0x0,-0x40(%rbp)
jle    13e4 <daemonize+0x1d4>
mov    0x2bbb(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    $0x0,%al
call   1080 <setsid@plt>
cmp    $0x0,%rax
jge    141b <daemonize+0x20b>
mov    0x2bbc(%rip),%rax
movslq (%rax),%rdi
lea    0xc5c(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2b94(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2bb6(%rip),%rax
mov    (%rax),%edi
mov    0x2b9d(%rip),%rax
mov    (%rax),%esi
call   1090 <signal@plt>
mov    0x2bb7(%rip),%rax
mov    (%rax),%edi
mov    0x2b86(%rip),%rax
mov    (%rax),%esi
call   1090 <signal@plt>
mov    $0x0,%al
call   1130 <fork@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jge    1484 <daemonize+0x274>
mov    0x2b53(%rip),%rax
movslq (%rax),%rdi
lea    0xbdf(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2b2b(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
cmpq   $0x0,-0x40(%rbp)
jle    14c7 <daemonize+0x2b7>
cmpq   $0x0,-0x50(%rbp)
je     14b9 <daemonize+0x2a9>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xbcf(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x50(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2ad8(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
xor    %edi,%edi
call   10c0 <umask@plt>
mov    0x10(%rbp),%rdi
mov    0x2b07(%rip),%rax
mov    (%rax),%edx
lea    0xb9a(%rip),%rsi
call   1060 <freopen@plt>
cmp    $0x0,%rax
je     1537 <daemonize+0x327>
mov    -0x28(%rbp),%rdi
mov    0x2aa4(%rip),%rax
mov    (%rax),%edx
lea    0xb79(%rip),%rsi
call   1060 <freopen@plt>
cmp    $0x0,%rax
jne    1537 <daemonize+0x327>
mov    -0x30(%rbp),%rdi
mov    0x2a99(%rip),%rax
mov    (%rax),%edx
lea    0xb56(%rip),%rsi
call   1060 <freopen@plt>
cmp    $0x0,%rax
je     1571 <daemonize+0x361>
mov    0x2a92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    0x2a5e(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rdx
mov    %rax,%rcx
lea    0xb17(%rip),%rsi
mov    $0x0,%al
call   10d0 <syslog@plt>
mov    -0x18(%rbp),%rdi
call   1030 <chroot@plt>
cmp    $0x0,%rax
jge    15d8 <daemonize+0x3c8>
mov    0x29fd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    0x2a0b(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rdx
mov    %rax,%rcx
lea    0xadb(%rip),%rsi
mov    $0x0,%al
call   10d0 <syslog@plt>
mov    0x29d7(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1050 <chdir@plt>
cmp    $0x0,%rax
jge    162d <daemonize+0x41d>
mov    0x2996(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x90(%rbp)
mov    0x29af(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x90(%rbp),%edi
mov    %rax,%rdx
lea    0xa9d(%rip),%rsi
mov    $0x0,%al
call   10d0 <syslog@plt>
mov    0x2982(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x48(%rbp),%rsi
add    $0x4,%rsi
mov    $0x1,%edi
call   1070 <setgroups@plt>
cmp    $0x0,%rax
jge    168b <daemonize+0x47b>
mov    0x2938(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    0x2951(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x94(%rbp),%edi
mov    %rax,%rdx
lea    0xa56(%rip),%rsi
mov    $0x0,%al
call   10d0 <syslog@plt>
mov    0x2924(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%edi
call   10e0 <setgid@plt>
cmp    $0x0,%rax
je     170b <daemonize+0x4fb>
mov    0x28e0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    -0x48(%rbp),%rax
movslq 0x4(%rax),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    0x28df(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0xac(%rbp),%edi
mov    -0xa8(%rbp),%rdx
mov    -0xa0(%rbp),%rcx
mov    %rax,%r8
lea    0x9ee(%rip),%rsi
mov    $0x0,%al
call   10d0 <syslog@plt>
mov    0x28a4(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x48(%rbp),%rax
mov    (%rax),%edi
call   1110 <setuid@plt>
cmp    $0x0,%rax
je     1789 <daemonize+0x579>
mov    0x2861(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0x48(%rbp),%rax
movslq (%rax),%rax
mov    %rax,-0xc0(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    0x2861(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0xc4(%rbp),%edi
mov    -0xc0(%rbp),%rdx
mov    -0xb8(%rbp),%rcx
mov    %rax,%r8
lea    0x990(%rip),%rsi
mov    $0x0,%al
call   10d0 <syslog@plt>
mov    0x2826(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daemonize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %rdx,%r12
test   %rcx,%rcx
lea    0xdc2(%rip),%rax
cmove  %rax,%r15
mov    0x50(%rsp),%r14
test   %rdx,%rdx
cmove  %rax,%r12
test   %r14,%r14
lea    0xdaa(%rip),%rax
cmove  %rax,%r14
mov    %r9,%rbp
mov    %r8,%r13
test   %r8,%r8
cmove  %rax,%r13
test   %r9,%r9
cmove  %rax,%rbp
test   %rsi,%rsi
lea    0xd92(%rip),%rax
cmovne %rsi,%rax
mov    %rax,0x8(%rsp)
test   %rdi,%rdi
je     12e1 <daemonize+0xc1>
mov    %rdi,%rbx
lea    0xd81(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,%rcx
mov    %rax,(%rsp)
test   %rax,%rax
jne    12e7 <daemonize+0xc7>
mov    0x2d0e(%rip),%rax
movslq (%rax),%rax
mov    %rax,0x10(%rsp)
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xd4e(%rip),%rsi
xor    %ecx,%ecx
mov    %rcx,(%rsp)
mov    0x10(%rsp),%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    12e7 <daemonize+0xc7>
xor    %eax,%eax
mov    %rax,(%rsp)
mov    0x8(%rsp),%rdi
call   10a0 <getpwnam@plt>
test   %rax,%rax
je     1485 <daemonize+0x265>
mov    %rax,%rbx
xor    %eax,%eax
call   1140 <fork@plt>
test   %rax,%rax
js     146d <daemonize+0x24d>
mov    %rbp,0x10(%rsp)
jne    1507 <daemonize+0x2e7>
mov    %r15,%rbp
mov    %rbx,%r15
xor    %eax,%eax
call   1080 <setsid@plt>
test   %rax,%rax
js     14bb <daemonize+0x29b>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
mov    0x2c8a(%rip),%rbx
mov    (%rbx),%esi
call   1090 <signal@plt>
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1090 <signal@plt>
xor    %eax,%eax
call   1140 <fork@plt>
test   %rax,%rax
js     146d <daemonize+0x24d>
jne    14e0 <daemonize+0x2c0>
xor    %edi,%edi
call   10c0 <umask@plt>
mov    0x2c67(%rip),%rax
mov    (%rax),%edx
lea    0xcfa(%rip),%rsi
mov    %r14,%rdi
call   1060 <freopen@plt>
test   %rax,%rax
mov    %rbp,%rbx
je     13ce <daemonize+0x1ae>
mov    0x2c07(%rip),%rax
mov    (%rax),%edx
lea    0xcdc(%rip),%rsi
mov    %r13,%rdi
call   1060 <freopen@plt>
test   %rax,%rax
jne    13ce <daemonize+0x1ae>
mov    0x2c02(%rip),%rax
mov    (%rax),%edx
lea    0xcbf(%rip),%rsi
mov    0x10(%rsp),%rdi
call   1060 <freopen@plt>
test   %rax,%rax
je     13fb <daemonize+0x1db>
mov    0x2bfb(%rip),%rax
mov    (%rax),%ebp
mov    0x2bd2(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xc95(%rip),%rsi
mov    %ebp,%edi
mov    %r12,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10d0 <syslog@plt>
mov    %r12,%rdi
call   1030 <chroot@plt>
test   %rax,%rax
js     1515 <daemonize+0x2f5>
mov    %rbx,%rdi
call   1050 <chdir@plt>
test   %rax,%rax
js     1547 <daemonize+0x327>
lea    0x4(%r15),%rbp
mov    $0x1,%edi
mov    %rbp,%rsi
call   1070 <setgroups@plt>
test   %rax,%rax
js     1567 <daemonize+0x347>
mov    0x0(%rbp),%edi
call   10e0 <setgid@plt>
test   %rax,%rax
jne    1593 <daemonize+0x373>
mov    (%r15),%edi
call   1120 <setuid@plt>
test   %rax,%rax
jne    15bc <daemonize+0x39c>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b44(%rip),%rax
movslq (%rax),%rcx
lea    0xbd0(%rip),%rdi
mov    $0x13,%esi
jmp    14d1 <daemonize+0x2b1>
mov    0x2b2c(%rip),%rax
movslq (%rax),%rbx
mov    0x2b1a(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xb91(%rip),%rsi
mov    %rbx,%rdi
mov    0x8(%rsp),%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    15f1 <daemonize+0x3d1>
mov    0x2af6(%rip),%rax
movslq (%rax),%rcx
lea    0xb96(%rip),%rdi
mov    $0x15,%esi
mov    $0x1,%edx
call   1110 <fwrite@plt>
jmp    15f1 <daemonize+0x3d1>
cmpq   $0x0,(%rsp)
je     1507 <daemonize+0x2e7>
lea    0xb8a(%rip),%rsi
mov    (%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2a8a(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2a6c(%rip),%rax
mov    (%rax),%ebx
mov    0x2a8b(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xb6b(%rip),%rsi
mov    %ebx,%edi
mov    %r12,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10d0 <syslog@plt>
jmp    15f1 <daemonize+0x3d1>
mov    0x2a3a(%rip),%rax
mov    (%rax),%ebx
mov    0x2a59(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xb50(%rip),%rsi
jmp    1585 <daemonize+0x365>
mov    0x2a1a(%rip),%rax
mov    (%rax),%ebx
mov    0x2a39(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xb47(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <syslog@plt>
jmp    15f1 <daemonize+0x3d1>
mov    0x29ee(%rip),%rax
mov    (%rax),%ebx
movslq 0x0(%rbp),%rbp
mov    0x2a09(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xb2f(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
jmp    15e2 <daemonize+0x3c2>
mov    0x29c5(%rip),%rax
mov    (%rax),%ebp
movslq (%r15),%rbx
mov    0x29e1(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xb27(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    0x8(%rsp),%rcx
mov    %rax,%r8
xor    %eax,%eax
call   10d0 <syslog@plt>
mov    0x29b0(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32, i32 }
@.str = [2 x i8] c"/\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@.str.2 = [7 x i8] c"nobody\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.4 = [32 x i8] c"Failed to open pid file %s: %s\0A\00"
@errno = global i32 0
@.str.5 = [25 x i8] c"getpwnam(%s) failed: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [20 x i8] c"error: failed fork\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.7 = [22 x i8] c"error: failed setsid\0A\00"
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@SIGHUP = global i32 0
@.str.8 = [4 x i8] c"%d\0A\00"
@.str.9 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.10 = [3 x i8] c"w+\00"
@stdout = global i32 0
@LOG_WARNING = global i32 0
@.str.11 = [29 x i8] c"close std fds %s failed: %s\0A\00"
@LOG_ERR = global i32 0
@.str.12 = [23 x i8] c"chroot(%s) failed: %s\0A\00"
@.str.13 = [23 x i8] c"chdir(\22/\22) failed: %s\0A\00"
@.str.14 = [24 x i8] c"setgroups() failed: %s\0A\00"
@.str.15 = [32 x i8] c"setgid %i (user=%s) failed: %s\0A\00"
@.str.16 = [32 x i8] c"setuid %i (user=%s) failed: %s\0A\00"
define i32 @daemonize(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i64
%17 = alloca %struct.passwd*
%18 = alloca i32*
store i8* %0, i8** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i8* %6, i8** %14
store i32* null, i32** %18
%19 = load i8*, i8** %11
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %7
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %11
br label %22
22: ; preds = %21, %7
%23 = load i8*, i8** %10
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %22
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %10
br label %26
26: ; preds = %25, %22
%27 = load i8*, i8** %14
%28 = icmp ne i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %26
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %14
br label %30
30: ; preds = %29, %26
%31 = load i8*, i8** %12
%32 = icmp ne i8* %31, null
br i1 %32, label %34, label %33
33: ; preds = %30
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %12
br label %34
34: ; preds = %33, %30
%35 = load i8*, i8** %13
%36 = icmp ne i8* %35, null
br i1 %36, label %38, label %37
37: ; preds = %34
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %13
br label %38
38: ; preds = %37, %34
%39 = load i8*, i8** %9
%40 = icmp ne i8* %39, null
br i1 %40, label %42, label %41
41: ; preds = %38
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %9
br label %42
42: ; preds = %41, %38
%43 = load i8*, i8** %8
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %58
45: ; preds = %42
%46 = load i8*, i8** %8
%47 = call i32* @fopen(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %47, i32** %18
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %57
49: ; preds = %45
%50 = load i32, i32* @stderr
%51 = sext i32 %50 to i64
%52 = inttoptr i64 %51 to i32*
%53 = load i8*, i8** %8
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %53, i8* %55)
br label %57
57: ; preds = %49, %45
br label %58
58: ; preds = %57, %42
%59 = load i8*, i8** %9
%60 = call %struct.passwd* @getpwnam(i8* %59)
store %struct.passwd* %60, %struct.passwd** %17
%61 = icmp eq %struct.passwd* %60, null
br i1 %61, label %62, label %72
62: ; preds = %58
%63 = load i32, i32* @stderr
%64 = sext i32 %63 to i64
%65 = inttoptr i64 %64 to i32*
%66 = load i8*, i8** %9
%67 = load i32, i32* @errno
%68 = call i8* @strerror(i32 %67)
%69 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %66, i8* %68)
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %58
%73 = call i64 (...) @fork()
store i64 %73, i64* %16
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %82
75: ; preds = %72
%76 = load i32, i32* @stderr
%77 = sext i32 %76 to i64
%78 = inttoptr i64 %77 to i32*
%79 = call i32 (i32*, i8*, ...) @fprintf(i32* %78, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%80 = load i32, i32* @EXIT_FAILURE
%81 = call i32 @exit(i32 %80)
unreachable
82: ; preds = %72
%83 = load i64, i64* %16
%84 = icmp sgt i64 %83, 0
br i1 %84, label %85, label %88
85: ; preds = %82
%86 = load i32, i32* @EXIT_SUCCESS
%87 = call i32 @exit(i32 %86)
unreachable
88: ; preds = %82
%89 = call i64 (...) @setsid()
%90 = icmp slt i64 %89, 0
br i1 %90, label %91, label %98
91: ; preds = %88
%92 = load i32, i32* @stderr
%93 = sext i32 %92 to i64
%94 = inttoptr i64 %93 to i32*
%95 = call i32 (i32*, i8*, ...) @fprintf(i32* %94, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%96 = load i32, i32* @EXIT_FAILURE
%97 = call i32 @exit(i32 %96)
unreachable
98: ; preds = %88
%99 = load i32, i32* @SIGCHLD
%100 = load i32, i32* @SIG_IGN
%101 = call i32 @signal(i32 %99, i32 %100)
%102 = load i32, i32* @SIGHUP
%103 = load i32, i32* @SIG_IGN
%104 = call i32 @signal(i32 %102, i32 %103)
%105 = call i64 (...) @fork()
store i64 %105, i64* %16
%106 = icmp slt i64 %105, 0
br i1 %106, label %107, label %114
107: ; preds = %98
%108 = load i32, i32* @stderr
%109 = sext i32 %108 to i64
%110 = inttoptr i64 %109 to i32*
%111 = call i32 (i32*, i8*, ...) @fprintf(i32* %110, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%112 = load i32, i32* @EXIT_FAILURE
%113 = call i32 @exit(i32 %112)
unreachable
114: ; preds = %98
%115 = load i64, i64* %16
%116 = icmp sgt i64 %115, 0
br i1 %116, label %117, label %129
117: ; preds = %114
%118 = load i32*, i32** %18
%119 = icmp ne i32* %118, null
br i1 %119, label %120, label %126
120: ; preds = %117
%121 = load i32*, i32** %18
%122 = load i64, i64* %16
%123 = call i32 (i32*, i8*, ...) @fprintf(i32* %121, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 %122)
%124 = load i32*, i32** %18
%125 = call i32 @fclose(i32* %124)
br label %126
126: ; preds = %120, %117
%127 = load i32, i32* @EXIT_SUCCESS
%128 = call i32 @exit(i32 %127)
unreachable
129: ; preds = %114
%130 = call i32 @umask(i32 0)
%131 = load i8*, i8** %14
%132 = load i32, i32* @stdin
%133 = call i64 @freopen(i8* %131, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 %132)
%134 = icmp ne i64 %133, 0
br i1 %134, label %135, label %145
135: ; preds = %129
%136 = load i8*, i8** %12
%137 = load i32, i32* @stdout
%138 = call i64 @freopen(i8* %136, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 %137)
%139 = icmp ne i64 %138, 0
br i1 %139, label %145, label %140
140: ; preds = %135
%141 = load i8*, i8** %13
%142 = load i32, i32* @stderr
%143 = call i64 @freopen(i8* %141, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 %142)
%144 = icmp ne i64 %143, 0
br i1 %144, label %145, label %151
145: ; preds = %140, %135, %129
%146 = load i32, i32* @LOG_WARNING
%147 = load i8*, i8** %10
%148 = load i32, i32* @errno
%149 = call i8* @strerror(i32 %148)
%150 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %146, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0), i8* %147, i8* %149)
br label %151
151: ; preds = %145, %140
%152 = load i8*, i8** %10
%153 = call i64 @chroot(i8* %152)
%154 = icmp slt i64 %153, 0
br i1 %154, label %155, label %163
155: ; preds = %151
%156 = load i32, i32* @LOG_ERR
%157 = load i8*, i8** %10
%158 = load i32, i32* @errno
%159 = call i8* @strerror(i32 %158)
%160 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %156, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.12, i64 0, i64 0), i8* %157, i8* %159)
%161 = load i32, i32* @EXIT_FAILURE
%162 = call i32 @exit(i32 %161)
unreachable
163: ; preds = %151
%164 = load i8*, i8** %11
%165 = call i64 @chdir(i8* %164)
%166 = icmp slt i64 %165, 0
br i1 %166, label %167, label %174
167: ; preds = %163
%168 = load i32, i32* @LOG_ERR
%169 = load i32, i32* @errno
%170 = call i8* @strerror(i32 %169)
%171 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %168, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0), i8* %170)
%172 = load i32, i32* @EXIT_FAILURE
%173 = call i32 @exit(i32 %172)
unreachable
174: ; preds = %163
%175 = load %struct.passwd*, %struct.passwd** %17
%176 = getelementptr inbounds %struct.passwd, %struct.passwd* %175, i32 0, i32 1
%177 = call i64 @setgroups(i32 1, i32* %176)
%178 = icmp slt i64 %177, 0
br i1 %178, label %179, label %186
179: ; preds = %174
%180 = load i32, i32* @LOG_ERR
%181 = load i32, i32* @errno
%182 = call i8* @strerror(i32 %181)
%183 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %180, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.14, i64 0, i64 0), i8* %182)
%184 = load i32, i32* @EXIT_FAILURE
%185 = call i32 @exit(i32 %184)
unreachable
186: ; preds = %174
%187 = load %struct.passwd*, %struct.passwd** %17
%188 = getelementptr inbounds %struct.passwd, %struct.passwd* %187, i32 0, i32 1
%189 = load i32, i32* %188
%190 = call i64 @setgid(i32 %189)
%191 = icmp ne i64 %190, 0
br i1 %191, label %192, label %205
192: ; preds = %186
%193 = load i32, i32* @LOG_ERR
%194 = load %struct.passwd*, %struct.passwd** %17
%195 = getelementptr inbounds %struct.passwd, %struct.passwd* %194, i32 0, i32 1
%196 = load i32, i32* %195
%197 = sext i32 %196 to i64
%198 = inttoptr i64 %197 to i8*
%199 = load i8*, i8** %9
%200 = load i32, i32* @errno
%201 = call i8* @strerror(i32 %200)
%202 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %193, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i8* %198, i8* %199, i8* %201)
%203 = load i32, i32* @EXIT_FAILURE
%204 = call i32 @exit(i32 %203)
unreachable
205: ; preds = %186
%206 = load %struct.passwd*, %struct.passwd** %17
%207 = getelementptr inbounds %struct.passwd, %struct.passwd* %206, i32 0, i32 0
%208 = load i32, i32* %207
%209 = call i64 @setuid(i32 %208)
%210 = icmp ne i64 %209, 0
br i1 %210, label %211, label %224
211: ; preds = %205
%212 = load i32, i32* @LOG_ERR
%213 = load %struct.passwd*, %struct.passwd** %17
%214 = getelementptr inbounds %struct.passwd, %struct.passwd* %213, i32 0, i32 0
%215 = load i32, i32* %214
%216 = sext i32 %215 to i64
%217 = inttoptr i64 %216 to i8*
%218 = load i8*, i8** %9
%219 = load i32, i32* @errno
%220 = call i8* @strerror(i32 %219)
%221 = call i32 (i32, i8*, i8*, ...) @syslog(i32 %212, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.16, i64 0, i64 0), i8* %217, i8* %218, i8* %220)
%222 = load i32, i32* @EXIT_FAILURE
%223 = call i32 @exit(i32 %222)
unreachable
224: ; preds = %205
store i32 1, i32* %15
%225 = load i32, i32* %15
ret i32 %225
}

LLVM IR (-O2):
%struct.passwd = type { i32, i32 }
@.str = [2 x i8] c"/\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@.str.2 = [7 x i8] c"nobody\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.4 = [32 x i8] c"Failed to open pid file %s: %s\0A\00"
@errno = global i32 0
@.str.5 = [25 x i8] c"getpwnam(%s) failed: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [20 x i8] c"error: failed fork\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.7 = [22 x i8] c"error: failed setsid\0A\00"
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@SIGHUP = global i32 0
@.str.8 = [4 x i8] c"%d\0A\00"
@.str.9 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.10 = [3 x i8] c"w+\00"
@stdout = global i32 0
@LOG_WARNING = global i32 0
@.str.11 = [29 x i8] c"close std fds %s failed: %s\0A\00"
@LOG_ERR = global i32 0
@.str.12 = [23 x i8] c"chroot(%s) failed: %s\0A\00"
@.str.13 = [23 x i8] c"chdir(\22/\22) failed: %s\0A\00"
@.str.14 = [24 x i8] c"setgroups() failed: %s\0A\00"
@.str.15 = [32 x i8] c"setgid %i (user=%s) failed: %s\0A\00"
@.str.16 = [32 x i8] c"setuid %i (user=%s) failed: %s\0A\00"
define i32 @daemonize(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5, i8* %6) {
%8 = icmp eq i8* %3, null
%9 = select i1 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %3
%10 = icmp eq i8* %2, null
%11 = select i1 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %2
%12 = icmp eq i8* %6, null
%13 = select i1 %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %6
%14 = icmp eq i8* %4, null
%15 = select i1 %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %4
%16 = icmp eq i8* %5, null
%17 = select i1 %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %5
%18 = icmp eq i8* %1, null
%19 = select i1 %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %1
%20 = icmp eq i8* %0, null
br i1 %20, label %31, label %21
21: ; preds = %7
%22 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i32*
%28 = load i32, i32* @errno
%29 = tail call i8* @strerror(i32 %28)
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %29)
br label %31
31: ; preds = %21, %24, %7
%32 = phi i32* [ null, %24 ], [ %22, %21 ], [ null, %7 ]
%33 = tail call %struct.passwd* @getpwnam(i8* %19)
%34 = icmp eq %struct.passwd* %33, null
br i1 %34, label %35, label %44
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = sext i32 %36 to i64
%38 = inttoptr i64 %37 to i32*
%39 = load i32, i32* @errno
%40 = tail call i8* @strerror(i32 %39)
%41 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %19, i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
%43 = tail call i32 @exit(i32 %42)
unreachable
44: ; preds = %31
%45 = tail call i64 (...) @fork()
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %54
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = sext i32 %48 to i64
%50 = inttoptr i64 %49 to i32*
%51 = tail call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i64 19, i64 1, i32* %50)
%52 = load i32, i32* @EXIT_FAILURE
%53 = tail call i32 @exit(i32 %52)
unreachable
54: ; preds = %44
%55 = icmp eq i64 %45, 0
br i1 %55, label %59, label %56
56: ; preds = %54
%57 = load i32, i32* @EXIT_SUCCESS
%58 = tail call i32 @exit(i32 %57)
unreachable
59: ; preds = %54
%60 = tail call i64 (...) @setsid()
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %69
62: ; preds = %59
%63 = load i32, i32* @stderr
%64 = sext i32 %63 to i64
%65 = inttoptr i64 %64 to i32*
%66 = tail call i64 @fwrite(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i64 21, i64 1, i32* %65)
%67 = load i32, i32* @EXIT_FAILURE
%68 = tail call i32 @exit(i32 %67)
unreachable
69: ; preds = %59
%70 = load i32, i32* @SIGCHLD
%71 = load i32, i32* @SIG_IGN
%72 = tail call i32 @signal(i32 %70, i32 %71)
%73 = load i32, i32* @SIGHUP
%74 = load i32, i32* @SIG_IGN
%75 = tail call i32 @signal(i32 %73, i32 %74)
%76 = tail call i64 (...) @fork()
%77 = icmp slt i64 %76, 0
br i1 %77, label %78, label %85
78: ; preds = %69
%79 = load i32, i32* @stderr
%80 = sext i32 %79 to i64
%81 = inttoptr i64 %80 to i32*
%82 = tail call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i64 19, i64 1, i32* %81)
%83 = load i32, i32* @EXIT_FAILURE
%84 = tail call i32 @exit(i32 %83)
unreachable
85: ; preds = %69
%86 = icmp eq i64 %76, 0
br i1 %86, label %95, label %87
87: ; preds = %85
%88 = icmp eq i32* %32, null
br i1 %88, label %92, label %89
89: ; preds = %87
%90 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 %76)
%91 = tail call i32 @fclose(i32* %32)
br label %92
92: ; preds = %89, %87
%93 = load i32, i32* @EXIT_SUCCESS
%94 = tail call i32 @exit(i32 %93)
unreachable
95: ; preds = %85
%96 = tail call i32 @umask(i32 0)
%97 = load i32, i32* @stdin
%98 = tail call i64 @freopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 %97)
%99 = icmp eq i64 %98, 0
br i1 %99, label %108, label %100
100: ; preds = %95
%101 = load i32, i32* @stdout
%102 = tail call i64 @freopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 %101)
%103 = icmp eq i64 %102, 0
br i1 %103, label %104, label %108
104: ; preds = %100
%105 = load i32, i32* @stderr
%106 = tail call i64 @freopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 %105)
%107 = icmp eq i64 %106, 0
br i1 %107, label %113, label %108
108: ; preds = %104, %100, %95
%109 = load i32, i32* @LOG_WARNING
%110 = load i32, i32* @errno
%111 = tail call i8* @strerror(i32 %110)
%112 = tail call i32 (i32, i8*, i8*, ...) @syslog(i32 %109, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0), i8* %11, i8* %111)
br label %113
113: ; preds = %108, %104
%114 = tail call i64 @chroot(i8* %11)
%115 = icmp slt i64 %114, 0
br i1 %115, label %116, label %123
116: ; preds = %113
%117 = load i32, i32* @LOG_ERR
%118 = load i32, i32* @errno
%119 = tail call i8* @strerror(i32 %118)
%120 = tail call i32 (i32, i8*, i8*, ...) @syslog(i32 %117, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.12, i64 0, i64 0), i8* %11, i8* %119)
%121 = load i32, i32* @EXIT_FAILURE
%122 = tail call i32 @exit(i32 %121)
unreachable
123: ; preds = %113
%124 = tail call i64 @chdir(i8* %9)
%125 = icmp slt i64 %124, 0
br i1 %125, label %126, label %133
126: ; preds = %123
%127 = load i32, i32* @LOG_ERR
%128 = load i32, i32* @errno
%129 = tail call i8* @strerror(i32 %128)
%130 = tail call i32 (i32, i8*, i8*, ...) @syslog(i32 %127, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0), i8* %129)
%131 = load i32, i32* @EXIT_FAILURE
%132 = tail call i32 @exit(i32 %131)
unreachable
133: ; preds = %123
%134 = getelementptr inbounds %struct.passwd, %struct.passwd* %33, i64 0, i32 1
%135 = tail call i64 @setgroups(i32 1, i32* %134)
%136 = icmp slt i64 %135, 0
br i1 %136, label %137, label %144
137: ; preds = %133
%138 = load i32, i32* @LOG_ERR
%139 = load i32, i32* @errno
%140 = tail call i8* @strerror(i32 %139)
%141 = tail call i32 (i32, i8*, i8*, ...) @syslog(i32 %138, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.14, i64 0, i64 0), i8* %140)
%142 = load i32, i32* @EXIT_FAILURE
%143 = tail call i32 @exit(i32 %142)
unreachable
144: ; preds = %133
%145 = load i32, i32* %134
%146 = tail call i64 @setgid(i32 %145)
%147 = icmp eq i64 %146, 0
br i1 %147, label %158, label %148
148: ; preds = %144
%149 = load i32, i32* @LOG_ERR
%150 = load i32, i32* %134
%151 = sext i32 %150 to i64
%152 = inttoptr i64 %151 to i8*
%153 = load i32, i32* @errno
%154 = tail call i8* @strerror(i32 %153)
%155 = tail call i32 (i32, i8*, i8*, ...) @syslog(i32 %149, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i8* %152, i8* %19, i8* %154)
%156 = load i32, i32* @EXIT_FAILURE
%157 = tail call i32 @exit(i32 %156)
unreachable
158: ; preds = %144
%159 = getelementptr inbounds %struct.passwd, %struct.passwd* %33, i64 0, i32 0
%160 = load i32, i32* %159
%161 = tail call i64 @setuid(i32 %160)
%162 = icmp eq i64 %161, 0
br i1 %162, label %173, label %163
163: ; preds = %158
%164 = load i32, i32* @LOG_ERR
%165 = load i32, i32* %159
%166 = sext i32 %165 to i64
%167 = inttoptr i64 %166 to i8*
%168 = load i32, i32* @errno
%169 = tail call i8* @strerror(i32 %168)
%170 = tail call i32 (i32, i8*, i8*, ...) @syslog(i32 %164, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.16, i64 0, i64 0), i8* %167, i8* %19, i8* %169)
%171 = load i32, i32* @EXIT_FAILURE
%172 = tail call i32 @exit(i32 %171)
unreachable
173: ; preds = %158
ret i32 1
}