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

/* Variables and functions */
scalar_t__ ECHILD;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ dup2(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ getpid();
int mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ proxy(int /*<<< orphan*/);
int read(int, int *, int);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int wait(int /*<<< orphan*/ *);
scalar_t__ write(int, int *, int);
int main(int argc, char **argv) {
  dup2(STDOUT_FILENO, STDERR_FILENO);
  int buf[1024];
  int dfifos, dfifoe, numbytes;
  char nombrefifoe[50], nombrefifos[50];
  setbuf(stdout, NULL);
  if (argc != 2) {
    printf("Uso: %s <nombre_fifo>\n", argv[0]);
    exit(1);
  }
  sprintf(nombrefifoe, "%se", argv[1]);
  sprintf(nombrefifos, "%ss", argv[1]);
  unlink(nombrefifoe);
  unlink(nombrefifos);
  int pid;
  umask(0);
  if ((mkfifo(nombrefifoe, 0777)) == -1) {
    perror("Error en mkfifo\n");
    exit(EXIT_FAILURE);
  }
  if ((mkfifo(nombrefifos, 0777)) == -1) {
    perror("Error en mkfifo\n");
    exit(EXIT_FAILURE);
  }
  printf("crear caucd salida\n");
  dfifos = open(nombrefifos, O_RDWR);
  dfifoe = open(nombrefifoe, O_RDWR);
  printf("creados\n");
  numbytes = read(dfifos, buf, sizeof(buf));
  while (numbytes > 0) {
    printf("Leyendo fifo salida\n");
    pid = fork();
    if (pid == 0) {
      proxy(getpid());
    } else if (pid > 0) {
      printf("padre pid es %d\n", pid);
      if (write(dfifoe, &pid, sizeof(int)) < 0) {
        perror("Error en write\n");
        exit(EXIT_FAILURE);
      }
    } else if (pid == -1) {
      perror("fallo en fork\n");
      exit(EXIT_FAILURE);
    }
    numbytes = read(dfifos, buf, sizeof(buf));
  }
  if (numbytes == -1) {
    perror("\nError en read\n");
    exit(EXIT_FAILURE);
  }
  pid = wait(NULL);
  while (pid > 0) {
    pid = wait(NULL);
  }
  if (pid == -1 && errno != ECHILD) {
    perror("fallo en wait");
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
call   1080 <dup2@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <setbuf@plt>
cmpl   $0x2,-0x8(%rbp)
je     126b <main+0x6b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    -0x1050(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd96(%rip),%rsi
call   10f0 <sprintf@plt>
lea    -0x1090(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd7f(%rip),%rsi
call   10f0 <sprintf@plt>
lea    -0x1050(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x1090(%rbp),%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
call   10c0 <umask@plt>
lea    -0x1050(%rbp),%rdi
mov    $0x1ff,%esi
call   10b0 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    12f4 <main+0xf4>
lea    0xd3e(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    -0x1090(%rbp),%rdi
mov    $0x1ff,%esi
call   10b0 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    1328 <main+0x128>
lea    0xd0a(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    0xd01(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x1090(%rbp),%rdi
mov    0x2c9c(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x1014(%rbp)
lea    -0x1050(%rbp),%rdi
mov    0x2c81(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x1018(%rbp)
lea    0xcd1(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x1014(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   10a0 <read@plt>
mov    %eax,-0x101c(%rbp)
cmpl   $0x0,-0x101c(%rbp)
jle    1493 <main+0x293>
lea    0xca2(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0x0,%al
call   1120 <fork@plt>
mov    %eax,-0x1094(%rbp)
cmpl   $0x0,-0x1094(%rbp)
jne    13df <main+0x1df>
mov    $0x0,%al
call   1060 <getpid@plt>
mov    %eax,%edi
call   1040 <proxy@plt>
jmp    1471 <main+0x271>
cmpl   $0x0,-0x1094(%rbp)
jle    1440 <main+0x240>
mov    -0x1094(%rbp),%esi
lea    0xc69(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x1018(%rbp),%edi
lea    -0x1094(%rbp),%rsi
mov    $0x4,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    143b <main+0x23b>
lea    0xc4b(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2b8c(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
jmp    146c <main+0x26c>
cmpl   $0xffffffff,-0x1094(%rbp)
jne    1467 <main+0x267>
lea    0xc2f(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2b60(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
jmp    146c <main+0x26c>
jmp    1471 <main+0x271>
mov    -0x1014(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   10a0 <read@plt>
mov    %eax,-0x101c(%rbp)
jmp    1397 <main+0x197>
cmpl   $0xffffffff,-0x101c(%rbp)
jne    14ba <main+0x2ba>
lea    0xbeb(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2b0d(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1110 <wait@plt>
mov    %eax,-0x1094(%rbp)
cmpl   $0x0,-0x1094(%rbp)
jle    14ea <main+0x2ea>
xor    %eax,%eax
mov    %eax,%edi
call   1110 <wait@plt>
mov    %eax,-0x1094(%rbp)
jmp    14c9 <main+0x2c9>
cmpl   $0xffffffff,-0x1094(%rbp)
jne    152b <main+0x32b>
mov    0x2ad2(%rip),%rax
mov    (%rax),%rax
mov    0x2aa8(%rip),%rcx
cmp    (%rcx),%rax
je     152b <main+0x32b>
lea    0xb8a(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2a9c(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2a76(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1098,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
call   1090 <dup2@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1080 <setbuf@plt>
cmp    $0x2,%ebp
jne    12dd <main+0xcd>
mov    0x8(%rbx),%rdx
lea    0xdb6(%rip),%rsi
lea    0x50(%rsp),%rbp
mov    %rbp,%rdi
call   1100 <sprintf@plt>
mov    0x8(%rbx),%rdx
lea    0xda2(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1100 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
call   10d0 <umask@plt>
mov    %rbp,%rdi
mov    $0x1ff,%esi
call   10c0 <mkfifo@plt>
cmp    $0xffffffff,%eax
je     12c3 <main+0xb3>
lea    0x10(%rsp),%rdi
mov    $0x1ff,%esi
call   10c0 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    12f8 <main+0xe8>
lea    0xd55(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    (%rbx),%rsi
lea    0xd19(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xd7f(%rip),%rdi
call   1040 <puts@plt>
mov    0x2cd5(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0x10(%rsp),%rdi
call   10e0 <open@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%esi
lea    0x50(%rsp),%rdi
call   10e0 <open@plt>
mov    %eax,%r14d
lea    0xd60(%rip),%rdi
call   1040 <puts@plt>
lea    0x90(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1000,%edx
call   10b0 <read@plt>
test   %eax,%eax
jle    13e1 <main+0x1d1>
lea    0xd40(%rip),%r15
lea    0x90(%rsp),%rbp
lea    0xcc8(%rip),%r12
lea    0xc(%rsp),%r13
jmp    1391 <main+0x181>
nop
xor    %eax,%eax
call   1070 <getpid@plt>
mov    %eax,%edi
call   1050 <proxy@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   10b0 <read@plt>
test   %eax,%eax
jle    13e1 <main+0x1d1>
mov    %r15,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1130 <fork@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
je     1370 <main+0x160>
jle    13d0 <main+0x1c0>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0x4,%edx
call   1060 <write@plt>
test   %rax,%rax
jns    137e <main+0x16e>
jmp    1434 <main+0x224>
nopl   (%rax)
cmp    $0xffffffff,%eax
jne    137e <main+0x16e>
lea    0xc75(%rip),%rdi
jmp    12ca <main+0xba>
cmp    $0xffffffff,%eax
jne    1400 <main+0x1f0>
lea    0xc73(%rip),%rdi
jmp    12ca <main+0xba>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edi,%edi
call   1120 <wait@plt>
test   %eax,%eax
jg     1400 <main+0x1f0>
cmp    $0xffffffff,%eax
jne    1426 <main+0x216>
mov    0x2bb9(%rip),%rax
mov    (%rax),%rax
mov    0x2b8f(%rip),%rcx
cmp    (%rcx),%rax
jne    1440 <main+0x230>
mov    0x2b7b(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
lea    0xc06(%rip),%rdi
jmp    12ca <main+0xba>
lea    0xc29(%rip),%rdi
jmp    12ca <main+0xba>

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@stdout = global i32 0
@.str = [23 x i8] c"Uso: %s <nombre_fifo>\0A\00"
@.str.1 = [4 x i8] c"%se\00"
@.str.2 = [4 x i8] c"%ss\00"
@.str.3 = [17 x i8] c"Error en mkfifo\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [20 x i8] c"crear caucd salida\0A\00"
@O_RDWR = global i32 0
@.str.5 = [9 x i8] c"creados\0A\00"
@.str.6 = [21 x i8] c"Leyendo fifo salida\0A\00"
@.str.7 = [17 x i8] c"padre pid es %d\0A\00"
@.str.8 = [16 x i8] c"Error en write\0A\00"
@.str.9 = [15 x i8] c"fallo en fork\0A\00"
@.str.10 = [16 x i8] c"\0AError en read\0A\00"
@errno = global i64 0
@ECHILD = global i64 0
@.str.11 = [14 x i8] c"fallo en wait\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [50 x i8]
%11 = alloca [50 x i8]
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @STDOUT_FILENO
%14 = load i32, i32* @STDERR_FILENO
%15 = call i32 @dup2(i32 %13, i32 %14)
%16 = load i32, i32* @stdout
%17 = call i32 @setbuf(i32 %16, i32* null)
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 2
br i1 %19, label %20, label %26
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%38 = call i32 @unlink(i8* %37)
%39 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%40 = call i32 @unlink(i8* %39)
%41 = call i32 @umask(i32 0)
%42 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%43 = call i32 @mkfifo(i8* %42, i32 511)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %49
45: ; preds = %26
%46 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %26
%50 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%51 = call i32 @mkfifo(i8* %50, i32 511)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %49
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%59 = getelementptr inbounds [50 x i8], [50 x i8]* %11, i64 0, i64 0
%60 = load i32, i32* @O_RDWR
%61 = call i32 @open(i8* %59, i32 %60)
store i32 %61, i32* %7
%62 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%63 = load i32, i32* @O_RDWR
%64 = call i32 @open(i8* %62, i32 %63)
store i32 %64, i32* %8
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%66 = load i32, i32* %7
%67 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%68 = call i32 @read(i32 %66, i32* %67, i32 4096)
store i32 %68, i32* %9
br label %69
69: ; preds = %103, %57
%70 = load i32, i32* %9
%71 = icmp sgt i32 %70, 0
br i1 %71, label %72, label %107
72: ; preds = %69
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%74 = call i32 (...) @fork()
store i32 %74, i32* %12
%75 = load i32, i32* %12
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %72
%78 = call i32 (...) @getpid()
%79 = call i32 @proxy(i32 %78)
br label %103
80: ; preds = %72
%81 = load i32, i32* %12
%82 = icmp sgt i32 %81, 0
br i1 %82, label %83, label %94
83: ; preds = %80
%84 = load i32, i32* %12
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 %84)
%86 = load i32, i32* %8
%87 = call i64 @write(i32 %86, i32* %12, i32 4)
%88 = icmp slt i64 %87, 0
br i1 %88, label %89, label %93
89: ; preds = %83
%90 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%91 = load i32, i32* @EXIT_FAILURE
%92 = call i32 @exit(i32 %91)
unreachable
93: ; preds = %83
br label %102
94: ; preds = %80
%95 = load i32, i32* %12
%96 = icmp eq i32 %95, -1
br i1 %96, label %97, label %101
97: ; preds = %94
%98 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%99 = load i32, i32* @EXIT_FAILURE
%100 = call i32 @exit(i32 %99)
unreachable
101: ; preds = %94
br label %102
102: ; preds = %101, %93
br label %103
103: ; preds = %102, %77
%104 = load i32, i32* %7
%105 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%106 = call i32 @read(i32 %104, i32* %105, i32 4096)
store i32 %106, i32* %9
br label %69
107: ; preds = %69
%108 = load i32, i32* %9
%109 = icmp eq i32 %108, -1
br i1 %109, label %110, label %114
110: ; preds = %107
%111 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
%112 = load i32, i32* @EXIT_FAILURE
%113 = call i32 @exit(i32 %112)
unreachable
114: ; preds = %107
%115 = call i32 @wait(i32* null)
store i32 %115, i32* %12
br label %116
116: ; preds = %119, %114
%117 = load i32, i32* %12
%118 = icmp sgt i32 %117, 0
br i1 %118, label %119, label %121
119: ; preds = %116
%120 = call i32 @wait(i32* null)
store i32 %120, i32* %12
br label %116
121: ; preds = %116
%122 = load i32, i32* %12
%123 = icmp eq i32 %122, -1
br i1 %123, label %124, label %132
124: ; preds = %121
%125 = load i64, i64* @errno
%126 = load i64, i64* @ECHILD
%127 = icmp ne i64 %125, %126
br i1 %127, label %128, label %132
128: ; preds = %124
%129 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
%130 = load i32, i32* @EXIT_FAILURE
%131 = call i32 @exit(i32 %130)
unreachable
132: ; preds = %124, %121
%133 = load i32, i32* @EXIT_SUCCESS
%134 = call i32 @exit(i32 %133)
unreachable
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@stdout = global i32 0
@.str = [23 x i8] c"Uso: %s <nombre_fifo>\0A\00"
@.str.1 = [4 x i8] c"%se\00"
@.str.2 = [4 x i8] c"%ss\00"
@.str.3 = [17 x i8] c"Error en mkfifo\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@.str.7 = [17 x i8] c"padre pid es %d\0A\00"
@.str.8 = [16 x i8] c"Error en write\0A\00"
@.str.9 = [15 x i8] c"fallo en fork\0A\00"
@.str.10 = [16 x i8] c"\0AError en read\0A\00"
@errno = global i64 0
@ECHILD = global i64 0
@.str.11 = [14 x i8] c"fallo en wait\00"
@EXIT_SUCCESS = global i32 0
@str = [19 x i8] c"crear caucd salida\00"
@str.12 = [8 x i8] c"creados\00"
@str.13 = [20 x i8] c"Leyendo fifo salida\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i32]
%4 = alloca [50 x i8]
%5 = alloca [50 x i8]
%6 = alloca i32
%7 = load i32, i32* @STDOUT_FILENO
%8 = load i32, i32* @STDERR_FILENO
%9 = tail call i32 @dup2(i32 %7, i32 %8)
%10 = bitcast [1024 x i32]* %3 to i8*
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%13 = load i32, i32* @stdout
%14 = tail call i32 @setbuf(i32 %13, i32* null)
%15 = icmp eq i32 %0, 2
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = load i8*, i8** %1
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %21
%25 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = call i32 @unlink(i8* %11)
%27 = call i32 @unlink(i8* %12)
%28 = bitcast i32* %6 to i8*
%29 = tail call i32 @umask(i32 0)
%30 = call i32 @mkfifo(i8* %11, i32 511)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %20
%33 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %20
%37 = call i32 @mkfifo(i8* %12, i32 511)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %36
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%45 = load i32, i32* @O_RDWR
%46 = call i32 @open(i8* %12, i32 %45)
%47 = load i32, i32* @O_RDWR
%48 = call i32 @open(i8* %11, i32 %47)
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.12, i64 0, i64 0))
%50 = getelementptr inbounds [1024 x i32], [1024 x i32]* %3, i64 0, i64 0
%51 = call i32 @read(i32 %46, i32* %50, i32 4096)
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %79
53: ; preds = %43, %76
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.13, i64 0, i64 0))
%55 = call i32 (...) @fork()
store i32 %55, i32* %6
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = call i32 (...) @getpid()
%59 = call i32 @proxy(i32 %58)
br label %76
60: ; preds = %53
%61 = icmp sgt i32 %55, 0
br i1 %61, label %62, label %70
62: ; preds = %60
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 %55)
%64 = call i64 @write(i32 %48, i32* %6, i32 4)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %76
66: ; preds = %62
%67 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%68 = load i32, i32* @EXIT_FAILURE
%69 = call i32 @exit(i32 %68)
unreachable
70: ; preds = %60
%71 = icmp eq i32 %55, -1
br i1 %71, label %72, label %76
72: ; preds = %70
%73 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %62, %70, %57
%77 = call i32 @read(i32 %46, i32* %50, i32 4096)
%78 = icmp sgt i32 %77, 0
br i1 %78, label %53, label %79
79: ; preds = %76, %43
%80 = phi i32 [ %51, %43 ], [ %77, %76 ]
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %86
82: ; preds = %79
%83 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
%84 = load i32, i32* @EXIT_FAILURE
%85 = call i32 @exit(i32 %84)
unreachable
86: ; preds = %79
%87 = call i32 @wait(i32* null)
%88 = icmp sgt i32 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %86, %89
%90 = call i32 @wait(i32* null)
%91 = icmp sgt i32 %90, 0
br i1 %91, label %89, label %92
92: ; preds = %89, %86
%93 = phi i32 [ %87, %86 ], [ %90, %89 ]
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %103
95: ; preds = %92
%96 = load i64, i64* @errno
%97 = load i64, i64* @ECHILD
%98 = icmp eq i64 %96, %97
br i1 %98, label %103, label %99
99: ; preds = %95
%100 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
%101 = load i32, i32* @EXIT_FAILURE
%102 = call i32 @exit(i32 %101)
unreachable
103: ; preds = %95, %92
%104 = load i32, i32* @EXIT_SUCCESS
%105 = call i32 @exit(i32 %104)
unreachable
}