#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;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ BUFSIZ;
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int write(int, char *, int);
int main() {
  int bytes_enviados, bytes_leidos, i, descriptor_archivo[2];
  char buffer[BUFSIZ + 1];
  pid_t pid;
  if (pipe(descriptor_archivo) == 0) {
    pid = fork();
    if (pid == -1) {
      perror("Error al ejecutar fork");
      exit(-1);
    }
    if (pid == 0) {
      for (i = 1; i < 27; i++) {
        memset(buffer, '\0', sizeof(buffer));
        bytes_leidos = read(descriptor_archivo[0], buffer, BUFSIZ);
        printf("El proceso hijo ha leído %d bytes y el contenido es: %s\n",
               bytes_leidos, buffer);
      }
      exit(0);
    } else {
      for (i = 65; i < 91; i++) {
        bytes_enviados = write(descriptor_archivo[1], (char *)&i, sizeof(char));
        printf("El proceso padre ha enviado por la tuberia %d bytes\n",
               bytes_enviados);
        sleep(1);
      }
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jne    12d5 <main+0x145>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    120f <main+0x7f>
lea    0xe00(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    127d <main+0xed>
movl   $0x1,-0x10(%rbp)
cmpl   $0x1b,-0x10(%rbp)
jge    1276 <main+0xe6>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%edi
mov    0x2d97(%rip),%rax
mov    (%rax),%edx
call   1070 <read@plt>
mov    -0x38(%rbp),%rdx
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1220 <main+0x90>
xor    %edi,%edi
call   1090 <exit@plt>
movl   $0x41,-0x10(%rbp)
cmpl   $0x5b,-0x10(%rbp)
jge    12cb <main+0x13b>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1284 <main+0xf4>
jmp    12d0 <main+0x140>
jmp    12d5 <main+0x145>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e38(%rip),%r12
mov    (%r12),%r14d
add    $0x1,%r14d
mov    %rsp,%r13
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    -0x34(%rbp),%rdi
call   1060 <pipe@plt>
test   %rax,%rax
jne    1281 <main+0xf1>
xor    %eax,%eax
call   10b0 <fork@plt>
cmp    $0xffffffff,%eax
je     1222 <main+0x92>
test   %eax,%eax
jne    1238 <main+0xa8>
mov    $0x1a,%ebx
lea    0xe28(%rip),%r15
nop
mov    %r13,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1050 <memset@plt>
mov    -0x34(%rbp),%edi
mov    (%r12),%edx
mov    %r13,%rsi
call   1070 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebx
jne    11f0 <main+0x60>
jmp    1281 <main+0xf1>
lea    0xdd7(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
movl   $0x41,-0x2c(%rbp)
mov    $0x42,%ebx
lea    -0x2c(%rbp),%r14
lea    0xe02(%rip),%r15
nop
mov    -0x30(%rbp),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebx,-0x2c(%rbp)
add    $0x1,%ebx
cmp    $0x5c,%ebx
jne    1250 <main+0xc0>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [23 x i8] c"Error al ejecutar fork\00"
@.str.1 = [58 x i8] c"El proceso hijo ha le\C3\ADdo %d bytes y el contenido es: %s\0A\00"
@.str.2 = [53 x i8] c"El proceso padre ha enviado por la tuberia %d bytes\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x i32]
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* @BUFSIZ
%10 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8, i64 %11
store i64 %11, i64* %7
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%15 = call i64 @pipe(i32* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %62
17: ; preds = %0
%18 = call i32 (...) @fork()
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %17
%25 = load i32, i32* %8
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %45
27: ; preds = %24
store i32 1, i32* %4
br label %28
28: ; preds = %40, %27
%29 = load i32, i32* %4
%30 = icmp slt i32 %29, 27
br i1 %30, label %31, label %43
31: ; preds = %28
%32 = trunc i64 %11 to i32
%33 = call i32 @memset(i8* %13, i8 signext 0, i32 %32)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%35 = load i32, i32* %34
%36 = load i32, i32* @BUFSIZ
%37 = call i32 @read(i32 %35, i8* %13, i32 %36)
store i32 %37, i32* %3
%38 = load i32, i32* %3
%39 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %38, i8* %13)
br label %40
40: ; preds = %31
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
br label %28
43: ; preds = %28
%44 = call i32 @exit(i32 0)
unreachable
45: ; preds = %24
store i32 65, i32* %4
br label %46
46: ; preds = %57, %45
%47 = load i32, i32* %4
%48 = icmp slt i32 %47, 91
br i1 %48, label %49, label %60
49: ; preds = %46
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%51 = load i32, i32* %50
%52 = bitcast i32* %4 to i8*
%53 = call i32 @write(i32 %51, i8* %52, i32 1)
store i32 %53, i32* %2
%54 = load i32, i32* %2
%55 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = call i32 @sleep(i32 1)
br label %57
57: ; preds = %49
%58 = load i32, i32* %4
%59 = add nsw i32 %58, 1
store i32 %59, i32* %4
br label %46
60: ; preds = %46
br label %61
61: ; preds = %60
br label %62
62: ; preds = %61, %0
%63 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [23 x i8] c"Error al ejecutar fork\00"
@.str.1 = [58 x i8] c"El proceso hijo ha le\C3\ADdo %d bytes y el contenido es: %s\0A\00"
@.str.2 = [53 x i8] c"El proceso padre ha enviado por la tuberia %d bytes\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [2 x i32]* %2 to i8*
%5 = load i32, i32* @BUFSIZ
%6 = add nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%10 = call i64 @pipe(i32* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %38
12: ; preds = %0
%13 = call i32 (...) @fork()
switch i32 %13, label %14 [
i32 -1, label %16
i32 0, label %19
]
14: ; preds = %12
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
store i32 65, i32* %1
br label %30
16: ; preds = %12
%17 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %12, %19
%20 = phi i32 [ %26, %19 ], [ 1, %12 ]
%21 = call i32 @memset(i8* %8, i8 signext 0, i32 %6)
%22 = load i32, i32* %9
%23 = load i32, i32* @BUFSIZ
%24 = call i32 @read(i32 %22, i8* %8, i32 %23)
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %24, i8* %8)
%26 = add nuw nsw i32 %20, 1
%27 = icmp eq i32 %26, 27
br i1 %27, label %28, label %19
28: ; preds = %19
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %14, %30
%31 = phi i32 [ 65, %14 ], [ %36, %30 ]
%32 = load i32, i32* %15
%33 = call i32 @write(i32 %32, i8* %3, i32 1)
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = call i32 @sleep(i32 1)
%36 = add nuw nsw i32 %31, 1
store i32 %36, i32* %1
%37 = icmp eq i32 %36, 91
br i1 %37, label %38, label %30
38: ; preds = %30, %0
%39 = call i32 @exit(i32 0)
unreachable
}