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

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int write(int /*<<< orphan*/, char *, int);
void filtro(char *nombre) {
  int count;
  char buf[1024];
  while ((count = read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
    if (write(STDOUT_FILENO, buf, count) != count) {
      fprintf(stderr, "%s: no pudo leer del escribir en el tubo\n", nombre);
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<filtro>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jle    11be <filtro+0x7e>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
cmp    -0xc(%rbp),%eax
je     11b9 <filtro+0x79>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe56(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    114f <filtro+0xf>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filtro>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
mov    0x2e77(%rip),%r15
mov    %rsp,%rbx
mov    0x2e8d(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    11ba <filtro+0x7a>
mov    %eax,%ebp
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    %ebp,%eax
je     1170 <filtro+0x30>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"%s: no pudo leer del escribir en el tubo\0A\00"
define void @filtro(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [1024 x i8]
store i8* %0, i8** %2
br label %5
5: ; preds = %22, %1
%6 = load i32, i32* @STDIN_FILENO
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = call i32 @read(i32 %6, i8* %7, i32 1024)
store i32 %8, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %5
%11 = load i32, i32* @STDOUT_FILENO
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%13 = load i32, i32* %3
%14 = call i32 @write(i32 %11, i8* %12, i32 %13)
%15 = load i32, i32* %3
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %2
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %10
br label %5
23: ; preds = %5
ret void
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"%s: no pudo leer del escribir en el tubo\0A\00"
define void @filtro(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %8, %1
%5 = load i32, i32* @STDIN_FILENO
%6 = call i32 @read(i32 %5, i8* %3, i32 1024)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %4
%9 = load i32, i32* @STDOUT_FILENO
%10 = call i32 @write(i32 %9, i8* %3, i32 %6)
%11 = icmp eq i32 %10, %6
br i1 %11, label %4, label %12
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %0)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %4
ret void
}