#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 scalar_t__ time_t;
typedef int /*<<< orphan*/ sigset_t;
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
#define SIGALRM 135
#define SIGCHLD 134
#define SIGHUP 133
int SIGKILL;
#define SIGPIPE 132
#define SIGQUIT 131
#define SIGTERM 130
#define SIGUSR1 129
#define SIGUSR2 128
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ WNOHANG;
int WTERMSIG(int);
int /*<<< orphan*/ _IONBF;
long atoi_or_default(char *, int);
scalar_t__ chdir(char *);
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execvp(char *, char **);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int help();
scalar_t__ install_signal_handlers(int /*<<< orphan*/ *);
int /*<<< orphan*/ kill(scalar_t__, int const);
int /*<<< orphan*/ open(char *, int /*<<< orphan*/);
char *optarg;
int optind;
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe_to_logger(char *, char *, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
char *program_name(char *);
int /*<<< orphan*/ remove_pid_file(char *);
int /*<<< orphan*/ reset_alarm(int);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ signal(int, int /*<<< orphan*/);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
scalar_t__ sigwait(int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
char *strsignal(int);
scalar_t__ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
scalar_t__ waitpid(int, int *, int /*<<< orphan*/);
int /*<<< orphan*/ write_pid_file(char *);
int main(int argc, char *argv[]) {
  int respawn = 1;
  sigset_t signals;
  char *log_tag = NULL;
  char *stdout_pri = "user.info";
  char *stderr_pri = "user.err";
  char *pid_file = NULL;
  char *dir = "/";
  long terminate_timeout = -1;
  int detach = 1;
  int c;
  while ((c = getopt(argc, argv, "e:o:t:p:k:c:")) != -1) {
    switch (c) {
    case 'e':
      stderr_pri = optarg;
      break;
    case 'o':
      stdout_pri = optarg;
      break;
    case 't':
      log_tag = optarg;
      break;
    case 'p':
      pid_file = optarg;
      break;
    case 'k':
      terminate_timeout = atoi_or_default(optarg, -1);
      if (terminate_timeout <= 0)
        return help();
      break;
    case 'd':
      detach = 0;
      break;
    case 'c':
      dir = optarg;
      break;
    case '?':
      return help();
    }
  }
  if (optind >= argc)
    return help();
  char **program_arguments = argv + optind;
  if (!log_tag)
    log_tag = program_name(program_arguments[0]);
  if (detach) {
    signal(SIGHUP, SIG_IGN);
    if (fork() != 0)
      return 0;
    setsid();
    if (fork() != 0)
      return 0;
    close(STDIN_FILENO);
    open("/dev/null", O_RDONLY);
  }
  chdir("/");
  umask(0);
  if (install_signal_handlers(&signals) < 0) {
    return 6;
  }
  if (pid_file)
    write_pid_file(pid_file);
  setvbuf(stdout, NULL, _IONBF, 0);
  setvbuf(stderr, NULL, _IONBF, 0);
  while (respawn) {
    time_t start_time, end_time;
    pid_t child;
    if (pipe_to_logger(stdout_pri, log_tag, STDOUT_FILENO, &signals) < 0)
      return 1;
    if (pipe_to_logger(stderr_pri, log_tag, STDERR_FILENO, &signals) < 0)
      return 2;
    fprintf(stdout, "Running %s\n", program_arguments[0]);
    start_time = time(NULL);
    child = fork();
    if (child < 0) {
      perror("Couldn't fork to start program");
      return 3;
    } else if (child == 0) {
      if (chdir(dir) < 0) {
        fprintf(stderr, "Couldn't change directory to %s: %s\n", dir,
                strerror(errno));
        return 7;
      }
      sigprocmask(SIG_UNBLOCK, &signals, NULL);
      execvp(program_arguments[0], program_arguments);
      fprintf(stderr, "Couldn't execute %s: %s\n", program_arguments[0],
              strerror(errno));
      return 4;
    } else {
      int signo;
      int terminated = 0, killed = 0;
      while (child) {
        if (sigwait(&signals, &signo) < 0) {
          perror("Failed to wait on signals");
          return 5;
        }
        switch (signo) {
        case SIGCHLD:
          while (1) {
            int status;
            int result = waitpid(-1, &status, WNOHANG);
            if (result == child) {
              if (WIFEXITED(status)) {
                if (WEXITSTATUS(status) != 0) {
                  fprintf(stderr, "%s exited with status %d\n",
                          program_arguments[0], WEXITSTATUS(status));
                } else if (terminated) {
                  fprintf(stdout, "%s finished as requested\n",
                          program_arguments[0]);
                } else {
                  fprintf(stdout, "%s finished\n", program_arguments[0]);
                }
              } else if (WTERMSIG(status) == SIGTERM && terminated) {
                fprintf(stdout, "%s terminated as requested\n",
                        program_arguments[0]);
              } else if (WTERMSIG(status) == SIGKILL && killed) {
                fprintf(stdout, "%s was killed\n", program_arguments[0]);
              } else {
                fprintf(stderr, "%s was terminated by signal %d\n",
                        program_arguments[0], WTERMSIG(status));
              }
              child = 0;
              break;
            } else if (result <= 0) {
              break;
            }
          }
          break;
        case SIGPIPE:
        case SIGTERM:
          if (signo != SIGPIPE)
            fprintf(stdout, "Asking %s to terminate so we can restart it\n",
                    program_arguments[0]);
          kill(child, SIGTERM);
          if (terminate_timeout > 0)
            reset_alarm(terminate_timeout);
          terminated = 1;
          break;
        case SIGQUIT:
          fprintf(stdout, "Asking %s to terminate so we can shut down\n",
                  program_arguments[0]);
          kill(child, SIGTERM);
          if (terminate_timeout > 0)
            reset_alarm(terminate_timeout);
          terminated = 1;
          respawn = 0;
          break;
        case SIGALRM:
          fprintf(stdout, "Waited %ld seconds, killing %s\n", terminate_timeout,
                  program_arguments[0]);
          kill(child, SIGKILL);
          killed = 1;
          break;
        case SIGUSR1:
        case SIGUSR2:
        case SIGHUP:
          fprintf(stdout, "Passing the '%s' signal on to %s\n",
                  strsignal(signo), program_arguments[0]);
          kill(child, signo);
          break;
        default:
          fprintf(stderr, "Unexpected signal %d\n", signo);
        }
      }
      end_time = time(NULL);
      if (!terminated && end_time >= start_time && end_time < start_time + 60) {
        int seconds = 60 - (end_time - start_time);
        reset_alarm(seconds);
        fprintf(stdout, "Waiting %ds before respawning %s\n", seconds,
                program_arguments[0]);
        while (1) {
          sigwait(&signals, &signo);
          if (signo == SIGCHLD) {
            while (waitpid(-1, NULL, WNOHANG) <= 0)
              ;
          } else if (signo == SIGQUIT) {
            respawn = 0;
            break;
          } else if (signo == SIGTERM || signo == SIGALRM) {
            break;
          }
        }
      }
      reset_alarm(0);
    }
  }
  if (pid_file)
    remove_pid_file(pid_file);
  fprintf(stdout, "Shut down by request.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xde9(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xde8(%rip),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
lea    0xdde(%rip),%rax
mov    %rax,-0x40(%rbp)
movq   $0xffffffffffffffff,-0x48(%rbp)
ff
movl   $0x1,-0x4c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdbf(%rip),%rdx
call   11a0 <getopt@plt>
mov    %eax,-0x50(%rbp)
cmp    $0xffffffff,%eax
je     1444 <main+0x164>
mov    -0x50(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x90(%rbp)
sub    $0x35,%eax
ja     143f <main+0x15f>
mov    -0x90(%rbp),%rax
lea    0xc9b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2c63(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    143f <main+0x15f>
mov    0x2c50(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    143f <main+0x15f>
mov    0x2c3d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    143f <main+0x15f>
mov    0x2c2a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    143f <main+0x15f>
mov    0x2c17(%rip),%rax
mov    (%rax),%rdi
mov    $0xffffffff,%esi
call   1050 <atoi_or_default@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jg     140c <main+0x12c>
mov    $0x0,%al
call   11b0 <help@plt>
mov    %eax,-0x4(%rbp)
jmp    1c5b <main+0x97b>
jmp    143f <main+0x15f>
movl   $0x0,-0x4c(%rbp)
jmp    143f <main+0x15f>
mov    0x2bd4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    143f <main+0x15f>
mov    $0x0,%al
call   11b0 <help@plt>
mov    %eax,-0x4(%rbp)
jmp    1c5b <main+0x97b>
jmp    1340 <main+0x60>
mov    0x2b6d(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     1465 <main+0x185>
mov    $0x0,%al
call   11b0 <help@plt>
mov    %eax,-0x4(%rbp)
jmp    1c5b <main+0x97b>
mov    -0x10(%rbp),%rax
mov    0x2b48(%rip),%rcx
movslq (%rcx),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1499 <main+0x1b9>
mov    -0x58(%rbp),%rax
mov    (%rax),%rdi
call   1180 <program_name@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     151a <main+0x23a>
mov    0x2b06(%rip),%rax
mov    (%rax),%esi
mov    $0x85,%edi
call   10a0 <signal@plt>
mov    $0x0,%al
call   1200 <fork@plt>
cmp    $0x0,%rax
je     14d3 <main+0x1f3>
movl   $0x0,-0x4(%rbp)
jmp    1c5b <main+0x97b>
mov    $0x0,%al
call   1080 <setsid@plt>
mov    $0x0,%al
call   1200 <fork@plt>
cmp    $0x0,%rax
je     14f7 <main+0x217>
movl   $0x0,-0x4(%rbp)
jmp    1c5b <main+0x97b>
mov    0x2a7a(%rip),%rax
mov    (%rax),%edi
call   1070 <close@plt>
mov    0x2ac4(%rip),%rax
mov    (%rax),%esi
lea    0xc05(%rip),%rdi
call   1170 <open@plt>
lea    0xbea(%rip),%rdi
call   1060 <chdir@plt>
xor    %edi,%edi
call   10d0 <umask@plt>
lea    -0x18(%rbp),%rdi
call   10c0 <install_signal_handlers@plt>
cmp    $0x0,%rax
jge    154c <main+0x26c>
movl   $0x6,-0x4(%rbp)
jmp    1c5b <main+0x97b>
cmpq   $0x0,-0x38(%rbp)
je     1560 <main+0x280>
mov    -0x38(%rbp),%rdi
call   1040 <write_pid_file@plt>
mov    0x2a19(%rip),%rax
mov    (%rax),%edi
mov    0x2a50(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1140 <setvbuf@plt>
mov    0x2a1c(%rip),%rax
mov    (%rax),%edi
mov    0x2a33(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1140 <setvbuf@plt>
cmpl   $0x0,-0x14(%rbp)
je     1c29 <main+0x949>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2a35(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
call   1090 <pipe_to_logger@plt>
cmp    $0x0,%rax
jge    15d4 <main+0x2f4>
movl   $0x1,-0x4(%rbp)
jmp    1c5b <main+0x97b>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x29ad(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
call   1090 <pipe_to_logger@plt>
cmp    $0x0,%rax
jge    1604 <main+0x324>
movl   $0x2,-0x4(%rbp)
jmp    1c5b <main+0x97b>
mov    0x2975(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rax
mov    (%rax),%rdx
lea    0xb09(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10f0 <time@plt>
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   1200 <fork@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jge    165d <main+0x37d>
lea    0xae4(%rip),%rdi
call   1190 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    1c5b <main+0x97b>
cmpq   $0x0,-0x70(%rbp)
jne    1748 <main+0x468>
mov    -0x40(%rbp),%rdi
call   1060 <chdir@plt>
cmp    $0x0,%rax
jge    16cd <main+0x3ed>
mov    0x291e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    0x28fc(%rip),%rax
mov    (%rax),%edi
call   11f0 <strerror@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rdx
mov    %rax,%rcx
lea    0xa95(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x7,-0x4(%rbp)
jmp    1c5b <main+0x97b>
mov    0x2904(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    -0x58(%rbp),%rax
mov    (%rax),%rdi
mov    -0x58(%rbp),%rsi
call   11c0 <execvp@plt>
mov    0x28a6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xa8(%rbp)
mov    0x2881(%rip),%rax
mov    (%rax),%edi
call   11f0 <strerror@plt>
mov    -0xac(%rbp),%edi
mov    -0xa8(%rbp),%rdx
mov    %rax,%rcx
lea    0xa3f(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x4,-0x4(%rbp)
jmp    1c5b <main+0x97b>
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
cmpq   $0x0,-0x70(%rbp)
je     1b03 <main+0x823>
lea    -0x18(%rbp),%rdi
lea    -0x74(%rbp),%rsi
call   11d0 <sigwait@plt>
cmp    $0x0,%rax
jge    1790 <main+0x4b0>
lea    0xa0e(%rip),%rdi
call   1190 <perror@plt>
movl   $0x5,-0x4(%rbp)
jmp    1c5b <main+0x97b>
mov    -0x74(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0xb8(%rbp)
sub    $0x7,%eax
ja     1ae4 <main+0x804>
mov    -0xb8(%rbp),%rax
lea    0x84a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    17c4 <main+0x4e4>
mov    0x27fd(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
lea    -0x80(%rbp),%rsi
call   1160 <waitpid@plt>
mov    %eax,-0x84(%rbp)
movslq -0x84(%rbp),%rax
cmp    -0x70(%rbp),%rax
jne    198d <main+0x6ad>
mov    -0x80(%rbp),%edi
call   11e0 <WIFEXITED@plt>
cmp    $0x0,%eax
je     18b0 <main+0x5d0>
mov    -0x80(%rbp),%edi
call   1150 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     185b <main+0x57b>
mov    0x2785(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xc0(%rbp)
mov    -0x80(%rbp),%edi
call   1150 <WEXITSTATUS@plt>
mov    -0xc4(%rbp),%edi
mov    -0xc0(%rbp),%rdx
mov    %eax,%ecx
lea    0x958(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    18ab <main+0x5cb>
cmpl   $0x0,-0x78(%rbp)
je     1888 <main+0x5a8>
mov    0x2714(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rax
mov    (%rax),%rdx
lea    0x945(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    18a6 <main+0x5c6>
mov    0x26f1(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rax
mov    (%rax),%rdx
lea    0x93c(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    18ab <main+0x5cb>
jmp    1980 <main+0x6a0>
mov    -0x80(%rbp),%edi
call   1120 <WTERMSIG@plt>
cmp    $0x82,%eax
jne    18f0 <main+0x610>
cmpl   $0x0,-0x78(%rbp)
je     18f0 <main+0x610>
mov    0x26ac(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rax
mov    (%rax),%rdx
lea    0x904(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    197b <main+0x69b>
mov    -0x80(%rbp),%edi
call   1120 <WTERMSIG@plt>
mov    0x2689(%rip),%rcx
cmp    (%rcx),%eax
jne    1934 <main+0x654>
cmpl   $0x0,-0x7c(%rbp)
je     1934 <main+0x654>
mov    0x2668(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rax
mov    (%rax),%rdx
lea    0x8dc(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    1976 <main+0x696>
mov    0x2665(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd4(%rbp)
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xd0(%rbp)
mov    -0x80(%rbp),%edi
call   1120 <WTERMSIG@plt>
mov    -0xd4(%rbp),%edi
mov    -0xd0(%rbp),%rdx
mov    %eax,%ecx
lea    0x8a4(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    197b <main+0x69b>
jmp    1980 <main+0x6a0>
movq   $0x0,-0x70(%rbp)
jmp    19a9 <main+0x6c9>
cmpl   $0x0,-0x84(%rbp)
jg     199f <main+0x6bf>
jmp    19a9 <main+0x6c9>
jmp    19a4 <main+0x6c4>
jmp    17c4 <main+0x4e4>
jmp    1afe <main+0x81e>
cmpl   $0x84,-0x74(%rbp)
je     19d9 <main+0x6f9>
mov    0x25be(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rax
mov    (%rax),%rdx
lea    0x861(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x70(%rbp),%rdi
mov    $0x82,%esi
call   10e0 <kill@plt>
cmpq   $0x0,-0x48(%rbp)
jle    19fd <main+0x71d>
mov    -0x48(%rbp),%rax
mov    %eax,%edi
call   1100 <reset_alarm@plt>
movl   $0x1,-0x78(%rbp)
jmp    1afe <main+0x81e>
mov    0x2570(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rax
mov    (%rax),%rdx
lea    0x840(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x70(%rbp),%rdi
mov    $0x82,%esi
call   10e0 <kill@plt>
cmpq   $0x0,-0x48(%rbp)
jle    1a4b <main+0x76b>
mov    -0x48(%rbp),%rax
mov    %eax,%edi
call   1100 <reset_alarm@plt>
movl   $0x1,-0x78(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    1afe <main+0x81e>
mov    0x251b(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rdx
mov    -0x58(%rbp),%rax
mov    (%rax),%rcx
lea    0x813(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x70(%rbp),%rdi
mov    0x24fd(%rip),%rax
mov    (%rax),%esi
call   10e0 <kill@plt>
movl   $0x1,-0x7c(%rbp)
jmp    1afe <main+0x81e>
mov    0x24db(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd8(%rbp)
mov    -0x74(%rbp),%edi
call   1130 <strsignal@plt>
mov    -0xd8(%rbp),%edi
mov    %rax,%rdx
mov    -0x58(%rbp),%rax
mov    (%rax),%rcx
lea    0x7e0(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x70(%rbp),%rdi
mov    -0x74(%rbp),%esi
call   10e0 <kill@plt>
jmp    1afe <main+0x81e>
mov    0x24b5(%rip),%rax
mov    (%rax),%edi
mov    -0x74(%rbp),%edx
lea    0x7d7(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    1756 <main+0x476>
xor    %eax,%eax
mov    %eax,%edi
call   10f0 <time@plt>
mov    %rax,-0x68(%rbp)
cmpl   $0x0,-0x78(%rbp)
jne    1c18 <main+0x938>
mov    -0x68(%rbp),%rax
cmp    -0x60(%rbp),%rax
jl     1c18 <main+0x938>
mov    -0x68(%rbp),%rax
mov    -0x60(%rbp),%rcx
add    $0x3c,%rcx
cmp    %rcx,%rax
jge    1c18 <main+0x938>
mov    -0x68(%rbp),%rcx
sub    -0x60(%rbp),%rcx
mov    $0x3c,%eax
sub    %rcx,%rax
mov    %eax,-0x88(%rbp)
mov    -0x88(%rbp),%edi
call   1100 <reset_alarm@plt>
mov    0x241b(%rip),%rax
mov    (%rax),%edi
mov    -0x88(%rbp),%edx
mov    -0x58(%rbp),%rax
mov    (%rax),%rcx
lea    0x769(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    -0x18(%rbp),%rdi
lea    -0x74(%rbp),%rsi
call   11d0 <sigwait@plt>
cmpl   $0x86,-0x74(%rbp)
jne    1bcc <main+0x8ec>
jmp    1ba1 <main+0x8c1>
mov    0x2420(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1160 <waitpid@plt>
cmp    $0x0,%rax
jg     1bc7 <main+0x8e7>
jmp    1ba1 <main+0x8c1>
jmp    1c0e <main+0x92e>
cmpl   $0x83,-0x74(%rbp)
jne    1be5 <main+0x905>
movl   $0x0,-0x14(%rbp)
jmp    1c13 <main+0x933>
cmpl   $0x82,-0x74(%rbp)
je     1bff <main+0x91f>
cmpl   $0x87,-0x74(%rbp)
jne    1c04 <main+0x924>
jmp    1c13 <main+0x933>
jmp    1c09 <main+0x929>
jmp    1c0e <main+0x92e>
jmp    1b82 <main+0x8a2>
jmp    1c18 <main+0x938>
xor    %edi,%edi
call   1100 <reset_alarm@plt>
jmp    1c24 <main+0x944>
jmp    159a <main+0x2ba>
cmpq   $0x0,-0x38(%rbp)
je     1c3d <main+0x95d>
mov    -0x38(%rbp),%rdi
call   1110 <remove_pid_file@plt>
mov    0x233c(%rip),%rax
mov    (%rax),%edi
lea    0x6b9(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xe16(%rip),%rax
mov    %rax,0x38(%rsp)
lea    0xe14(%rip),%rax
mov    %rax,0x30(%rsp)
movl   $0x1,(%rsp)
mov    $0xffffffffffffffff,%r13
lea    0xe03(%rip),%rax
mov    %rax,0x28(%rsp)
xor    %eax,%eax
mov    %rax,0x20(%rsp)
lea    0xdf2(%rip),%r14
lea    0xcc6(%rip),%r15
mov    0x2cb7(%rip),%r12
xor    %eax,%eax
jmp    1354 <main+0x74>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12),%rax
mov    %rax,0x10(%rsp)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   11a0 <getopt@plt>
lea    -0x3f(%rax),%ecx
cmp    $0x35,%ecx
ja     13ce <main+0xee>
movslq (%r15,%rcx,4),%rax
add    %r15,%rax
jmp    *%rax
mov    (%r12),%rax
mov    %rax,0x28(%rsp)
jmp    1360 <main+0x80>
movl   $0x0,(%rsp)
jmp    1360 <main+0x80>
mov    (%r12),%rax
mov    %rax,0x30(%rsp)
jmp    1360 <main+0x80>
mov    (%r12),%rdi
mov    $0xffffffff,%esi
call   1050 <atoi_or_default@plt>
mov    %rax,%r13
test   %rax,%rax
jg     1360 <main+0x80>
jmp    14ef <main+0x20f>
mov    (%r12),%rax
mov    %rax,0x38(%rsp)
jmp    1360 <main+0x80>
mov    (%r12),%rax
mov    %rax,0x20(%rsp)
jmp    1360 <main+0x80>
cmp    $0xffffffff,%eax
jne    1360 <main+0x80>
mov    0x2bde(%rip),%rax
movslq (%rax),%rax
cmp    %ebx,%eax
jge    14ef <main+0x20f>
lea    0x0(,%rax,8),%r15
add    %rbp,%r15
mov    0x10(%rsp),%r14
test   %r14,%r14
jne    1405 <main+0x125>
mov    (%r15),%rdi
call   1180 <program_name@plt>
mov    %rax,%r14
cmpl   $0x0,(%rsp)
je     146c <main+0x18c>
mov    0x2b9e(%rip),%rax
mov    (%rax),%esi
mov    $0x85,%edi
call   10a0 <signal@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1200 <fork@plt>
test   %rax,%rax
jne    19c3 <main+0x6e3>
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <setsid@plt>
xor    %eax,%eax
call   1200 <fork@plt>
test   %rax,%rax
jne    19c3 <main+0x6e3>
mov    0x2b28(%rip),%rax
mov    (%rax),%edi
call   1070 <close@plt>
mov    0x2b72(%rip),%rax
mov    (%rax),%esi
lea    0xccb(%rip),%rdi
call   1170 <open@plt>
lea    0xcb0(%rip),%rdi
call   1060 <chdir@plt>
xor    %edi,%edi
call   10d0 <umask@plt>
lea    0x4(%rsp),%rdi
call   10c0 <install_signal_handlers@plt>
test   %rax,%rax
js     18c6 <main+0x5e6>
mov    0x20(%rsp),%rdi
test   %rdi,%rdi
je     14a1 <main+0x1c1>
call   1040 <write_pid_file@plt>
mov    0x2ad8(%rip),%rax
mov    (%rax),%edi
mov    0x2b0f(%rip),%rbp
mov    0x0(%rbp),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1140 <setvbuf@plt>
mov    0x2adc(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1140 <setvbuf@plt>
mov    0x2aef(%rip),%rbp
lea    0xbf8(%rip),%r12
movl   $0x1,0x18(%rsp)
mov    %r14,0x10(%rsp)
jmp    1523 <main+0x243>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    11b0 <help@plt>
movl   $0x0,0x18(%rsp)
mov    0x10(%rsp),%r14
xor    %edi,%edi
call   1100 <reset_alarm@plt>
cmpl   $0x0,0x18(%rsp)
je     1967 <main+0x687>
mov    0x2abe(%rip),%rax
mov    (%rax),%edx
mov    0x38(%rsp),%rdi
mov    %r14,%rsi
lea    0x4(%rsp),%rbx
mov    %rbx,%rcx
call   1090 <pipe_to_logger@plt>
test   %rax,%rax
js     18e6 <main+0x606>
mov    0x2a3f(%rip),%rax
mov    (%rax),%edx
mov    0x30(%rsp),%rdi
mov    %r14,%rsi
mov    %rbx,%rcx
call   1090 <pipe_to_logger@plt>
test   %rax,%rax
js     18f0 <main+0x610>
mov    0x2a0d(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xbbd(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
xor    %edi,%edi
call   10f0 <time@plt>
mov    %rax,0x40(%rsp)
xor    %eax,%eax
call   1200 <fork@plt>
test   %rax,%rax
js     19d4 <main+0x6f4>
je     18fa <main+0x61a>
mov    %rax,%r14
movl   $0x0,0x1c(%rsp)
movl   $0x0,(%rsp)
lea    0x4(%rsp),%rbx
jmp    15e9 <main+0x309>
mov    0x29d8(%rip),%rax
mov    (%rax),%edi
lea    0xd15(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
nopl   0x0(%rax,%rax,1)
test   %r14,%r14
je     1814 <main+0x534>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
call   11d0 <sigwait@plt>
test   %rax,%rax
js     18d0 <main+0x5f0>
mov    0xc(%rsp),%edx
lea    -0x80(%rdx),%eax
cmp    $0x7,%eax
ja     15c1 <main+0x2e1>
mov    %r12,%rcx
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    0x2962(%rip),%rax
mov    (%rax),%ebx
mov    %edx,%edi
call   1130 <strsignal@plt>
mov    (%r15),%rcx
mov    %ebx,%edi
lea    0x4(%rsp),%rbx
lea    0xc8c(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   10e0 <kill@plt>
jmp    15e0 <main+0x300>
mov    0x0(%rbp),%edx
mov    $0xffffffff,%edi
lea    0x8(%rsp),%rsi
call   1160 <waitpid@plt>
movslq %eax,%rcx
cmp    %r14,%rcx
je     1713 <main+0x433>
test   %eax,%eax
jg     1650 <main+0x370>
jmp    15e0 <main+0x300>
mov    0x2902(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xbc1(%rip),%rsi
jmp    16a7 <main+0x3c7>
mov    0x28ed(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
movl   $0x0,0x18(%rsp)
lea    0xbd1(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r14,%rdi
mov    $0x82,%esi
call   10e0 <kill@plt>
movl   $0x1,(%rsp)
test   %r13,%r13
jle    15e0 <main+0x300>
mov    %r13d,%edi
call   1100 <reset_alarm@plt>
jmp    15e0 <main+0x300>
mov    0x28a1(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rcx
lea    0xbb9(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x288c(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10e0 <kill@plt>
movl   $0x1,0x1c(%rsp)
jmp    15e0 <main+0x300>
mov    0x8(%rsp),%edi
call   11e0 <WIFEXITED@plt>
mov    0x8(%rsp),%edi
test   %eax,%eax
je     1764 <main+0x484>
call   1150 <WEXITSTATUS@plt>
test   %eax,%eax
je     178b <main+0x4ab>
mov    0x286c(%rip),%rax
mov    (%rax),%ebx
mov    (%r15),%r14
mov    0x8(%rsp),%edi
call   1150 <WEXITSTATUS@plt>
mov    %ebx,%edi
lea    0x4(%rsp),%rbx
lea    0xa6f(%rip),%rsi
mov    %r14,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   10b0 <fprintf@plt>
xor    %r14d,%r14d
jmp    15e0 <main+0x300>
call   1120 <WTERMSIG@plt>
cmp    $0x82,%eax
jne    17a6 <main+0x4c6>
cmpl   $0x0,(%rsp)
je     17a6 <main+0x4c6>
mov    0x2803(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xa77(%rip),%rsi
jmp    1805 <main+0x525>
mov    0x27ee(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
cmpl   $0x0,(%rsp)
je     17fe <main+0x51e>
lea    0xa35(%rip),%rsi
jmp    1805 <main+0x525>
mov    0x8(%rsp),%edi
call   1120 <WTERMSIG@plt>
mov    0x27d2(%rip),%rcx
cmp    (%rcx),%eax
jne    17d6 <main+0x4f6>
cmpl   $0x0,0x1c(%rsp)
je     17d6 <main+0x4f6>
mov    0x27b8(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xa48(%rip),%rsi
jmp    1805 <main+0x525>
mov    0x27c3(%rip),%rax
mov    (%rax),%ebx
mov    (%r15),%r14
mov    0x8(%rsp),%edi
call   1120 <WTERMSIG@plt>
mov    %ebx,%edi
lea    0x4(%rsp),%rbx
lea    0xa32(%rip),%rsi
jmp    1750 <main+0x470>
lea    0x9ee(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
xor    %r14d,%r14d
jmp    15e0 <main+0x300>
xor    %edi,%edi
call   10f0 <time@plt>
cmpl   $0x0,(%rsp)
jne    150c <main+0x22c>
mov    0x40(%rsp),%r14
cmp    %rax,%r14
mov    $0xffffff7e,%ebx
jg     150c <main+0x22c>
mov    %r14,%rcx
add    $0x3c,%rcx
cmp    %rcx,%rax
jge    150c <main+0x22c>
sub    %eax,%r14d
add    $0x3c,%r14d
mov    %r14d,%edi
call   1100 <reset_alarm@plt>
mov    0x2722(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rcx
lea    0xa92(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x4(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   11d0 <sigwait@plt>
mov    0xc(%rsp),%eax
add    %ebx,%eax
cmp    $0x5,%eax
ja     1880 <main+0x5a0>
lea    0x857(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edx
mov    $0xffffffff,%edi
xor    %esi,%esi
call   1160 <waitpid@plt>
test   %rax,%rax
jle    18b0 <main+0x5d0>
jmp    1880 <main+0x5a0>
mov    $0x6,%ebp
jmp    19c3 <main+0x6e3>
lea    0x8ce(%rip),%rdi
call   1190 <perror@plt>
mov    $0x5,%ebp
jmp    19c3 <main+0x6e3>
mov    $0x1,%ebp
jmp    19c3 <main+0x6e3>
mov    $0x2,%ebp
jmp    19c3 <main+0x6e3>
mov    0x28(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <chdir@plt>
test   %rax,%rax
js     1991 <main+0x6b1>
mov    0x26c1(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    (%r15),%rdi
mov    %r15,%rsi
call   11c0 <execvp@plt>
mov    0x2669(%rip),%rax
mov    (%rax),%ebx
mov    (%r15),%rbp
mov    0x2655(%rip),%rax
mov    (%rax),%edi
call   11f0 <strerror@plt>
lea    0x83b(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x4,%ebp
jmp    19c3 <main+0x6e3>
mov    0x20(%rsp),%rdi
test   %rdi,%rdi
je     1976 <main+0x696>
call   1110 <remove_pid_file@plt>
mov    0x2603(%rip),%rax
mov    (%rax),%edi
lea    0x998(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    19c3 <main+0x6e3>
mov    0x2608(%rip),%rax
mov    (%rax),%ebx
mov    0x25f7(%rip),%rax
mov    (%rax),%edi
call   11f0 <strerror@plt>
lea    0x7b8(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x7,%ebp
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x76d(%rip),%rdi
call   1190 <perror@plt>
mov    $0x3,%ebp
jmp    19c3 <main+0x6e3>

LLVM IR (-O0):
@.str = [10 x i8] c"user.info\00"
@.str.1 = [9 x i8] c"user.err\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [13 x i8] c"e:o:t:p:k:c:\00"
@optarg = global i8* null
@optind = global i32 0
@SIG_IGN = global i32 0
@STDIN_FILENO = global i32 0
@.str.4 = [10 x i8] c"/dev/null\00"
@O_RDONLY = global i32 0
@stdout = global i32 0
@_IONBF = global i32 0
@stderr = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.5 = [12 x i8] c"Running %s\0A\00"
@.str.6 = [31 x i8] c"Couldn't fork to start program\00"
@.str.7 = [37 x i8] c"Couldn't change directory to %s: %s\0A\00"
@errno = global i32 0
@SIG_UNBLOCK = global i32 0
@.str.8 = [25 x i8] c"Couldn't execute %s: %s\0A\00"
@.str.9 = [26 x i8] c"Failed to wait on signals\00"
@WNOHANG = global i32 0
@.str.10 = [26 x i8] c"%s exited with status %d\0A\00"
@.str.11 = [26 x i8] c"%s finished as requested\0A\00"
@.str.12 = [13 x i8] c"%s finished\0A\00"
@.str.13 = [28 x i8] c"%s terminated as requested\0A\00"
@SIGKILL = global i32 0
@.str.14 = [15 x i8] c"%s was killed\0A\00"
@.str.15 = [32 x i8] c"%s was terminated by signal %d\0A\00"
@.str.16 = [45 x i8] c"Asking %s to terminate so we can restart it\0A\00"
@.str.17 = [44 x i8] c"Asking %s to terminate so we can shut down\0A\00"
@.str.18 = [32 x i8] c"Waited %ld seconds, killing %s\0A\00"
@.str.19 = [34 x i8] c"Passing the '%s' signal on to %s\0A\00"
@.str.20 = [22 x i8] c"Unexpected signal %d\0A\00"
@.str.21 = [34 x i8] c"Waiting %ds before respawning %s\0A\00"
@.str.22 = [23 x i8] c"Shut down by request.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8**
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
store i8* null, i8** %8
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %10
store i8* null, i8** %11
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %12
store i64 -1, i64* %13
store i32 1, i32* %14
br label %26
26: ; preds = %54, %2
%27 = load i32, i32* %4
%28 = load i8**, i8*** %5
%29 = call i32 @getopt(i32 %27, i8** %28, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 %29, i32* %15
%30 = icmp ne i32 %29, -1
br i1 %30, label %31, label %55
31: ; preds = %26
%32 = load i32, i32* %15
switch i32 %32, label %54 [
i32 101, label %33
i32 111, label %35
i32 116, label %37
i32 112, label %39
i32 107, label %41
i32 100, label %49
i32 99, label %50
i32 63, label %52
]
33: ; preds = %31
%34 = load i8*, i8** @optarg
store i8* %34, i8** %10
br label %54
35: ; preds = %31
%36 = load i8*, i8** @optarg
store i8* %36, i8** %9
br label %54
37: ; preds = %31
%38 = load i8*, i8** @optarg
store i8* %38, i8** %8
br label %54
39: ; preds = %31
%40 = load i8*, i8** @optarg
store i8* %40, i8** %11
br label %54
41: ; preds = %31
%42 = load i8*, i8** @optarg
%43 = call i64 @atoi_or_default(i8* %42, i32 -1)
store i64 %43, i64* %13
%44 = load i64, i64* %13
%45 = icmp sle i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 (...) @help()
store i32 %47, i32* %3
br label %392
48: ; preds = %41
br label %54
49: ; preds = %31
store i32 0, i32* %14
br label %54
50: ; preds = %31
%51 = load i8*, i8** @optarg
store i8* %51, i8** %12
br label %54
52: ; preds = %31
%53 = call i32 (...) @help()
store i32 %53, i32* %3
br label %392
54: ; preds = %31, %50, %49, %48, %39, %37, %35, %33
br label %26
55: ; preds = %26
%56 = load i32, i32* @optind
%57 = load i32, i32* %4
%58 = icmp sge i32 %56, %57
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 (...) @help()
store i32 %60, i32* %3
br label %392
61: ; preds = %55
%62 = load i8**, i8*** %5
%63 = load i32, i32* @optind
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8*, i8** %62, i64 %64
store i8** %65, i8*** %16
%66 = load i8*, i8** %8
%67 = icmp ne i8* %66, null
br i1 %67, label %73, label %68
68: ; preds = %61
%69 = load i8**, i8*** %16
%70 = getelementptr inbounds i8*, i8** %69, i64 0
%71 = load i8*, i8** %70
%72 = call i8* @program_name(i8* %71)
store i8* %72, i8** %8
br label %73
73: ; preds = %68, %61
%74 = load i32, i32* %14
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %92
76: ; preds = %73
%77 = load i32, i32* @SIG_IGN
%78 = call i32 @signal(i32 133, i32 %77)
%79 = call i64 (...) @fork()
%80 = icmp ne i64 %79, 0
br i1 %80, label %81, label %82
81: ; preds = %76
store i32 0, i32* %3
br label %392
82: ; preds = %76
%83 = call i32 (...) @setsid()
%84 = call i64 (...) @fork()
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %87
86: ; preds = %82
store i32 0, i32* %3
br label %392
87: ; preds = %82
%88 = load i32, i32* @STDIN_FILENO
%89 = call i32 @close(i32 %88)
%90 = load i32, i32* @O_RDONLY
%91 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %90)
br label %92
92: ; preds = %87, %73
%93 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%94 = call i32 @umask(i32 0)
%95 = call i64 @install_signal_handlers(i32* %7)
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %98
97: ; preds = %92
store i32 6, i32* %3
br label %392
98: ; preds = %92
%99 = load i8*, i8** %11
%100 = icmp ne i8* %99, null
br i1 %100, label %101, label %104
101: ; preds = %98
%102 = load i8*, i8** %11
%103 = call i32 @write_pid_file(i8* %102)
br label %104
104: ; preds = %101, %98
%105 = load i32, i32* @stdout
%106 = load i32, i32* @_IONBF
%107 = call i32 @setvbuf(i32 %105, i32* null, i32 %106, i32 0)
%108 = load i32, i32* @stderr
%109 = load i32, i32* @_IONBF
%110 = call i32 @setvbuf(i32 %108, i32* null, i32 %109, i32 0)
br label %111
111: ; preds = %382, %104
%112 = load i32, i32* %6
%113 = icmp ne i32 %112, 0
br i1 %113, label %114, label %383
114: ; preds = %111
%115 = load i8*, i8** %9
%116 = load i8*, i8** %8
%117 = load i32, i32* @STDOUT_FILENO
%118 = call i64 @pipe_to_logger(i8* %115, i8* %116, i32 %117, i32* %7)
%119 = icmp slt i64 %118, 0
br i1 %119, label %120, label %121
120: ; preds = %114
store i32 1, i32* %3
br label %392
121: ; preds = %114
%122 = load i8*, i8** %10
%123 = load i8*, i8** %8
%124 = load i32, i32* @STDERR_FILENO
%125 = call i64 @pipe_to_logger(i8* %122, i8* %123, i32 %124, i32* %7)
%126 = icmp slt i64 %125, 0
br i1 %126, label %127, label %128
127: ; preds = %121
store i32 2, i32* %3
br label %392
128: ; preds = %121
%129 = load i32, i32* @stdout
%130 = load i8**, i8*** %16
%131 = getelementptr inbounds i8*, i8** %130, i64 0
%132 = load i8*, i8** %131
%133 = call i32 (i32, i8*, ...) @fprintf(i32 %129, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %132)
%134 = call i64 @time(i32* null)
store i64 %134, i64* %17
%135 = call i64 (...) @fork()
store i64 %135, i64* %19
%136 = load i64, i64* %19
%137 = icmp slt i64 %136, 0
br i1 %137, label %138, label %140
138: ; preds = %128
%139 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
store i32 3, i32* %3
br label %392
140: ; preds = %128
%141 = load i64, i64* %19
%142 = icmp eq i64 %141, 0
br i1 %142, label %143, label %168
143: ; preds = %140
%144 = load i8*, i8** %12
%145 = call i64 @chdir(i8* %144)
%146 = icmp slt i64 %145, 0
br i1 %146, label %147, label %153
147: ; preds = %143
%148 = load i32, i32* @stderr
%149 = load i8*, i8** %12
%150 = load i32, i32* @errno
%151 = call i8* @strerror(i32 %150)
%152 = call i32 (i32, i8*, ...) @fprintf(i32 %148, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i8* %149, i8* %151)
store i32 7, i32* %3
br label %392
153: ; preds = %143
%154 = load i32, i32* @SIG_UNBLOCK
%155 = call i32 @sigprocmask(i32 %154, i32* %7, i32* null)
%156 = load i8**, i8*** %16
%157 = getelementptr inbounds i8*, i8** %156, i64 0
%158 = load i8*, i8** %157
%159 = load i8**, i8*** %16
%160 = call i32 @execvp(i8* %158, i8** %159)
%161 = load i32, i32* @stderr
%162 = load i8**, i8*** %16
%163 = getelementptr inbounds i8*, i8** %162, i64 0
%164 = load i8*, i8** %163
%165 = load i32, i32* @errno
%166 = call i8* @strerror(i32 %165)
%167 = call i32 (i32, i8*, ...) @fprintf(i32 %161, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %164, i8* %166)
store i32 4, i32* %3
br label %392
168: ; preds = %140
store i32 0, i32* %21
store i32 0, i32* %22
br label %169
169: ; preds = %325, %168
%170 = load i64, i64* %19
%171 = icmp ne i64 %170, 0
br i1 %171, label %172, label %326
172: ; preds = %169
%173 = call i64 @sigwait(i32* %7, i32* %20)
%174 = icmp slt i64 %173, 0
br i1 %174, label %175, label %177
175: ; preds = %172
%176 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
store i32 5, i32* %3
br label %392
177: ; preds = %172
%178 = load i32, i32* %20
switch i32 %178, label %321 [
i32 134, label %179
i32 132, label %266
i32 130, label %266
i32 131, label %285
i32 135, label %300
i32 129, label %310
i32 128, label %310
i32 133, label %310
]
179: ; preds = %177
br label %180
180: ; preds = %179, %264
%181 = load i32, i32* @WNOHANG
%182 = call i64 @waitpid(i32 -1, i32* %23, i32 %181)
%183 = trunc i64 %182 to i32
store i32 %183, i32* %24
%184 = load i32, i32* %24
%185 = sext i32 %184 to i64
%186 = load i64, i64* %19
%187 = icmp eq i64 %185, %186
br i1 %187, label %188, label %259
188: ; preds = %180
%189 = load i32, i32* %23
%190 = call i32 @WIFEXITED(i32 %189)
%191 = icmp ne i32 %190, 0
br i1 %191, label %192, label %221
192: ; preds = %188
%193 = load i32, i32* %23
%194 = call i32 @WEXITSTATUS(i32 %193)
%195 = icmp ne i32 %194, 0
br i1 %195, label %196, label %204
196: ; preds = %192
%197 = load i32, i32* @stderr
%198 = load i8**, i8*** %16
%199 = getelementptr inbounds i8*, i8** %198, i64 0
%200 = load i8*, i8** %199
%201 = load i32, i32* %23
%202 = call i32 @WEXITSTATUS(i32 %201)
%203 = call i32 (i32, i8*, ...) @fprintf(i32 %197, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i8* %200, i32 %202)
br label %220
204: ; preds = %192
%205 = load i32, i32* %21
%206 = icmp ne i32 %205, 0
br i1 %206, label %207, label %213
207: ; preds = %204
%208 = load i32, i32* @stdout
%209 = load i8**, i8*** %16
%210 = getelementptr inbounds i8*, i8** %209, i64 0
%211 = load i8*, i8** %210
%212 = call i32 (i32, i8*, ...) @fprintf(i32 %208, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i8* %211)
br label %219
213: ; preds = %204
%214 = load i32, i32* @stdout
%215 = load i8**, i8*** %16
%216 = getelementptr inbounds i8*, i8** %215, i64 0
%217 = load i8*, i8** %216
%218 = call i32 (i32, i8*, ...) @fprintf(i32 %214, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i8* %217)
br label %219
219: ; preds = %213, %207
br label %220
220: ; preds = %219, %196
br label %258
221: ; preds = %188
%222 = load i32, i32* %23
%223 = call i32 @WTERMSIG(i32 %222)
%224 = icmp eq i32 %223, 130
br i1 %224, label %225, label %234
225: ; preds = %221
%226 = load i32, i32* %21
%227 = icmp ne i32 %226, 0
br i1 %227, label %228, label %234
228: ; preds = %225
%229 = load i32, i32* @stdout
%230 = load i8**, i8*** %16
%231 = getelementptr inbounds i8*, i8** %230, i64 0
%232 = load i8*, i8** %231
%233 = call i32 (i32, i8*, ...) @fprintf(i32 %229, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.13, i64 0, i64 0), i8* %232)
br label %257
234: ; preds = %225, %221
%235 = load i32, i32* %23
%236 = call i32 @WTERMSIG(i32 %235)
%237 = load i32, i32* @SIGKILL
%238 = icmp eq i32 %236, %237
br i1 %238, label %239, label %248
239: ; preds = %234
%240 = load i32, i32* %22
%241 = icmp ne i32 %240, 0
br i1 %241, label %242, label %248
242: ; preds = %239
%243 = load i32, i32* @stdout
%244 = load i8**, i8*** %16
%245 = getelementptr inbounds i8*, i8** %244, i64 0
%246 = load i8*, i8** %245
%247 = call i32 (i32, i8*, ...) @fprintf(i32 %243, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.14, i64 0, i64 0), i8* %246)
br label %256
248: ; preds = %239, %234
%249 = load i32, i32* @stderr
%250 = load i8**, i8*** %16
%251 = getelementptr inbounds i8*, i8** %250, i64 0
%252 = load i8*, i8** %251
%253 = load i32, i32* %23
%254 = call i32 @WTERMSIG(i32 %253)
%255 = call i32 (i32, i8*, ...) @fprintf(i32 %249, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i8* %252, i32 %254)
br label %256
256: ; preds = %248, %242
br label %257
257: ; preds = %256, %228
br label %258
258: ; preds = %257, %220
store i64 0, i64* %19
br label %265
259: ; preds = %180
%260 = load i32, i32* %24
%261 = icmp sle i32 %260, 0
br i1 %261, label %262, label %263
262: ; preds = %259
br label %265
263: ; preds = %259
br label %264
264: ; preds = %263
br label %180
265: ; preds = %262, %258
br label %325
266: ; preds = %177, %177
%267 = load i32, i32* %20
%268 = icmp ne i32 %267, 132
br i1 %268, label %269, label %275
269: ; preds = %266
%270 = load i32, i32* @stdout
%271 = load i8**, i8*** %16
%272 = getelementptr inbounds i8*, i8** %271, i64 0
%273 = load i8*, i8** %272
%274 = call i32 (i32, i8*, ...) @fprintf(i32 %270, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.16, i64 0, i64 0), i8* %273)
br label %275
275: ; preds = %269, %266
%276 = load i64, i64* %19
%277 = call i32 @kill(i64 %276, i32 130)
%278 = load i64, i64* %13
%279 = icmp sgt i64 %278, 0
br i1 %279, label %280, label %284
280: ; preds = %275
%281 = load i64, i64* %13
%282 = trunc i64 %281 to i32
%283 = call i32 @reset_alarm(i32 %282)
br label %284
284: ; preds = %280, %275
store i32 1, i32* %21
br label %325
285: ; preds = %177
%286 = load i32, i32* @stdout
%287 = load i8**, i8*** %16
%288 = getelementptr inbounds i8*, i8** %287, i64 0
%289 = load i8*, i8** %288
%290 = call i32 (i32, i8*, ...) @fprintf(i32 %286, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.17, i64 0, i64 0), i8* %289)
%291 = load i64, i64* %19
%292 = call i32 @kill(i64 %291, i32 130)
%293 = load i64, i64* %13
%294 = icmp sgt i64 %293, 0
br i1 %294, label %295, label %299
295: ; preds = %285
%296 = load i64, i64* %13
%297 = trunc i64 %296 to i32
%298 = call i32 @reset_alarm(i32 %297)
br label %299
299: ; preds = %295, %285
store i32 1, i32* %21
store i32 0, i32* %6
br label %325
300: ; preds = %177
%301 = load i32, i32* @stdout
%302 = load i64, i64* %13
%303 = load i8**, i8*** %16
%304 = getelementptr inbounds i8*, i8** %303, i64 0
%305 = load i8*, i8** %304
%306 = call i32 (i32, i8*, ...) @fprintf(i32 %301, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.18, i64 0, i64 0), i64 %302, i8* %305)
%307 = load i64, i64* %19
%308 = load i32, i32* @SIGKILL
%309 = call i32 @kill(i64 %307, i32 %308)
store i32 1, i32* %22
br label %325
310: ; preds = %177, %177, %177
%311 = load i32, i32* @stdout
%312 = load i32, i32* %20
%313 = call i8* @strsignal(i32 %312)
%314 = load i8**, i8*** %16
%315 = getelementptr inbounds i8*, i8** %314, i64 0
%316 = load i8*, i8** %315
%317 = call i32 (i32, i8*, ...) @fprintf(i32 %311, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.19, i64 0, i64 0), i8* %313, i8* %316)
%318 = load i64, i64* %19
%319 = load i32, i32* %20
%320 = call i32 @kill(i64 %318, i32 %319)
br label %325
321: ; preds = %177
%322 = load i32, i32* @stderr
%323 = load i32, i32* %20
%324 = call i32 (i32, i8*, ...) @fprintf(i32 %322, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.20, i64 0, i64 0), i32 %323)
br label %325
325: ; preds = %321, %310, %300, %299, %284, %265
br label %169
326: ; preds = %169
%327 = call i64 @time(i32* null)
store i64 %327, i64* %18
%328 = load i32, i32* %21
%329 = icmp ne i32 %328, 0
br i1 %329, label %379, label %330
330: ; preds = %326
%331 = load i64, i64* %18
%332 = load i64, i64* %17
%333 = icmp sge i64 %331, %332
br i1 %333, label %334, label %379
334: ; preds = %330
%335 = load i64, i64* %18
%336 = load i64, i64* %17
%337 = add nsw i64 %336, 60
%338 = icmp slt i64 %335, %337
br i1 %338, label %339, label %379
339: ; preds = %334
%340 = load i64, i64* %18
%341 = load i64, i64* %17
%342 = sub nsw i64 %340, %341
%343 = sub nsw i64 60, %342
%344 = trunc i64 %343 to i32
store i32 %344, i32* %25
%345 = load i32, i32* %25
%346 = call i32 @reset_alarm(i32 %345)
%347 = load i32, i32* @stdout
%348 = load i32, i32* %25
%349 = load i8**, i8*** %16
%350 = getelementptr inbounds i8*, i8** %349, i64 0
%351 = load i8*, i8** %350
%352 = call i32 (i32, i8*, ...) @fprintf(i32 %347, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.21, i64 0, i64 0), i32 %348, i8* %351)
br label %353
353: ; preds = %339, %377
%354 = call i64 @sigwait(i32* %7, i32* %20)
%355 = load i32, i32* %20
%356 = icmp eq i32 %355, 134
br i1 %356, label %357, label %364
357: ; preds = %353
br label %358
358: ; preds = %362, %357
%359 = load i32, i32* @WNOHANG
%360 = call i64 @waitpid(i32 -1, i32* null, i32 %359)
%361 = icmp sle i64 %360, 0
br i1 %361, label %362, label %363
362: ; preds = %358
br label %358
363: ; preds = %358
br label %377
364: ; preds = %353
%365 = load i32, i32* %20
%366 = icmp eq i32 %365, 131
br i1 %366, label %367, label %368
367: ; preds = %364
store i32 0, i32* %6
br label %378
368: ; preds = %364
%369 = load i32, i32* %20
%370 = icmp eq i32 %369, 130
br i1 %370, label %374, label %371
371: ; preds = %368
%372 = load i32, i32* %20
%373 = icmp eq i32 %372, 135
br i1 %373, label %374, label %375
374: ; preds = %371, %368
br label %378
375: ; preds = %371
br label %376
376: ; preds = %375
br label %377
377: ; preds = %376, %363
br label %353
378: ; preds = %374, %367
br label %379
379: ; preds = %378, %334, %330, %326
%380 = call i32 @reset_alarm(i32 0)
br label %381
381: ; preds = %379
br label %382
382: ; preds = %381
br label %111
383: ; preds = %111
%384 = load i8*, i8** %11
%385 = icmp ne i8* %384, null
br i1 %385, label %386, label %389
386: ; preds = %383
%387 = load i8*, i8** %11
%388 = call i32 @remove_pid_file(i8* %387)
br label %389
389: ; preds = %386, %383
%390 = load i32, i32* @stdout
%391 = call i32 (i32, i8*, ...) @fprintf(i32 %390, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.22, i64 0, i64 0))
store i32 0, i32* %3
br label %392
392: ; preds = %389, %175, %153, %147, %138, %127, %120, %97, %86, %81, %59, %52, %46
%393 = load i32, i32* %3
ret i32 %393
}

LLVM IR (-O2):
@.str = [10 x i8] c"user.info\00"
@.str.1 = [9 x i8] c"user.err\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [13 x i8] c"e:o:t:p:k:c:\00"
@optarg = global i8* null
@optind = global i32 0
@SIG_IGN = global i32 0
@STDIN_FILENO = global i32 0
@.str.4 = [10 x i8] c"/dev/null\00"
@O_RDONLY = global i32 0
@stdout = global i32 0
@_IONBF = global i32 0
@stderr = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.5 = [12 x i8] c"Running %s\0A\00"
@.str.6 = [31 x i8] c"Couldn't fork to start program\00"
@.str.7 = [37 x i8] c"Couldn't change directory to %s: %s\0A\00"
@errno = global i32 0
@SIG_UNBLOCK = global i32 0
@.str.8 = [25 x i8] c"Couldn't execute %s: %s\0A\00"
@.str.9 = [26 x i8] c"Failed to wait on signals\00"
@WNOHANG = global i32 0
@.str.10 = [26 x i8] c"%s exited with status %d\0A\00"
@.str.11 = [26 x i8] c"%s finished as requested\0A\00"
@.str.12 = [13 x i8] c"%s finished\0A\00"
@.str.13 = [28 x i8] c"%s terminated as requested\0A\00"
@SIGKILL = global i32 0
@.str.14 = [15 x i8] c"%s was killed\0A\00"
@.str.15 = [32 x i8] c"%s was terminated by signal %d\0A\00"
@.str.16 = [45 x i8] c"Asking %s to terminate so we can restart it\0A\00"
@.str.17 = [44 x i8] c"Asking %s to terminate so we can shut down\0A\00"
@.str.18 = [32 x i8] c"Waited %ld seconds, killing %s\0A\00"
@.str.19 = [34 x i8] c"Passing the '%s' signal on to %s\0A\00"
@.str.20 = [22 x i8] c"Unexpected signal %d\0A\00"
@.str.21 = [34 x i8] c"Waiting %ds before respawning %s\0A\00"
@.str.22 = [23 x i8] c"Shut down by request.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
br label %7
7: ; preds = %16, %2
%8 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %2 ], [ %17, %16 ]
%9 = phi i64 [ -1, %2 ], [ %18, %16 ]
%10 = phi i32 [ 1, %2 ], [ %19, %16 ]
%11 = phi i8* [ null, %2 ], [ %20, %16 ]
%12 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %2 ], [ %21, %16 ]
%13 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %2 ], [ %22, %16 ]
%14 = phi i8* [ null, %2 ], [ %23, %16 ]
%15 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
switch i32 %15, label %16 [
i32 -1, label %43
i32 101, label %24
i32 111, label %26
i32 116, label %28
i32 112, label %30
i32 107, label %32
i32 100, label %38
i32 99, label %39
i32 63, label %41
]
16: ; preds = %7, %32, %39, %38, %30, %28, %26, %24
%17 = phi i8* [ %40, %39 ], [ %8, %38 ], [ %8, %32 ], [ %8, %30 ], [ %8, %28 ], [ %8, %26 ], [ %8, %24 ], [ %8, %7 ]
%18 = phi i64 [ %9, %39 ], [ %9, %38 ], [ %34, %32 ], [ %9, %30 ], [ %9, %28 ], [ %9, %26 ], [ %9, %24 ], [ %9, %7 ]
%19 = phi i32 [ %10, %39 ], [ 0, %38 ], [ %10, %32 ], [ %10, %30 ], [ %10, %28 ], [ %10, %26 ], [ %10, %24 ], [ %10, %7 ]
%20 = phi i8* [ %11, %39 ], [ %11, %38 ], [ %11, %32 ], [ %31, %30 ], [ %11, %28 ], [ %11, %26 ], [ %11, %24 ], [ %11, %7 ]
%21 = phi i8* [ %12, %39 ], [ %12, %38 ], [ %12, %32 ], [ %12, %30 ], [ %12, %28 ], [ %12, %26 ], [ %25, %24 ], [ %12, %7 ]
%22 = phi i8* [ %13, %39 ], [ %13, %38 ], [ %13, %32 ], [ %13, %30 ], [ %13, %28 ], [ %27, %26 ], [ %13, %24 ], [ %13, %7 ]
%23 = phi i8* [ %14, %39 ], [ %14, %38 ], [ %14, %32 ], [ %14, %30 ], [ %29, %28 ], [ %14, %26 ], [ %14, %24 ], [ %14, %7 ]
br label %7
24: ; preds = %7
%25 = load i8*, i8** @optarg
br label %16
26: ; preds = %7
%27 = load i8*, i8** @optarg
br label %16
28: ; preds = %7
%29 = load i8*, i8** @optarg
br label %16
30: ; preds = %7
%31 = load i8*, i8** @optarg
br label %16
32: ; preds = %7
%33 = load i8*, i8** @optarg
%34 = tail call i64 @atoi_or_default(i8* %33, i32 -1)
%35 = icmp slt i64 %34, 1
br i1 %35, label %36, label %16
36: ; preds = %32
%37 = tail call i32 (...) @help()
br label %280
38: ; preds = %7
br label %16
39: ; preds = %7
%40 = load i8*, i8** @optarg
br label %16
41: ; preds = %7
%42 = tail call i32 (...) @help()
br label %280
43: ; preds = %7
%44 = load i32, i32* @optind
%45 = icmp slt i32 %44, %0
br i1 %45, label %48, label %46
46: ; preds = %43
%47 = tail call i32 (...) @help()
br label %280
48: ; preds = %43
%49 = sext i32 %44 to i64
%50 = getelementptr inbounds i8*, i8** %1, i64 %49
%51 = icmp eq i8* %14, null
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i8*, i8** %50
%54 = tail call i8* @program_name(i8* %53)
br label %55
55: ; preds = %52, %48
%56 = phi i8* [ %14, %48 ], [ %54, %52 ]
%57 = icmp eq i32 %10, 0
br i1 %57, label %72, label %58
58: ; preds = %55
%59 = load i32, i32* @SIG_IGN
%60 = tail call i32 @signal(i32 133, i32 %59)
%61 = tail call i64 (...) @fork()
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %280
63: ; preds = %58
%64 = tail call i32 (...) @setsid()
%65 = tail call i64 (...) @fork()
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %280
67: ; preds = %63
%68 = load i32, i32* @STDIN_FILENO
%69 = tail call i32 @close(i32 %68)
%70 = load i32, i32* @O_RDONLY
%71 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %70)
br label %72
72: ; preds = %67, %55
%73 = tail call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%74 = tail call i32 @umask(i32 0)
%75 = call i64 @install_signal_handlers(i32* %3)
%76 = icmp slt i64 %75, 0
br i1 %76, label %280, label %77
77: ; preds = %72
%78 = icmp eq i8* %11, null
br i1 %78, label %81, label %79
79: ; preds = %77
%80 = call i32 @write_pid_file(i8* %11)
br label %81
81: ; preds = %79, %77
%82 = load i32, i32* @stdout
%83 = load i32, i32* @_IONBF
%84 = call i32 @setvbuf(i32 %82, i32* null, i32 %83, i32 0)
%85 = load i32, i32* @stderr
%86 = load i32, i32* @_IONBF
%87 = call i32 @setvbuf(i32 %85, i32* null, i32 %86, i32 0)
%88 = bitcast i32* %4 to i8*
%89 = icmp sgt i64 %9, 0
%90 = trunc i64 %9 to i32
%91 = bitcast i32* %5 to i8*
br label %92
92: ; preds = %81, %270
%93 = phi i32 [ 1, %81 ], [ %271, %270 ]
%94 = load i32, i32* @STDOUT_FILENO
%95 = call i64 @pipe_to_logger(i8* %13, i8* %56, i32 %94, i32* %3)
%96 = icmp slt i64 %95, 0
br i1 %96, label %280, label %97
97: ; preds = %92
%98 = load i32, i32* @STDERR_FILENO
%99 = call i64 @pipe_to_logger(i8* %12, i8* %56, i32 %98, i32* %3)
%100 = icmp slt i64 %99, 0
br i1 %100, label %280, label %101
101: ; preds = %97
%102 = load i32, i32* @stdout
%103 = load i8*, i8** %50
%104 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %103)
%105 = call i64 @time(i32* null)
%106 = call i64 (...) @fork()
%107 = icmp slt i64 %106, 0
br i1 %107, label %108, label %110
108: ; preds = %101
%109 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
br label %280
110: ; preds = %101
%111 = icmp eq i64 %106, 0
br i1 %111, label %112, label %130
112: ; preds = %110
%113 = call i64 @chdir(i8* %8)
%114 = icmp slt i64 %113, 0
br i1 %114, label %115, label %120
115: ; preds = %112
%116 = load i32, i32* @stderr
%117 = load i32, i32* @errno
%118 = call i8* @strerror(i32 %117)
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i8* %8, i8* %118)
br label %280
120: ; preds = %112
%121 = load i32, i32* @SIG_UNBLOCK
%122 = call i32 @sigprocmask(i32 %121, i32* %3, i32* null)
%123 = load i8*, i8** %50
%124 = call i32 @execvp(i8* %123, i8** %50)
%125 = load i32, i32* @stderr
%126 = load i8*, i8** %50
%127 = load i32, i32* @errno
%128 = call i8* @strerror(i32 %127)
%129 = call i32 (i32, i8*, ...) @fprintf(i32 %125, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %126, i8* %128)
br label %280
130: ; preds = %110
br label %131
131: ; preds = %130, %239
%132 = phi i32 [ %93, %130 ], [ %243, %239 ]
%133 = phi i32 [ 0, %130 ], [ %242, %239 ]
%134 = phi i32 [ 0, %130 ], [ %241, %239 ]
%135 = phi i64 [ %106, %130 ], [ %240, %239 ]
%136 = call i64 @sigwait(i32* %3, i32* %4)
%137 = icmp slt i64 %136, 0
br i1 %137, label %138, label %140
138: ; preds = %131
%139 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %280
140: ; preds = %131
%141 = load i32, i32* %4
switch i32 %141, label %236 [
i32 134, label %142
i32 133, label %229
i32 128, label %229
i32 131, label %216
i32 135, label %223
i32 129, label %229
i32 132, label %212
i32 130, label %208
]
142: ; preds = %140
%143 = load i32, i32* @WNOHANG
%144 = call i64 @waitpid(i32 -1, i32* %5, i32 %143)
%145 = shl i64 %144, 32
%146 = ashr exact i64 %145, 32
%147 = icmp eq i64 %146, %135
br i1 %147, label %148, label %196
148: ; preds = %202, %142
%149 = load i32, i32* %5
%150 = call i32 @WIFEXITED(i32 %149)
%151 = icmp eq i32 %150, 0
%152 = load i32, i32* %5
br i1 %151, label %170, label %153
153: ; preds = %148
%154 = call i32 @WEXITSTATUS(i32 %152)
%155 = icmp eq i32 %154, 0
br i1 %155, label %162, label %156
156: ; preds = %153
%157 = load i32, i32* @stderr
%158 = load i8*, i8** %50
%159 = load i32, i32* %5
%160 = call i32 @WEXITSTATUS(i32 %159)
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %157, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i8* %158, i32 %160)
br label %200
162: ; preds = %153
%163 = icmp eq i32 %134, 0
%164 = load i32, i32* @stdout
%165 = load i8*, i8** %50
br i1 %163, label %168, label %166
166: ; preds = %162
%167 = call i32 (i32, i8*, ...) @fprintf(i32 %164, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i8* %165)
br label %200
168: ; preds = %162
%169 = call i32 (i32, i8*, ...) @fprintf(i32 %164, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i8* %165)
br label %200
170: ; preds = %148
%171 = call i32 @WTERMSIG(i32 %152)
%172 = icmp eq i32 %171, 130
%173 = icmp ne i32 %134, 0
%174 = select i1 %172, i1 %173, i1 false
br i1 %174, label %175, label %179
175: ; preds = %170
%176 = load i32, i32* @stdout
%177 = load i8*, i8** %50
%178 = call i32 (i32, i8*, ...) @fprintf(i32 %176, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.13, i64 0, i64 0), i8* %177)
br label %200
179: ; preds = %170
%180 = load i32, i32* %5
%181 = call i32 @WTERMSIG(i32 %180)
%182 = load i32, i32* @SIGKILL
%183 = icmp eq i32 %181, %182
%184 = icmp ne i32 %133, 0
%185 = select i1 %183, i1 %184, i1 false
br i1 %185, label %186, label %190
186: ; preds = %179
%187 = load i32, i32* @stdout
%188 = load i8*, i8** %50
%189 = call i32 (i32, i8*, ...) @fprintf(i32 %187, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.14, i64 0, i64 0), i8* %188)
br label %200
190: ; preds = %179
%191 = load i32, i32* @stderr
%192 = load i8*, i8** %50
%193 = load i32, i32* %5
%194 = call i32 @WTERMSIG(i32 %193)
%195 = call i32 (i32, i8*, ...) @fprintf(i32 %191, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i8* %192, i32 %194)
br label %200
196: ; preds = %142, %202
%197 = phi i64 [ %204, %202 ], [ %144, %142 ]
%198 = trunc i64 %197 to i32
%199 = icmp slt i32 %198, 1
br i1 %199, label %200, label %202
200: ; preds = %196, %175, %190, %186, %156, %168, %166
%201 = phi i64 [ 0, %166 ], [ 0, %168 ], [ 0, %156 ], [ 0, %186 ], [ 0, %190 ], [ 0, %175 ], [ %135, %196 ]
br label %239
202: ; preds = %196
%203 = load i32, i32* @WNOHANG
%204 = call i64 @waitpid(i32 -1, i32* %5, i32 %203)
%205 = shl i64 %204, 32
%206 = ashr exact i64 %205, 32
%207 = icmp eq i64 %206, %135
br i1 %207, label %148, label %196
208: ; preds = %140
%209 = load i32, i32* @stdout
%210 = load i8*, i8** %50
%211 = call i32 (i32, i8*, ...) @fprintf(i32 %209, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.16, i64 0, i64 0), i8* %210)
br label %212
212: ; preds = %140, %208
%213 = call i32 @kill(i64 %135, i32 130)
br i1 %89, label %214, label %239
214: ; preds = %212
%215 = call i32 @reset_alarm(i32 %90)
br label %239
216: ; preds = %140
%217 = load i32, i32* @stdout
%218 = load i8*, i8** %50
%219 = call i32 (i32, i8*, ...) @fprintf(i32 %217, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.17, i64 0, i64 0), i8* %218)
%220 = call i32 @kill(i64 %135, i32 130)
br i1 %89, label %221, label %239
221: ; preds = %216
%222 = call i32 @reset_alarm(i32 %90)
br label %239
223: ; preds = %140
%224 = load i32, i32* @stdout
%225 = load i8*, i8** %50
%226 = call i32 (i32, i8*, ...) @fprintf(i32 %224, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.18, i64 0, i64 0), i64 %9, i8* %225)
%227 = load i32, i32* @SIGKILL
%228 = call i32 @kill(i64 %135, i32 %227)
br label %239
229: ; preds = %140, %140, %140
%230 = load i32, i32* @stdout
%231 = call i8* @strsignal(i32 %141)
%232 = load i8*, i8** %50
%233 = call i32 (i32, i8*, ...) @fprintf(i32 %230, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.19, i64 0, i64 0), i8* %231, i8* %232)
%234 = load i32, i32* %4
%235 = call i32 @kill(i64 %135, i32 %234)
br label %239
236: ; preds = %140
%237 = load i32, i32* @stderr
%238 = call i32 (i32, i8*, ...) @fprintf(i32 %237, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.20, i64 0, i64 0), i32 %141)
br label %239
239: ; preds = %200, %216, %221, %212, %214, %236, %229, %223
%240 = phi i64 [ %135, %236 ], [ %135, %229 ], [ %135, %223 ], [ %135, %214 ], [ %135, %212 ], [ %135, %221 ], [ %135, %216 ], [ %201, %200 ]
%241 = phi i32 [ %134, %236 ], [ %134, %229 ], [ %134, %223 ], [ 1, %214 ], [ 1, %212 ], [ 1, %221 ], [ 1, %216 ], [ %134, %200 ]
%242 = phi i32 [ %133, %236 ], [ %133, %229 ], [ 1, %223 ], [ %133, %214 ], [ %133, %212 ], [ %133, %221 ], [ %133, %216 ], [ %133, %200 ]
%243 = phi i32 [ %132, %236 ], [ %132, %229 ], [ %132, %223 ], [ %132, %214 ], [ %132, %212 ], [ 0, %221 ], [ 0, %216 ], [ %132, %200 ]
%244 = icmp eq i64 %240, 0
br i1 %244, label %245, label %131
245: ; preds = %239
%246 = call i64 @time(i32* null)
%247 = icmp eq i32 %241, 0
%248 = icmp sle i64 %105, %246
%249 = select i1 %247, i1 %248, i1 false
%250 = add nsw i64 %105, 60
%251 = icmp slt i64 %246, %250
%252 = select i1 %249, i1 %251, i1 false
br i1 %252, label %253, label %270
253: ; preds = %245
%254 = sub i64 %105, %246
%255 = trunc i64 %254 to i32
%256 = add i32 %255, 60
%257 = call i32 @reset_alarm(i32 %256)
%258 = load i32, i32* @stdout
%259 = load i8*, i8** %50
%260 = call i32 (i32, i8*, ...) @fprintf(i32 %258, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.21, i64 0, i64 0), i32 %256, i8* %259)
br label %261
261: ; preds = %264, %253
%262 = call i64 @sigwait(i32* %3, i32* %4)
%263 = load i32, i32* %4
switch i32 %263, label %264 [
i32 134, label %265
i32 131, label %269
i32 135, label %270
i32 130, label %270
]
264: ; preds = %265, %261
br label %261
265: ; preds = %261, %265
%266 = load i32, i32* @WNOHANG
%267 = call i64 @waitpid(i32 -1, i32* null, i32 %266)
%268 = icmp slt i64 %267, 1
br i1 %268, label %265, label %264
269: ; preds = %261
br label %270
270: ; preds = %261, %261, %269, %245
%271 = phi i32 [ %243, %245 ], [ 0, %269 ], [ %243, %261 ], [ %243, %261 ]
%272 = call i32 @reset_alarm(i32 0)
%273 = icmp eq i32 %271, 0
br i1 %273, label %274, label %92
274: ; preds = %270
br i1 %78, label %277, label %275
275: ; preds = %274
%276 = call i32 @remove_pid_file(i8* %11)
br label %277
277: ; preds = %275, %274
%278 = load i32, i32* @stdout
%279 = call i32 (i32, i8*, ...) @fprintf(i32 %278, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.22, i64 0, i64 0))
br label %280
280: ; preds = %97, %92, %108, %115, %120, %138, %277, %58, %63, %72, %46, %41, %36
%281 = phi i32 [ %42, %41 ], [ %37, %36 ], [ %47, %46 ], [ 0, %277 ], [ 0, %58 ], [ 0, %63 ], [ 6, %72 ], [ 5, %138 ], [ 3, %108 ], [ 7, %115 ], [ 4, %120 ], [ 2, %97 ], [ 1, %92 ]
ret i32 %281
}