#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 /*<<< orphan*/ pid;
typedef int /*<<< orphan*/ chorada;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, int *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ write(int, char *, int);
void peticion(const char *argv1, const char *argv2) {
  int fd, fd1, fd2, numbytes;
  int pid;
  char nombre[15];
  char buf[] = "peticion";
  char chorada[] =
      "Si tienes 1 manzana y yo tengo otra manzana...y las intercambiamos, "
      "ambos seguiremos teniendo 1 manzana.Pero...si tu tienes 1 idea y yo "
      "tengo otra idea...y las intercambiamos, ambos tendremos 2 ideas.\n";
  if ((fd1 = open(argv1, O_RDONLY)) < 0) {
    perror("Error en open_1\n");
    exit(EXIT_FAILURE);
  }
  if ((fd2 = open(argv2, O_WRONLY)) < 0) {
    perror("Error en open_2\n");
    exit(EXIT_FAILURE);
  }
  if (write(fd2, buf, sizeof(buf)) < 0) {
    perror("Error en write_1\n");
    exit(EXIT_FAILURE);
  }
  printf("\nHemos abierto \n");
  if (read(fd1, &pid, sizeof(pid)) < 0) {
    perror("Error en read_1\n");
    exit(EXIT_FAILURE);
  }
  printf("\nHemos leido \n");
  printf("\n el numero de pid es %d\n", pid);
  sprintf(nombre, "/tmp/fifo.%d", pid);
  if (fd = open(nombre, O_RDWR) < 0) {
    perror("Error en open_3\n");
    exit(EXIT_FAILURE);
  }
  if (numbytes = write(fd, chorada, sizeof(chorada)) < 0) {
    perror("Error en write_2\n");
    exit(EXIT_FAILURE);
  }
  close(fd2);
  close(fd1);
  close(fd);
}


