#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*/ O_WRONLY;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, int *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int write(int, int *, int);
int obtenerfifo(int dfifoe, int dfifos, int mipid) {
  int mififo, resultado, pidproxy;
  char nombrefifoproxy[50];
  if (!(resultado = write(dfifoe, &mipid, sizeof(int)))) {
    perror("Cliente: error al escribir peticion en fifo conocido del servidor");
    exit(1);
  }
  printf("Cliente %d: escrito pid en fifo conocido del servidor.\n", mipid);
  if (!(resultado = read(dfifos, &pidproxy, sizeof(int)))) {
    perror("Cliente: error al leer fifo proxy asignado por servidor");
    exit(1);
  }
  printf("Cliente %d: leido pid %d en fifo de servidor. \n", mipid, pidproxy);
  sprintf(nombrefifoproxy, "/tmp/fifo.%d", pidproxy);
  if ((mififo = open(nombrefifoproxy, O_WRONLY)) == -1) {
    perror("Cliente: problema al abrir fifo proxy asignado");
    exit(1);
  }
  return (mififo);
}


x86 assembly (clang, -O0):
<obtenerfifo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    11b4 <obtenerfifo+0x44>
lea    0xe5b(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    11f8 <obtenerfifo+0x88>
lea    0xe91(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xec8(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    1253 <obtenerfifo+0xe3>
lea    0xeab(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<obtenerfifo>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edx,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
test   %eax,%eax
je     11ff <obtenerfifo+0x8f>
lea    0xeaa(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1050 <read@plt>
test   %eax,%eax
je     1208 <obtenerfifo+0x98>
mov    0x8(%rsp),%ebp
lea    0xef1(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf0f(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
call   1080 <sprintf@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1211 <obtenerfifo+0xa1>
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdfa(%rip),%rdi
jmp    1218 <obtenerfifo+0xa8>
lea    0xe6b(%rip),%rdi
jmp    1218 <obtenerfifo+0xa8>
lea    0xed7(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [66 x i8] c"Cliente: error al escribir peticion en fifo conocido del servidor\00"
@.str.1 = [56 x i8] c"Cliente %d: escrito pid en fifo conocido del servidor.\0A\00"
@.str.2 = [56 x i8] c"Cliente: error al leer fifo proxy asignado por servidor\00"
@.str.3 = [48 x i8] c"Cliente %d: leido pid %d en fifo de servidor. \0A\00"
@.str.4 = [13 x i8] c"/tmp/fifo.%d\00"
@O_WRONLY = global i32 0
@.str.5 = [47 x i8] c"Cliente: problema al abrir fifo proxy asignado\00"
define i32 @obtenerfifo(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [50 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %4
%12 = call i32 @write(i32 %11, i32* %6, i32 4)
store i32 %12, i32* %8
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %3
%15 = call i32 @perror(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %3
%18 = load i32, i32* %6
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %5
%21 = call i32 @read(i32 %20, i32* %9, i32 4)
store i32 %21, i32* %8
%22 = icmp ne i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %17
%27 = load i32, i32* %6
%28 = load i32, i32* %9
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 %28)
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%31 = load i32, i32* %9
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%34 = load i32, i32* @O_WRONLY
%35 = call i32 @open(i8* %33, i32 %34)
store i32 %35, i32* %7
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %26
%38 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %26
%41 = load i32, i32* %7
ret i32 %41
}

LLVM IR (-O2):
@.str = [66 x i8] c"Cliente: error al escribir peticion en fifo conocido del servidor\00"
@.str.1 = [56 x i8] c"Cliente %d: escrito pid en fifo conocido del servidor.\0A\00"
@.str.2 = [56 x i8] c"Cliente: error al leer fifo proxy asignado por servidor\00"
@.str.3 = [48 x i8] c"Cliente %d: leido pid %d en fifo de servidor. \0A\00"
@.str.4 = [13 x i8] c"/tmp/fifo.%d\00"
@O_WRONLY = global i32 0
@.str.5 = [47 x i8] c"Cliente: problema al abrir fifo proxy asignado\00"
define i32 @obtenerfifo(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca [50 x i8]
store i32 %2, i32* %4
%7 = bitcast i32* %5 to i8*
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%9 = call i32 @write(i32 %0, i32* %4, i32 4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = tail call i32 @perror(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %3
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%16 = call i32 @read(i32 %1, i32* %5, i32 4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = tail call i32 @perror(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %14
%22 = load i32, i32* %5
%23 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i32 %2, i32 %22)
%24 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%25 = load i32, i32* @O_WRONLY
%26 = call i32 @open(i8* %8, i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = tail call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %21
ret i32 %26
}