#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ R_OK;
int /*<<< orphan*/ STDIN_FILENO;
scalar_t__ access(char *, int /*<<< orphan*/);
int ceil(int /*<<< orphan*/);
int dup2(int, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ execvp(char *, char **);
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getpid();
int /*<<< orphan*/ log10(int);
char *malloc(int);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
char *strerror(int);
int strlen(char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("Usage: fi2sti <fifo_file> <program> [args]\n");
    return EXIT_SUCCESS;
  }
  if (access(argv[1], R_OK) != 0) {
    int err = errno;
    fprintf(stderr, "Cannot read from file \"%s\":\n%s\n", argv[1],
            strerror(err));
    return EXIT_FAILURE;
  }
  int mypid = getpid();
  size_t mypid_str_len = (size_t)((ceil(log10(mypid)) + 1) * sizeof(char));
  char mypid_str[mypid_str_len];
  if (sprintf(mypid_str, "%i", mypid) < 0)
    return EXIT_FAILURE;
  char tail_cmd_first[] = "tail --pid=";
  char tail_cmd_middle[] = " -f ";
  char *popen_cmd = malloc(strlen(tail_cmd_first) + mypid_str_len +
                           strlen(tail_cmd_middle) + strlen(argv[1]));
  if (popen_cmd == NULL) {
    fprintf(stderr, "memory allocation failed!\n");
    return EXIT_FAILURE;
  }
  strcat(popen_cmd, tail_cmd_first);
  strcat(popen_cmd + strlen(tail_cmd_first), mypid_str);
  strcat(popen_cmd + strlen(tail_cmd_first) + mypid_str_len - 1,
         tail_cmd_middle);
  strcat(popen_cmd + strlen(tail_cmd_first) + mypid_str_len - 1 +
             strlen(tail_cmd_middle),
         argv[1]);
  FILE *input_of_program = popen(popen_cmd, "r");
  if (input_of_program == NULL) {
    int err = errno;
    fprintf(stderr, "Cannot create subprocess \"tail\":\n%s\n", strerror(err));
    return EXIT_FAILURE;
  }
  int input_fd = fileno(input_of_program);
  if (input_fd == -1) {
    int err = errno;
    fprintf(stderr, "Cannot create file descriptor:\n%s\n", strerror(err));
    return EXIT_FAILURE;
  }
  if (dup2(input_fd, STDIN_FILENO) == -1) {
    int err = errno;
    fprintf(stderr,
            "Cannot change the stdin file descriptor to the newly generated "
            "file descriptor:\n%s\n",
            strerror(err));
    return EXIT_FAILURE;
  }
  execvp(argv[2], argv + 2);
  int err = errno;
  fprintf(stderr,
          "Cannot execute the specified program \"%s\" with arguments: [",
          argv[2]);
  for (int i = 3; i < argc; i++)
    fprintf(stderr, "\"%s\" ", argv[i]);
  fprintf(stderr, "] because of:\n%s\n", strerror(err));
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1230 <main+0x40>
lea    0xde6(%rip),%rdi
call   1070 <printf@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    16ad <main+0x4bd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d89(%rip),%rax
mov    (%rax),%esi
call   10b0 <access@plt>
cmp    $0x0,%rax
je     12a5 <main+0xb5>
mov    0x2d81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x78(%rbp)
mov    -0x14(%rbp),%edi
call   1110 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rdx
mov    %rax,%rcx
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    16ad <main+0x4bd>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   10d0 <log10@plt>
mov    %eax,%edi
call   1040 <ceil@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x88(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%edx
lea    0xd51(%rip),%rsi
call   1100 <sprintf@plt>
cmp    $0x0,%rax
jge    1322 <main+0x132>
mov    0x2cbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    16a6 <main+0x4b6>
mov    0xd26(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xd24(%rip),%eax
mov    %eax,-0x38(%rbp)
mov    0xd1f(%rip),%eax
mov    %eax,-0x45(%rbp)
mov    0xd1a(%rip),%al
mov    %al,-0x41(%rbp)
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
cltq
add    -0x20(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x45(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x98(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x90(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    13de <main+0x1ee>
mov    0x2c2a(%rip),%rax
mov    (%rax),%edi
lea    0xca1(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    16a6 <main+0x4b6>
mov    -0x50(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10f0 <strcat@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xb8(%rbp),%rdi
mov    -0x88(%rbp),%rsi
cltq
add    %rax,%rdi
call   10f0 <strcat@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xb0(%rbp),%rdi
cltq
add    %rax,%rdi
add    -0x20(%rbp),%rdi
add    $0xffffffffffffffff,%rdi
lea    -0x45(%rbp),%rsi
call   10f0 <strcat@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0xa8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0xa0(%rbp)
lea    -0x45(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xa0(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   10f0 <strcat@plt>
mov    -0x50(%rbp),%rdi
lea    0xbd4(%rip),%rsi
call   10c0 <popen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    150d <main+0x31d>
mov    0x2b16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2b12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xbc(%rbp)
mov    -0x5c(%rbp),%edi
call   1110 <strerror@plt>
mov    -0xbc(%rbp),%edi
mov    %rax,%rdx
lea    0xb8f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2ad4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    16a6 <main+0x4b6>
mov    -0x58(%rbp),%rdi
call   1090 <fileno@plt>
mov    %eax,-0x60(%rbp)
cmpl   $0xffffffff,-0x60(%rbp)
jne    1575 <main+0x385>
mov    0x2aae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2aaa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc0(%rbp)
mov    -0x64(%rbp),%edi
call   1110 <strerror@plt>
mov    -0xc0(%rbp),%edi
mov    %rax,%rdx
lea    0xb4c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2a6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    16a6 <main+0x4b6>
mov    -0x60(%rbp),%edi
mov    0x2a39(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
cmp    $0xffffffff,%eax
jne    15e1 <main+0x3f1>
mov    0x2a42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2a3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0x68(%rbp),%edi
call   1110 <strerror@plt>
mov    -0xc4(%rbp),%edi
mov    %rax,%rdx
lea    0xb03(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2a00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    16a6 <main+0x4b6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
call   10e0 <execvp@plt>
mov    0x29db(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x29d7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xaff(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x3,-0x70(%rbp)
mov    -0x70(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1665 <main+0x475>
mov    0x29a5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x70(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xb05(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    1628 <main+0x438>
mov    0x2974(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc8(%rbp)
mov    -0x6c(%rbp),%edi
call   1110 <strerror@plt>
mov    -0xc8(%rbp),%edi
mov    %rax,%rdx
lea    0xacf(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2936(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x2,%edi
jg     1220 <main+0x30>
lea    0xf34(%rip),%rdi
call   1030 <puts@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%eax
jmp    14f3 <main+0x303>
mov    %rsi,%r15
mov    %edi,%r14d
mov    0x8(%rsi),%rdi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
call   10b0 <access@plt>
test   %rax,%rax
je     127c <main+0x8c>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
mov    0x2d93(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r15),%r14
call   1110 <strerror@plt>
lea    0xda1(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
jmp    14f3 <main+0x303>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   10d0 <log10@plt>
mov    %eax,%edi
call   1050 <ceil@plt>
mov    %rsp,%r12
cltq
mov    %rsp,%r13
mov    %rax,-0x40(%rbp)
add    $0x10,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    0xd6c(%rip),%rsi
mov    %r13,%rdi
mov    %ebx,%edx
call   1100 <sprintf@plt>
test   %rax,%rax
js     14e7 <main+0x2f7>
mov    %r12,-0x38(%rbp)
mov    -0x40(%rbp),%rbx
add    $0x1,%rbx
movabs $0x702d2d206c696174,%rax
2d 2d 70
mov    %rax,-0x50(%rbp)
movl   $0x3d6469,-0x48(%rbp)
movb   $0x0,-0x2c(%rbp)
movl   $0x20662d20,-0x30(%rbp)
lea    -0x50(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rbx,-0x40(%rbp)
add    %eax,%ebx
lea    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
add    %eax,%ebx
mov    0x8(%r15),%rdi
call   1060 <strlen@plt>
add    %eax,%ebx
mov    %ebx,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1460 <main+0x270>
mov    %rax,%r12
lea    -0x50(%rbp),%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
call   10f0 <strcat@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
movslq %eax,%rdi
add    %r12,%rdi
mov    %r13,%rsi
call   10f0 <strcat@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
add    %r12,%rax
mov    -0x40(%rbp),%r13
lea    (%rax,%r13,1),%rdi
add    $0xffffffffffffffff,%rdi
lea    -0x30(%rbp),%rsi
call   10f0 <strcat@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
movslq %eax,%rbx
add    %r12,%rbx
add    %r13,%rbx
lea    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rdi
add    $0xffffffffffffffff,%rdi
mov    0x8(%r15),%rsi
call   10f0 <strcat@plt>
lea    0xca9(%rip),%rsi
mov    %r12,%rdi
call   10c0 <popen@plt>
test   %rax,%rax
je     1479 <main+0x289>
mov    %rax,%rdi
call   1090 <fileno@plt>
cmp    $0xffffffff,%eax
je     1499 <main+0x2a9>
mov    0x2be9(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1070 <dup2@plt>
cmp    $0xffffffff,%eax
je     14b9 <main+0x2c9>
lea    0x10(%r15),%rsi
mov    0x10(%r15),%rdi
call   10e0 <execvp@plt>
mov    0x2be3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2bdf(%rip),%r13
mov    0x0(%r13),%edi
mov    0x10(%r15),%rdx
lea    0xcdd(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
cmp    $0x4,%r14d
jb     144b <main+0x25b>
mov    %r14d,%ebx
mov    $0x3,%r12d
lea    0xcfc(%rip),%r14
nopl   (%rax)
mov    0x0(%r13),%edi
mov    (%r15,%r12,8),%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%rbx
jne    1430 <main+0x240>
mov    0x0(%r13),%ebx
mov    -0x40(%rbp),%edi
call   1110 <strerror@plt>
lea    0xcd1(%rip),%rsi
jmp    14d7 <main+0x2e7>
mov    0x2b79(%rip),%rax
mov    (%rax),%edi
lea    0xbc4(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    14e3 <main+0x2f3>
mov    0x2b58(%rip),%rax
mov    (%rax),%edi
mov    0x2b57(%rip),%rax
mov    (%rax),%ebx
call   1110 <strerror@plt>
lea    0xbba(%rip),%rsi
jmp    14d7 <main+0x2e7>
mov    0x2b38(%rip),%rax
mov    (%rax),%edi
mov    0x2b37(%rip),%rax
mov    (%rax),%ebx
call   1110 <strerror@plt>
lea    0xbbf(%rip),%rsi
jmp    14d7 <main+0x2e7>
mov    0x2b18(%rip),%rax
mov    (%rax),%edi
mov    0x2b17(%rip),%rax
mov    (%rax),%ebx
call   1110 <strerror@plt>
lea    0xbc2(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%r12
mov    0x2ae2(%rip),%rax
mov    (%rax),%eax
mov    %r12,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Usage: fi2sti <fifo_file> <program> [args]\0A\00"
@EXIT_SUCCESS = global i32 0
@R_OK = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"Cannot read from file \22%s\22:\0A%s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%i\00"
@__const.main.tail_cmd_first = [12 x i8] c"tail --pid=\00"
@__const.main.tail_cmd_middle = [5 x i8] c" -f \00"
@.str.3 = [27 x i8] c"memory allocation failed!\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [37 x i8] c"Cannot create subprocess \22tail\22:\0A%s\0A\00"
@.str.6 = [35 x i8] c"Cannot create file descriptor:\0A%s\0A\00"
@STDIN_FILENO = global i32 0
@.str.7 = [84 x i8] c"Cannot change the stdin file descriptor to the newly generated file descriptor:\0A%s\0A\00"
@.str.8 = [60 x i8] c"Cannot execute the specified program \22%s\22 with arguments: [\00"
@.str.9 = [6 x i8] c"\22%s\22 \00"
@.str.10 = [18 x i8] c"] because of:\0A%s\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 i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca [12 x i8]
%13 = alloca [5 x i8]
%14 = alloca i8*
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 3
br i1 %23, label %24, label %27
24: ; preds = %2
%25 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_SUCCESS
store i32 %26, i32* %3
br label %193
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = load i32, i32* @R_OK
%32 = call i64 @access(i8* %30, i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %27
%35 = load i32, i32* @errno
store i32 %35, i32* %6
%36 = load i32, i32* @stderr
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = load i32, i32* %6
%41 = call i8* @strerror(i32 %40)
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
store i32 %43, i32* %3
br label %193
44: ; preds = %27
%45 = call i32 (...) @getpid()
store i32 %45, i32* %7
%46 = load i32, i32* %7
%47 = call i32 @log10(i32 %46)
%48 = call i32 @ceil(i32 %47)
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = mul i64 %50, 1
store i64 %51, i64* %8
%52 = load i64, i64* %8
%53 = call i8* @llvm.stacksave()
store i8* %53, i8** %9
%54 = alloca i8, i64 %52
store i64 %52, i64* %10
%55 = load i32, i32* %7
%56 = call i64 @sprintf(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %55)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %44
%59 = load i32, i32* @EXIT_FAILURE
store i32 %59, i32* %3
store i32 1, i32* %11
br label %191
60: ; preds = %44
%61 = bitcast [12 x i8]* %12 to i8*
%62 = bitcast [5 x i8]* %13 to i8*
%63 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%64 = call i32 @strlen(i8* %63)
%65 = sext i32 %64 to i64
%66 = load i64, i64* %8
%67 = add i64 %65, %66
%68 = getelementptr inbounds [5 x i8], [5 x i8]* %13, i64 0, i64 0
%69 = call i32 @strlen(i8* %68)
%70 = sext i32 %69 to i64
%71 = add i64 %67, %70
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 1
%74 = load i8*, i8** %73
%75 = call i32 @strlen(i8* %74)
%76 = sext i32 %75 to i64
%77 = add i64 %71, %76
%78 = trunc i64 %77 to i32
%79 = call i8* @malloc(i32 %78)
store i8* %79, i8** %14
%80 = load i8*, i8** %14
%81 = icmp eq i8* %80, null
br i1 %81, label %82, label %86
82: ; preds = %60
%83 = load i32, i32* @stderr
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%85 = load i32, i32* @EXIT_FAILURE
store i32 %85, i32* %3
store i32 1, i32* %11
br label %191
86: ; preds = %60
%87 = load i8*, i8** %14
%88 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%89 = call i32 @strcat(i8* %87, i8* %88)
%90 = load i8*, i8** %14
%91 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%92 = call i32 @strlen(i8* %91)
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8, i8* %90, i64 %93
%95 = call i32 @strcat(i8* %94, i8* %54)
%96 = load i8*, i8** %14
%97 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%98 = call i32 @strlen(i8* %97)
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i8, i8* %96, i64 %99
%101 = load i64, i64* %8
%102 = getelementptr inbounds i8, i8* %100, i64 %101
%103 = getelementptr inbounds i8, i8* %102, i64 -1
%104 = getelementptr inbounds [5 x i8], [5 x i8]* %13, i64 0, i64 0
%105 = call i32 @strcat(i8* %103, i8* %104)
%106 = load i8*, i8** %14
%107 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%108 = call i32 @strlen(i8* %107)
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i8, i8* %106, i64 %109
%111 = load i64, i64* %8
%112 = getelementptr inbounds i8, i8* %110, i64 %111
%113 = getelementptr inbounds i8, i8* %112, i64 -1
%114 = getelementptr inbounds [5 x i8], [5 x i8]* %13, i64 0, i64 0
%115 = call i32 @strlen(i8* %114)
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i8, i8* %113, i64 %116
%118 = load i8**, i8*** %5
%119 = getelementptr inbounds i8*, i8** %118, i64 1
%120 = load i8*, i8** %119
%121 = call i32 @strcat(i8* %117, i8* %120)
%122 = load i8*, i8** %14
%123 = call i32* @popen(i8* %122, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %123, i32** %15
%124 = load i32*, i32** %15
%125 = icmp eq i32* %124, null
br i1 %125, label %126, label %133
126: ; preds = %86
%127 = load i32, i32* @errno
store i32 %127, i32* %16
%128 = load i32, i32* @stderr
%129 = load i32, i32* %16
%130 = call i8* @strerror(i32 %129)
%131 = call i32 (i32, i8*, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %130)
%132 = load i32, i32* @EXIT_FAILURE
store i32 %132, i32* %3
store i32 1, i32* %11
br label %191
133: ; preds = %86
%134 = load i32*, i32** %15
%135 = call i32 @fileno(i32* %134)
store i32 %135, i32* %17
%136 = load i32, i32* %17
%137 = icmp eq i32 %136, -1
br i1 %137, label %138, label %145
138: ; preds = %133
%139 = load i32, i32* @errno
store i32 %139, i32* %18
%140 = load i32, i32* @stderr
%141 = load i32, i32* %18
%142 = call i8* @strerror(i32 %141)
%143 = call i32 (i32, i8*, ...) @fprintf(i32 %140, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* %142)
%144 = load i32, i32* @EXIT_FAILURE
store i32 %144, i32* %3
store i32 1, i32* %11
br label %191
145: ; preds = %133
%146 = load i32, i32* %17
%147 = load i32, i32* @STDIN_FILENO
%148 = call i32 @dup2(i32 %146, i32 %147)
%149 = icmp eq i32 %148, -1
br i1 %149, label %150, label %157
150: ; preds = %145
%151 = load i32, i32* @errno
store i32 %151, i32* %19
%152 = load i32, i32* @stderr
%153 = load i32, i32* %19
%154 = call i8* @strerror(i32 %153)
%155 = call i32 (i32, i8*, ...) @fprintf(i32 %152, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.7, i64 0, i64 0), i8* %154)
%156 = load i32, i32* @EXIT_FAILURE
store i32 %156, i32* %3
store i32 1, i32* %11
br label %191
157: ; preds = %145
%158 = load i8**, i8*** %5
%159 = getelementptr inbounds i8*, i8** %158, i64 2
%160 = load i8*, i8** %159
%161 = load i8**, i8*** %5
%162 = getelementptr inbounds i8*, i8** %161, i64 2
%163 = call i32 @execvp(i8* %160, i8** %162)
%164 = load i32, i32* @errno
store i32 %164, i32* %20
%165 = load i32, i32* @stderr
%166 = load i8**, i8*** %5
%167 = getelementptr inbounds i8*, i8** %166, i64 2
%168 = load i8*, i8** %167
%169 = call i32 (i32, i8*, ...) @fprintf(i32 %165, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.8, i64 0, i64 0), i8* %168)
store i32 3, i32* %21
br label %170
170: ; preds = %182, %157
%171 = load i32, i32* %21
%172 = load i32, i32* %4
%173 = icmp slt i32 %171, %172
br i1 %173, label %174, label %185
174: ; preds = %170
%175 = load i32, i32* @stderr
%176 = load i8**, i8*** %5
%177 = load i32, i32* %21
%178 = sext i32 %177 to i64
%179 = getelementptr inbounds i8*, i8** %176, i64 %178
%180 = load i8*, i8** %179
%181 = call i32 (i32, i8*, ...) @fprintf(i32 %175, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8* %180)
br label %182
182: ; preds = %174
%183 = load i32, i32* %21
%184 = add nsw i32 %183, 1
store i32 %184, i32* %21
br label %170
185: ; preds = %170
%186 = load i32, i32* @stderr
%187 = load i32, i32* %20
%188 = call i8* @strerror(i32 %187)
%189 = call i32 (i32, i8*, ...) @fprintf(i32 %186, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* %188)
%190 = load i32, i32* @EXIT_FAILURE
store i32 %190, i32* %3
store i32 1, i32* %11
br label %191
191: ; preds = %185, %150, %138, %126, %82, %58
%192 = load i8*, i8** %9
br label %193
193: ; preds = %191, %34, %24
%194 = load i32, i32* %3
ret i32 %194
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@R_OK = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"Cannot read from file \22%s\22:\0A%s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%i\00"
@__const.main.tail_cmd_first = [12 x i8] c"tail --pid=\00"
@__const.main.tail_cmd_middle = [5 x i8] c" -f \00"
@.str.3 = [27 x i8] c"memory allocation failed!\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [37 x i8] c"Cannot create subprocess \22tail\22:\0A%s\0A\00"
@.str.6 = [35 x i8] c"Cannot create file descriptor:\0A%s\0A\00"
@STDIN_FILENO = global i32 0
@.str.7 = [84 x i8] c"Cannot change the stdin file descriptor to the newly generated file descriptor:\0A%s\0A\00"
@.str.8 = [60 x i8] c"Cannot execute the specified program \22%s\22 with arguments: [\00"
@.str.9 = [6 x i8] c"\22%s\22 \00"
@.str.10 = [18 x i8] c"] because of:\0A%s\0A\00"
@str = [43 x i8] c"Usage: fi2sti <fifo_file> <program> [args]\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [12 x i8]
%4 = alloca [5 x i8]
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_SUCCESS
br label %122
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @R_OK
%13 = tail call i64 @access(i8* %11, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %9
%16 = load i32, i32* @errno
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %10
%19 = tail call i8* @strerror(i32 %16)
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
br label %122
22: ; preds = %9
%23 = tail call i32 (...) @getpid()
%24 = tail call i32 @log10(i32 %23)
%25 = tail call i32 @ceil(i32 %24)
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = tail call i8* @llvm.stacksave()
%29 = alloca i8, i64 %27
%30 = call i64 @sprintf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %22
%33 = load i32, i32* @EXIT_FAILURE
br label %120
34: ; preds = %22
%35 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%37 = call i32 @strlen(i8* %35)
%38 = add i32 %37, %26
%39 = call i32 @strlen(i8* %36)
%40 = add i32 %38, %39
%41 = load i8*, i8** %10
%42 = call i32 @strlen(i8* %41)
%43 = add i32 %40, %42
%44 = call i8* @malloc(i32 %43)
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %49
46: ; preds = %34
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %118
49: ; preds = %34
%50 = call i32 @strcat(i8* %44, i8* %35)
%51 = call i32 @strlen(i8* %35)
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %44, i64 %52
%54 = call i32 @strcat(i8* %53, i8* %29)
%55 = call i32 @strlen(i8* %35)
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %44, i64 %56
%58 = getelementptr inbounds i8, i8* %57, i64 %27
%59 = getelementptr inbounds i8, i8* %58, i64 -1
%60 = call i32 @strcat(i8* %59, i8* %36)
%61 = call i32 @strlen(i8* %35)
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %44, i64 %62
%64 = getelementptr inbounds i8, i8* %63, i64 %27
%65 = getelementptr inbounds i8, i8* %64, i64 -1
%66 = call i32 @strlen(i8* %36)
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = load i8*, i8** %10
%70 = call i32 @strcat(i8* %68, i8* %69)
%71 = call i32* @popen(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%72 = icmp eq i32* %71, null
br i1 %72, label %73, label %78
73: ; preds = %49
%74 = load i32, i32* @errno
%75 = load i32, i32* @stderr
%76 = call i8* @strerror(i32 %74)
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %76)
br label %118
78: ; preds = %49
%79 = call i32 @fileno(i32* %71)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %86
81: ; preds = %78
%82 = load i32, i32* @errno
%83 = load i32, i32* @stderr
%84 = call i8* @strerror(i32 %82)
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* %84)
br label %118
86: ; preds = %78
%87 = load i32, i32* @STDIN_FILENO
%88 = call i32 @dup2(i32 %79, i32 %87)
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %95
90: ; preds = %86
%91 = load i32, i32* @errno
%92 = load i32, i32* @stderr
%93 = call i8* @strerror(i32 %91)
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.7, i64 0, i64 0), i8* %93)
br label %118
95: ; preds = %86
%96 = getelementptr inbounds i8*, i8** %1, i64 2
%97 = load i8*, i8** %96
%98 = call i32 @execvp(i8* %97, i8** %96)
%99 = load i32, i32* @errno
%100 = load i32, i32* @stderr
%101 = load i8*, i8** %96
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.8, i64 0, i64 0), i8* %101)
%103 = icmp ugt i32 %0, 3
br i1 %103, label %104, label %106
104: ; preds = %95
%105 = zext i32 %0 to i64
br label %110
106: ; preds = %110, %95
%107 = load i32, i32* @stderr
%108 = call i8* @strerror(i32 %99)
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* %108)
br label %118
110: ; preds = %104, %110
%111 = phi i64 [ 3, %104 ], [ %116, %110 ]
%112 = load i32, i32* @stderr
%113 = getelementptr inbounds i8*, i8** %1, i64 %111
%114 = load i8*, i8** %113
%115 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8* %114)
%116 = add nuw nsw i64 %111, 1
%117 = icmp eq i64 %116, %105
br i1 %117, label %106, label %110
118: ; preds = %73, %106, %90, %81, %46
%119 = load i32, i32* @EXIT_FAILURE
br label %120
120: ; preds = %118, %32
%121 = phi i32 [ %33, %32 ], [ %119, %118 ]
br label %122
122: ; preds = %120, %15, %6
%123 = phi i32 [ %8, %6 ], [ %21, %15 ], [ %121, %120 ]
ret i32 %123
}