x86 assembly (clang, -O0):
<peticion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe56(%rip),%rax
mov    %rax,-0x3c(%rbp)
mov    0xe54(%rip),%al
mov    %al,-0x34(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xefb(%rip),%rsi
mov    $0xca,%edx
call   1070 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1207 <peticion+0x77>
lea    0xe15(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    123f <peticion+0xaf>
lea    0xdee(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x1c(%rbp),%edi
lea    -0x3c(%rbp),%rsi
mov    $0x9,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1274 <peticion+0xe4>
lea    0xdca(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
jge    12b7 <peticion+0x127>
lea    0xdaa(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x33(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xda4(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x33(%rbp),%rdi
mov    0x2cf4(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x14(%rbp)
test   $0x1,%al
jne    131a <peticion+0x18a>
jmp    1334 <peticion+0x1a4>
lea    0xd74(%rip),%rdi
call   1090 <perror@plt>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xca,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x20(%rbp)
test   $0x1,%al
jne    1367 <peticion+0x1d7>
jmp    1381 <peticion+0x1f1>
lea    0xd38(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<peticion>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
movabs $0x6e6f696369746570,%rax
69 6f 6e
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
lea    0xef1(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    $0xca,%edx
call   1080 <memcpy@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
mov    %rax,%r14
test   %r14d,%r14d
js     12e8 <peticion+0x148>
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1090 <open@plt>
mov    %rax,%r15
test   %r15d,%r15d
js     12f1 <peticion+0x151>
lea    0x8(%rsp),%rsi
mov    %r15d,%edi
mov    $0x9,%edx
call   1040 <write@plt>
test   %rax,%rax
js     12fa <peticion+0x15a>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rsi
mov    %r14d,%edi
mov    $0x4,%edx
call   1070 <read@plt>
test   %rax,%rax
js     1303 <peticion+0x163>
lea    0xe47(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%ebx
lea    0xddd(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xde7(%rip),%rsi
lea    0x11(%rsp),%r12
mov    %r12,%rdi
mov    %ebx,%edx
call   10b0 <sprintf@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   1090 <open@plt>
test   %rax,%rax
js     130c <peticion+0x16c>
mov    %rax,%rbx
shr    $0x3f,%rbx
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0xca,%edx
call   1040 <write@plt>
test   %rax,%rax
js     1315 <peticion+0x175>
mov    %r15d,%edi
call   1060 <close@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    %ebx,%edi
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <close@plt>
lea    0xd1a(%rip),%rdi
jmp    131c <peticion+0x17c>
lea    0xd22(%rip),%rdi
jmp    131c <peticion+0x17c>
lea    0xd2a(%rip),%rdi
jmp    131c <peticion+0x17c>
lea    0xd33(%rip),%rdi
jmp    131c <peticion+0x17c>
lea    0xd62(%rip),%rdi
jmp    131c <peticion+0x17c>
lea    0xd6a(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@__const.peticion.buf = [9 x i8] c"peticion\00"
@__const.peticion.chorada = [202 x i8] c"Si tienes 1 manzana y yo tengo otra manzana...y las intercambiamos, ambos seguiremos teniendo 1 manzana.Pero...si tu tienes 1 idea y yo tengo otra idea...y las intercambiamos, ambos tendremos 2 ideas.\0A\00"
@O_RDONLY = global i32 0
@.str = [17 x i8] c"Error en open_1\0A\00"
@EXIT_FAILURE = global i32 0
@O_WRONLY = global i32 0
@.str.1 = [17 x i8] c"Error en open_2\0A\00"
@.str.2 = [18 x i8] c"Error en write_1\0A\00"
@.str.3 = [17 x i8] c"\0AHemos abierto \0A\00"
@.str.4 = [17 x i8] c"Error en read_1\0A\00"
@.str.5 = [15 x i8] c"\0AHemos leido \0A\00"
@.str.6 = [26 x i8] c"\0A el numero de pid es %d\0A\00"
@.str.7 = [13 x i8] c"/tmp/fifo.%d\00"
@O_RDWR = global i32 0
@.str.8 = [17 x i8] c"Error en open_3\0A\00"
@.str.9 = [18 x i8] c"Error en write_2\0A\00"
define void @peticion(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [15 x i8]
%11 = alloca [9 x i8]
%12 = alloca [202 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%13 = bitcast [9 x i8]* %11 to i8*
%14 = bitcast [202 x i8]* %12 to i8*
%15 = load i8*, i8** %3
%16 = load i32, i32* @O_RDONLY
%17 = call i64 @open(i8* %15, i32 %16)
%18 = trunc i64 %17 to i32
store i32 %18, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
%25 = load i8*, i8** %4
%26 = load i32, i32* @O_WRONLY
%27 = call i64 @open(i8* %25, i32 %26)
%28 = trunc i64 %27 to i32
store i32 %28, i32* %7
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %24
%35 = load i32, i32* %7
%36 = getelementptr inbounds [9 x i8], [9 x i8]* %11, i64 0, i64 0
%37 = call i64 @write(i32 %35, i8* %36, i32 9)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %34
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%45 = load i32, i32* %6
%46 = call i64 @read(i32 %45, i32* %9, i32 4)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %43
%49 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %43
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%54 = load i32, i32* %9
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %54)
%56 = getelementptr inbounds [15 x i8], [15 x i8]* %10, i64 0, i64 0
%57 = load i32, i32* %9
%58 = call i32 @sprintf(i8* %56, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %57)
%59 = getelementptr inbounds [15 x i8], [15 x i8]* %10, i64 0, i64 0
%60 = load i32, i32* @O_RDWR
%61 = call i64 @open(i8* %59, i32 %60)
%62 = icmp slt i64 %61, 0
%63 = zext i1 %62 to i32
store i32 %63, i32* %5
br i1 %62, label %64, label %68
64: ; preds = %52
%65 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %52
%69 = load i32, i32* %5
%70 = getelementptr inbounds [202 x i8], [202 x i8]* %12, i64 0, i64 0
%71 = call i64 @write(i32 %69, i8* %70, i32 202)
%72 = icmp slt i64 %71, 0
%73 = zext i1 %72 to i32
store i32 %73, i32* %8
br i1 %72, label %74, label %78
74: ; preds = %68
%75 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %68
%79 = load i32, i32* %7
%80 = call i32 @close(i32 %79)
%81 = load i32, i32* %6
%82 = call i32 @close(i32 %81)
%83 = load i32, i32* %5
%84 = call i32 @close(i32 %83)
ret void
}

LLVM IR (-O2):
@__const.peticion.buf = [9 x i8] c"peticion\00"
@__const.peticion.chorada = [202 x i8] c"Si tienes 1 manzana y yo tengo otra manzana...y las intercambiamos, ambos seguiremos teniendo 1 manzana.Pero...si tu tienes 1 idea y yo tengo otra idea...y las intercambiamos, ambos tendremos 2 ideas.\0A\00"
@O_RDONLY = global i32 0
@.str = [17 x i8] c"Error en open_1\0A\00"
@EXIT_FAILURE = global i32 0
@O_WRONLY = global i32 0
@.str.1 = [17 x i8] c"Error en open_2\0A\00"
@.str.2 = [18 x i8] c"Error en write_1\0A\00"
@.str.4 = [17 x i8] c"Error en read_1\0A\00"
@.str.6 = [26 x i8] c"\0A el numero de pid es %d\0A\00"
@.str.7 = [13 x i8] c"/tmp/fifo.%d\00"
@O_RDWR = global i32 0
@.str.8 = [17 x i8] c"Error en open_3\0A\00"
@.str.9 = [18 x i8] c"Error en write_2\0A\00"
@str = [16 x i8] c"\0AHemos abierto \00"
@str.10 = [14 x i8] c"\0AHemos leido \00"
define void @peticion(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca i32
%4 = alloca [15 x i8]
%5 = alloca [9 x i8]
%6 = alloca [202 x i8]
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [202 x i8], [202 x i8]* %6, i64 0, i64 0
%11 = load i32, i32* @O_RDONLY
%12 = tail call i64 @open(i8* %0, i32 %11)
%13 = trunc i64 %12 to i32
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i32, i32* @O_WRONLY
%21 = tail call i64 @open(i8* %1, i32 %20)
%22 = trunc i64 %21 to i32
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %19
%29 = call i64 @write(i32 %22, i8* %9, i32 9)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = tail call i32 @exit(i32 %33)
unreachable
35: ; preds = %28
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%37 = call i64 @read(i32 %13, i32* %3, i32 4)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = tail call i32 @exit(i32 %41)
unreachable
43: ; preds = %35
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.10, i64 0, i64 0))
%45 = load i32, i32* %3
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %45)
%47 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %45)
%48 = load i32, i32* @O_RDWR
%49 = call i64 @open(i8* %8, i32 %48)
%50 = icmp slt i64 %49, 0
%51 = lshr i64 %49, 63
%52 = trunc i64 %51 to i32
br i1 %50, label %53, label %57
53: ; preds = %43
%54 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
%56 = tail call i32 @exit(i32 %55)
unreachable
57: ; preds = %43
%58 = call i64 @write(i32 %52, i8* %10, i32 202)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %57
%61 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = tail call i32 @exit(i32 %62)
unreachable
64: ; preds = %57
%65 = tail call i32 @close(i32 %22)
%66 = tail call i32 @close(i32 %13)
%67 = tail call i32 @close(i32 %52)
ret void
}