#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 */
scalar_t__ ECHILD;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int atoi(char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ peticion(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("\nError. Argumentos clientes <nombre_fifo_escritura> "
           "<número_clientes>\n");
    exit(-1);
  }
  char fifoe[6];
  char fifos[6];
  sprintf(fifoe, "/tmp/fifo%s", argv[1]);
  sprintf(fifos, "/tmp/fifo%s", argv[2]);
  int NUM_HIJOS = atoi(argv[3]);
  int pid, i;
  for (i = 0; i < NUM_HIJOS; i++) {
    pid = fork();
    if (pid == 0) {
      printf("\nEstoy aqui1\n");
      peticion(fifoe, fifos);
      exit(EXIT_SUCCESS);
    } else if (pid == -1) {
      perror("fallo en fork");
      exit(EXIT_FAILURE);
    }
  }
  pid = wait(NULL);
  while (pid > 0) {
    pid = wait(NULL);
  }
  if (pid == -1 && errno != ECHILD) {
    perror("fallo en wait");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b6 <main+0x36>
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    -0x16(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe7f(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x1c(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe67(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1280 <main+0x100>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1244 <main+0xc4>
lea    0xe30(%rip),%rdi
call   1040 <printf@plt>
lea    -0x16(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1030 <peticion@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpl   $0xffffffff,-0x24(%rbp)
jne    1268 <main+0xe8>
lea    0xe0d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    126d <main+0xed>
jmp    1272 <main+0xf2>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11fd <main+0x7d>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <wait@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    12a7 <main+0x127>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <wait@plt>
mov    %eax,-0x24(%rbp)
jmp    128c <main+0x10c>
cmpl   $0xffffffff,-0x24(%rbp)
jne    12e5 <main+0x165>
mov    0x2d28(%rip),%rax
mov    (%rax),%rax
mov    0x2d0e(%rip),%rcx
cmp    (%rcx),%rax
je     12e5 <main+0x165>
lea    0xd9e(%rip),%rdi
call   1050 <perror@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x3,%edi
jne    1263 <main+0xe3>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdx
lea    0xe62(%rip),%r14
lea    0x12(%rsp),%rdi
mov    %r14,%rsi
call   1070 <sprintf@plt>
mov    0x10(%rbx),%rdx
lea    0xc(%rsp),%rdi
mov    %r14,%rsi
call   1070 <sprintf@plt>
mov    0x18(%rbx),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    11f0 <main+0x70>
mov    %eax,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <fork@plt>
cmp    $0xffffffff,%eax
je     1220 <main+0xa0>
test   %eax,%eax
je     123a <main+0xba>
add    $0xffffffff,%ebx
jne    11d0 <main+0x50>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edi,%edi
call   1090 <wait@plt>
test   %eax,%eax
jg     11f0 <main+0x70>
cmp    $0xffffffff,%eax
jne    1216 <main+0x96>
mov    0x2dd9(%rip),%rax
mov    (%rax),%rax
mov    0x2dbf(%rip),%rcx
cmp    (%rcx),%rax
jne    1279 <main+0xf9>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xde5(%rip),%rdi
call   1050 <perror@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xde7(%rip),%rdi
call   1030 <puts@plt>
lea    0x12(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1040 <peticion@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xdcb(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xd9a(%rip),%rdi
jmp    1227 <main+0xa7>

LLVM IR (-O0):
@.str = [72 x i8] c"\0AError. Argumentos clientes <nombre_fifo_escritura> <n\C3\BAmero_clientes>\0A\00"
@.str.1 = [12 x i8] c"/tmp/fifo%s\00"
@.str.2 = [14 x i8] c"\0AEstoy aqui1\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.3 = [14 x i8] c"fallo en fork\00"
@EXIT_FAILURE = global i32 0
@errno = global i64 0
@ECHILD = global i64 0
@.str.4 = [14 x i8] c"fallo en wait\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [6 x i8]
%7 = alloca [6 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %8
store i32 0, i32* %10
br label %31
31: ; preds = %55, %16
%32 = load i32, i32* %10
%33 = load i32, i32* %8
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %58
35: ; preds = %31
%36 = call i32 (...) @fork()
store i32 %36, i32* %9
%37 = load i32, i32* %9
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %35
%40 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%41 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%42 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%43 = call i32 @peticion(i8* %41, i8* %42)
%44 = load i32, i32* @EXIT_SUCCESS
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %35
%47 = load i32, i32* %9
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %46
br label %54
54: ; preds = %53
br label %55
55: ; preds = %54
%56 = load i32, i32* %10
%57 = add nsw i32 %56, 1
store i32 %57, i32* %10
br label %31
58: ; preds = %31
%59 = call i32 @wait(i32* null)
store i32 %59, i32* %9
br label %60
60: ; preds = %63, %58
%61 = load i32, i32* %9
%62 = icmp sgt i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %60
%64 = call i32 @wait(i32* null)
store i32 %64, i32* %9
br label %60
65: ; preds = %60
%66 = load i32, i32* %9
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %76
68: ; preds = %65
%69 = load i64, i64* @errno
%70 = load i64, i64* @ECHILD
%71 = icmp ne i64 %69, %70
br i1 %71, label %72, label %76
72: ; preds = %68
%73 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %68, %65
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"/tmp/fifo%s\00"
@EXIT_SUCCESS = global i32 0
@.str.3 = [14 x i8] c"fallo en fork\00"
@EXIT_FAILURE = global i32 0
@errno = global i64 0
@ECHILD = global i64 0
@.str.4 = [14 x i8] c"fallo en wait\00"
@str = [13 x i8] c"\0AEstoy aqui1\00"
@str.5 = [71 x i8] c"\0AError. Argumentos clientes <nombre_fifo_escritura> <n\C3\BAmero_clientes>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [6 x i8]
%4 = alloca [6 x i8]
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.5, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds i8*, i8** %1, i64 3
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %37
22: ; preds = %9, %34
%23 = phi i32 [ %35, %34 ], [ 0, %9 ]
%24 = tail call i32 (...) @fork()
switch i32 %24, label %34 [
i32 0, label %25
i32 -1, label %30
]
25: ; preds = %22
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%27 = call i32 @peticion(i8* %10, i8* %11)
%28 = load i32, i32* @EXIT_SUCCESS
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %22
%31 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
34: ; preds = %22
%35 = add nuw nsw i32 %23, 1
%36 = icmp eq i32 %35, %20
br i1 %36, label %37, label %22
37: ; preds = %34, %9
%38 = tail call i32 @wait(i32* null)
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37, %40
%41 = tail call i32 @wait(i32* null)
%42 = icmp sgt i32 %41, 0
br i1 %42, label %40, label %43
43: ; preds = %40, %37
%44 = phi i32 [ %38, %37 ], [ %41, %40 ]
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %54
46: ; preds = %43
%47 = load i64, i64* @errno
%48 = load i64, i64* @ECHILD
%49 = icmp eq i64 %47, %48
br i1 %49, label %54, label %50
50: ; preds = %46
%51 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%52 = load i32, i32* @EXIT_FAILURE
%53 = tail call i32 @exit(i32 %52)
unreachable
54: ; preds = %46, %43
ret i32 0
}