#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void proxy(int pid) {
  char *nombre;
  int fd;
  sprintf(nombre, "/tmp/fifo.%d", pid);
  mkfifo(nombre, 0777);
  fd = open(nombre, O_RDWR);
  if (fd < 0) {
    perror("Error en write\n");
    exit(EXIT_FAILURE);
  }
  dup2(fd, STDIN_FILENO);
  execlp("./proxy", "./proxy", NULL);
  perror("Fallo en execlp");
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<proxy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe77(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkfifo@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d5 <proxy+0x65>
lea    0xe4b(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
lea    0xe30(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1090 <execlp@plt>
lea    0xe25(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<proxy>:
push   %rax
lea    0xe88(%rip),%rsi
mov    %edi,%edx
call   1070 <sprintf@plt>
mov    $0x1ff,%esi
call   1040 <mkfifo@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
jns    11a4 <proxy+0x34>
lea    0xe6b(%rip),%rdi
jmp    11cc <proxy+0x5c>
mov    0x2e25(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1030 <dup2@plt>
lea    0xe62(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1090 <execlp@plt>
lea    0xe59(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/tmp/fifo.%d\00"
@O_RDWR = global i32 0
@.str.1 = [16 x i8] c"Error en write\0A\00"
@EXIT_FAILURE = global i32 0
@STDIN_FILENO = global i32 0
@.str.2 = [8 x i8] c"./proxy\00"
@.str.3 = [16 x i8] c"Fallo en execlp\00"
define void @proxy(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i8*, i8** %3
%6 = load i32, i32* %2
%7 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i8*, i8** %3
%9 = call i32 @mkfifo(i8* %8, i32 511)
%10 = load i8*, i8** %3
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %1
%20 = load i32, i32* %4
%21 = load i32, i32* @STDIN_FILENO
%22 = call i32 @dup2(i32 %20, i32 %21)
%23 = call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* null)
%24 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
}

LLVM IR (-O2):
@.str = [13 x i8] c"/tmp/fifo.%d\00"
@O_RDWR = global i32 0
@.str.1 = [16 x i8] c"Error en write\0A\00"
@EXIT_FAILURE = global i32 0
@STDIN_FILENO = global i32 0
@.str.2 = [8 x i8] c"./proxy\00"
@.str.3 = [16 x i8] c"Fallo en execlp\00"
define void @proxy(i32 %0) {
%2 = tail call i32 @sprintf(i8* dereferenceable(1) undef, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = tail call i32 @mkfifo(i8* undef, i32 511)
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* undef, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = load i32, i32* @STDIN_FILENO
%13 = tail call i32 @dup2(i32 %5, i32 %12)
%14 = tail call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* null)
%15 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
}