#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*/ buffer;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int write(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "Error in number of arguments\n");
    return EXIT_FAILURE;
  }
  int pipefd, n_read_char;
  char buffer[4096];
  if ((pipefd = open(argv[1], O_RDONLY)) == -1) {
    fprintf(stderr, "Error opening pipe %s", argv[1]);
    return EXIT_FAILURE;
  }
  while (1) {
    if ((n_read_char = (read(pipefd, buffer, sizeof(buffer)))) != 0) {
      if (n_read_char != write(STDIN_FILENO, buffer, n_read_char)) {
        fprintf(stderr, "Error in writing pipe %s in stdin", argv[1]);
        return EXIT_FAILURE;
      }
    } else {
      buffer[0] = '\0';
    }
    sleep(1);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119b <main+0x4b>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    128e <main+0x13e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11ed <main+0x9d>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    128e <main+0x13e>
jmp    11f2 <main+0xa2>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     1278 <main+0x128>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1024(%rbp)
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    -0x1024(%rbp),%eax
cmp    %ecx,%eax
je     1273 <main+0x123>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    128e <main+0x13e>
jmp    127f <main+0x12f>
movb   $0x0,-0x1020(%rbp)
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    11f2 <main+0xa2>
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
cmp    $0x2,%edi
jne    11d7 <main+0x87>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11f0 <main+0xa0>
mov    %eax,%ebp
mov    %rsp,%r12
mov    0x2e3c(%rip),%r13
lea    0xea1(%rip),%r14
jmp    11ae <main+0x5e>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,(%rsp)
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
test   %eax,%eax
je     11a0 <main+0x50>
mov    %eax,%ebx
mov    0x0(%r13),%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    %eax,%ebx
je     11a4 <main+0x54>
jmp    11f7 <main+0xa7>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    120e <main+0xbe>
lea    0xe27(%rip),%r14
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Error in number of arguments\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [22 x i8] c"Error opening pipe %s\00"
@STDIN_FILENO = global i32 0
@.str.2 = [34 x i8] c"Error in writing pipe %s in stdin\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %3
br label %54
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %6
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %29
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %3
br label %54
29: ; preds = %15
br label %30
30: ; preds = %29, %52
%31 = load i32, i32* %6
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%33 = call i32 @read(i32 %31, i8* %32, i32 4096)
store i32 %33, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %50
35: ; preds = %30
%36 = load i32, i32* %7
%37 = load i32, i32* @STDIN_FILENO
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%39 = load i32, i32* %7
%40 = call i32 @write(i32 %37, i8* %38, i32 %39)
%41 = icmp ne i32 %36, %40
br i1 %41, label %42, label %49
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
store i32 %48, i32* %3
br label %54
49: ; preds = %35
br label %52
50: ; preds = %30
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
store i8 0, i8* %51
br label %52
52: ; preds = %50, %49
%53 = call i32 @sleep(i32 1)
br label %30
54: ; preds = %42, %22, %11
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Error in number of arguments\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [22 x i8] c"Error opening pipe %s\00"
@STDIN_FILENO = global i32 0
@.str.2 = [34 x i8] c"Error in writing pipe %s in stdin\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
br label %32
9: ; preds = %2
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %26, label %16
16: ; preds = %9, %24
%17 = call i32 @read(i32 %14, i8* %10, i32 4096)
%18 = icmp eq i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = load i32, i32* @STDIN_FILENO
%21 = call i32 @write(i32 %20, i8* %10, i32 %17)
%22 = icmp eq i32 %17, %21
br i1 %22, label %24, label %26
23: ; preds = %16
store i8 0, i8* %10
br label %24
24: ; preds = %19, %23
%25 = tail call i32 @sleep(i32 1)
br label %16
26: ; preds = %19, %9
%27 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), %19 ]
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %11
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* %27, i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
br label %32
32: ; preds = %26, %5
%33 = phi i32 [ %8, %5 ], [ %31, %26 ]
ret i32 %33
}