#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*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ gets(char *);
scalar_t__ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main1(int argc, char *argv[]) {
  pid_t pid;
  int fd1;
  int fd2;
  char mensajeEnv[256];
  char mensajeRec[256];
  if (fd1 = open("pipe1", O_WRONLY) < 0) {
    perror("ERROR OPEN FIFO 1\n");
    exit(1);
  }
  printf("COMIENZA PROC1////\n");
  if (fd2 = open("pipe2", O_RDONLY) < 0) {
    perror("ERROR OPEN FIFO 2\n");
    exit(1);
  }
  printf("COMIENZA PROC2////\n");
  pid = fork();
  switch (pid) {
  case 0:
    while (1) {
      read(fd2, mensajeRec, strlen(mensajeRec));
      printf("RCB:|%s|%d", mensajeRec, strlen(mensajeRec));
    }
    break;
  case -1:
    perror("ERROR AL CREAR EL FORK");
    exit(1);
    break;
  default:
    gets(mensajeEnv);
    mensajeEnv[strlen(mensajeEnv)] = '\0';
    printf("SND:|%s|%d", mensajeEnv, strlen(mensajeEnv));
    write(fd1, mensajeEnv, strlen(mensajeEnv) + 1);
    break;
  }
  close(fd1);
}


x86 assembly (clang, -O0):
<main1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
call   1090 <open@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x18(%rbp)
test   $0x1,%al
jne    11e6 <main1+0x46>
jmp    11fc <main1+0x5c>
lea    0xe19(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
lea    0xe13(%rip),%rdi
call   1090 <open@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x1c(%rbp)
test   $0x1,%al
jne    123e <main1+0x9e>
jmp    1254 <main1+0xb4>
lea    0xdee(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdeb(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x225(%rbp)
call   1050 <printf@plt>
mov    -0x225(%rbp),%al
call   10c0 <fork@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x224(%rbp)
sub    $0xffffffff,%eax
je     1312 <main1+0x172>
jmp    128d <main1+0xed>
mov    -0x224(%rbp),%eax
test   %eax,%eax
jne    1328 <main1+0x188>
jmp    12a0 <main1+0x100>
jmp    12a5 <main1+0x105>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x23c(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x238(%rbp)
lea    -0x220(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x23c(%rbp),%edi
mov    -0x238(%rbp),%rsi
mov    %eax,%edx
call   1070 <read@plt>
lea    -0x220(%rbp),%rax
mov    %rax,-0x230(%rbp)
lea    -0x220(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x230(%rbp),%rsi
mov    %eax,%edx
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12a5 <main1+0x105>
lea    0xd4c(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x120(%rbp),%rdi
call   1080 <gets@plt>
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rax
mov    %rax,-0x258(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x258(%rbp),%rsi
mov    %eax,%edx
lea    0xd08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24c(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x248(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24c(%rbp),%edi
mov    -0x248(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main1>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
lea    0xe34(%rip),%rdi
call   10a0 <open@plt>
test   %rax,%rax
js     12ce <main1+0x11e>
mov    %rax,%r14
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
lea    0xe20(%rip),%rdi
call   10a0 <open@plt>
test   %rax,%rax
js     12d7 <main1+0x127>
mov    %rax,%r15
lea    0xe61(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
je     128d <main1+0xdd>
cmp    $0xffffffff,%eax
je     12e0 <main1+0x130>
shr    $0x3f,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1090 <gets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xdfe(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <write@plt>
mov    %r14d,%edi
call   1070 <close@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
shr    $0x3f,%r15
mov    %rsp,%rbx
lea    0xd97(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1080 <read@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12a0 <main1+0xf0>
lea    0xd31(%rip),%rdi
jmp    12e7 <main1+0x137>
lea    0xd41(%rip),%rdi
jmp    12e7 <main1+0x137>
lea    0xd56(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"pipe1\00"
@O_WRONLY = global i32 0
@.str.1 = [19 x i8] c"ERROR OPEN FIFO 1\0A\00"
@.str.2 = [20 x i8] c"COMIENZA PROC1////\0A\00"
@.str.3 = [6 x i8] c"pipe2\00"
@O_RDONLY = global i32 0
@.str.4 = [19 x i8] c"ERROR OPEN FIFO 2\0A\00"
@.str.5 = [20 x i8] c"COMIENZA PROC2////\0A\00"
@.str.6 = [11 x i8] c"RCB:|%s|%d\00"
@.str.7 = [23 x i8] c"ERROR AL CREAR EL FORK\00"
@.str.8 = [11 x i8] c"SND:|%s|%d\00"
define i32 @main1(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca [256 x i8]
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @O_WRONLY
%12 = call i64 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp slt i64 %12, 0
%14 = zext i1 %13 to i32
store i32 %14, i32* %7
br i1 %13, label %15, label %18
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @O_RDONLY
%21 = call i64 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = icmp slt i64 %21, 0
%23 = zext i1 %22 to i32
store i32 %23, i32* %8
br i1 %22, label %24, label %27
24: ; preds = %18
%25 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %18
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%29 = call i32 (...) @fork()
store i32 %29, i32* %6
%30 = load i32, i32* %6
switch i32 %30, label %45 [
i32 0, label %31
i32 -1, label %42
]
31: ; preds = %27
br label %32
32: ; preds = %31, %32
%33 = load i32, i32* %8
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = call i32 @read(i32 %33, i8* %34, i32 %36)
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %38, i32 %40)
br label %32
42: ; preds = %27
%43 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %27
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%47 = call i32 @gets(i8* %46)
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %50
store i8 0, i8* %51
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%54 = call i32 @strlen(i8* %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* %52, i32 %54)
%56 = load i32, i32* %7
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%59 = call i32 @strlen(i8* %58)
%60 = add nsw i32 %59, 1
%61 = call i32 @write(i32 %56, i8* %57, i32 %60)
br label %62
62: ; preds = %45
%63 = load i32, i32* %7
%64 = call i32 @close(i32 %63)
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [6 x i8] c"pipe1\00"
@O_WRONLY = global i32 0
@.str.1 = [19 x i8] c"ERROR OPEN FIFO 1\0A\00"
@.str.3 = [6 x i8] c"pipe2\00"
@O_RDONLY = global i32 0
@.str.4 = [19 x i8] c"ERROR OPEN FIFO 2\0A\00"
@.str.6 = [11 x i8] c"RCB:|%s|%d\00"
@.str.7 = [23 x i8] c"ERROR AL CREAR EL FORK\00"
@.str.8 = [11 x i8] c"SND:|%s|%d\00"
@str = [19 x i8] c"COMIENZA PROC1////\00"
@str.9 = [19 x i8] c"COMIENZA PROC2////\00"
define i32 @main1(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @O_WRONLY
%8 = tail call i64 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp slt i64 %8, 0
%10 = lshr i64 %8, 63
%11 = trunc i64 %10 to i32
br i1 %9, label %12, label %15
12: ; preds = %2
%13 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%17 = load i32, i32* @O_RDONLY
%18 = tail call i64 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = icmp slt i64 %18, 0
%20 = lshr i64 %18, 63
%21 = trunc i64 %20 to i32
br i1 %19, label %22, label %25
22: ; preds = %15
%23 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %15
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.9, i64 0, i64 0))
%27 = tail call i32 (...) @fork()
switch i32 %27, label %36 [
i32 0, label %28
i32 -1, label %33
]
28: ; preds = %25, %28
%29 = call i32 @strlen(i8* %6)
%30 = call i32 @read(i32 %21, i8* %6, i32 %29)
%31 = call i32 @strlen(i8* %6)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %6, i32 %31)
br label %28
33: ; preds = %25
%34 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %25
%37 = call i32 @gets(i8* %5)
%38 = call i32 @strlen(i8* %5)
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %39
store i8 0, i8* %40
%41 = call i32 @strlen(i8* %5)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* %5, i32 %41)
%43 = call i32 @strlen(i8* %5)
%44 = add nsw i32 %43, 1
%45 = call i32 @write(i32 %11, i8* %5, i32 %44)
%46 = call i32 @close(i32 %11)
ret i32 undef
}