#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
scalar_t__ close(int);
int /*<<< orphan*/ compat_warn(char *, ...);
int /*<<< orphan*/ compat_warnx(char *, ...);
scalar_t__ errno;
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fork();
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, int);
int getpid();
scalar_t__ pipe(int *);
int /*<<< orphan*/ read(int, char *, int);
int setsid();
int write(int, char *, int);
int daemonize(const char *spid) {
  FILE *f;
  int fd[2];
  char dummy = 0;
  if (pipe(fd)) {
    do {
      ;
      if (errno != 0) {
        compat_warn("pipe");
        errno = 0;
      } else
        compat_warnx("pipe");
    } while (0);
    goto err0;
  }
  switch (fork()) {
  case -1:
    do {
      ;
      if (errno != 0) {
        compat_warn("fork");
        errno = 0;
      } else
        compat_warnx("fork");
    } while (0);
    goto err2;
  case 0:
    break;
  default:
    while (close(fd[1])) {
      if (errno == EINTR)
        continue;
      do {
        ;
        if (errno != 0) {
          compat_warn("close");
          errno = 0;
        } else
          compat_warnx("close");
      } while (0);
      goto err1;
    }
    do {
      switch (read(fd[0], &dummy, 1)) {
      case -1:
        break;
      case 0:
        goto err1;
      case 1:
        _exit(0);
      }
      if (errno != EINTR) {
        do {
          ;
          if (errno != 0) {
            compat_warn("read");
            errno = 0;
          } else
            compat_warnx("read");
        } while (0);
        goto err1;
      }
    } while (1);
  }
  if (setsid() == -1) {
    do {
      ;
      if (errno != 0) {
        compat_warn("setsid");
        errno = 0;
      } else
        compat_warnx("setsid");
    } while (0);
    goto die;
  }
  if ((f = fopen(spid, "w")) == NULL) {
    do {
      ;
      if (errno != 0) {
        compat_warn("fopen(%s)", spid);
        errno = 0;
      } else
        compat_warnx("fopen(%s)", spid);
    } while (0);
    goto die;
  }
  if (fprintf(f, "%d", getpid()) < 0) {
    do {
      ;
      if (errno != 0) {
        compat_warn("fprintf");
        errno = 0;
      } else
        compat_warnx("fprintf");
    } while (0);
    goto die;
  }
  if (fclose(f)) {
    do {
      ;
      if (errno != 0) {
        compat_warn("fclose");
        errno = 0;
      } else
        compat_warnx("fclose");
    } while (0);
    goto die;
  }
  while (write(fd[1], &dummy, 1) == -1) {
    if (errno == EINTR)
      continue;
    do {
      ;
      if (errno != 0) {
        compat_warn("write");
        errno = 0;
      } else
        compat_warnx("write");
    } while (0);
    goto die;
  }
  while (close(fd[0])) {
    if (errno == EINTR)
      continue;
    do {
      ;
      if (errno != 0) {
        compat_warn("close");
        errno = 0;
      } else
        compat_warnx("close");
    } while (0);
    goto die;
  }
  while (close(fd[1])) {
    if (errno == EINTR)
      continue;
    do {
      ;
      if (errno != 0) {
        compat_warn("close");
        errno = 0;
      } else
        compat_warnx("close");
    } while (0);
    goto die;
  }
  return (0);
err2:
  close(fd[1]);
err1:
  close(fd[0]);
err0:
  return (-1);
die:
  _exit(0);
}


