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

/* Variables and functions */
int crearZonaMemoriaCompartida(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int *apuntarZonaMemoriaCompartida(key_t clave, int tamano) {
  int *punteroMemoria;
  int idMemoria;
  idMemoria = crearZonaMemoriaCompartida(clave, tamano);
  if (idMemoria == -1) {
    printf("No consigo la memoria compartida");
    return NULL;
  } else {
    if ((punteroMemoria = shmat(idMemoria, NULL, 0)) == (int *)-1) {
      return NULL;
    } else {
      printf("Creado Memoria compartida y puntero\n");
      return punteroMemoria;
    }
  }
}


x86 assembly (clang, -O0):
<apuntarZonaMemoriaCompartida>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <crearZonaMemoriaCompartida@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    116f <apuntarZonaMemoriaCompartida+0x3f>
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11b2 <apuntarZonaMemoriaCompartida+0x82>
mov    -0x1c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <shmat@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    119e <apuntarZonaMemoriaCompartida+0x6e>
movq   $0x0,-0x8(%rbp)
jmp    11b2 <apuntarZonaMemoriaCompartida+0x82>
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apuntarZonaMemoriaCompartida>:
push   %r14
push   %rbx
push   %rax
call   1050 <crearZonaMemoriaCompartida@plt>
cmp    $0xffffffff,%eax
je     1175 <apuntarZonaMemoriaCompartida+0x35>
xor    %ebx,%ebx
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
je     1183 <apuntarZonaMemoriaCompartida+0x43>
mov    %rax,%r14
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rbx
jmp    1183 <apuntarZonaMemoriaCompartida+0x43>
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [33 x i8] c"No consigo la memoria compartida\00"
@.str.1 = [37 x i8] c"Creado Memoria compartida y puntero\0A\00"
define i32* @apuntarZonaMemoriaCompartida(i32 %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = load i32, i32* %5
%10 = call i32 @crearZonaMemoriaCompartida(i32 %8, i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32* null, i32** %3
br label %23
15: ; preds = %2
%16 = load i32, i32* %7
%17 = call i32* @shmat(i32 %16, i32* null, i32 0)
store i32* %17, i32** %6
%18 = icmp eq i32* %17, inttoptr (i64 -1 to i32*)
br i1 %18, label %19, label %20
19: ; preds = %15
store i32* null, i32** %3
br label %23
20: ; preds = %15
%21 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32*, i32** %6
store i32* %22, i32** %3
br label %23
23: ; preds = %20, %19, %13
%24 = load i32*, i32** %3
ret i32* %24
}

LLVM IR (-O2):
@.str = [33 x i8] c"No consigo la memoria compartida\00"
@str = [36 x i8] c"Creado Memoria compartida y puntero\00"
define i32* @apuntarZonaMemoriaCompartida(i32 %0, i32 %1) {
%3 = tail call i32 @crearZonaMemoriaCompartida(i32 %0, i32 %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %12
7: ; preds = %2
%8 = tail call i32* @shmat(i32 %3, i32* null, i32 0)
%9 = icmp eq i32* %8, inttoptr (i64 -1 to i32*)
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %7, %10, %5
%13 = phi i32* [ null, %5 ], [ %8, %10 ], [ null, %7 ]
ret i32* %13
}