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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int tuberia[2];
  pid_t pid;
  pipe(tuberia);
  pid = fork();
  if (pid == -1)
    perror("Error de pid.\n");
  else if (pid == 0) {
    close(tuberia[1]);
    dup2(tuberia[0], 0);
    close(tuberia[0]);
    execlp(argv[3], argv[3], argv[4], NULL);
    printf("HIJO.\n");
  } else {
    close(tuberia[0]);
    dup2(tuberia[1], 1);
    close(tuberia[1]);
    execlp(argv[1], argv[1], argv[2], NULL);
    printf("PADRE.\n");
  }
  waitpid(pid, NULL, 0);
  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   1060 <pipe@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11c4 <main+0x44>
lea    0xe46(%rip),%rdi
call   1080 <perror@plt>
jmp    1269 <main+0xe9>
cmpl   $0x0,-0x1c(%rbp)
jne    121a <main+0x9a>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1090 <execlp@plt>
lea    0xdff(%rip),%rdi
call   1040 <printf@plt>
jmp    1264 <main+0xe4>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1090 <execlp@plt>
lea    0xdb7(%rip),%rdi
call   1040 <printf@plt>
jmp    1269 <main+0xe9>
mov    -0x1c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <waitpid@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rsp,%rdi
call   1060 <pipe@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11de <main+0x5e>
cmp    $0xffffffff,%ebp
je     122b <main+0xab>
mov    (%rsp),%edi
call   1050 <close@plt>
mov    0x4(%rsp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1090 <execlp@plt>
lea    0xe33(%rip),%rdi
jmp    1212 <main+0x92>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
mov    (%rsp),%edi
xor    %esi,%esi
call   1040 <dup2@plt>
mov    (%rsp),%edi
call   1050 <close@plt>
mov    0x18(%rbx),%rdi
mov    0x20(%rbx),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1090 <execlp@plt>
lea    0xe04(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <waitpid@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdce(%rip),%rdi
call   1080 <perror@plt>
jmp    1217 <main+0x97>

LLVM IR (-O0):
@.str = [15 x i8] c"Error de pid.\0A\00"
@.str.1 = [7 x i8] c"HIJO.\0A\00"
@.str.2 = [8 x i8] c"PADRE.\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 i32
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 i32 (...) @fork()
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %61
15: ; preds = %2
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %39
18: ; preds = %15
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @close(i32 %20)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%23 = load i32, i32* %22
%24 = call i32 @dup2(i32 %23, i32 0)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%26 = load i32, i32* %25
%27 = call i32 @close(i32 %26)
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 3
%30 = load i8*, i8** %29
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 4
%36 = load i8*, i8** %35
%37 = call i32 @execlp(i8* %30, i8* %33, i8* %36, i32* null)
%38 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %60
39: ; preds = %15
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%41 = load i32, i32* %40
%42 = call i32 @close(i32 %41)
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%44 = load i32, i32* %43
%45 = call i32 @dup2(i32 %44, i32 1)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%47 = load i32, i32* %46
%48 = call i32 @close(i32 %47)
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = load i8*, i8** %56
%58 = call i32 @execlp(i8* %51, i8* %54, i8* %57, i32* null)
%59 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %60
60: ; preds = %39, %18
br label %61
61: ; preds = %60, %13
%62 = load i32, i32* %7
%63 = call i32 @waitpid(i32 %62, i32* null, i32 0)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Error de pid.\0A\00"
@str = [7 x i8] c"PADRE.\00"
@str.3 = [6 x i8] c"HIJO.\00"
define i32 @main(i32 %0, i8** nocapture %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 i32 (...) @fork()
switch i32 %7, label %24 [
i32 -1, label %8
i32 0, label %10
]
8: ; preds = %2
%9 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %38
10: ; preds = %2
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%12 = load i32, i32* %11
%13 = call i32 @close(i32 %12)
%14 = load i32, i32* %5
%15 = call i32 @dup2(i32 %14, i32 0)
%16 = load i32, i32* %5
%17 = call i32 @close(i32 %16)
%18 = getelementptr inbounds i8*, i8** %1, i64 3
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 4
%21 = load i8*, i8** %20
%22 = call i32 @execlp(i8* %19, i8* %19, i8* %21, i32* null)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.3, i64 0, i64 0))
br label %38
24: ; preds = %2
%25 = load i32, i32* %5
%26 = call i32 @close(i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32 @dup2(i32 %28, i32 1)
%30 = load i32, i32* %27
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8*, i8** %1, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @execlp(i8* %33, i8* %33, i8* %35, i32* null)
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %38
38: ; preds = %10, %24, %8
%39 = call i32 @waitpid(i32 %7, i32* null, i32 0)
ret i32 0
}