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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ perror_exit(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, char *, int);
scalar_t__ read(int, char *, int);
scalar_t__ strlen(char *);
scalar_t__ write(int, char *, int);
int main() {
  int pipes[2], child;
  if (pipe(pipes) < 0)
    perror_exit("pipe");
  child = fork();
  if (child == -1)
    perror_exit("fork");
  if (child != 0) {
    char buf[1024];
    close(pipes[1]);
    if (read(pipes[0], buf, 1024) < 0)
      perror_exit("leyendo datos");
    printf("caracteres de la frase \"%s\": %d\n", buf, (int)strlen(buf));
    close(pipes[0]);
  } else {
    close(pipes[0]);
    if (write(pipes[1], "sistemas es lo más", sizeof("sistemas es lo más")) < 0)
      perror("escribiendo datos");
    close(pipes[1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0x0,%rax
jge    11c1 <main+0x31>
lea    0xe44(%rip),%rdi
call   10a0 <perror_exit@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11e1 <main+0x51>
lea    0xe29(%rip),%rdi
call   10a0 <perror_exit@plt>
cmpl   $0x0,-0x10(%rbp)
je     1259 <main+0xc9>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
cmp    $0x0,%rax
jge    121d <main+0x8d>
lea    0xdf2(%rip),%rdi
call   10a0 <perror_exit@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x418(%rbp),%rsi
mov    %eax,%edx
lea    0xdd1(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
jmp    1293 <main+0x103>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%edi
lea    0xdce(%rip),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    128b <main+0xfb>
lea    0xdc7(%rip),%rdi
call   1090 <perror@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x410,%rsp
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
jns    11b3 <main+0x23>
lea    0xe52(%rip),%rdi
call   10a0 <perror_exit@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     1220 <main+0x90>
cmp    $0xffffffff,%eax
jne    11cf <main+0x3f>
lea    0xe3b(%rip),%rdi
call   10a0 <perror_exit@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
test   %rax,%rax
jns    11fc <main+0x6c>
lea    0xe13(%rip),%rdi
call   10a0 <perror_exit@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe08(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
jmp    1247 <main+0xb7>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0xc(%rsp),%edi
lea    0xe05(%rip),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
test   %rax,%rax
js     1257 <main+0xc7>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
ret
lea    0xdef(%rip),%rdi
call   1090 <perror@plt>
jmp    1243 <main+0xb3>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [14 x i8] c"leyendo datos\00"
@.str.3 = [33 x i8] c"caracteres de la frase \22%s\22: %d\0A\00"
@.str.4 = [20 x i8] c"sistemas es lo m\C3\A1s\00"
@.str.5 = [18 x i8] c"escribiendo datos\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca [1024 x i8]
store i32 0, i32* %1
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror_exit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = call i32 (...) @fork()
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @perror_exit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = load i32, i32* %3
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %39
19: ; preds = %16
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 @close(i32 %21)
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%26 = call i64 @read(i32 %24, i8* %25, i32 1024)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = call i32 @perror_exit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %19
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%33 = call i64 @strlen(i8* %32)
%34 = trunc i64 %33 to i32
%35 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %31, i32 %34)
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
br label %53
39: ; preds = %16
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%41 = load i32, i32* %40
%42 = call i32 @close(i32 %41)
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%44 = load i32, i32* %43
%45 = call i64 @write(i32 %44, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 20)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %39
%48 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %49
49: ; preds = %47, %39
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%51 = load i32, i32* %50
%52 = call i32 @close(i32 %51)
br label %53
53: ; preds = %49, %30
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [14 x i8] c"leyendo datos\00"
@.str.3 = [33 x i8] c"caracteres de la frase \22%s\22: %d\0A\00"
@.str.4 = [20 x i8] c"sistemas es lo m\C3\A1s\00"
@.str.5 = [18 x i8] c"escribiendo datos\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [1024 x i8]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%5 = call i64 @pipe(i32* %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror_exit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call i32 (...) @fork()
switch i32 %10, label %13 [
i32 -1, label %11
i32 0, label %29
]
11: ; preds = %9
%12 = call i32 @perror_exit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %9
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%16 = load i32, i32* %15
%17 = call i32 @close(i32 %16)
%18 = load i32, i32* %4
%19 = call i64 @read(i32 %18, i8* %14, i32 1024)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = call i32 @perror_exit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %13
%24 = call i64 @strlen(i8* %14)
%25 = trunc i64 %24 to i32
%26 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %14, i32 %25)
%27 = load i32, i32* %4
%28 = call i32 @close(i32 %27)
br label %41
29: ; preds = %9
%30 = load i32, i32* %4
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%33 = load i32, i32* %32
%34 = call i64 @write(i32 %33, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 20)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %36, %29
%39 = load i32, i32* %32
%40 = call i32 @close(i32 %39)
br label %41
41: ; preds = %38, %23
ret i32 0
}