x86 assembly (clang, -O0):
<daemonize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movb   $0x0,-0x21(%rbp)
lea    -0x20(%rbp),%rdi
call   1090 <pipe@plt>
cmp    $0x0,%rax
je     1242 <daemonize+0x72>
jmp    11f8 <daemonize+0x28>
mov    0x2de1(%rip),%rax
cmpq   $0x0,(%rax)
je     122a <daemonize+0x5a>
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1030 <compat_warn@plt>
mov    0x2dc2(%rip),%rax
movq   $0x0,(%rax)
jmp    1238 <daemonize+0x68>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   10d0 <compat_warnx@plt>
jmp    123d <daemonize+0x6d>
jmp    1785 <daemonize+0x5b5>
xor    %eax,%eax
call   10f0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x28(%rbp)
sub    $0xffffffff,%eax
je     126c <daemonize+0x9c>
jmp    125c <daemonize+0x8c>
mov    -0x28(%rbp),%eax
test   %eax,%eax
je     12bb <daemonize+0xeb>
jmp    12c0 <daemonize+0xf0>
jmp    1271 <daemonize+0xa1>
mov    0x2d68(%rip),%rax
cmpq   $0x0,(%rax)
je     12a3 <daemonize+0xd3>
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1030 <compat_warn@plt>
mov    0x2d49(%rip),%rax
movq   $0x0,(%rax)
jmp    12b1 <daemonize+0xe1>
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   10d0 <compat_warnx@plt>
jmp    12b6 <daemonize+0xe6>
jmp    1775 <daemonize+0x5a5>
jmp    1422 <daemonize+0x252>
jmp    12c5 <daemonize+0xf5>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
je     1345 <daemonize+0x175>
mov    0x2d02(%rip),%rax
mov    (%rax),%rax
mov    0x2cf0(%rip),%rcx
cmp    (%rcx),%rax
jne    12f6 <daemonize+0x126>
jmp    12c5 <daemonize+0xf5>
jmp    12fb <daemonize+0x12b>
mov    0x2cde(%rip),%rax
cmpq   $0x0,(%rax)
je     132d <daemonize+0x15d>
lea    0xd1b(%rip),%rdi
mov    $0x0,%al
call   1030 <compat_warn@plt>
mov    0x2cbf(%rip),%rax
movq   $0x0,(%rax)
jmp    133b <daemonize+0x16b>
lea    0xcfa(%rip),%rdi
mov    $0x0,%al
call   10d0 <compat_warnx@plt>
jmp    1340 <daemonize+0x170>
jmp    177d <daemonize+0x5ad>
jmp    134a <daemonize+0x17a>
mov    -0x20(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   10b0 <read@plt>
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
sub    $0xffffffff,%eax
je     138f <daemonize+0x1bf>
jmp    136e <daemonize+0x19e>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
je     1394 <daemonize+0x1c4>
jmp    137e <daemonize+0x1ae>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
je     1399 <daemonize+0x1c9>
jmp    13a0 <daemonize+0x1d0>
jmp    13a0 <daemonize+0x1d0>
jmp    177d <daemonize+0x5ad>
xor    %edi,%edi
call   1040 <_exit@plt>
mov    0x2c39(%rip),%rax
mov    (%rax),%rax
mov    0x2c27(%rip),%rcx
cmp    (%rcx),%rax
je     1409 <daemonize+0x239>
jmp    13bf <daemonize+0x1ef>
mov    0x2c1a(%rip),%rax
cmpq   $0x0,(%rax)
je     13f1 <daemonize+0x221>
lea    0xc33(%rip),%rdi
mov    $0x0,%al
call   1030 <compat_warn@plt>
mov    0x2bfb(%rip),%rax
movq   $0x0,(%rax)
jmp    13ff <daemonize+0x22f>
lea    0xc12(%rip),%rdi
mov    $0x0,%al
call   10d0 <compat_warnx@plt>
jmp    1404 <daemonize+0x234>
jmp    177d <daemonize+0x5ad>
jmp    140e <daemonize+0x23e>
mov    $0x1,%al
test   $0x1,%al
jne    134a <daemonize+0x17a>
jmp    141d <daemonize+0x24d>
jmp    1422 <daemonize+0x252>
mov    $0x0,%al
call   10a0 <setsid@plt>
cmp    $0xffffffff,%eax
jne    1481 <daemonize+0x2b1>
jmp    1437 <daemonize+0x267>
mov    0x2ba2(%rip),%rax
cmpq   $0x0,(%rax)
je     1469 <daemonize+0x299>
lea    0xbc0(%rip),%rdi
mov    $0x0,%al
call   1030 <compat_warn@plt>
mov    0x2b83(%rip),%rax
movq   $0x0,(%rax)
jmp    1477 <daemonize+0x2a7>
lea    0xb9f(%rip),%rdi
mov    $0x0,%al
call   10d0 <compat_warnx@plt>
jmp    147c <daemonize+0x2ac>
jmp    1791 <daemonize+0x5c1>
mov    -0x10(%rbp),%rdi
lea    0xb8a(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    14f6 <daemonize+0x326>
jmp    14a4 <daemonize+0x2d4>
mov    0x2b35(%rip),%rax
cmpq   $0x0,(%rax)
je     14da <daemonize+0x30a>
mov    -0x10(%rbp),%rsi
lea    0xb58(%rip),%rdi
mov    $0x0,%al
call   1030 <compat_warn@plt>
mov    0x2b12(%rip),%rax
movq   $0x0,(%rax)
jmp    14ec <daemonize+0x31c>
mov    -0x10(%rbp),%rsi
lea    0xb33(%rip),%rdi
mov    $0x0,%al
call   10d0 <compat_warnx@plt>
jmp    14f1 <daemonize+0x321>
jmp    1791 <daemonize+0x5c1>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xb10(%rip),%rsi
call   10c0 <fprintf@plt>
cmp    $0x0,%rax
jge    1570 <daemonize+0x3a0>
jmp    1526 <daemonize+0x356>
mov    0x2ab3(%rip),%rax
cmpq   $0x0,(%rax)
je     1558 <daemonize+0x388>
lea    0xae7(%rip),%rdi
mov    $0x0,%al
call   1030 <compat_warn@plt>
mov    0x2a94(%rip),%rax
movq   $0x0,(%rax)
jmp    1566 <daemonize+0x396>
lea    0xac6(%rip),%rdi
mov    $0x0,%al
call   10d0 <compat_warnx@plt>
jmp    156b <daemonize+0x39b>
jmp    1791 <daemonize+0x5c1>
mov    -0x18(%rbp),%rdi
call   1070 <fclose@plt>
cmp    $0x0,%rax
je     15d2 <daemonize+0x402>
jmp    1588 <daemonize+0x3b8>
mov    0x2a51(%rip),%rax
cmpq   $0x0,(%rax)
je     15ba <daemonize+0x3ea>
lea    0xa8d(%rip),%rdi
mov    $0x0,%al
call   1030 <compat_warn@plt>
mov    0x2a32(%rip),%rax
movq   $0x0,(%rax)
jmp    15c8 <daemonize+0x3f8>
lea    0xa6c(%rip),%rdi
mov    $0x0,%al
call   10d0 <compat_warnx@plt>
jmp    15cd <daemonize+0x3fd>
jmp    1791 <daemonize+0x5c1>
jmp    15d7 <daemonize+0x407>
mov    -0x1c(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
jne    165f <daemonize+0x48f>
mov    0x29e8(%rip),%rax
mov    (%rax),%rax
mov    0x29d6(%rip),%rcx
cmp    (%rcx),%rax
jne    1610 <daemonize+0x440>
jmp    15d7 <daemonize+0x407>
jmp    1615 <daemonize+0x445>
mov    0x29c4(%rip),%rax
cmpq   $0x0,(%rax)
je     1647 <daemonize+0x477>
lea    0xa07(%rip),%rdi
mov    $0x0,%al
call   1030 <compat_warn@plt>
mov    0x29a5(%rip),%rax
movq   $0x0,(%rax)
jmp    1655 <daemonize+0x485>
lea    0x9e6(%rip),%rdi
mov    $0x0,%al
call   10d0 <compat_warnx@plt>
jmp    165a <daemonize+0x48a>
jmp    1791 <daemonize+0x5c1>
jmp    1664 <daemonize+0x494>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
je     16e4 <daemonize+0x514>
mov    0x2963(%rip),%rax
mov    (%rax),%rax
mov    0x2951(%rip),%rcx
cmp    (%rcx),%rax
jne    1695 <daemonize+0x4c5>
jmp    1664 <daemonize+0x494>
jmp    169a <daemonize+0x4ca>
mov    0x293f(%rip),%rax
cmpq   $0x0,(%rax)
je     16cc <daemonize+0x4fc>
lea    0x97c(%rip),%rdi
mov    $0x0,%al
call   1030 <compat_warn@plt>
mov    0x2920(%rip),%rax
movq   $0x0,(%rax)
jmp    16da <daemonize+0x50a>
lea    0x95b(%rip),%rdi
mov    $0x0,%al
call   10d0 <compat_warnx@plt>
jmp    16df <daemonize+0x50f>
jmp    1791 <daemonize+0x5c1>
jmp    16e9 <daemonize+0x519>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
je     1769 <daemonize+0x599>
mov    0x28de(%rip),%rax
mov    (%rax),%rax
mov    0x28cc(%rip),%rcx
cmp    (%rcx),%rax
jne    171a <daemonize+0x54a>
jmp    16e9 <daemonize+0x519>
jmp    171f <daemonize+0x54f>
mov    0x28ba(%rip),%rax
cmpq   $0x0,(%rax)
je     1751 <daemonize+0x581>
lea    0x8f7(%rip),%rdi
mov    $0x0,%al
call   1030 <compat_warn@plt>
mov    0x289b(%rip),%rax
movq   $0x0,(%rax)
jmp    175f <daemonize+0x58f>
lea    0x8d6(%rip),%rdi
mov    $0x0,%al
call   10d0 <compat_warnx@plt>
jmp    1764 <daemonize+0x594>
jmp    1791 <daemonize+0x5c1>
movl   $0x0,-0x4(%rbp)
jmp    1798 <daemonize+0x5c8>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1798 <daemonize+0x5c8>
xor    %edi,%edi
call   1040 <_exit@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daemonize>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movb   $0x0,0x7(%rsp)
lea    0x8(%rsp),%rdi
call   1090 <pipe@plt>
test   %rax,%rax
je     121b <daemonize+0x4b>
mov    0x2de9(%rip),%rbx
cmpq   $0x0,(%rbx)
je     1321 <daemonize+0x151>
lea    0xdf8(%rip),%rdi
xor    %eax,%eax
call   1030 <compat_warn@plt>
movq   $0x0,(%rbx)
jmp    1407 <daemonize+0x237>
xor    %eax,%eax
call   10f0 <fork@plt>
cmp    $0xffffffff,%eax
je     1334 <daemonize+0x164>
test   %eax,%eax
jne    135f <daemonize+0x18f>
xor    %eax,%eax
call   10a0 <setsid@plt>
cmp    $0xffffffff,%eax
je     1445 <daemonize+0x275>
lea    0xdcc(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     145b <daemonize+0x28b>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xdb6(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   10c0 <fprintf@plt>
test   %rax,%rax
js     1480 <daemonize+0x2b0>
mov    %r14,%rdi
call   1070 <fclose@plt>
test   %rax,%rax
jne    1496 <daemonize+0x2c6>
lea    0x7(%rsp),%r14
mov    0x2d44(%rip),%r15
mov    0x2d35(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0xc(%rsp),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
jne    12ec <daemonize+0x11c>
mov    (%r15),%rax
cmp    (%rbx),%rax
je     12b0 <daemonize+0xe0>
lea    0xd5f(%rip),%rdi
jmp    141d <daemonize+0x24d>
nopw   0x0(%rax,%rax,1)
mov    (%r15),%rax
cmp    (%rbx),%rax
jne    1416 <daemonize+0x246>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
test   %rax,%rax
jne    12e0 <daemonize+0x110>
jmp    130c <daemonize+0x13c>
nopl   0x0(%rax)
mov    (%r15),%rax
cmp    (%rbx),%rax
jne    1416 <daemonize+0x246>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
test   %rax,%rax
jne    1300 <daemonize+0x130>
xor    %eax,%eax
jmp    140c <daemonize+0x23c>
lea    0xcd8(%rip),%rdi
xor    %eax,%eax
call   10d0 <compat_warnx@plt>
jmp    1407 <daemonize+0x237>
mov    0x2ca5(%rip),%rbx
cmpq   $0x0,(%rbx)
je     13e7 <daemonize+0x217>
lea    0xcb9(%rip),%rdi
xor    %eax,%eax
call   1030 <compat_warn@plt>
movq   $0x0,(%rbx)
jmp    13f5 <daemonize+0x225>
mov    0x2c7a(%rip),%r15
mov    0x2c6b(%rip),%rbx
nopl   (%rax)
mov    0xc(%rsp),%edi
call   1080 <close@plt>
test   %rax,%rax
je     13a2 <daemonize+0x1d2>
mov    (%r15),%rax
cmp    (%rbx),%rax
je     1370 <daemonize+0x1a0>
lea    0xca1(%rip),%rdi
test   %rax,%rax
je     13de <daemonize+0x20e>
xor    %eax,%eax
call   1030 <compat_warn@plt>
movq   $0x0,(%r15)
jmp    13fe <daemonize+0x22e>
lea    0x7(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   10b0 <read@plt>
test   %eax,%eax
je     13fe <daemonize+0x22e>
cmp    $0x1,%eax
je     143e <daemonize+0x26e>
mov    (%r15),%rax
cmp    (%rbx),%rax
je     13b0 <daemonize+0x1e0>
lea    0xc31(%rip),%rdi
test   %rax,%rax
jne    1392 <daemonize+0x1c2>
xor    %eax,%eax
call   10d0 <compat_warnx@plt>
jmp    13fe <daemonize+0x22e>
lea    0xc17(%rip),%rdi
xor    %eax,%eax
call   10d0 <compat_warnx@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xc11(%rip),%rdi
test   %rax,%rax
jne    1430 <daemonize+0x260>
xor    %eax,%eax
call   10d0 <compat_warnx@plt>
xor    %edi,%edi
call   1040 <_exit@plt>
xor    %eax,%eax
call   1030 <compat_warn@plt>
movq   $0x0,(%r15)
xor    %edi,%edi
call   1040 <_exit@plt>
mov    0x2b94(%rip),%rbx
cmpq   $0x0,(%rbx)
jne    14af <daemonize+0x2df>
lea    0xbb6(%rip),%rdi
jmp    1422 <daemonize+0x252>
mov    0x2b7e(%rip),%r14
cmpq   $0x0,(%r14)
jne    14b8 <daemonize+0x2e8>
lea    0xba9(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10d0 <compat_warnx@plt>
xor    %edi,%edi
call   1040 <_exit@plt>
mov    0x2b59(%rip),%rbx
cmpq   $0x0,(%rbx)
jne    14d7 <daemonize+0x307>
lea    0xb91(%rip),%rdi
jmp    1422 <daemonize+0x252>
mov    0x2b43(%rip),%rbx
cmpq   $0x0,(%rbx)
jne    14e0 <daemonize+0x310>
lea    0xb83(%rip),%rdi
jmp    1422 <daemonize+0x252>
lea    0xb59(%rip),%rdi
jmp    14e7 <daemonize+0x317>
lea    0xb59(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <compat_warn@plt>
movq   $0x0,(%r14)
xor    %edi,%edi
call   1040 <_exit@plt>
lea    0xb47(%rip),%rdi
jmp    14e7 <daemonize+0x317>
lea    0xb46(%rip),%rdi
xor    %eax,%eax
call   1030 <compat_warn@plt>
movq   $0x0,(%rbx)
xor    %edi,%edi
call   1040 <_exit@plt>

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

LLVM IR (-O2):
@errno = global i64 0
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@EINTR = global i64 0
@.str.2 = [6 x i8] c"close\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [7 x i8] c"setsid\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [10 x i8] c"fopen(%s)\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [8 x i8] c"fprintf\00"
@.str.9 = [7 x i8] c"fclose\00"
@.str.10 = [6 x i8] c"write\00"
define i32 @daemonize(i8* %0) {
%2 = alloca [2 x i32]
%3 = alloca i8
%4 = bitcast [2 x i32]* %2 to i8*
store i8 0, i8* %3
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %1
%9 = load i64, i64* @errno
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 (i8*, ...) @compat_warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* @errno
br label %149
13: ; preds = %8
%14 = call i32 (i8*, ...) @compat_warnx(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %149
15: ; preds = %1
%16 = call i32 (...) @fork()
switch i32 %16, label %17 [
i32 -1, label %19
i32 0, label %55
]
17: ; preds = %15
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
br label %26
19: ; preds = %15
%20 = load i64, i64* @errno
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 (i8*, ...) @compat_warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i64 0, i64* @errno
br label %140
24: ; preds = %19
%25 = call i32 (i8*, ...) @compat_warnx(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %140
26: ; preds = %17, %30
%27 = load i32, i32* %18
%28 = call i64 @close(i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %40, label %30
30: ; preds = %26
%31 = load i64, i64* @errno
%32 = load i64, i64* @EINTR
%33 = icmp eq i64 %31, %32
br i1 %33, label %26, label %34
34: ; preds = %30
%35 = icmp eq i64 %31, 0
br i1 %35, label %38, label %36
36: ; preds = %34
%37 = call i32 (i8*, ...) @compat_warn(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* @errno
br label %144
38: ; preds = %34
%39 = call i32 (i8*, ...) @compat_warnx(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %144
40: ; preds = %26, %45
%41 = load i32, i32* %5
%42 = call i32 @read(i32 %41, i8* %3, i32 1)
switch i32 %42, label %45 [
i32 1, label %43
i32 0, label %144
]
43: ; preds = %40
%44 = call i32 @_exit(i32 0)
unreachable
45: ; preds = %40
%46 = load i64, i64* @errno
%47 = load i64, i64* @EINTR
%48 = icmp eq i64 %46, %47
br i1 %48, label %40, label %49
49: ; preds = %45
%50 = icmp eq i64 %46, 0
br i1 %50, label %53, label %51
51: ; preds = %49
%52 = call i32 (i8*, ...) @compat_warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i64 0, i64* @errno
br label %144
53: ; preds = %49
%54 = call i32 (i8*, ...) @compat_warnx(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %144
55: ; preds = %15
%56 = call i32 (...) @setsid()
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %65
58: ; preds = %55
%59 = load i64, i64* @errno
%60 = icmp eq i64 %59, 0
br i1 %60, label %63, label %61
61: ; preds = %58
%62 = call i32 (i8*, ...) @compat_warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i64 0, i64* @errno
br label %147
63: ; preds = %58
%64 = call i32 (i8*, ...) @compat_warnx(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %147
65: ; preds = %55
%66 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%67 = icmp eq i32* %66, null
br i1 %67, label %68, label %75
68: ; preds = %65
%69 = load i64, i64* @errno
%70 = icmp eq i64 %69, 0
br i1 %70, label %73, label %71
71: ; preds = %68
%72 = call i32 (i8*, ...) @compat_warn(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %0)
store i64 0, i64* @errno
br label %147
73: ; preds = %68
%74 = call i32 (i8*, ...) @compat_warnx(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %0)
br label %147
75: ; preds = %65
%76 = call i32 (...) @getpid()
%77 = call i64 @fprintf(i32* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %76)
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %86
79: ; preds = %75
%80 = load i64, i64* @errno
%81 = icmp eq i64 %80, 0
br i1 %81, label %84, label %82
82: ; preds = %79
%83 = call i32 (i8*, ...) @compat_warn(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
store i64 0, i64* @errno
br label %147
84: ; preds = %79
%85 = call i32 (i8*, ...) @compat_warnx(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
br label %147
86: ; preds = %75
%87 = call i64 @fclose(i32* %66)
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %86
%90 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
br label %98
91: ; preds = %86
%92 = load i64, i64* @errno
%93 = icmp eq i64 %92, 0
br i1 %93, label %96, label %94
94: ; preds = %91
%95 = call i32 (i8*, ...) @compat_warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
store i64 0, i64* @errno
br label %147
96: ; preds = %91
%97 = call i32 (i8*, ...) @compat_warnx(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
br label %147
98: ; preds = %89, %102
%99 = load i32, i32* %90
%100 = call i32 @write(i32 %99, i8* %3, i32 1)
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %112
102: ; preds = %98
%103 = load i64, i64* @errno
%104 = load i64, i64* @EINTR
%105 = icmp eq i64 %103, %104
br i1 %105, label %98, label %106
106: ; preds = %102
%107 = icmp eq i64 %103, 0
br i1 %107, label %110, label %108
108: ; preds = %106
%109 = call i32 (i8*, ...) @compat_warn(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
store i64 0, i64* @errno
br label %147
110: ; preds = %106
%111 = call i32 (i8*, ...) @compat_warnx(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %147
112: ; preds = %98, %116
%113 = load i32, i32* %5
%114 = call i64 @close(i32 %113)
%115 = icmp eq i64 %114, 0
br i1 %115, label %126, label %116
116: ; preds = %112
%117 = load i64, i64* @errno
%118 = load i64, i64* @EINTR
%119 = icmp eq i64 %117, %118
br i1 %119, label %112, label %120
120: ; preds = %116
%121 = icmp eq i64 %117, 0
br i1 %121, label %124, label %122
122: ; preds = %120
%123 = call i32 (i8*, ...) @compat_warn(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* @errno
br label %147
124: ; preds = %120
%125 = call i32 (i8*, ...) @compat_warnx(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %147
126: ; preds = %112, %130
%127 = load i32, i32* %90
%128 = call i64 @close(i32 %127)
%129 = icmp eq i64 %128, 0
br i1 %129, label %149, label %130
130: ; preds = %126
%131 = load i64, i64* @errno
%132 = load i64, i64* @EINTR
%133 = icmp eq i64 %131, %132
br i1 %133, label %126, label %134
134: ; preds = %130
%135 = icmp eq i64 %131, 0
br i1 %135, label %138, label %136
136: ; preds = %134
%137 = call i32 (i8*, ...) @compat_warn(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* @errno
br label %147
138: ; preds = %134
%139 = call i32 (i8*, ...) @compat_warnx(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %147
140: ; preds = %22, %24
%141 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%142 = load i32, i32* %141
%143 = call i64 @close(i32 %142)
br label %144
144: ; preds = %40, %51, %53, %36, %38, %140
%145 = load i32, i32* %5
%146 = call i64 @close(i32 %145)
br label %149
147: ; preds = %136, %138, %122, %124, %108, %110, %94, %96, %82, %84, %71, %73, %61, %63
%148 = call i32 @_exit(i32 0)
unreachable
149: ; preds = %126, %144, %13, %11
%150 = phi i32 [ -1, %11 ], [ -1, %13 ], [ -1, %144 ], [ 0, %126 ]
ret i32 %150
}