#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*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_DAEMON;
int /*<<< orphan*/ LOG_EMERG;
int /*<<< orphan*/ LOG_NOTICE;
int /*<<< orphan*/ MS_BIND;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_UNBLOCK;
int chdir(char *);
int chroot(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ errno;
int execl(char *, char *, char *, ...);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getpid();
int /*<<< orphan*/ mkdir(char *, int);
int mount(char *, char *, int /*<<< orphan*/ *, int /*<<< orphan*/,
          int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ openlog(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ setpgid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ wait(int *);
int main() {
  sigset_t set;
  int status;
  if (getpid() != 1)
    return 1;
  sigfillset(&set);
  sigprocmask(SIG_BLOCK, &set, 0);
  if (fork()) {
    for (;;)
      wait(&status);
  }
  sigprocmask(SIG_UNBLOCK, &set, 0);
  setsid();
  setpgid(0, 0);
  fprintf(stderr, "P1\n");
  switch (fork()) {
    int logfd;
    fprintf(stderr, "P2\n");
  case 0:
    fprintf(stderr, "succes 1\n");
    logfd = open("/dev/com0", O_RDWR);
    if (logfd == -1) {
      fprintf(stderr, "failed\n");
      exit(1);
    }
    fprintf(stderr, "succes 2\n");
    dup2(logfd, 0);
    dup2(logfd, 1);
    dup2(logfd, 2);
    fprintf(stderr, "succes 3\n");
    execl("/bin/syslogd", "syslogd", (char *)NULL);
    fprintf(stderr, "done\n");
    exit(1);
  case -1:
    fprintf(stderr, "fork err\n");
    return 1;
  }
  int fd;
  while ((fd = open("/dev/log", O_WRONLY)) == -1)
    ;
  close(fd);
  openlog("init", 0, LOG_DAEMON);
  syslog(LOG_NOTICE, "mounting root");
  if (mount("/dev/ada0", "/mnt", NULL, 0, NULL) == -1) {
    syslog(LOG_EMERG, "failed to mount root device: %s", strerror(errno));
    exit(1);
  }
  syslog(LOG_NOTICE, "remounting devfs");
  mkdir("/mnt/dev", 0777);
  if (mount("/dev", "/mnt/dev", NULL, MS_BIND, NULL) == -1) {
    syslog(LOG_EMERG, "failed to remount devfs: %s", strerror(errno));
    exit(1);
  }
  syslog(LOG_NOTICE, "remounting procfs");
  mkdir("/mnt/proc", 0777);
  if (mount("/proc", "/mnt/proc", NULL, MS_BIND, NULL) == -1) {
    syslog(LOG_EMERG, "failed to remount procfs: %s", strerror(errno));
    exit(1);
  }
  syslog(LOG_NOTICE, "chrooting");
  if (chdir("/mnt") == -1) {
    syslog(LOG_EMERG, "failed to chdir: %s", strerror(errno));
    exit(1);
  }
  if (chroot("/mnt") == -1) {
    syslog(LOG_EMERG, "failed to chroot: %s", strerror(errno));
    exit(1);
  }
  mkdir("/tmp", 0777);
  return execl("/bin/cond", "cond", "-a", "bash --login", "-1", "bash --login",
               (char *)NULL);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
cmp    $0x1,%eax
je     126b <main+0x2b>
movl   $0x1,-0x4(%rbp)
jmp    16e4 <main+0x4a4>
lea    -0x8(%rbp),%rdi
call   10d0 <sigfillset@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    $0x0,%al
call   1160 <fork@plt>
cmp    $0x0,%eax
je     12ab <main+0x6b>
jmp    129d <main+0x5d>
lea    -0xc(%rbp),%rdi
call   1150 <wait@plt>
jmp    129d <main+0x5d>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
mov    %edx,-0x20(%rbp)
call   1030 <sigprocmask@plt>
mov    -0x20(%rbp),%eax
mov    %al,-0x19(%rbp)
call   10b0 <setsid@plt>
mov    -0x20(%rbp),%esi
mov    %esi,%edi
call   1110 <setpgid@plt>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
lea    0xd19(%rip),%rsi
call   10c0 <fprintf@plt>
mov    -0x19(%rbp),%al
call   1160 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
sub    $0xffffffff,%eax
je     13f3 <main+0x1b3>
jmp    1307 <main+0xc7>
mov    -0x18(%rbp),%eax
test   %eax,%eax
jne    1414 <main+0x1d4>
jmp    1317 <main+0xd7>
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
lea    0xcdd(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2cb5(%rip),%rax
mov    (%rax),%esi
lea    0xcd2(%rip),%rdi
call   10f0 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    136d <main+0x12d>
mov    0x2c63(%rip),%rax
mov    (%rax),%edi
lea    0xcba(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2c44(%rip),%rax
mov    (%rax),%edi
lea    0xca3(%rip),%rsi
call   10c0 <fprintf@plt>
mov    -0x10(%rbp),%edi
xor    %esi,%esi
call   1090 <dup2@plt>
mov    -0x10(%rbp),%edi
mov    $0x1,%esi
call   1090 <dup2@plt>
mov    -0x10(%rbp),%edi
mov    $0x2,%esi
call   1090 <dup2@plt>
mov    0x2c0b(%rip),%rax
mov    (%rax),%edi
lea    0xc74(%rip),%rsi
call   10c0 <fprintf@plt>
lea    0xc72(%rip),%rdi
lea    0xc70(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1140 <execl@plt>
mov    0x2bdd(%rip),%rax
mov    (%rax),%edi
lea    0xc5d(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2bbe(%rip),%rax
mov    (%rax),%edi
lea    0xc44(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16e4 <main+0x4a4>
jmp    1419 <main+0x1d9>
mov    0x2b70(%rip),%rax
mov    (%rax),%esi
lea    0xc28(%rip),%rdi
call   10f0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    143f <main+0x1ff>
jmp    1419 <main+0x1d9>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
mov    0x2b8a(%rip),%rax
mov    (%rax),%edx
lea    0xc03(%rip),%rdi
xor    %esi,%esi
call   1100 <openlog@plt>
mov    0x2b3b(%rip),%rax
mov    (%rax),%edi
lea    0xbf1(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
lea    0xbf1(%rip),%rdi
lea    0xbf4(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
xor    %ecx,%ecx
mov    %r8,%rdx
call   1070 <mount@plt>
cmp    $0xffffffff,%eax
jne    14d2 <main+0x292>
mov    0x2b2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2b02(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
lea    0xbbb(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2ac7(%rip),%rax
mov    (%rax),%edi
lea    0xbba(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
lea    0xbbd(%rip),%rdi
mov    $0x1ff,%esi
call   1050 <mkdir@plt>
mov    0x2ac7(%rip),%rax
mov    (%rax),%ecx
lea    0xba7(%rip),%rdi
lea    0xb9c(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
call   1070 <mount@plt>
cmp    $0xffffffff,%eax
jne    155e <main+0x31e>
mov    0x2aa2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2a76(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%edx
lea    0xb69(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2a3b(%rip),%rax
mov    (%rax),%edi
lea    0xb64(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
lea    0xb68(%rip),%rdi
mov    $0x1ff,%esi
call   1050 <mkdir@plt>
mov    0x2a3b(%rip),%rax
mov    (%rax),%ecx
lea    0xb52(%rip),%rdi
lea    0xb47(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
call   1070 <mount@plt>
cmp    $0xffffffff,%eax
jne    15ea <main+0x3aa>
mov    0x2a16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x29ea(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%edx
lea    0xb15(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x29af(%rip),%rax
mov    (%rax),%edi
lea    0xb11(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
lea    0xa6f(%rip),%rdi
call   1080 <chdir@plt>
cmp    $0xffffffff,%eax
jne    164d <main+0x40d>
mov    0x29b3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2987(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%edx
lea    0xad9(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xa23(%rip),%rdi
call   1040 <chroot@plt>
cmp    $0xffffffff,%eax
jne    1699 <main+0x459>
mov    0x2967(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x293b(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%edx
lea    0xaa1(%rip),%rsi
mov    $0x0,%al
call   10e0 <syslog@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xa9e(%rip),%rdi
mov    $0x1ff,%esi
call   1050 <mkdir@plt>
lea    0xa92(%rip),%rdi
lea    0xa90(%rip),%rsi
lea    0xa8e(%rip),%rdx
lea    0xa8a(%rip),%r9
lea    0xa90(%rip),%r8
xor    %eax,%eax
mov    %r9,%rcx
movq   $0x0,(%rsp)
mov    $0x0,%al
call   1140 <execl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1060 <getpid@plt>
mov    $0x1,%ebp
cmp    $0x1,%eax
jne    148d <main+0x24d>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   10d0 <sigfillset@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
xor    %eax,%eax
call   1160 <fork@plt>
test   %eax,%eax
je     129a <main+0x5a>
lea    0xc(%rsp),%rbx
nopl   (%rax)
mov    %rbx,%rdi
call   1150 <wait@plt>
jmp    1290 <main+0x50>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
xor    %eax,%eax
call   10b0 <setsid@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1110 <setpgid@plt>
mov    0x2cf2(%rip),%rbx
mov    (%rbx),%edi
lea    0xd31(%rip),%rsi
call   10c0 <fprintf@plt>
xor    %eax,%eax
call   1160 <fork@plt>
cmp    $0xffffffff,%eax
je     147f <main+0x23f>
test   %eax,%eax
je     1498 <main+0x258>
mov    0x2c9d(%rip),%rbp
lea    0xd57(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   10f0 <open@plt>
cmp    $0xffffffff,%eax
je     1300 <main+0xc0>
mov    %eax,%edi
call   10a0 <close@plt>
mov    0x2cba(%rip),%rax
mov    (%rax),%edx
lea    0xd33(%rip),%rdi
xor    %esi,%esi
call   1100 <openlog@plt>
mov    0x2c6b(%rip),%r14
mov    (%r14),%edi
lea    0xd20(%rip),%rsi
xor    %eax,%eax
call   10e0 <syslog@plt>
lea    0xd20(%rip),%rdi
lea    0xd23(%rip),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <mount@plt>
cmp    $0xffffffff,%eax
je     14d2 <main+0x292>
mov    (%r14),%edi
lea    0xd29(%rip),%rsi
xor    %eax,%eax
call   10e0 <syslog@plt>
lea    0xd2c(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1050 <mkdir@plt>
mov    0x2c33(%rip),%rbp
mov    0x0(%rbp),%ecx
lea    0xd12(%rip),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %r8d,%r8d
call   1070 <mount@plt>
cmp    $0xffffffff,%eax
je     14f2 <main+0x2b2>
mov    (%r14),%edi
lea    0xd13(%rip),%rsi
xor    %eax,%eax
call   10e0 <syslog@plt>
lea    0xd17(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1050 <mkdir@plt>
mov    0x0(%rbp),%ecx
lea    0xd04(%rip),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %r8d,%r8d
call   1070 <mount@plt>
cmp    $0xffffffff,%eax
je     1512 <main+0x2d2>
mov    (%r14),%edi
lea    0xd07(%rip),%rsi
xor    %eax,%eax
call   10e0 <syslog@plt>
lea    0xc65(%rip),%rdi
call   1080 <chdir@plt>
cmp    $0xffffffff,%eax
je     1532 <main+0x2f2>
lea    0xc50(%rip),%rdi
call   1040 <chroot@plt>
cmp    $0xffffffff,%eax
je     1552 <main+0x312>
lea    0xd02(%rip),%rdi
mov    $0x1ff,%esi
call   1050 <mkdir@plt>
movq   $0x0,(%rsp)
lea    0xcee(%rip),%rdi
lea    0xcec(%rip),%rsi
lea    0xcea(%rip),%rdx
lea    0xcf3(%rip),%r8
lea    0xcdf(%rip),%rcx
mov    %rcx,%r9
xor    %eax,%eax
call   1140 <execl@plt>
mov    %eax,%ebp
jmp    148d <main+0x24d>
mov    (%rbx),%edi
lea    0xbbf(%rip),%rsi
call   10c0 <fprintf@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%edi
lea    0xb63(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2b3b(%rip),%rax
mov    (%rax),%esi
lea    0xb58(%rip),%rdi
call   10f0 <open@plt>
mov    (%rbx),%edi
cmp    $0xffffffff,%eax
jne    1585 <main+0x345>
lea    0xb4b(%rip),%rsi
jmp    15e2 <main+0x3a2>
mov    0x2af7(%rip),%rax
mov    (%rax),%ebx
mov    0x2ace(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xb8c(%rip),%rsi
jmp    1570 <main+0x330>
mov    0x2ad7(%rip),%rax
mov    (%rax),%ebx
mov    0x2aae(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xba6(%rip),%rsi
jmp    1570 <main+0x330>
mov    0x2ab7(%rip),%rax
mov    (%rax),%ebx
mov    0x2a8e(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xbbe(%rip),%rsi
jmp    1570 <main+0x330>
mov    0x2a97(%rip),%rax
mov    (%rax),%ebx
mov    0x2a6e(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xbc5(%rip),%rsi
jmp    1570 <main+0x330>
mov    0x2a77(%rip),%rax
mov    (%rax),%ebx
mov    0x2a4e(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xbb9(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   10e0 <syslog@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    %eax,%ebp
lea    0xa92(%rip),%rsi
call   10c0 <fprintf@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1090 <dup2@plt>
mov    %ebp,%edi
mov    $0x1,%esi
call   1090 <dup2@plt>
mov    %ebp,%edi
mov    $0x2,%esi
call   1090 <dup2@plt>
mov    (%rbx),%edi
lea    0xa6d(%rip),%rsi
call   10c0 <fprintf@plt>
lea    0xa6b(%rip),%rdi
lea    0xa69(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1140 <execl@plt>
mov    (%rbx),%edi
lea    0xa5f(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
@SIG_BLOCK = global i32 0
@SIG_UNBLOCK = global i32 0
@stderr = global i32 0
@.str = [4 x i8] c"P1\0A\00"
@.str.1 = [10 x i8] c"succes 1\0A\00"
@.str.2 = [10 x i8] c"/dev/com0\00"
@O_RDWR = global i32 0
@.str.3 = [8 x i8] c"failed\0A\00"
@.str.4 = [10 x i8] c"succes 2\0A\00"
@.str.5 = [10 x i8] c"succes 3\0A\00"
@.str.6 = [13 x i8] c"/bin/syslogd\00"
@.str.7 = [8 x i8] c"syslogd\00"
@.str.8 = [6 x i8] c"done\0A\00"
@.str.9 = [10 x i8] c"fork err\0A\00"
@.str.10 = [9 x i8] c"/dev/log\00"
@O_WRONLY = global i32 0
@.str.11 = [5 x i8] c"init\00"
@LOG_DAEMON = global i32 0
@LOG_NOTICE = global i32 0
@.str.12 = [14 x i8] c"mounting root\00"
@.str.13 = [10 x i8] c"/dev/ada0\00"
@.str.14 = [5 x i8] c"/mnt\00"
@LOG_EMERG = global i32 0
@.str.15 = [32 x i8] c"failed to mount root device: %s\00"
@errno = global i32 0
@.str.16 = [17 x i8] c"remounting devfs\00"
@.str.17 = [9 x i8] c"/mnt/dev\00"
@.str.18 = [5 x i8] c"/dev\00"
@MS_BIND = global i32 0
@.str.19 = [28 x i8] c"failed to remount devfs: %s\00"
@.str.20 = [18 x i8] c"remounting procfs\00"
@.str.21 = [10 x i8] c"/mnt/proc\00"
@.str.22 = [6 x i8] c"/proc\00"
@.str.23 = [29 x i8] c"failed to remount procfs: %s\00"
@.str.24 = [10 x i8] c"chrooting\00"
@.str.25 = [20 x i8] c"failed to chdir: %s\00"
@.str.26 = [21 x i8] c"failed to chroot: %s\00"
@.str.27 = [5 x i8] c"/tmp\00"
@.str.28 = [10 x i8] c"/bin/cond\00"
@.str.29 = [5 x i8] c"cond\00"
@.str.30 = [3 x i8] c"-a\00"
@.str.31 = [13 x i8] c"bash --login\00"
@.str.32 = [3 x i8] c"-1\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (...) @getpid()
%7 = icmp ne i32 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 1, i32* %1
br label %125
9: ; preds = %0
%10 = call i32 @sigfillset(i32* %2)
%11 = load i32, i32* @SIG_BLOCK
%12 = call i32 @sigprocmask(i32 %11, i32* %2, i32 0)
%13 = call i32 (...) @fork()
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %9
br label %16
16: ; preds = %16, %15
%17 = call i32 @wait(i32* %3)
br label %16
18: ; preds = %9
%19 = load i32, i32* @SIG_UNBLOCK
%20 = call i32 @sigprocmask(i32 %19, i32* %2, i32 0)
%21 = call i32 (...) @setsid()
%22 = call i32 @setpgid(i32 0, i32 0)
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%25 = call i32 (...) @fork()
switch i32 %25, label %55 [
i32 0, label %26
i32 -1, label %52
]
26: ; preds = %18
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @O_RDWR
%30 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %29)
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %26
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %26
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%40 = load i32, i32* %4
%41 = call i32 @dup2(i32 %40, i32 0)
%42 = load i32, i32* %4
%43 = call i32 @dup2(i32 %42, i32 1)
%44 = load i32, i32* %4
%45 = call i32 @dup2(i32 %44, i32 2)
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%48 = call i32 (i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* null)
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %18
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %1
br label %125
55: ; preds = %18
br label %56
56: ; preds = %60, %55
%57 = load i32, i32* @O_WRONLY
%58 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i32 %57)
store i32 %58, i32* %5
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %61
60: ; preds = %56
br label %56
61: ; preds = %56
%62 = load i32, i32* %5
%63 = call i32 @close(i32 %62)
%64 = load i32, i32* @LOG_DAEMON
%65 = call i32 @openlog(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 0, i32 %64)
%66 = load i32, i32* @LOG_NOTICE
%67 = call i32 (i32, i8*, ...) @syslog(i32 %66, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
%68 = call i32 @mount(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), i32* null, i32 0, i32* null)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %76
70: ; preds = %61
%71 = load i32, i32* @LOG_EMERG
%72 = load i32, i32* @errno
%73 = call i32 @strerror(i32 %72)
%74 = call i32 (i32, i8*, ...) @syslog(i32 %71, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i32 %73)
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %61
%77 = load i32, i32* @LOG_NOTICE
%78 = call i32 (i32, i8*, ...) @syslog(i32 %77, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.16, i64 0, i64 0))
%79 = call i32 @mkdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.17, i64 0, i64 0), i32 511)
%80 = load i32, i32* @MS_BIND
%81 = call i32 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.18, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.17, i64 0, i64 0), i32* null, i32 %80, i32* null)
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %89
83: ; preds = %76
%84 = load i32, i32* @LOG_EMERG
%85 = load i32, i32* @errno
%86 = call i32 @strerror(i32 %85)
%87 = call i32 (i32, i8*, ...) @syslog(i32 %84, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.19, i64 0, i64 0), i32 %86)
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %76
%90 = load i32, i32* @LOG_NOTICE
%91 = call i32 (i32, i8*, ...) @syslog(i32 %90, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.20, i64 0, i64 0))
%92 = call i32 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.21, i64 0, i64 0), i32 511)
%93 = load i32, i32* @MS_BIND
%94 = call i32 @mount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.22, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.21, i64 0, i64 0), i32* null, i32 %93, i32* null)
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %102
96: ; preds = %89
%97 = load i32, i32* @LOG_EMERG
%98 = load i32, i32* @errno
%99 = call i32 @strerror(i32 %98)
%100 = call i32 (i32, i8*, ...) @syslog(i32 %97, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.23, i64 0, i64 0), i32 %99)
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %89
%103 = load i32, i32* @LOG_NOTICE
%104 = call i32 (i32, i8*, ...) @syslog(i32 %103, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.24, i64 0, i64 0))
%105 = call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %113
107: ; preds = %102
%108 = load i32, i32* @LOG_EMERG
%109 = load i32, i32* @errno
%110 = call i32 @strerror(i32 %109)
%111 = call i32 (i32, i8*, ...) @syslog(i32 %108, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.25, i64 0, i64 0), i32 %110)
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %102
%114 = call i32 @chroot(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %122
116: ; preds = %113
%117 = load i32, i32* @LOG_EMERG
%118 = load i32, i32* @errno
%119 = call i32 @strerror(i32 %118)
%120 = call i32 (i32, i8*, ...) @syslog(i32 %117, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.26, i64 0, i64 0), i32 %119)
%121 = call i32 @exit(i32 1)
unreachable
122: ; preds = %113
%123 = call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.27, i64 0, i64 0), i32 511)
%124 = call i32 (i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.28, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.29, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.30, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.31, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.32, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.31, i64 0, i64 0), i8* null)
store i32 %124, i32* %1
br label %125
125: ; preds = %122, %52, %8
%126 = load i32, i32* %1
ret i32 %126
}

LLVM IR (-O2):
@SIG_BLOCK = global i32 0
@SIG_UNBLOCK = global i32 0
@stderr = global i32 0
@.str = [4 x i8] c"P1\0A\00"
@.str.1 = [10 x i8] c"succes 1\0A\00"
@.str.2 = [10 x i8] c"/dev/com0\00"
@O_RDWR = global i32 0
@.str.3 = [8 x i8] c"failed\0A\00"
@.str.4 = [10 x i8] c"succes 2\0A\00"
@.str.5 = [10 x i8] c"succes 3\0A\00"
@.str.6 = [13 x i8] c"/bin/syslogd\00"
@.str.7 = [8 x i8] c"syslogd\00"
@.str.8 = [6 x i8] c"done\0A\00"
@.str.9 = [10 x i8] c"fork err\0A\00"
@.str.10 = [9 x i8] c"/dev/log\00"
@O_WRONLY = global i32 0
@.str.11 = [5 x i8] c"init\00"
@LOG_DAEMON = global i32 0
@LOG_NOTICE = global i32 0
@.str.12 = [14 x i8] c"mounting root\00"
@.str.13 = [10 x i8] c"/dev/ada0\00"
@.str.14 = [5 x i8] c"/mnt\00"
@LOG_EMERG = global i32 0
@.str.15 = [32 x i8] c"failed to mount root device: %s\00"
@errno = global i32 0
@.str.16 = [17 x i8] c"remounting devfs\00"
@.str.17 = [9 x i8] c"/mnt/dev\00"
@.str.18 = [5 x i8] c"/dev\00"
@MS_BIND = global i32 0
@.str.19 = [28 x i8] c"failed to remount devfs: %s\00"
@.str.20 = [18 x i8] c"remounting procfs\00"
@.str.21 = [10 x i8] c"/mnt/proc\00"
@.str.22 = [6 x i8] c"/proc\00"
@.str.23 = [29 x i8] c"failed to remount procfs: %s\00"
@.str.24 = [10 x i8] c"chrooting\00"
@.str.25 = [20 x i8] c"failed to chdir: %s\00"
@.str.26 = [21 x i8] c"failed to chroot: %s\00"
@.str.27 = [5 x i8] c"/tmp\00"
@.str.28 = [10 x i8] c"/bin/cond\00"
@.str.29 = [5 x i8] c"cond\00"
@.str.30 = [3 x i8] c"-a\00"
@.str.31 = [13 x i8] c"bash --login\00"
@.str.32 = [3 x i8] c"-1\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (...) @getpid()
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %114
7: ; preds = %0
%8 = call i32 @sigfillset(i32* %1)
%9 = load i32, i32* @SIG_BLOCK
%10 = call i32 @sigprocmask(i32 %9, i32* %1, i32 0)
%11 = call i32 (...) @fork()
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %7, %13
%14 = call i32 @wait(i32* %2)
br label %13
15: ; preds = %7
%16 = load i32, i32* @SIG_UNBLOCK
%17 = call i32 @sigprocmask(i32 %16, i32* %1, i32 0)
%18 = call i32 (...) @setsid()
%19 = call i32 @setpgid(i32 0, i32 0)
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%22 = call i32 (...) @fork()
switch i32 %22, label %47 [
i32 0, label %23
i32 -1, label %44
]
23: ; preds = %15
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @O_RDWR
%27 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = icmp eq i32 %27, -1
%29 = load i32, i32* @stderr
br i1 %28, label %30, label %33
30: ; preds = %23
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %23
%34 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @dup2(i32 %27, i32 0)
%36 = call i32 @dup2(i32 %27, i32 1)
%37 = call i32 @dup2(i32 %27, i32 2)
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%40 = call i32 (i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* null)
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %15
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
br label %114
47: ; preds = %15, %47
%48 = load i32, i32* @O_WRONLY
%49 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %47, label %51
51: ; preds = %47
%52 = call i32 @close(i32 %49)
%53 = load i32, i32* @LOG_DAEMON
%54 = call i32 @openlog(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 0, i32 %53)
%55 = load i32, i32* @LOG_NOTICE
%56 = call i32 (i32, i8*, ...) @syslog(i32 %55, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
%57 = call i32 @mount(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), i32* null, i32 0, i32* null)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %65
59: ; preds = %51
%60 = load i32, i32* @LOG_EMERG
%61 = load i32, i32* @errno
%62 = call i32 @strerror(i32 %61)
%63 = call i32 (i32, i8*, ...) @syslog(i32 %60, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i32 %62)
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %51
%66 = load i32, i32* @LOG_NOTICE
%67 = call i32 (i32, i8*, ...) @syslog(i32 %66, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.16, i64 0, i64 0))
%68 = call i32 @mkdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.17, i64 0, i64 0), i32 511)
%69 = load i32, i32* @MS_BIND
%70 = call i32 @mount(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.18, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.17, i64 0, i64 0), i32* null, i32 %69, i32* null)
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %78
72: ; preds = %65
%73 = load i32, i32* @LOG_EMERG
%74 = load i32, i32* @errno
%75 = call i32 @strerror(i32 %74)
%76 = call i32 (i32, i8*, ...) @syslog(i32 %73, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.19, i64 0, i64 0), i32 %75)
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %65
%79 = load i32, i32* @LOG_NOTICE
%80 = call i32 (i32, i8*, ...) @syslog(i32 %79, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.20, i64 0, i64 0))
%81 = call i32 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.21, i64 0, i64 0), i32 511)
%82 = load i32, i32* @MS_BIND
%83 = call i32 @mount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.22, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.21, i64 0, i64 0), i32* null, i32 %82, i32* null)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %91
85: ; preds = %78
%86 = load i32, i32* @LOG_EMERG
%87 = load i32, i32* @errno
%88 = call i32 @strerror(i32 %87)
%89 = call i32 (i32, i8*, ...) @syslog(i32 %86, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.23, i64 0, i64 0), i32 %88)
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %78
%92 = load i32, i32* @LOG_NOTICE
%93 = call i32 (i32, i8*, ...) @syslog(i32 %92, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.24, i64 0, i64 0))
%94 = call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %102
96: ; preds = %91
%97 = load i32, i32* @LOG_EMERG
%98 = load i32, i32* @errno
%99 = call i32 @strerror(i32 %98)
%100 = call i32 (i32, i8*, ...) @syslog(i32 %97, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.25, i64 0, i64 0), i32 %99)
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %91
%103 = call i32 @chroot(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %111
105: ; preds = %102
%106 = load i32, i32* @LOG_EMERG
%107 = load i32, i32* @errno
%108 = call i32 @strerror(i32 %107)
%109 = call i32 (i32, i8*, ...) @syslog(i32 %106, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.26, i64 0, i64 0), i32 %108)
%110 = call i32 @exit(i32 1)
unreachable
111: ; preds = %102
%112 = call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.27, i64 0, i64 0), i32 511)
%113 = call i32 (i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.28, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.29, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.30, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.31, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.32, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.31, i64 0, i64 0), i8* null)
br label %114
114: ; preds = %0, %111, %44
%115 = phi i32 [ %113, %111 ], [ 1, %44 ], [ 1, %0 ]
ret i32 %115
}