#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 /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  char buffer[4096];
  int tuberia, c_read;
  if (argc != 2) {
    fprintf(stderr,
            "Incorrect number of arguments, use: consumidor <pipe_name>\n");
    _exit(EXIT_FAILURE);
  }
  if ((tuberia = open(argv[1], O_RDONLY)) == -1) {
    printf("Fail to open the pipe %s\n", argv[1]);
    _exit(EXIT_FAILURE);
  }
  while (1) {
    if ((c_read = read(tuberia, buffer, sizeof(buffer))) != 0) {
      write(1, buffer, c_read);
    } else {
      buffer[0] = '\0';
    }
    sleep(5);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b6 <main+0x46>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1014(%rbp)
cmp    $0xffffffff,%eax
jne    11fd <main+0x8d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe52(%rip),%rdi
call   1050 <printf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
jmp    1202 <main+0x92>
mov    -0x1014(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,-0x1018(%rbp)
cmp    $0x0,%eax
je     1244 <main+0xd4>
lea    -0x1010(%rbp),%rsi
mov    -0x1018(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
jmp    124b <main+0xdb>
movb   $0x0,-0x1010(%rbp)
mov    $0x5,%edi
call   1090 <sleep@plt>
jmp    1202 <main+0x92>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
cmp    $0x2,%edi
jne    11d2 <main+0x62>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     11e9 <main+0x79>
mov    %eax,%ebx
mov    %rsp,%r14
jmp    11ae <main+0x3e>
movb   $0x0,(%rsp)
mov    $0x5,%edi
call   1090 <sleep@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
test   %eax,%eax
je     11a0 <main+0x30>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    11a4 <main+0x34>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11f9 <main+0x89>
mov    0x8(%r14),%rsi
lea    0xe48(%rip),%rdi
call   1050 <printf@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [60 x i8] c"Incorrect number of arguments, use: consumidor <pipe_name>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"Fail to open the pipe %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca i32
%8 = alloca i32
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 %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @_exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %7
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %30
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @_exit(i32 %28)
unreachable
30: ; preds = %16
br label %31
31: ; preds = %30, %42
%32 = load i32, i32* %7
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 4096)
store i32 %34, i32* %8
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%38 = load i32, i32* %8
%39 = call i32 @write(i32 1, i8* %37, i32 %38)
br label %42
40: ; preds = %31
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
store i8 0, i8* %41
br label %42
42: ; preds = %40, %36
%43 = call i32 @sleep(i32 5)
br label %31
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [60 x i8] c"Incorrect number of arguments, use: consumidor <pipe_name>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"Fail to open the pipe %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @_exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = load i8*, i8** %12
%19 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @_exit(i32 %20)
unreachable
22: ; preds = %11, %28
%23 = call i32 @read(i32 %15, i8* %4, i32 4096)
%24 = icmp eq i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = call i32 @write(i32 1, i8* %4, i32 %23)
br label %28
27: ; preds = %22
store i8 0, i8* %4
br label %28
28: ; preds = %27, %25
%29 = tail call i32 @sleep(i32 5)
br label %22
}