#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);
int /*<<< orphan*/ ftok(char *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int /*<<< orphan*/, int, int);
int *recursoCompartido(int cont, int *variable) {
  key_t shmkey;
  int shmid;
  shmkey = ftok("/dev/null", cont);
  shmid = shmget(shmkey, sizeof(int), 0644 | IPC_CREAT);
  if (shmid < 0) {
    perror("shmget\n");
    exit(1);
  }
  variable = (int *)shmat(shmid, NULL, 0);
  *variable = 0;
  return variable;
}


x86 assembly (clang, -O0):
<recursoCompartido>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe97(%rip),%rdi
call   1070 <ftok@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
or     $0x1a4,%edx
mov    $0x4,%esi
call   1050 <shmget@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11b0 <recursoCompartido+0x60>
lea    0xe69(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursoCompartido>:
push   %rax
mov    %edi,%esi
lea    0xea6(%rip),%rdi
call   1070 <ftok@plt>
mov    0x2e7a(%rip),%rcx
mov    $0x1a4,%edx
or     (%rcx),%edx
mov    %eax,%edi
mov    $0x4,%esi
call   1050 <shmget@plt>
test   %eax,%eax
js     1190 <recursoCompartido+0x40>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
movl   $0x0,(%rax)
pop    %rcx
ret
lea    0xe73(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@IPC_CREAT = global i32 0
@.str.1 = [8 x i8] c"shmget\0A\00"
define i32* @recursoCompartido(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%7 = load i32, i32* %3
%8 = call i32 @ftok(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = load i32, i32* @IPC_CREAT
%11 = or i32 420, %10
%12 = call i32 @shmget(i32 %9, i32 4, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32, i32* %6
%20 = call i64 @shmat(i32 %19, i32* null, i32 0)
%21 = inttoptr i64 %20 to i32*
store i32* %21, i32** %4
%22 = load i32*, i32** %4
store i32 0, i32* %22
%23 = load i32*, i32** %4
ret i32* %23
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@IPC_CREAT = global i32 0
@.str.1 = [8 x i8] c"shmget\0A\00"
define i32* @recursoCompartido(i32 %0, i32* nocapture readnone %1) {
%3 = tail call i32 @ftok(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = load i32, i32* @IPC_CREAT
%5 = or i32 %4, 420
%6 = tail call i32 @shmget(i32 %3, i32 4, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = tail call i64 @shmat(i32 %6, i32* null, i32 0)
%13 = inttoptr i64 %12 to i32*
store i32 0, i32* %13
ret i32* %13
}