#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int main(int argc, char *argv[]) {
  int fd[2];
  pipe(fd);
  pid_t pid = fork();
  if (pid == 0) {
    dup2(fd[0], STDIN_FILENO);
    close(fd[0]);
    execlp("grep", "grep", "main", NULL);
    exit(EXIT_FAILURE);
  } else if (pid > 0) {
    dup2(fd[1], STDOUT_FILENO);
    close(fd[1]);
    execlp("cat", "cat", "untitled.c", NULL);
    exit(EXIT_FAILURE);
  } else {
    perror("no se creo\n\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e6 <main+0x76>
mov    -0x18(%rbp),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
lea    0xe3b(%rip),%rsi
lea    0xe39(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1080 <execlp@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jle    1232 <main+0xc2>
mov    -0x14(%rbp),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
lea    0xdf9(%rip),%rsi
lea    0xdf6(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1080 <execlp@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xde0(%rip),%rdi
call   1060 <perror@plt>
jmp    1243 <main+0xd3>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     1197 <main+0x27>
jg     11c0 <main+0x50>
lea    0xe8b(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    (%rsp),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
lea    0xe49(%rip),%rdi
lea    0xe47(%rip),%rdx
jmp    11e9 <main+0x79>
mov    0x4(%rsp),%edi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
lea    0xe28(%rip),%rdi
lea    0xe25(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1080 <execlp@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@.str = [5 x i8] c"grep\00"
@.str.1 = [5 x i8] c"main\00"
@EXIT_FAILURE = global i32 0
@STDOUT_FILENO = global i32 0
@.str.2 = [4 x i8] c"cat\00"
@.str.3 = [11 x i8] c"untitled.c\00"
@.str.4 = [13 x i8] c"no se creo\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = call i64 (...) @fork()
store i64 %10, i64* %7
%11 = load i64, i64* %7
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %2
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%15 = load i32, i32* %14
%16 = load i32, i32* @STDIN_FILENO
%17 = call i32 @dup2(i32 %15, i32 %16)
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%19 = load i32, i32* %18
%20 = call i32 @close(i32 %19)
%21 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* null)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
%25 = load i64, i64* %7
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %24
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%29 = load i32, i32* %28
%30 = load i32, i32* @STDOUT_FILENO
%31 = call i32 @dup2(i32 %29, i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%33 = load i32, i32* %32
%34 = call i32 @close(i32 %33)
%35 = call i32 @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* null)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %24
%39 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %38
br label %41
41: ; preds = %40
ret i32 0
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str = [5 x i8] c"grep\00"
@.str.1 = [5 x i8] c"main\00"
@EXIT_FAILURE = global i32 0
@STDOUT_FILENO = global i32 0
@.str.2 = [4 x i8] c"cat\00"
@.str.3 = [11 x i8] c"untitled.c\00"
@.str.4 = [13 x i8] c"no se creo\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %2
%10 = load i32, i32* %5
%11 = load i32, i32* @STDIN_FILENO
%12 = call i32 @dup2(i32 %10, i32 %11)
%13 = load i32, i32* %5
%14 = call i32 @close(i32 %13)
%15 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* null)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = icmp sgt i64 %7, 0
br i1 %19, label %20, label %30
20: ; preds = %18
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%22 = load i32, i32* %21
%23 = load i32, i32* @STDOUT_FILENO
%24 = call i32 @dup2(i32 %22, i32 %23)
%25 = load i32, i32* %21
%26 = call i32 @close(i32 %25)
%27 = call i32 @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* null)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %18
%31 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}