#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 stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_CREAT;
int O_NONBLOCK;
int O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ S_ISCHR(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISFIFO(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int execvp(char *const, char *const *);
int fcntl(int /*<<< orphan*/, int /*<<< orphan*/, ...);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *const, ...);
int open(char *const, int, ...);
scalar_t__ stat(char *const, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ strlen(char *const);
int main(int argc, char *const argv[]) {
  if (argc < 4) {
    fprintf(stderr,
            "%s [input pipe]|\"\" [output pipe]|\"\" [program name] "
            "(arguments...)\n",
            argv[0]);
    return 1;
  }
  struct stat test_type;
  int current_state = 0;
  if (strlen(argv[1])) {
    if (stat(argv[1], &test_type) < 0) {
      fprintf(stderr, "%s: can't access input file '%s' (%s)\n", argv[0],
              argv[1], strerror(errno));
      return 1;
    }
    if (!S_ISFIFO(test_type.st_mode) && !S_ISCHR(test_type.st_mode)) {
      fprintf(stderr, "%s: input file '%s' is not a pipe or character device\n",
              argv[0], argv[1]);
      return 1;
    }
    int input_file = open(argv[1], O_RDONLY | O_NONBLOCK);
    if (input_file < 0) {
      fprintf(stderr, "%s: can't open input file '%s' (%s)\n", argv[0], argv[1],
              strerror(errno));
      return 1;
    }
    if (dup2(input_file, STDIN_FILENO) < 0) {
      fprintf(stderr, "%s: can't duplicate input descriptor (%s)\n", argv[0],
              strerror(errno));
      return 1;
    }
    close(input_file);
    if ((current_state = fcntl(STDIN_FILENO, F_GETFL)) < 0) {
      fprintf(stderr, "%s: can't set blocking mode for input descriptor (%s)\n",
              argv[0], strerror(errno));
      return 1;
    }
    if (fcntl(STDIN_FILENO, F_SETFL, current_state & ~O_NONBLOCK) < 0) {
      fprintf(stderr, "%s: can't set blocking mode for input descriptor (%s)\n",
              argv[0], strerror(errno));
      return 1;
    }
  }
  if (strlen(argv[2])) {
    if (stat(argv[2], &test_type) == 0 && !S_ISFIFO(test_type.st_mode) &&
        !S_ISCHR(test_type.st_mode) && !S_ISREG(test_type.st_mode)) {
      fprintf(stderr, "%s: output file '%s' is not a writable file type\n",
              argv[0], argv[2]);
      return 1;
    }
    int output_file = open(argv[2], O_CREAT | O_WRONLY, 0600);
    if (output_file < 0) {
      fprintf(stderr, "%s: can't open output file '%s' (%s)\n", argv[0],
              argv[2], strerror(errno));
      return 1;
    }
    if (dup2(output_file, STDOUT_FILENO) < 0) {
      fprintf(stderr, "%s: can't duplicate output descriptor (%s)\n", argv[0],
              strerror(errno));
      return 1;
    }
    close(output_file);
  }
  int outcome = execvp(argv[3], argv + 3);
  fprintf(stderr, "%s: execution error '%s'\n", argv[0], strerror(errno));
  return outcome;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    120d <main+0x4d>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16ef <main+0x52f>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     14db <main+0x31b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
jge    129f <main+0xdf>
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    %rax,%r8
lea    0xdb7(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16ef <main+0x52f>
mov    -0x18(%rbp),%edi
call   1050 <S_ISFIFO@plt>
cmp    $0x0,%eax
jne    12f3 <main+0x133>
mov    -0x18(%rbp),%edi
call   10b0 <S_ISCHR@plt>
cmp    $0x0,%eax
jne    12f3 <main+0x133>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16ef <main+0x52f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2cce(%rip),%rax
mov    (%rax),%esi
mov    0x2ccd(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    137a <main+0x1ba>
mov    0x2c98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    %rax,%r8
lea    0xd3a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16ef <main+0x52f>
mov    -0x20(%rbp),%edi
mov    0x2c1c(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
cmp    $0x0,%rax
jge    13de <main+0x21e>
mov    0x2c24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
mov    0x2bfd(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xcfb(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16ef <main+0x52f>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
mov    0x2bb3(%rip),%rax
mov    (%rax),%edi
mov    0x2bb2(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1454 <main+0x294>
mov    0x2bae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x70(%rbp)
mov    0x2b87(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    %rax,%rcx
lea    0xcb0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16ef <main+0x52f>
mov    0x2b45(%rip),%rax
mov    (%rax),%edi
mov    0x2b54(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
mov    0x2b68(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%eax
jge    14d6 <main+0x316>
mov    0x2b32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x80(%rbp)
mov    0x2b08(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%rdx
mov    %rax,%rcx
lea    0xc2e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16ef <main+0x52f>
jmp    14db <main+0x31b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     1688 <main+0x4c8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
jne    1572 <main+0x3b2>
mov    -0x18(%rbp),%edi
call   1050 <S_ISFIFO@plt>
cmp    $0x0,%eax
jne    1572 <main+0x3b2>
mov    -0x18(%rbp),%edi
call   10b0 <S_ISCHR@plt>
cmp    $0x0,%eax
jne    1572 <main+0x3b2>
mov    -0x18(%rbp),%edi
call   10a0 <S_ISREG@plt>
cmp    $0x0,%eax
jne    1572 <main+0x3b2>
mov    0x2a79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xbc9(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16ef <main+0x52f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2a77(%rip),%rax
mov    (%rax),%esi
mov    0x2a06(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1610 <main+0x450>
mov    0x2a14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x98(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x90(%rbp)
mov    0x29d8(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rdx
mov    -0x90(%rbp),%rcx
mov    %rax,%r8
lea    0xb5d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16ef <main+0x52f>
mov    -0x24(%rbp),%edi
mov    0x29ce(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
cmp    $0x0,%rax
jge    1680 <main+0x4c0>
mov    0x298e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xa8(%rbp)
mov    0x2961(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0xac(%rbp),%edi
mov    -0xa8(%rbp),%rdx
mov    %rax,%rcx
lea    0xb13(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16ef <main+0x52f>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x18,%rsi
call   10d0 <execvp@plt>
mov    %eax,-0x28(%rbp)
mov    0x2919(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xbc(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xb8(%rbp)
mov    0x28ec(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rdx
mov    %rax,%rcx
lea    0xaca(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jg     11de <main+0x2e>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe2e(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    148d <main+0x2dd>
mov    0x8(%rbx),%rdi
cmpb   $0x0,(%rdi)
je     12a0 <main+0xf0>
mov    %rsp,%rsi
call   1080 <stat@plt>
test   %rax,%rax
js     1374 <main+0x1c4>
mov    (%rsp),%edi
call   1040 <S_ISFIFO@plt>
test   %eax,%eax
jne    1218 <main+0x68>
mov    (%rsp),%edi
call   10a0 <S_ISCHR@plt>
test   %eax,%eax
je     146f <main+0x2bf>
mov    0x8(%rbx),%rdi
mov    0x2dad(%rip),%rax
mov    0x2dae(%rip),%r14
mov    (%r14),%esi
or     (%rax),%esi
xor    %eax,%eax
call   10b0 <open@plt>
test   %eax,%eax
js     139b <main+0x1eb>
mov    %eax,%ebp
mov    0x2d59(%rip),%r15
mov    (%r15),%esi
mov    %eax,%edi
call   1050 <dup2@plt>
test   %rax,%rax
js     1421 <main+0x271>
mov    %ebp,%edi
call   1060 <close@plt>
mov    (%r15),%edi
mov    0x2d3d(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     13fe <main+0x24e>
mov    (%r15),%edi
mov    0x2d32(%rip),%rcx
mov    (%rcx),%esi
mov    (%r14),%ecx
not    %ecx
and    %ecx,%eax
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     13fe <main+0x24e>
mov    0x10(%rbx),%rdi
cmpb   $0x0,(%rdi)
je     132e <main+0x17e>
mov    %rsp,%rsi
call   1080 <stat@plt>
test   %rax,%rax
jne    12e2 <main+0x132>
mov    (%rsp),%edi
call   1040 <S_ISFIFO@plt>
test   %eax,%eax
jne    12e2 <main+0x132>
mov    (%rsp),%edi
call   10a0 <S_ISCHR@plt>
test   %eax,%eax
jne    12e2 <main+0x132>
mov    (%rsp),%edi
call   1090 <S_ISREG@plt>
test   %eax,%eax
je     149f <main+0x2ef>
mov    0x10(%rbx),%rdi
mov    0x2d0b(%rip),%rax
mov    0x2c9c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x180,%edx
xor    %eax,%eax
call   10b0 <open@plt>
test   %eax,%eax
js     13c2 <main+0x212>
mov    %eax,%ebp
mov    0x2cd3(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1050 <dup2@plt>
test   %rax,%rax
js     1444 <main+0x294>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0x18(%rbx),%rsi
mov    0x18(%rbx),%rdi
call   10c0 <execvp@plt>
mov    %eax,%ebp
mov    0x2c7c(%rip),%rax
mov    (%rax),%r14d
mov    (%rbx),%rbx
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xe4d(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1492 <main+0x2e2>
mov    0x2c45(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%r14
mov    0x8(%rbx),%rbx
mov    0x2c25(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xcaa(%rip),%rsi
jmp    13e7 <main+0x237>
mov    0x2c1e(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%r14
mov    0x8(%rbx),%rbx
mov    0x2bfe(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xce1(%rip),%rsi
jmp    13e7 <main+0x237>
mov    0x2bf7(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%r14
mov    0x10(%rbx),%rbx
mov    0x2bd7(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd73(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    148d <main+0x2dd>
mov    0x2bbb(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2b9f(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xcd2(%rip),%rsi
jmp    1465 <main+0x2b5>
mov    0x2b98(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2b7c(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xc84(%rip),%rsi
jmp    1465 <main+0x2b5>
mov    0x2b75(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2b59(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd1b(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
jmp    1486 <main+0x2d6>
mov    0x2b4a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    0x8(%rbx),%rcx
lea    0xbe4(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b1a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    0x10(%rbx),%rcx
lea    0xc72(%rip),%rsi
jmp    1486 <main+0x2d6>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [67 x i8] c"%s [input pipe]|\22\22 [output pipe]|\22\22 [program name] (arguments...)\0A\00"
@.str.1 = [39 x i8] c"%s: can't access input file '%s' (%s)\0A\00"
@errno = global i32 0
@.str.2 = [55 x i8] c"%s: input file '%s' is not a pipe or character device\0A\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.3 = [37 x i8] c"%s: can't open input file '%s' (%s)\0A\00"
@STDIN_FILENO = global i32 0
@.str.4 = [43 x i8] c"%s: can't duplicate input descriptor (%s)\0A\00"
@F_GETFL = global i32 0
@.str.5 = [55 x i8] c"%s: can't set blocking mode for input descriptor (%s)\0A\00"
@F_SETFL = global i32 0
@.str.6 = [50 x i8] c"%s: output file '%s' is not a writable file type\0A\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str.7 = [38 x i8] c"%s: can't open output file '%s' (%s)\0A\00"
@STDOUT_FILENO = global i32 0
@.str.8 = [44 x i8] c"%s: can't duplicate output descriptor (%s)\0A\00"
@.str.9 = [26 x i8] c"%s: execution error '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %216
19: ; preds = %2
store i32 0, i32* %7
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @strlen(i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %128
25: ; preds = %19
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @stat(i8* %28, %struct.stat* %6)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %42
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %35, i8* %38, i8* %40)
store i32 1, i32* %3
br label %216
42: ; preds = %25
%43 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i32 @S_ISFIFO(i32 %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %61, label %47
47: ; preds = %42
%48 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 @S_ISCHR(i32 %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %61, label %52
52: ; preds = %47
%53 = load i32, i32* @stderr
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 0
%56 = load i8*, i8** %55
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %56, i8* %59)
store i32 1, i32* %3
br label %216
61: ; preds = %47, %42
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 1
%64 = load i8*, i8** %63
%65 = load i32, i32* @O_RDONLY
%66 = load i32, i32* @O_NONBLOCK
%67 = or i32 %65, %66
%68 = call i32 (i8*, i32, ...) @open(i8* %64, i32 %67)
store i32 %68, i32* %8
%69 = load i32, i32* %8
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %82
71: ; preds = %61
%72 = load i32, i32* @stderr
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 0
%75 = load i8*, i8** %74
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 1
%78 = load i8*, i8** %77
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %75, i8* %78, i8* %80)
store i32 1, i32* %3
br label %216
82: ; preds = %61
%83 = load i32, i32* %8
%84 = load i32, i32* @STDIN_FILENO
%85 = call i64 @dup2(i32 %83, i32 %84)
%86 = icmp slt i64 %85, 0
br i1 %86, label %87, label %95
87: ; preds = %82
%88 = load i32, i32* @stderr
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 0
%91 = load i8*, i8** %90
%92 = load i32, i32* @errno
%93 = call i8* @strerror(i32 %92)
%94 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %91, i8* %93)
store i32 1, i32* %3
br label %216
95: ; preds = %82
%96 = load i32, i32* %8
%97 = call i32 @close(i32 %96)
%98 = load i32, i32* @STDIN_FILENO
%99 = load i32, i32* @F_GETFL
%100 = call i32 (i32, i32, ...) @fcntl(i32 %98, i32 %99)
store i32 %100, i32* %7
%101 = icmp slt i32 %100, 0
br i1 %101, label %102, label %110
102: ; preds = %95
%103 = load i32, i32* @stderr
%104 = load i8**, i8*** %5
%105 = getelementptr inbounds i8*, i8** %104, i64 0
%106 = load i8*, i8** %105
%107 = load i32, i32* @errno
%108 = call i8* @strerror(i32 %107)
%109 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0), i8* %106, i8* %108)
store i32 1, i32* %3
br label %216
110: ; preds = %95
%111 = load i32, i32* @STDIN_FILENO
%112 = load i32, i32* @F_SETFL
%113 = load i32, i32* %7
%114 = load i32, i32* @O_NONBLOCK
%115 = xor i32 %114, -1
%116 = and i32 %113, %115
%117 = call i32 (i32, i32, ...) @fcntl(i32 %111, i32 %112, i32 %116)
%118 = icmp slt i32 %117, 0
br i1 %118, label %119, label %127
119: ; preds = %110
%120 = load i32, i32* @stderr
%121 = load i8**, i8*** %5
%122 = getelementptr inbounds i8*, i8** %121, i64 0
%123 = load i8*, i8** %122
%124 = load i32, i32* @errno
%125 = call i8* @strerror(i32 %124)
%126 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0), i8* %123, i8* %125)
store i32 1, i32* %3
br label %216
127: ; preds = %110
br label %128
128: ; preds = %127, %19
%129 = load i8**, i8*** %5
%130 = getelementptr inbounds i8*, i8** %129, i64 2
%131 = load i8*, i8** %130
%132 = call i64 @strlen(i8* %131)
%133 = icmp ne i64 %132, 0
br i1 %133, label %134, label %201
134: ; preds = %128
%135 = load i8**, i8*** %5
%136 = getelementptr inbounds i8*, i8** %135, i64 2
%137 = load i8*, i8** %136
%138 = call i64 @stat(i8* %137, %struct.stat* %6)
%139 = icmp eq i64 %138, 0
br i1 %139, label %140, label %164
140: ; preds = %134
%141 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%142 = load i32, i32* %141
%143 = call i32 @S_ISFIFO(i32 %142)
%144 = icmp ne i32 %143, 0
br i1 %144, label %164, label %145
145: ; preds = %140
%146 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%147 = load i32, i32* %146
%148 = call i32 @S_ISCHR(i32 %147)
%149 = icmp ne i32 %148, 0
br i1 %149, label %164, label %150
150: ; preds = %145
%151 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%152 = load i32, i32* %151
%153 = call i32 @S_ISREG(i32 %152)
%154 = icmp ne i32 %153, 0
br i1 %154, label %164, label %155
155: ; preds = %150
%156 = load i32, i32* @stderr
%157 = load i8**, i8*** %5
%158 = getelementptr inbounds i8*, i8** %157, i64 0
%159 = load i8*, i8** %158
%160 = load i8**, i8*** %5
%161 = getelementptr inbounds i8*, i8** %160, i64 2
%162 = load i8*, i8** %161
%163 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %156, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i8* %159, i8* %162)
store i32 1, i32* %3
br label %216
164: ; preds = %150, %145, %140, %134
%165 = load i8**, i8*** %5
%166 = getelementptr inbounds i8*, i8** %165, i64 2
%167 = load i8*, i8** %166
%168 = load i32, i32* @O_CREAT
%169 = load i32, i32* @O_WRONLY
%170 = or i32 %168, %169
%171 = call i32 (i8*, i32, ...) @open(i8* %167, i32 %170, i32 384)
store i32 %171, i32* %9
%172 = load i32, i32* %9
%173 = icmp slt i32 %172, 0
br i1 %173, label %174, label %185
174: ; preds = %164
%175 = load i32, i32* @stderr
%176 = load i8**, i8*** %5
%177 = getelementptr inbounds i8*, i8** %176, i64 0
%178 = load i8*, i8** %177
%179 = load i8**, i8*** %5
%180 = getelementptr inbounds i8*, i8** %179, i64 2
%181 = load i8*, i8** %180
%182 = load i32, i32* @errno
%183 = call i8* @strerror(i32 %182)
%184 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %175, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8* %178, i8* %181, i8* %183)
store i32 1, i32* %3
br label %216
185: ; preds = %164
%186 = load i32, i32* %9
%187 = load i32, i32* @STDOUT_FILENO
%188 = call i64 @dup2(i32 %186, i32 %187)
%189 = icmp slt i64 %188, 0
br i1 %189, label %190, label %198
190: ; preds = %185
%191 = load i32, i32* @stderr
%192 = load i8**, i8*** %5
%193 = getelementptr inbounds i8*, i8** %192, i64 0
%194 = load i8*, i8** %193
%195 = load i32, i32* @errno
%196 = call i8* @strerror(i32 %195)
%197 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %191, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.8, i64 0, i64 0), i8* %194, i8* %196)
store i32 1, i32* %3
br label %216
198: ; preds = %185
%199 = load i32, i32* %9
%200 = call i32 @close(i32 %199)
br label %201
201: ; preds = %198, %128
%202 = load i8**, i8*** %5
%203 = getelementptr inbounds i8*, i8** %202, i64 3
%204 = load i8*, i8** %203
%205 = load i8**, i8*** %5
%206 = getelementptr inbounds i8*, i8** %205, i64 3
%207 = call i32 @execvp(i8* %204, i8** %206)
store i32 %207, i32* %10
%208 = load i32, i32* @stderr
%209 = load i8**, i8*** %5
%210 = getelementptr inbounds i8*, i8** %209, i64 0
%211 = load i8*, i8** %210
%212 = load i32, i32* @errno
%213 = call i8* @strerror(i32 %212)
%214 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %208, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* %211, i8* %213)
%215 = load i32, i32* %10
store i32 %215, i32* %3
br label %216
216: ; preds = %201, %190, %174, %155, %119, %102, %87, %71, %52, %31, %13
%217 = load i32, i32* %3
ret i32 %217
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [67 x i8] c"%s [input pipe]|\22\22 [output pipe]|\22\22 [program name] (arguments...)\0A\00"
@.str.1 = [39 x i8] c"%s: can't access input file '%s' (%s)\0A\00"
@errno = global i32 0
@.str.2 = [55 x i8] c"%s: input file '%s' is not a pipe or character device\0A\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.3 = [37 x i8] c"%s: can't open input file '%s' (%s)\0A\00"
@STDIN_FILENO = global i32 0
@.str.4 = [43 x i8] c"%s: can't duplicate input descriptor (%s)\0A\00"
@F_GETFL = global i32 0
@.str.5 = [55 x i8] c"%s: can't set blocking mode for input descriptor (%s)\0A\00"
@F_SETFL = global i32 0
@.str.6 = [50 x i8] c"%s: output file '%s' is not a writable file type\0A\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str.7 = [38 x i8] c"%s: can't open output file '%s' (%s)\0A\00"
@STDOUT_FILENO = global i32 0
@.str.8 = [44 x i8] c"%s: can't duplicate output descriptor (%s)\0A\00"
@.str.9 = [26 x i8] c"%s: execution error '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = icmp slt i32 %0, 4
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %152
9: ; preds = %2
%10 = bitcast %struct.stat* %3 to i8*
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %89, label %15
15: ; preds = %9
%16 = call i64 @stat(i8* %12, %struct.stat* %3)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %1
%21 = load i8*, i8** %11
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21, i8* %23)
br label %150
25: ; preds = %15
%26 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @S_ISFIFO(i32 %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %25
%31 = load i32, i32* %26
%32 = call i32 @S_ISCHR(i32 %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %1
%37 = load i8*, i8** %11
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %36, i8* %37)
br label %150
39: ; preds = %30, %25
%40 = load i8*, i8** %11
%41 = load i32, i32* @O_RDONLY
%42 = load i32, i32* @O_NONBLOCK
%43 = or i32 %42, %41
%44 = call i32 (i8*, i32, ...) @open(i8* %40, i32 %43)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %39
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %1
%49 = load i8*, i8** %11
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %48, i8* %49, i8* %51)
br label %150
53: ; preds = %39
%54 = load i32, i32* @STDIN_FILENO
%55 = call i64 @dup2(i32 %44, i32 %54)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %1
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %59, i8* %61)
br label %150
63: ; preds = %53
%64 = call i32 @close(i32 %44)
%65 = load i32, i32* @STDIN_FILENO
%66 = load i32, i32* @F_GETFL
%67 = call i32 (i32, i32, ...) @fcntl(i32 %65, i32 %66)
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %75
69: ; preds = %63
%70 = load i32, i32* @stderr
%71 = load i8*, i8** %1
%72 = load i32, i32* @errno
%73 = call i8* @strerror(i32 %72)
%74 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0), i8* %71, i8* %73)
br label %150
75: ; preds = %63
%76 = load i32, i32* @STDIN_FILENO
%77 = load i32, i32* @F_SETFL
%78 = load i32, i32* @O_NONBLOCK
%79 = xor i32 %78, -1
%80 = and i32 %67, %79
%81 = call i32 (i32, i32, ...) @fcntl(i32 %76, i32 %77, i32 %80)
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %89
83: ; preds = %75
%84 = load i32, i32* @stderr
%85 = load i8*, i8** %1
%86 = load i32, i32* @errno
%87 = call i8* @strerror(i32 %86)
%88 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0), i8* %85, i8* %87)
br label %150
89: ; preds = %75, %9
%90 = getelementptr inbounds i8*, i8** %1, i64 2
%91 = load i8*, i8** %90
%92 = load i8, i8* %91
%93 = icmp eq i8 %92, 0
br i1 %93, label %141, label %94
94: ; preds = %89
%95 = call i64 @stat(i8* %91, %struct.stat* %3)
%96 = icmp eq i64 %95, 0
br i1 %96, label %97, label %115
97: ; preds = %94
%98 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%99 = load i32, i32* %98
%100 = call i32 @S_ISFIFO(i32 %99)
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %115
102: ; preds = %97
%103 = load i32, i32* %98
%104 = call i32 @S_ISCHR(i32 %103)
%105 = icmp eq i32 %104, 0
br i1 %105, label %106, label %115
106: ; preds = %102
%107 = load i32, i32* %98
%108 = call i32 @S_ISREG(i32 %107)
%109 = icmp eq i32 %108, 0
br i1 %109, label %110, label %115
110: ; preds = %106
%111 = load i32, i32* @stderr
%112 = load i8*, i8** %1
%113 = load i8*, i8** %90
%114 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i8* %112, i8* %113)
br label %150
115: ; preds = %106, %102, %97, %94
%116 = load i8*, i8** %90
%117 = load i32, i32* @O_CREAT
%118 = load i32, i32* @O_WRONLY
%119 = or i32 %118, %117
%120 = call i32 (i8*, i32, ...) @open(i8* %116, i32 %119, i32 384)
%121 = icmp slt i32 %120, 0
br i1 %121, label %122, label %129
122: ; preds = %115
%123 = load i32, i32* @stderr
%124 = load i8*, i8** %1
%125 = load i8*, i8** %90
%126 = load i32, i32* @errno
%127 = call i8* @strerror(i32 %126)
%128 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %123, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8* %124, i8* %125, i8* %127)
br label %150
129: ; preds = %115
%130 = load i32, i32* @STDOUT_FILENO
%131 = call i64 @dup2(i32 %120, i32 %130)
%132 = icmp slt i64 %131, 0
br i1 %132, label %133, label %139
133: ; preds = %129
%134 = load i32, i32* @stderr
%135 = load i8*, i8** %1
%136 = load i32, i32* @errno
%137 = call i8* @strerror(i32 %136)
%138 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %134, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.8, i64 0, i64 0), i8* %135, i8* %137)
br label %150
139: ; preds = %129
%140 = call i32 @close(i32 %120)
br label %141
141: ; preds = %139, %89
%142 = getelementptr inbounds i8*, i8** %1, i64 3
%143 = load i8*, i8** %142
%144 = call i32 @execvp(i8* %143, i8** %142)
%145 = load i32, i32* @stderr
%146 = load i8*, i8** %1
%147 = load i32, i32* @errno
%148 = call i8* @strerror(i32 %147)
%149 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %145, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* %146, i8* %148)
br label %150
150: ; preds = %122, %133, %46, %57, %69, %83, %141, %110, %34, %18
%151 = phi i32 [ 1, %18 ], [ %144, %141 ], [ 1, %110 ], [ 1, %34 ], [ 1, %83 ], [ 1, %69 ], [ 1, %57 ], [ 1, %46 ], [ 1, %133 ], [ 1, %122 ]
br label %152
152: ; preds = %150, %5
%153 = phi i32 [ 1, %5 ], [ %151, %150 ]
ret i32 %153
}