#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 IPC_CREAT;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
void *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int /*<<< orphan*/, long, int);
void *createShareMemory(key_t id, long bytes) {
  int shmID = shmget(id, bytes, 0666 | IPC_CREAT);
  void *mem;
  if (shmID == -1) {
    printf("No consigo id para memoria compartida \n");
    exit(0);
  }
  mem = shmat(shmID, NULL, 0);
  if (mem == NULL) {
    printf("No consigo memoria compartida \n ");
    exit(0);
  }
  return mem;
}


x86 assembly (clang, -O0):
<createShareMemory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
call   1050 <shmget@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    118a <createShareMemory+0x4a>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ba <createShareMemory+0x7a>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createShareMemory>:
push   %rax
mov    0x2e88(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
call   1060 <shmget@plt>
cmp    $0xffffffff,%eax
je     117b <createShareMemory+0x2b>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <shmat@plt>
test   %rax,%rax
je     118e <createShareMemory+0x3e>
pop    %rcx
ret
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@.str = [40 x i8] c"No consigo id para memoria compartida \0A\00"
@.str.1 = [33 x i8] c"No consigo memoria compartida \0A \00"
define i8* @createShareMemory(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %3
store i64 %1, i64* %4
%7 = load i32, i32* %3
%8 = load i64, i64* %4
%9 = load i32, i32* @IPC_CREAT
%10 = or i32 438, %9
%11 = call i32 @shmget(i32 %7, i64 %8, i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %2
%18 = load i32, i32* %5
%19 = call i8* @shmat(i32 %18, i32* null, i32 0)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %17
%26 = load i8*, i8** %6
ret i8* %26
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str.1 = [33 x i8] c"No consigo memoria compartida \0A \00"
@str = [39 x i8] c"No consigo id para memoria compartida \00"
define i8* @createShareMemory(i32 %0, i64 %1) {
%3 = load i32, i32* @IPC_CREAT
%4 = or i32 %3, 438
%5 = tail call i32 @shmget(i32 %0, i64 %1, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2
%11 = tail call i8* @shmat(i32 %5, i32* null, i32 0)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %10
ret i8* %11
}