#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 timeval {
  int member_1;
  int /*<<< orphan*/ member_0;
};
typedef int pid_t;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EIO;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
scalar_t__ daemon(int /*<<< orphan*/, int /*<<< orphan*/);
int dup(int);
int errno;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ *fopen(char *, char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ log_data(char *, int);
int /*<<< orphan*/ log_finish();
int /*<<< orphan*/ log_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ log_periodic();
scalar_t__ login_tty(int);
scalar_t__ openpty(int *, int *, char *, int /*<<< orphan*/ *,
                   int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ setlinebuf(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stderr;
char *strerror(int);
int /*<<< orphan*/ unlink(char *);
int bglog_main(int argc, char **argv) {
  char *args[20 + 1];
  int num_args = 0;
  int ind;
  if (argc == 1) {
    printf("usage: bglog ...\n");
    return 1;
  }
  for (ind = 1; ind < argc; ind++) {
    if (num_args >= 20) {
      printf("too many args, bailing out\n");
      return 1;
    }
    args[num_args++] = argv[ind];
  }
  args[num_args] = NULL;
  for (ind = 0; ind < num_args; ind++)
    printf("arg %d : %s\n", ind, args[ind]);
  int master_fd, slave_fd;
  char ttyname[256];
  if (openpty(&master_fd, &slave_fd, ttyname, NULL, NULL) < 0) {
    printf("fork failed: %d: %s\n", errno, strerror(errno));
    return 1;
  }
  printf("opened tty : %s\n", ttyname);
  int console_fd = dup(1);
  FILE *console_f = fdopen(console_fd, "w");
  setlinebuf(console_f);
  if (daemon(0, 0) < 0)
    fprintf(stderr, "daemon failed!\n");
  pid_t pid = fork();
  if (pid < 0) {
    fprintf(console_f, "fork failed: %d: %s\n", errno, strerror(errno));
    return 1;
  }
  if (pid == 0) {
    close(master_fd);
    if (login_tty(slave_fd) < 0) {
      fprintf(console_f, "login_tty failed: %d: %s\n", errno, strerror(errno));
      exit(1);
    }
    execvp(args[0], args);
    fprintf(console_f, "execvp failed: %d: %s\n", errno, strerror(errno));
    exit(1);
  }
  close(slave_fd);
  (void)unlink("/tmp/cleanup.sh");
  FILE *cleanup_f = fopen("/tmp/cleanup.sh", "w");
  fprintf(cleanup_f,
          "#!/bin/sh\n"
          "kill %d\n"
          "done=0\n"
          "while [ $done = 0 ] ; do\n"
          "    result=$( ps ax | awk '{ if ($1 == %d) print \"yes\" }' )\n"
          "    if [ x$result = xyes ] ; then\n"
          "        echo still waiting\n"
          "        sleep 0.5\n"
          "    else\n"
          "        done=1\n"
          "    fi\n"
          "done\n"
          "echo process is dead\n"
          "exit 0\n",
          pid, pid);
  fclose(cleanup_f);
  log_init(console_f);
  while (1) {
    struct timeval tv = {0, 500000};
    fd_set rfds;
    char buf[200];
    FD_ZERO(&rfds);
    FD_SET(master_fd, &rfds);
    if (select(master_fd + 1, &rfds, NULL, NULL, &tv) == 0) {
      log_periodic();
      continue;
    }
    if (FD_ISSET(master_fd, &rfds)) {
      int cc = read(master_fd, buf, sizeof(buf));
      if (cc < 0) {
        if (errno != EIO)
          fprintf(console_f, "read failed: %d: %s\n", errno, strerror(errno));
      }
      if (cc <= 0)
        break;
      log_data(buf, cc);
    }
  }
  close(master_fd);
  log_finish();
  (void)unlink("/tmp/cleanup.sh");
  fprintf(console_f, "bglog exiting\n");
  fclose(console_f);
  return 0;
}


x86 assembly (clang, -O0):
<bglog_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x320,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xc4(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    12d0 <bglog_main+0x40>
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    17d4 <bglog_main+0x544>
movl   $0x1,-0xc8(%rbp)
mov    -0xc8(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    134e <bglog_main+0xbe>
cmpl   $0x14,-0xc4(%rbp)
jl     1310 <bglog_main+0x80>
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    17d4 <bglog_main+0x544>
mov    -0x10(%rbp),%rax
movslq -0xc8(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0xc4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xc4(%rbp)
cltq
mov    %rcx,-0xc0(%rbp,%rax,8)
ff
mov    -0xc8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc8(%rbp)
jmp    12da <bglog_main+0x4a>
movslq -0xc4(%rbp),%rax
movq   $0x0,-0xc0(%rbp,%rax,8)
movl   $0x0,-0xc8(%rbp)
mov    -0xc8(%rbp),%eax
cmp    -0xc4(%rbp),%eax
jge    13b4 <bglog_main+0x124>
mov    -0xc8(%rbp),%esi
movslq -0xc8(%rbp),%rax
mov    -0xc0(%rbp,%rax,8),%rdx
ff
lea    0xc95(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0xc8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc8(%rbp)
jmp    136b <bglog_main+0xdb>
lea    -0x1d0(%rbp),%rdx
lea    -0xcc(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rcx
call   1120 <openpty@plt>
cmp    $0x0,%rax
jge    1420 <bglog_main+0x190>
mov    0x2be9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2d8(%rbp)
mov    0x2bda(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
mov    -0x2d8(%rbp),%esi
mov    %rax,%rdx
lea    0xc2e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    17d4 <bglog_main+0x544>
lea    -0x1d0(%rbp),%rsi
lea    0xc22(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   1090 <dup@plt>
mov    %eax,-0x1d4(%rbp)
mov    -0x1d4(%rbp),%edi
lea    0xc0f(%rip),%rsi
call   1140 <fdopen@plt>
mov    %rax,-0x1e0(%rbp)
mov    -0x1e0(%rbp),%rdi
call   10b0 <setlinebuf@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1130 <daemon@plt>
cmp    $0x0,%rax
jge    1495 <bglog_main+0x205>
mov    0x2b54(%rip),%rax
mov    (%rax),%rdi
lea    0xbd5(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
mov    $0x0,%al
call   11b0 <fork@plt>
mov    %eax,-0x1e4(%rbp)
cmpl   $0x0,-0x1e4(%rbp)
jge    1504 <bglog_main+0x274>
mov    -0x1e0(%rbp),%rax
mov    %rax,-0x2e8(%rbp)
mov    0x2b0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2dc(%rbp)
mov    0x2afd(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
mov    -0x2e8(%rbp),%rdi
mov    -0x2dc(%rbp),%edx
mov    %rax,%rcx
lea    0xb4a(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    17d4 <bglog_main+0x544>
cmpl   $0x0,-0x1e4(%rbp)
jne    15ea <bglog_main+0x35a>
mov    -0xcc(%rbp),%edi
call   10c0 <close@plt>
mov    -0xd0(%rbp),%edi
call   10e0 <login_tty@plt>
cmp    $0x0,%rax
jge    1584 <bglog_main+0x2f4>
mov    -0x1e0(%rbp),%rax
mov    %rax,-0x2f8(%rbp)
mov    0x2a8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2ec(%rbp)
mov    0x2a7b(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
mov    -0x2f8(%rbp),%rdi
mov    -0x2ec(%rbp),%edx
mov    %rax,%rcx
lea    0xb00(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
mov    $0x1,%edi
call   1180 <exit@plt>
mov    -0xc0(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
call   1170 <execvp@plt>
mov    -0x1e0(%rbp),%rax
mov    %rax,-0x308(%rbp)
mov    0x2a24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2fc(%rbp)
mov    0x2a15(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
mov    -0x308(%rbp),%rdi
mov    -0x2fc(%rbp),%edx
mov    %rax,%rcx
lea    0xab4(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
mov    $0x1,%edi
call   1180 <exit@plt>
mov    -0xd0(%rbp),%edi
call   10c0 <close@plt>
lea    0xaa8(%rip),%rdi
call   1040 <unlink@plt>
lea    0xa9c(%rip),%rdi
lea    0xa52(%rip),%rsi
call   1160 <fopen@plt>
mov    %rax,-0x1f0(%rbp)
mov    -0x1f0(%rbp),%rdi
mov    -0x1e4(%rbp),%edx
mov    -0x1e4(%rbp),%ecx
lea    0xa7f(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
mov    -0x1f0(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x1e0(%rbp),%rdi
call   1030 <log_init@plt>
mov    0xb7d(%rip),%rax
mov    %rax,-0x1f8(%rbp)
lea    -0x1fc(%rbp),%rdi
call   1100 <FD_ZERO@plt>
mov    -0xcc(%rbp),%edi
lea    -0x1fc(%rbp),%rsi
call   11a0 <FD_SET@plt>
mov    -0xcc(%rbp),%edi
add    $0x1,%edi
lea    -0x1fc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x1f8(%rbp),%r8
mov    %rcx,%rdx
call   1110 <select@plt>
cmp    $0x0,%rax
jne    16b9 <bglog_main+0x429>
mov    $0x0,%al
call   10a0 <log_periodic@plt>
jmp    1654 <bglog_main+0x3c4>
mov    -0xcc(%rbp),%edi
lea    -0x1fc(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1789 <bglog_main+0x4f9>
mov    -0xcc(%rbp),%edi
lea    -0x2d0(%rbp),%rsi
mov    $0xc8,%edx
call   10d0 <read@plt>
mov    %eax,-0x2d4(%rbp)
cmpl   $0x0,-0x2d4(%rbp)
jge    1765 <bglog_main+0x4d5>
mov    0x28ca(%rip),%rax
mov    (%rax),%eax
mov    0x28d1(%rip),%rcx
cmp    (%rcx),%eax
je     1760 <bglog_main+0x4d0>
mov    -0x1e0(%rbp),%rax
mov    %rax,-0x318(%rbp)
mov    0x28a4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30c(%rbp)
mov    0x2895(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
mov    -0x318(%rbp),%rdi
mov    -0x30c(%rbp),%edx
mov    %rax,%rcx
lea    0xa59(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
jmp    1765 <bglog_main+0x4d5>
cmpl   $0x0,-0x2d4(%rbp)
jg     1777 <bglog_main+0x4e7>
jmp    178e <bglog_main+0x4fe>
lea    -0x2d0(%rbp),%rdi
mov    -0x2d4(%rbp),%esi
call   1150 <log_data@plt>
jmp    1654 <bglog_main+0x3c4>
mov    -0xcc(%rbp),%edi
call   10c0 <close@plt>
mov    $0x0,%al
call   1050 <log_finish@plt>
lea    0x8fd(%rip),%rdi
call   1040 <unlink@plt>
mov    -0x1e0(%rbp),%rdi
lea    0xa0d(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
mov    -0x1e0(%rbp),%rdi
call   1070 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x320,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bglog_main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2a0,%rsp
cmp    $0x1,%edi
jne    12d6 <bglog_main+0x26>
lea    0xef7(%rip),%rdi
call   1060 <puts@plt>
jmp    16ee <bglog_main+0x43e>
jle    150c <bglog_main+0x25c>
add    $0xffffffff,%edi
mov    0x8(%rsi),%rax
mov    %rax,0x20(%rsp)
mov    $0x1,%r15d
cmp    $0x1,%edi
je     14d6 <bglog_main+0x226>
mov    0x10(%rsi),%rax
mov    %rax,0x28(%rsp)
mov    $0x2,%r15d
cmp    $0x2,%edi
je     14d6 <bglog_main+0x226>
mov    0x18(%rsi),%rax
mov    %rax,0x30(%rsp)
mov    $0x3,%r15d
cmp    $0x3,%edi
je     14d6 <bglog_main+0x226>
mov    0x20(%rsi),%rax
mov    %rax,0x38(%rsp)
mov    $0x4,%r15d
cmp    $0x4,%edi
je     14d6 <bglog_main+0x226>
mov    0x28(%rsi),%rax
mov    %rax,0x40(%rsp)
mov    $0x5,%r15d
cmp    $0x5,%edi
je     14d6 <bglog_main+0x226>
mov    0x30(%rsi),%rax
mov    %rax,0x48(%rsp)
mov    $0x6,%r15d
cmp    $0x6,%edi
je     14d6 <bglog_main+0x226>
mov    0x38(%rsi),%rax
mov    %rax,0x50(%rsp)
mov    $0x7,%r15d
cmp    $0x7,%edi
je     14d6 <bglog_main+0x226>
mov    0x40(%rsi),%rax
mov    %rax,0x58(%rsp)
mov    $0x8,%r15d
cmp    $0x8,%edi
je     14d6 <bglog_main+0x226>
mov    0x48(%rsi),%rax
mov    %rax,0x60(%rsp)
mov    $0x9,%r15d
cmp    $0x9,%edi
je     14d6 <bglog_main+0x226>
mov    0x50(%rsi),%rax
mov    %rax,0x68(%rsp)
mov    $0xa,%r15d
cmp    $0xa,%edi
je     14d6 <bglog_main+0x226>
mov    0x58(%rsi),%rax
mov    %rax,0x70(%rsp)
mov    $0xb,%r15d
cmp    $0xb,%edi
je     14d6 <bglog_main+0x226>
mov    0x60(%rsi),%rax
mov    %rax,0x78(%rsp)
mov    $0xc,%r15d
cmp    $0xc,%edi
je     14d6 <bglog_main+0x226>
mov    0x68(%rsi),%rax
mov    %rax,0x80(%rsp)
mov    $0xd,%r15d
cmp    $0xd,%edi
je     14d6 <bglog_main+0x226>
mov    0x70(%rsi),%rax
mov    %rax,0x88(%rsp)
mov    $0xe,%r15d
cmp    $0xe,%edi
je     14d6 <bglog_main+0x226>
mov    0x78(%rsi),%rax
mov    %rax,0x90(%rsp)
mov    $0xf,%r15d
cmp    $0xf,%edi
je     14d6 <bglog_main+0x226>
mov    0x80(%rsi),%rax
mov    %rax,0x98(%rsp)
mov    $0x10,%r15d
cmp    $0x10,%edi
je     14d6 <bglog_main+0x226>
mov    0x88(%rsi),%rax
mov    %rax,0xa0(%rsp)
mov    $0x11,%r15d
cmp    $0x11,%edi
je     14d6 <bglog_main+0x226>
mov    0x90(%rsi),%rax
mov    %rax,0xa8(%rsp)
mov    $0x12,%r15d
cmp    $0x12,%edi
je     14d6 <bglog_main+0x226>
mov    0x98(%rsi),%rax
mov    %rax,0xb0(%rsp)
mov    $0x13,%r15d
cmp    $0x13,%edi
je     14d6 <bglog_main+0x226>
mov    0xa0(%rsi),%rax
mov    %rax,0xb8(%rsp)
mov    $0x14,%r15d
cmp    $0x14,%edi
jne    177b <bglog_main+0x4cb>
movq   $0x0,0x20(%rsp,%r15,8)
lea    0xb1a(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x20(%rsp,%rbx,8),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1090 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    14f0 <bglog_main+0x240>
jmp    1515 <bglog_main+0x265>
movq   $0x0,0x20(%rsp)
lea    0x8(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0xd0(%rsp),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1130 <openpty@plt>
test   %rax,%rax
js     16a3 <bglog_main+0x3f3>
lea    0xae1(%rip),%rdi
lea    0xd0(%rsp),%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x1,%edi
call   10a0 <dup@plt>
lea    0xad2(%rip),%rsi
mov    %eax,%edi
call   1150 <fdopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   10c0 <setlinebuf@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1140 <daemon@plt>
test   %rax,%rax
jns    15a1 <bglog_main+0x2f1>
mov    0x2a50(%rip),%rax
mov    (%rax),%rcx
lea    0xaa3(%rip),%rdi
mov    $0xf,%esi
mov    $0x1,%edx
call   11a0 <fwrite@plt>
xor    %eax,%eax
call   11d0 <fork@plt>
test   %eax,%eax
js     16c8 <bglog_main+0x418>
je     1787 <bglog_main+0x4d7>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
call   10d0 <close@plt>
lea    0xaae(%rip),%r15
mov    %r15,%rdi
call   1040 <unlink@plt>
lea    0xa5c(%rip),%rsi
mov    %r15,%rdi
call   1170 <fopen@plt>
mov    %rax,%r15
lea    0xa9d(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1100 <fprintf@plt>
mov    %r15,%rdi
call   1080 <fclose@plt>
mov    %r14,%rdi
call   1030 <log_init@plt>
movabs $0x7a12000000000,%r13
lea    0x1c(%rsp),%rbx
lea    0x10(%rsp),%r15
lea    0x1d0(%rsp),%r12
jmp    1637 <bglog_main+0x387>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   10b0 <log_periodic@plt>
mov    %r13,0x10(%rsp)
mov    %rbx,%rdi
call   1110 <FD_ZERO@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
call   11c0 <FD_SET@plt>
mov    0x8(%rsp),%edi
add    $0x1,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1120 <select@plt>
test   %rax,%rax
je     1630 <bglog_main+0x380>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
call   1070 <FD_ISSET@plt>
test   %rax,%rax
je     1637 <bglog_main+0x387>
mov    0x8(%rsp),%edi
mov    %r12,%rsi
mov    $0xc8,%edx
call   10e0 <read@plt>
test   %eax,%eax
js     1706 <bglog_main+0x456>
je     1737 <bglog_main+0x487>
mov    %r12,%rdi
mov    %eax,%esi
call   1160 <log_data@plt>
jmp    1637 <bglog_main+0x387>
mov    0x2926(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   11b0 <strerror@plt>
lea    0x953(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <printf@plt>
jmp    16ee <bglog_main+0x43e>
mov    0x2901(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   11b0 <strerror@plt>
lea    0x92e(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1100 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x2a0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x28c3(%rip),%rax
mov    (%rax),%ebx
mov    0x28ca(%rip),%rax
cmp    (%rax),%ebx
je     1737 <bglog_main+0x487>
mov    %ebx,%edi
call   11b0 <strerror@plt>
lea    0xa5c(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1100 <fprintf@plt>
mov    0x8(%rsp),%edi
call   10d0 <close@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <log_finish@plt>
lea    0x926(%rip),%rdi
call   1040 <unlink@plt>
lea    0xa3d(%rip),%rdi
mov    $0xe,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   11a0 <fwrite@plt>
mov    %r14,%rdi
call   1080 <fclose@plt>
jmp    16f3 <bglog_main+0x443>
lea    0xa26(%rip),%rdi
jmp    12cc <bglog_main+0x1c>
mov    0x8(%rsp),%edi
call   10d0 <close@plt>
mov    0xc(%rsp),%edi
call   10f0 <login_tty@plt>
test   %rax,%rax
jns    17b7 <bglog_main+0x507>
mov    0x282b(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   11b0 <strerror@plt>
lea    0x890(%rip),%rsi
jmp    17dd <bglog_main+0x52d>
mov    0x20(%rsp),%rdi
lea    0x20(%rsp),%rsi
call   1180 <execvp@plt>
mov    0x2803(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   11b0 <strerror@plt>
lea    0x882(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1100 <fprintf@plt>
mov    $0x1,%edi
call   1190 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [18 x i8] c"usage: bglog ...\0A\00"
@.str.1 = [28 x i8] c"too many args, bailing out\0A\00"
@.str.2 = [13 x i8] c"arg %d : %s\0A\00"
@.str.3 = [21 x i8] c"fork failed: %d: %s\0A\00"
@errno = global i32 0
@.str.4 = [17 x i8] c"opened tty : %s\0A\00"
@.str.5 = [2 x i8] c"w\00"
@stderr = global i32* null
@.str.6 = [16 x i8] c"daemon failed!\0A\00"
@.str.7 = [26 x i8] c"login_tty failed: %d: %s\0A\00"
@.str.8 = [23 x i8] c"execvp failed: %d: %s\0A\00"
@.str.9 = [16 x i8] c"/tmp/cleanup.sh\00"
@.str.10 = [254 x i8] c"#!/bin/sh\0Akill %d\0Adone=0\0Awhile [ $done = 0 ] ; do\0A result=$( ps ax | awk '{ if ($1 == %d) print \22yes\22 }' )\0A if [ x$result = xyes ] ; then\0A echo still waiting\0A sleep 0.5\0A else\0A done=1\0A fi\0Adone\0Aecho process is dead\0Aexit 0\0A\00"
@__const.bglog_main.tv = %struct.timeval { i32 0, i32 500000 }
@EIO = global i32 0
@.str.11 = [21 x i8] c"read failed: %d: %s\0A\00"
@.str.12 = [15 x i8] c"bglog exiting\0A\00"
define i32 @bglog_main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [21 x i8*]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [256 x i8]
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32*
%16 = alloca %struct.timeval
%17 = alloca i32
%18 = alloca [200 x i8]
%19 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %187
24: ; preds = %2
store i32 1, i32* %8
br label %25
25: ; preds = %44, %24
%26 = load i32, i32* %8
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %47
29: ; preds = %25
%30 = load i32, i32* %7
%31 = icmp sge i32 %30, 20
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %187
34: ; preds = %29
%35 = load i8**, i8*** %5
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds [21 x i8*], [21 x i8*]* %6, i64 0, i64 %42
store i8* %39, i8** %43
br label %44
44: ; preds = %34
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %25
47: ; preds = %25
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [21 x i8*], [21 x i8*]* %6, i64 0, i64 %49
store i8* null, i8** %50
store i32 0, i32* %8
br label %51
51: ; preds = %62, %47
%52 = load i32, i32* %8
%53 = load i32, i32* %7
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %65
55: ; preds = %51
%56 = load i32, i32* %8
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [21 x i8*], [21 x i8*]* %6, i64 0, i64 %58
%60 = load i8*, i8** %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %56, i8* %60)
br label %62
62: ; preds = %55
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 1
store i32 %64, i32* %8
br label %51
65: ; preds = %51
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%67 = call i64 @openpty(i32* %9, i32* %10, i8* %66, i32* null, i32* null)
%68 = icmp slt i64 %67, 0
br i1 %68, label %69, label %74
69: ; preds = %65
%70 = load i32, i32* @errno
%71 = load i32, i32* @errno
%72 = call i8* @strerror(i32 %71)
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %70, i8* %72)
store i32 1, i32* %3
br label %187
74: ; preds = %65
%75 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %75)
%77 = call i32 @dup(i32 1)
store i32 %77, i32* %12
%78 = load i32, i32* %12
%79 = call i32* @fdopen(i32 %78, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %79, i32** %13
%80 = load i32*, i32** %13
%81 = call i32 @setlinebuf(i32* %80)
%82 = call i64 @daemon(i32 0, i32 0)
%83 = icmp slt i64 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %74
%85 = load i32*, i32** @stderr
%86 = call i32 (i32*, i8*, ...) @fprintf(i32* %85, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %87
87: ; preds = %84, %74
%88 = call i32 (...) @fork()
store i32 %88, i32* %14
%89 = load i32, i32* %14
%90 = icmp slt i32 %89, 0
br i1 %90, label %91, label %97
91: ; preds = %87
%92 = load i32*, i32** %13
%93 = load i32, i32* @errno
%94 = load i32, i32* @errno
%95 = call i8* @strerror(i32 %94)
%96 = call i32 (i32*, i8*, ...) @fprintf(i32* %92, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %93, i8* %95)
store i32 1, i32* %3
br label %187
97: ; preds = %87
%98 = load i32, i32* %14
%99 = icmp eq i32 %98, 0
br i1 %99, label %100, label %124
100: ; preds = %97
%101 = load i32, i32* %9
%102 = call i32 @close(i32 %101)
%103 = load i32, i32* %10
%104 = call i64 @login_tty(i32 %103)
%105 = icmp slt i64 %104, 0
br i1 %105, label %106, label %113
106: ; preds = %100
%107 = load i32*, i32** %13
%108 = load i32, i32* @errno
%109 = load i32, i32* @errno
%110 = call i8* @strerror(i32 %109)
%111 = call i32 (i32*, i8*, ...) @fprintf(i32* %107, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i32 %108, i8* %110)
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %100
%114 = getelementptr inbounds [21 x i8*], [21 x i8*]* %6, i64 0, i64 0
%115 = load i8*, i8** %114
%116 = getelementptr inbounds [21 x i8*], [21 x i8*]* %6, i64 0, i64 0
%117 = call i32 @execvp(i8* %115, i8** %116)
%118 = load i32*, i32** %13
%119 = load i32, i32* @errno
%120 = load i32, i32* @errno
%121 = call i8* @strerror(i32 %120)
%122 = call i32 (i32*, i8*, ...) @fprintf(i32* %118, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %119, i8* %121)
%123 = call i32 @exit(i32 1)
unreachable
124: ; preds = %97
%125 = load i32, i32* %10
%126 = call i32 @close(i32 %125)
%127 = call i32 @unlink(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%128 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %128, i32** %15
%129 = load i32*, i32** %15
%130 = load i32, i32* %14
%131 = load i32, i32* %14
%132 = call i32 (i32*, i8*, ...) @fprintf(i32* %129, i8* getelementptr inbounds ([254 x i8], [254 x i8]* @.str.10, i64 0, i64 0), i32 %130, i32 %131)
%133 = load i32*, i32** %15
%134 = call i32 @fclose(i32* %133)
%135 = load i32*, i32** %13
%136 = call i32 @log_init(i32* %135)
br label %137
137: ; preds = %124, %146, %177
%138 = bitcast %struct.timeval* %16 to i8*
%139 = call i32 @FD_ZERO(i32* %17)
%140 = load i32, i32* %9
%141 = call i32 @FD_SET(i32 %140, i32* %17)
%142 = load i32, i32* %9
%143 = add nsw i32 %142, 1
%144 = call i64 @select(i32 %143, i32* %17, i32* null, i32* null, %struct.timeval* %16)
%145 = icmp eq i64 %144, 0
br i1 %145, label %146, label %148
146: ; preds = %137
%147 = call i32 (...) @log_periodic()
br label %137
148: ; preds = %137
%149 = load i32, i32* %9
%150 = call i64 @FD_ISSET(i32 %149, i32* %17)
%151 = icmp ne i64 %150, 0
br i1 %151, label %152, label %177
152: ; preds = %148
%153 = load i32, i32* %9
%154 = getelementptr inbounds [200 x i8], [200 x i8]* %18, i64 0, i64 0
%155 = call i32 @read(i32 %153, i8* %154, i32 200)
store i32 %155, i32* %19
%156 = load i32, i32* %19
%157 = icmp slt i32 %156, 0
br i1 %157, label %158, label %169
158: ; preds = %152
%159 = load i32, i32* @errno
%160 = load i32, i32* @EIO
%161 = icmp ne i32 %159, %160
br i1 %161, label %162, label %168
162: ; preds = %158
%163 = load i32*, i32** %13
%164 = load i32, i32* @errno
%165 = load i32, i32* @errno
%166 = call i8* @strerror(i32 %165)
%167 = call i32 (i32*, i8*, ...) @fprintf(i32* %163, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %164, i8* %166)
br label %168
168: ; preds = %162, %158
br label %169
169: ; preds = %168, %152
%170 = load i32, i32* %19
%171 = icmp sle i32 %170, 0
br i1 %171, label %172, label %173
172: ; preds = %169
br label %178
173: ; preds = %169
%174 = getelementptr inbounds [200 x i8], [200 x i8]* %18, i64 0, i64 0
%175 = load i32, i32* %19
%176 = call i32 @log_data(i8* %174, i32 %175)
br label %177
177: ; preds = %173, %148
br label %137
178: ; preds = %172
%179 = load i32, i32* %9
%180 = call i32 @close(i32 %179)
%181 = call i32 (...) @log_finish()
%182 = call i32 @unlink(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%183 = load i32*, i32** %13
%184 = call i32 (i32*, i8*, ...) @fprintf(i32* %183, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0))
%185 = load i32*, i32** %13
%186 = call i32 @fclose(i32* %185)
store i32 0, i32* %3
br label %187
187: ; preds = %178, %91, %69, %32, %22
%188 = load i32, i32* %3
ret i32 %188
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str.2 = [13 x i8] c"arg %d : %s\0A\00"
@.str.3 = [21 x i8] c"fork failed: %d: %s\0A\00"
@errno = global i32 0
@.str.4 = [17 x i8] c"opened tty : %s\0A\00"
@.str.5 = [2 x i8] c"w\00"
@stderr = global i32* null
@.str.6 = [16 x i8] c"daemon failed!\0A\00"
@.str.7 = [26 x i8] c"login_tty failed: %d: %s\0A\00"
@.str.8 = [23 x i8] c"execvp failed: %d: %s\0A\00"
@.str.9 = [16 x i8] c"/tmp/cleanup.sh\00"
@.str.10 = [254 x i8] c"#!/bin/sh\0Akill %d\0Adone=0\0Awhile [ $done = 0 ] ; do\0A result=$( ps ax | awk '{ if ($1 == %d) print \22yes\22 }' )\0A if [ x$result = xyes ] ; then\0A echo still waiting\0A sleep 0.5\0A else\0A done=1\0A fi\0Adone\0Aecho process is dead\0Aexit 0\0A\00"
@EIO = global i32 0
@.str.11 = [21 x i8] c"read failed: %d: %s\0A\00"
@.str.12 = [15 x i8] c"bglog exiting\0A\00"
@str = [27 x i8] c"too many args, bailing out\00"
@str.13 = [17 x i8] c"usage: bglog ...\00"
define i32 @bglog_main(i32 %0, i8** nocapture %1) {
%3 = alloca [21 x i8*]
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i64
%8 = bitcast i64* %7 to %struct.timeval*
%9 = alloca i32
%10 = alloca [200 x i8]
%11 = bitcast [21 x i8*]* %3 to i8*
%12 = icmp eq i32 %0, 1
br i1 %12, label %21, label %13
13: ; preds = %2
%14 = icmp sgt i32 %0, 1
br i1 %14, label %15, label %120
15: ; preds = %13
%16 = add nsw i32 %0, -1
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 0
store i8* %18, i8** %19
%20 = icmp eq i32 %16, 1
br i1 %20, label %122, label %25
21: ; preds = %2
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.13, i64 0, i64 0))
br label %231
23: ; preds = %115
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %231
25: ; preds = %15
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 1
store i8* %27, i8** %28
%29 = icmp eq i32 %16, 2
br i1 %29, label %122, label %30
30: ; preds = %25
%31 = getelementptr inbounds i8*, i8** %1, i64 3
%32 = load i8*, i8** %31
%33 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 2
store i8* %32, i8** %33
%34 = icmp eq i32 %16, 3
br i1 %34, label %122, label %35
35: ; preds = %30
%36 = getelementptr inbounds i8*, i8** %1, i64 4
%37 = load i8*, i8** %36
%38 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 3
store i8* %37, i8** %38
%39 = icmp eq i32 %16, 4
br i1 %39, label %122, label %40
40: ; preds = %35
%41 = getelementptr inbounds i8*, i8** %1, i64 5
%42 = load i8*, i8** %41
%43 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 4
store i8* %42, i8** %43
%44 = icmp eq i32 %16, 5
br i1 %44, label %122, label %45
45: ; preds = %40
%46 = getelementptr inbounds i8*, i8** %1, i64 6
%47 = load i8*, i8** %46
%48 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 5
store i8* %47, i8** %48
%49 = icmp eq i32 %16, 6
br i1 %49, label %122, label %50
50: ; preds = %45
%51 = getelementptr inbounds i8*, i8** %1, i64 7
%52 = load i8*, i8** %51
%53 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 6
store i8* %52, i8** %53
%54 = icmp eq i32 %16, 7
br i1 %54, label %122, label %55
55: ; preds = %50
%56 = getelementptr inbounds i8*, i8** %1, i64 8
%57 = load i8*, i8** %56
%58 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 7
store i8* %57, i8** %58
%59 = icmp eq i32 %16, 8
br i1 %59, label %122, label %60
60: ; preds = %55
%61 = getelementptr inbounds i8*, i8** %1, i64 9
%62 = load i8*, i8** %61
%63 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 8
store i8* %62, i8** %63
%64 = icmp eq i32 %16, 9
br i1 %64, label %122, label %65
65: ; preds = %60
%66 = getelementptr inbounds i8*, i8** %1, i64 10
%67 = load i8*, i8** %66
%68 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 9
store i8* %67, i8** %68
%69 = icmp eq i32 %16, 10
br i1 %69, label %122, label %70
70: ; preds = %65
%71 = getelementptr inbounds i8*, i8** %1, i64 11
%72 = load i8*, i8** %71
%73 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 10
store i8* %72, i8** %73
%74 = icmp eq i32 %16, 11
br i1 %74, label %122, label %75
75: ; preds = %70
%76 = getelementptr inbounds i8*, i8** %1, i64 12
%77 = load i8*, i8** %76
%78 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 11
store i8* %77, i8** %78
%79 = icmp eq i32 %16, 12
br i1 %79, label %122, label %80
80: ; preds = %75
%81 = getelementptr inbounds i8*, i8** %1, i64 13
%82 = load i8*, i8** %81
%83 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 12
store i8* %82, i8** %83
%84 = icmp eq i32 %16, 13
br i1 %84, label %122, label %85
85: ; preds = %80
%86 = getelementptr inbounds i8*, i8** %1, i64 14
%87 = load i8*, i8** %86
%88 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 13
store i8* %87, i8** %88
%89 = icmp eq i32 %16, 14
br i1 %89, label %122, label %90
90: ; preds = %85
%91 = getelementptr inbounds i8*, i8** %1, i64 15
%92 = load i8*, i8** %91
%93 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 14
store i8* %92, i8** %93
%94 = icmp eq i32 %16, 15
br i1 %94, label %122, label %95
95: ; preds = %90
%96 = getelementptr inbounds i8*, i8** %1, i64 16
%97 = load i8*, i8** %96
%98 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 15
store i8* %97, i8** %98
%99 = icmp eq i32 %16, 16
br i1 %99, label %122, label %100
100: ; preds = %95
%101 = getelementptr inbounds i8*, i8** %1, i64 17
%102 = load i8*, i8** %101
%103 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 16
store i8* %102, i8** %103
%104 = icmp eq i32 %16, 17
br i1 %104, label %122, label %105
105: ; preds = %100
%106 = getelementptr inbounds i8*, i8** %1, i64 18
%107 = load i8*, i8** %106
%108 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 17
store i8* %107, i8** %108
%109 = icmp eq i32 %16, 18
br i1 %109, label %122, label %110
110: ; preds = %105
%111 = getelementptr inbounds i8*, i8** %1, i64 19
%112 = load i8*, i8** %111
%113 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 18
store i8* %112, i8** %113
%114 = icmp eq i32 %16, 19
br i1 %114, label %122, label %115
115: ; preds = %110
%116 = getelementptr inbounds i8*, i8** %1, i64 20
%117 = load i8*, i8** %116
%118 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 19
store i8* %117, i8** %118
%119 = icmp eq i32 %16, 20
br i1 %119, label %122, label %23
120: ; preds = %13
%121 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 0
store i8* null, i8** %121
br label %133
122: ; preds = %15, %25, %30, %35, %40, %45, %50, %55, %60, %65, %70, %75, %80, %85, %90, %95, %100, %105, %110, %115
%123 = phi i64 [ 20, %115 ], [ 19, %110 ], [ 18, %105 ], [ 17, %100 ], [ 16, %95 ], [ 15, %90 ], [ 14, %85 ], [ 13, %80 ], [ 12, %75 ], [ 11, %70 ], [ 10, %65 ], [ 9, %60 ], [ 8, %55 ], [ 7, %50 ], [ 6, %45 ], [ 5, %40 ], [ 4, %35 ], [ 3, %30 ], [ 2, %25 ], [ 1, %15 ]
%124 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 %123
store i8* null, i8** %124
br label %125
125: ; preds = %122, %125
%126 = phi i64 [ 0, %122 ], [ %131, %125 ]
%127 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 %126
%128 = load i8*, i8** %127
%129 = trunc i64 %126 to i32
%130 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %129, i8* %128)
%131 = add nuw nsw i64 %126, 1
%132 = icmp eq i64 %131, %123
br i1 %132, label %133, label %125
133: ; preds = %125, %120
%134 = bitcast i32* %4 to i8*
%135 = bitcast i32* %5 to i8*
%136 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%137 = call i64 @openpty(i32* %4, i32* %5, i8* %136, i32* null, i32* null)
%138 = icmp slt i64 %137, 0
br i1 %138, label %139, label %143
139: ; preds = %133
%140 = load i32, i32* @errno
%141 = call i8* @strerror(i32 %140)
%142 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %140, i8* %141)
br label %229
143: ; preds = %133
%144 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %136)
%145 = call i32 @dup(i32 1)
%146 = call i32* @fdopen(i32 %145, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%147 = call i32 @setlinebuf(i32* %146)
%148 = call i64 @daemon(i32 0, i32 0)
%149 = icmp slt i64 %148, 0
br i1 %149, label %150, label %153
150: ; preds = %143
%151 = load i32*, i32** @stderr
%152 = call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i64 15, i64 1, i32* %151)
br label %153
153: ; preds = %150, %143
%154 = call i32 (...) @fork()
%155 = icmp slt i32 %154, 0
br i1 %155, label %156, label %160
156: ; preds = %153
%157 = load i32, i32* @errno
%158 = call i8* @strerror(i32 %157)
%159 = call i32 (i32*, i8*, ...) @fprintf(i32* %146, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %157, i8* %158)
br label %229
160: ; preds = %153
%161 = icmp eq i32 %154, 0
br i1 %161, label %162, label %181
162: ; preds = %160
%163 = load i32, i32* %4
%164 = call i32 @close(i32 %163)
%165 = load i32, i32* %5
%166 = call i64 @login_tty(i32 %165)
%167 = icmp slt i64 %166, 0
br i1 %167, label %168, label %173
168: ; preds = %162
%169 = load i32, i32* @errno
%170 = call i8* @strerror(i32 %169)
%171 = call i32 (i32*, i8*, ...) @fprintf(i32* %146, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i32 %169, i8* %170)
%172 = call i32 @exit(i32 1)
unreachable
173: ; preds = %162
%174 = getelementptr inbounds [21 x i8*], [21 x i8*]* %3, i64 0, i64 0
%175 = load i8*, i8** %174
%176 = call i32 @execvp(i8* %175, i8** %174)
%177 = load i32, i32* @errno
%178 = call i8* @strerror(i32 %177)
%179 = call i32 (i32*, i8*, ...) @fprintf(i32* %146, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %177, i8* %178)
%180 = call i32 @exit(i32 1)
unreachable
181: ; preds = %160
%182 = load i32, i32* %5
%183 = call i32 @close(i32 %182)
%184 = call i32 @unlink(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%185 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%186 = call i32 (i32*, i8*, ...) @fprintf(i32* %185, i8* getelementptr inbounds ([254 x i8], [254 x i8]* @.str.10, i64 0, i64 0), i32 %154, i32 %154)
%187 = call i32 @fclose(i32* %185)
%188 = call i32 @log_init(i32* %146)
%189 = bitcast i64* %7 to i8*
%190 = bitcast i32* %9 to i8*
%191 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
br label %192
192: ; preds = %221, %181
store i64 2147483648000000, i64* %7
%193 = call i32 @FD_ZERO(i32* %9)
%194 = load i32, i32* %4
%195 = call i32 @FD_SET(i32 %194, i32* %9)
%196 = load i32, i32* %4
%197 = add nsw i32 %196, 1
%198 = call i64 @select(i32 %197, i32* %9, i32* null, i32* null, %struct.timeval* %8)
%199 = icmp eq i64 %198, 0
br i1 %199, label %200, label %202
200: ; preds = %192
%201 = call i32 (...) @log_periodic()
br label %221
202: ; preds = %192
%203 = load i32, i32* %4
%204 = call i64 @FD_ISSET(i32 %203, i32* %9)
%205 = icmp eq i64 %204, 0
br i1 %205, label %221, label %206
206: ; preds = %202
%207 = load i32, i32* %4
%208 = call i32 @read(i32 %207, i8* %191, i32 200)
%209 = icmp slt i32 %208, 0
br i1 %209, label %210, label %217
210: ; preds = %206
%211 = load i32, i32* @errno
%212 = load i32, i32* @EIO
%213 = icmp eq i32 %211, %212
br i1 %213, label %222, label %214
214: ; preds = %210
%215 = call i8* @strerror(i32 %211)
%216 = call i32 (i32*, i8*, ...) @fprintf(i32* %146, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %211, i8* %215)
br label %222
217: ; preds = %206
%218 = icmp eq i32 %208, 0
br i1 %218, label %222, label %219
219: ; preds = %217
%220 = call i32 @log_data(i8* %191, i32 %208)
br label %221
221: ; preds = %202, %219, %200
br label %192
222: ; preds = %217, %210, %214
%223 = load i32, i32* %4
%224 = call i32 @close(i32 %223)
%225 = call i32 (...) @log_finish()
%226 = call i32 @unlink(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%227 = call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i64 14, i64 1, i32* %146)
%228 = call i32 @fclose(i32* %146)
br label %229
229: ; preds = %156, %222, %139
%230 = phi i32 [ 1, %139 ], [ 1, %156 ], [ 0, %222 ]
br label %231
231: ; preds = %229, %23, %21
%232 = phi i32 [ 1, %21 ], [ 1, %23 ], [ %230, %229 ]
ret i32 %232
}