#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;
struct timeval {
  scalar_t__ tv_sec;
  scalar_t__ tv_usec;
};
typedef int /*<<< orphan*/ readbuf;
typedef int pid_t;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ die(char *, char *, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__, scalar_t__,
                           int);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int open_master_pty(char *);
int read(int, unsigned char *, int);
int /*<<< orphan*/ run_command(char **, int, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int master_in, master_out, cc, status;
  time_t starttime, now;
  pid_t child;
  unsigned char readbuf[1024];
  FILE *output;
  if (argc < 3) {
    die("%s: too few arguments\n"
        "usage: %s output-filename command [arguments...]\n",
        *argv, *argv);
  }
  master_in = open_master_pty("input");
  master_out = open_master_pty("output");
  if ((child = fork()) == -1) {
    die("fork() failed: %s\n", strerror(errno));
  }
  if (child == 0) {
    run_command(argv + 2, master_in, master_out);
  }
  if (!(output = fopen(argv[1], "w"))) {
    die("Unable to open \"%s\" for output: %s\n", argv[1], strerror(errno));
  }
  starttime = time(NULL);
  for (;;) {
    fd_set readfds;
    struct timeval tv;
    FD_ZERO(&readfds);
    FD_SET(master_out, &readfds);
    tv.tv_sec = starttime + 30 - time(NULL);
    if (tv.tv_sec < 0)
      tv.tv_sec = 0;
    tv.tv_usec = 0;
    cc = select(master_out + 1, &readfds, NULL, NULL, &tv);
    if (cc < 0) {
      die("select() failed: %s\n", strerror(errno));
    }
    if (cc > 0 && FD_ISSET(master_out, &readfds)) {
      cc = read(master_out, readbuf, sizeof(readbuf));
      if (cc <= 0)
        break;
      fwrite(readbuf, 1, cc, output);
      if (master_in != -1) {
        close(master_in);
        master_in = -1;
      }
    }
    now = time(NULL);
    if (now >= starttime + 30) {
      fprintf(stderr, "Command execution timed out: %ld to %ld: %d\n",
              starttime, now, cc);
      break;
    }
  }
  if (master_in != -1)
    close(master_in);
  close(master_out);
  fclose(output);
  waitpid(child, &status, 0);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    125f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   10f0 <die@plt>
lea    0xde2(%rip),%rdi
call   1040 <open_master_pty@plt>
mov    %eax,-0x14(%rbp)
lea    0xdd9(%rip),%rdi
call   1040 <open_master_pty@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1140 <fork@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
jne    12af <main+0x8f>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
movslq %eax,%rsi
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   10f0 <die@plt>
cmpl   $0x0,-0x34(%rbp)
jne    12cc <main+0xac>
mov    -0x10(%rbp),%rdi
add    $0x10,%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   10c0 <run_command@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd8d(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x448(%rbp)
cmp    $0x0,%rax
jne    1325 <main+0x105>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x468(%rbp)
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x468(%rbp),%rsi
mov    %eax,%edx
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   10f0 <die@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %rax,-0x28(%rbp)
lea    -0x44c(%rbp),%rdi
call   10a0 <FD_ZERO@plt>
mov    -0x18(%rbp),%edi
lea    -0x44c(%rbp),%rsi
call   1130 <FD_SET@plt>
mov    -0x28(%rbp),%rax
add    $0x1e,%rax
mov    %rax,-0x470(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %rax,%rcx
mov    -0x470(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x460(%rbp)
cmpq   $0x0,-0x460(%rbp)
jge    1392 <main+0x172>
movq   $0x0,-0x460(%rbp)
movq   $0x0,-0x458(%rbp)
mov    -0x18(%rbp),%edi
add    $0x1,%edi
lea    -0x44c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x460(%rbp),%r8
mov    %rcx,%rdx
call   10b0 <select@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    13e9 <main+0x1c9>
mov    0x2c07(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
movslq %eax,%rsi
lea    0xcac(%rip),%rdi
mov    $0x0,%al
call   10f0 <die@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    146b <main+0x24b>
mov    -0x18(%rbp),%edi
lea    -0x44c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     146b <main+0x24b>
mov    -0x18(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1432 <main+0x212>
jmp    14b8 <main+0x298>
lea    -0x440(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x448(%rbp),%rcx
mov    $0x1,%esi
call   1110 <fwrite@plt>
cmpl   $0xffffffff,-0x14(%rbp)
je     1466 <main+0x246>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    146b <main+0x24b>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    $0x1e,%rcx
cmp    %rcx,%rax
jl     14b3 <main+0x293>
mov    0x2b4c(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xbfa(%rip),%rsi
call   1080 <fprintf@plt>
jmp    14b8 <main+0x298>
jmp    1332 <main+0x112>
cmpl   $0xffffffff,-0x14(%rbp)
je     14ca <main+0x2aa>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x448(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x34(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   10d0 <waitpid@plt>
xor    %edi,%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x448,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     124d <main+0x2d>
mov    (%rbx),%rdx
lea    0xdbd(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   10f0 <die@plt>
lea    0xdf4(%rip),%rdi
call   1040 <open_master_pty@plt>
mov    %eax,0x8(%rsp)
lea    0xdea(%rip),%rdi
call   1040 <open_master_pty@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   1140 <fork@plt>
test   %eax,%eax
mov    %eax,0xc(%rsp)
je     12a1 <main+0x81>
cmp    $0xffffffff,%eax
jne    12b1 <main+0x91>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
movslq %eax,%rsi
lea    0xdbd(%rip),%rdi
xor    %eax,%eax
call   10f0 <die@plt>
jmp    12b1 <main+0x91>
lea    0x10(%rbx),%rdi
mov    0x8(%rsp),%esi
mov    %r13d,%edx
call   10c0 <run_command@plt>
mov    0x8(%rbx),%rdi
lea    0xdac(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
jne    12f0 <main+0xd0>
mov    0x8(%rbx),%rbx
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xd86(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10f0 <die@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %rax,0x20(%rsp)
mov    %rax,%rbx
add    $0x1e,%rbx
mov    %r13d,%r14d
add    $0x1,%r14d
lea    0x3c(%rsp),%rbp
lea    0x28(%rsp),%r12
mov    %rbx,0x10(%rsp)
jmp    134f <main+0x12f>
nopl   0x0(%rax,%rax,1)
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
movslq %eax,%rsi
lea    0xd56(%rip),%rdi
xor    %eax,%eax
call   10f0 <die@plt>
xor    %edi,%edi
call   1090 <time@plt>
cmp    %rbx,%rax
jge    1428 <main+0x208>
mov    %rbp,%rdi
call   10a0 <FD_ZERO@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
call   1130 <FD_SET@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %rbx,%rcx
sub    %rax,%rcx
mov    $0x0,%eax
cmovs  %rax,%rcx
mov    %rcx,0x28(%rsp)
movq   $0x0,0x30(%rsp)
mov    %r14d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   10b0 <select@plt>
mov    %eax,%r15d
test   %eax,%eax
js     1320 <main+0x100>
je     1420 <main+0x200>
mov    %r13d,%edi
mov    %rbp,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     133f <main+0x11f>
mov    %r13d,%edi
mov    %rbp,%r13
mov    %r12,%rbx
mov    %edi,%ebp
lea    0x40(%rsp),%r12
mov    %r12,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    144a <main+0x22a>
mov    %eax,%r15d
mov    %r12,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    0x18(%rsp),%rcx
call   1110 <fwrite@plt>
mov    0x8(%rsp),%edi
cmp    $0xffffffff,%edi
je     13f7 <main+0x1d7>
call   1060 <close@plt>
movl   $0xffffffff,0x8(%rsp)
ff
mov    %rbx,%r12
mov    %ebp,%eax
mov    %r13,%rbp
mov    %eax,%r13d
mov    0x10(%rsp),%rbx
jmp    133f <main+0x11f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %r15d,%r15d
jmp    133f <main+0x11f>
mov    0x2bb1(%rip),%rcx
mov    (%rcx),%edi
lea    0xc6b(%rip),%rsi
mov    0x20(%rsp),%rdx
mov    %rax,%rcx
mov    %r15d,%r8d
call   1080 <fprintf@plt>
jmp    144d <main+0x22d>
mov    %ebp,%r13d
mov    0x8(%rsp),%edi
cmp    $0xffffffff,%edi
je     145b <main+0x23b>
call   1060 <close@plt>
mov    %r13d,%edi
call   1060 <close@plt>
mov    0x18(%rsp),%rdi
call   1050 <fclose@plt>
lea    0x28(%rsp),%rsi
mov    0xc(%rsp),%edi
xor    %edx,%edx
call   10d0 <waitpid@plt>
xor    %edi,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [72 x i8] c"%s: too few arguments\0Ausage: %s output-filename command [arguments...]\0A\00"
@.str.1 = [6 x i8] c"input\00"
@.str.2 = [7 x i8] c"output\00"
@.str.3 = [19 x i8] c"fork() failed: %s\0A\00"
@errno = global i32 0
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [36 x i8] c"Unable to open \22%s\22 for output: %s\0A\00"
@.str.6 = [21 x i8] c"select() failed: %s\0A\00"
@stderr = global i32 0
@.str.7 = [45 x i8] c"Command execution timed out: %ld to %ld: %d\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 i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca [1024 x i8]
%14 = alloca i32*
%15 = alloca i32
%16 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = load i8**, i8*** %5
%23 = load i8*, i8** %22
%24 = call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %23)
br label %25
25: ; preds = %19, %2
%26 = call i32 @open_master_pty(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %26, i32* %6
%27 = call i32 @open_master_pty(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 %27, i32* %7
%28 = call i32 (...) @fork()
store i32 %28, i32* %12
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = load i32, i32* @errno
%32 = call i32 @strerror(i32 %31)
%33 = sext i32 %32 to i64
%34 = inttoptr i64 %33 to i8*
%35 = call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %30, %25
%37 = load i32, i32* %12
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %36
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i32, i32* %6
%43 = load i32, i32* %7
%44 = call i32 @run_command(i8** %41, i32 %42, i32 %43)
br label %45
45: ; preds = %39, %36
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32* @fopen(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %49, i32** %14
%50 = icmp ne i32* %49, null
br i1 %50, label %58, label %51
51: ; preds = %45
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = load i32, i32* @errno
%56 = call i32 @strerror(i32 %55)
%57 = call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %54, i32 %56)
br label %58
58: ; preds = %51, %45
%59 = call i64 @time(i32* null)
store i64 %59, i64* %10
br label %60
60: ; preds = %124, %58
%61 = call i32 @FD_ZERO(i32* %15)
%62 = load i32, i32* %7
%63 = call i32 @FD_SET(i32 %62, i32* %15)
%64 = load i64, i64* %10
%65 = add nsw i64 %64, 30
%66 = call i64 @time(i32* null)
%67 = sub nsw i64 %65, %66
%68 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
store i64 %67, i64* %68
%69 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
%70 = load i64, i64* %69
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %60
%73 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
store i64 0, i64* %73
br label %74
74: ; preds = %72, %60
%75 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
store i64 0, i64* %75
%76 = load i32, i32* %7
%77 = add nsw i32 %76, 1
%78 = call i32 @select(i32 %77, i32* %15, i32* null, i32* null, %struct.timeval* %16)
store i32 %78, i32* %8
%79 = load i32, i32* %8
%80 = icmp slt i32 %79, 0
br i1 %80, label %81, label %87
81: ; preds = %74
%82 = load i32, i32* @errno
%83 = call i32 @strerror(i32 %82)
%84 = sext i32 %83 to i64
%85 = inttoptr i64 %84 to i8*
%86 = call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %85)
br label %87
87: ; preds = %81, %74
%88 = load i32, i32* %8
%89 = icmp sgt i32 %88, 0
br i1 %89, label %90, label %112
90: ; preds = %87
%91 = load i32, i32* %7
%92 = call i64 @FD_ISSET(i32 %91, i32* %15)
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %112
94: ; preds = %90
%95 = load i32, i32* %7
%96 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%97 = call i32 @read(i32 %95, i8* %96, i32 1024)
store i32 %97, i32* %8
%98 = load i32, i32* %8
%99 = icmp sle i32 %98, 0
br i1 %99, label %100, label %101
100: ; preds = %94
br label %125
101: ; preds = %94
%102 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%103 = load i32, i32* %8
%104 = load i32*, i32** %14
%105 = call i32 @fwrite(i8* %102, i32 1, i32 %103, i32* %104)
%106 = load i32, i32* %6
%107 = icmp ne i32 %106, -1
br i1 %107, label %108, label %111
108: ; preds = %101
%109 = load i32, i32* %6
%110 = call i32 @close(i32 %109)
store i32 -1, i32* %6
br label %111
111: ; preds = %108, %101
br label %112
112: ; preds = %111, %90, %87
%113 = call i64 @time(i32* null)
store i64 %113, i64* %11
%114 = load i64, i64* %11
%115 = load i64, i64* %10
%116 = add nsw i64 %115, 30
%117 = icmp sge i64 %114, %116
br i1 %117, label %118, label %124
118: ; preds = %112
%119 = load i32, i32* @stderr
%120 = load i64, i64* %10
%121 = load i64, i64* %11
%122 = load i32, i32* %8
%123 = call i32 @fprintf(i32 %119, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i64 %120, i64 %121, i32 %122)
br label %125
124: ; preds = %112
br label %60
125: ; preds = %118, %100
%126 = load i32, i32* %6
%127 = icmp ne i32 %126, -1
br i1 %127, label %128, label %131
128: ; preds = %125
%129 = load i32, i32* %6
%130 = call i32 @close(i32 %129)
br label %131
131: ; preds = %128, %125
%132 = load i32, i32* %7
%133 = call i32 @close(i32 %132)
%134 = load i32*, i32** %14
%135 = call i32 @fclose(i32* %134)
%136 = load i32, i32* %12
%137 = call i32 @waitpid(i32 %136, i32* %9, i32 0)
%138 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [72 x i8] c"%s: too few arguments\0Ausage: %s output-filename command [arguments...]\0A\00"
@.str.1 = [6 x i8] c"input\00"
@.str.2 = [7 x i8] c"output\00"
@.str.3 = [19 x i8] c"fork() failed: %s\0A\00"
@errno = global i32 0
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [36 x i8] c"Unable to open \22%s\22 for output: %s\0A\00"
@.str.6 = [21 x i8] c"select() failed: %s\0A\00"
@stderr = global i32 0
@.str.7 = [45 x i8] c"Command execution timed out: %ld to %ld: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca %struct.timeval
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = icmp slt i32 %0, 3
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %11)
br label %13
13: ; preds = %10, %2
%14 = tail call i32 @open_master_pty(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @open_master_pty(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 (...) @fork()
switch i32 %16, label %26 [
i32 -1, label %17
i32 0, label %23
]
17: ; preds = %13
%18 = load i32, i32* @errno
%19 = tail call i32 @strerror(i32 %18)
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i8*
%22 = tail call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %21)
br label %26
23: ; preds = %13
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = tail call i32 @run_command(i8** %24, i32 %14, i32 %15)
br label %26
26: ; preds = %17, %13, %23
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = tail call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = load i8*, i8** %27
%33 = load i32, i32* @errno
%34 = tail call i32 @strerror(i32 %33)
%35 = tail call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %32, i32 %34)
br label %36
36: ; preds = %31, %26
%37 = tail call i64 @time(i32* null)
%38 = bitcast i32* %5 to i8*
%39 = bitcast %struct.timeval* %6 to i8*
%40 = add nsw i64 %37, 30
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%43 = add nsw i32 %15, 1
br label %44
44: ; preds = %81, %36
%45 = phi i32 [ %14, %36 ], [ %75, %81 ]
%46 = call i32 @FD_ZERO(i32* %5)
%47 = call i32 @FD_SET(i32 %15, i32* %5)
%48 = call i64 @time(i32* null)
%49 = sub nsw i64 %40, %48
%50 = icmp sgt i64 %49, 0
%51 = select i1 %50, i64 %49, i64 0
store i64 %51, i64* %41
store i64 0, i64* %42
%52 = call i32 @select(i32 %43, i32* %5, i32* null, i32* null, %struct.timeval* %6)
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %60
54: ; preds = %44
%55 = load i32, i32* @errno
%56 = call i32 @strerror(i32 %55)
%57 = sext i32 %56 to i64
%58 = inttoptr i64 %57 to i8*
%59 = call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %58)
br label %73
60: ; preds = %44
%61 = icmp eq i32 %52, 0
br i1 %61, label %73, label %62
62: ; preds = %60
%63 = call i64 @FD_ISSET(i32 %15, i32* %5)
%64 = icmp eq i64 %63, 0
br i1 %64, label %73, label %65
65: ; preds = %62
%66 = call i32 @read(i32 %15, i8* %8, i32 1024)
%67 = icmp slt i32 %66, 1
br i1 %67, label %82, label %68
68: ; preds = %65
%69 = call i32 @fwrite(i8* %8, i32 1, i32 %66, i32* %29)
%70 = icmp eq i32 %45, -1
br i1 %70, label %73, label %71
71: ; preds = %68
%72 = call i32 @close(i32 %45)
br label %73
73: ; preds = %54, %68, %71, %62, %60
%74 = phi i32 [ %66, %71 ], [ %66, %68 ], [ %52, %62 ], [ 0, %60 ], [ %52, %54 ]
%75 = phi i32 [ -1, %71 ], [ -1, %68 ], [ %45, %62 ], [ %45, %60 ], [ %45, %54 ]
%76 = call i64 @time(i32* null)
%77 = icmp slt i64 %76, %40
br i1 %77, label %81, label %78
78: ; preds = %73
%79 = load i32, i32* @stderr
%80 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i64 %37, i64 %76, i32 %74)
br label %82
81: ; preds = %73
br label %44
82: ; preds = %65, %78
%83 = phi i32 [ %75, %78 ], [ %45, %65 ]
%84 = icmp eq i32 %83, -1
br i1 %84, label %87, label %85
85: ; preds = %82
%86 = call i32 @close(i32 %83)
br label %87
87: ; preds = %85, %82
%88 = call i32 @close(i32 %15)
%89 = call i32 @fclose(i32* %29)
%90 = call i32 @waitpid(i32 %16, i32* %3, i32 0)
%91 = call i32 @exit(i32 0)
unreachable
}