#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 IPC_CREAT;
int IPC_EXCL;
int /*<<< orphan*/ IPC_RMID;
int SHM_R;
int SHM_W;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int shmget(int, int, int);
int /*<<< orphan*/ system(char *);
int main() {
  int shmid;
  shmid = shmget(2556, sizeof(int), (IPC_CREAT | SHM_R | SHM_W | IPC_EXCL));
  if (shmid == -1) {
    perror("shmget:");
    exit(-1);
  }
  printf("\n\n/*****CREACION DEL SEGMENTO %d*****/\n\n", shmid);
  system("ipcs");
  if ((shmctl(shmid, IPC_RMID, 0)) < 0) {
    perror("shmctl:");
    exit(-1);
  }
  printf("\n\n/*****ELIMINACION DEL SEGMENTO %d*****/\n\n", shmid);
  system("ipcs");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
mov    0x2e61(%rip),%rax
or     (%rax),%edx
mov    0x2e38(%rip),%rax
or     (%rax),%edx
mov    0x2e5f(%rip),%rax
or     (%rax),%edx
mov    $0x9fc,%edi
mov    $0x4,%esi
call   1070 <shmget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11c5 <main+0x65>
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%esi
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
lea    0xe56(%rip),%rdi
call   1030 <system@plt>
mov    -0x8(%rbp),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <shmctl@plt>
cmp    $0x0,%rax
jge    1213 <main+0xb3>
lea    0xe32(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%esi
lea    0xe21(%rip),%rdi
call   1040 <printf@plt>
lea    0xe08(%rip),%rdi
call   1030 <system@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e60(%rip),%rax
mov    0x2e71(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e46(%rip),%rax
or     (%rax),%edx
mov    0x2e6d(%rip),%rax
or     (%rax),%edx
mov    $0x9fc,%edi
mov    $0x4,%esi
call   1070 <shmget@plt>
cmp    $0xffffffff,%eax
jne    11a2 <main+0x42>
lea    0xe60(%rip),%rdi
jmp    11dc <main+0x7c>
mov    %eax,%ebx
lea    0xe5d(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xe78(%rip),%rdi
call   1030 <system@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <shmctl@plt>
test   %rax,%rax
jns    11eb <main+0x8b>
lea    0xe5a(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xe4c(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
lea    0xe31(%rip),%rdi
call   1030 <system@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@SHM_R = global i32 0
@SHM_W = global i32 0
@IPC_EXCL = global i32 0
@.str = [8 x i8] c"shmget:\00"
@.str.1 = [41 x i8] c"\0A\0A/*****CREACION DEL SEGMENTO %d*****/\0A\0A\00"
@.str.2 = [5 x i8] c"ipcs\00"
@IPC_RMID = global i32 0
@.str.3 = [8 x i8] c"shmctl:\00"
@.str.4 = [44 x i8] c"\0A\0A/*****ELIMINACION DEL SEGMENTO %d*****/\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @IPC_CREAT
%4 = load i32, i32* @SHM_R
%5 = or i32 %3, %4
%6 = load i32, i32* @SHM_W
%7 = or i32 %5, %6
%8 = load i32, i32* @IPC_EXCL
%9 = or i32 %7, %8
%10 = call i32 @shmget(i32 2556, i32 4, i32 %9)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %0
%17 = load i32, i32* %2
%18 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = call i32 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* %2
%21 = load i32, i32* @IPC_RMID
%22 = call i64 @shmctl(i32 %20, i32 %21, i32 0)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %16
%28 = load i32, i32* %2
%29 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = call i32 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@SHM_R = global i32 0
@SHM_W = global i32 0
@IPC_EXCL = global i32 0
@.str = [8 x i8] c"shmget:\00"
@.str.1 = [41 x i8] c"\0A\0A/*****CREACION DEL SEGMENTO %d*****/\0A\0A\00"
@.str.2 = [5 x i8] c"ipcs\00"
@IPC_RMID = global i32 0
@.str.3 = [8 x i8] c"shmctl:\00"
@.str.4 = [44 x i8] c"\0A\0A/*****ELIMINACION DEL SEGMENTO %d*****/\0A\0A\00"
define i32 @main() {
%1 = load i32, i32* @IPC_CREAT
%2 = load i32, i32* @SHM_R
%3 = or i32 %2, %1
%4 = load i32, i32* @SHM_W
%5 = or i32 %3, %4
%6 = load i32, i32* @IPC_EXCL
%7 = or i32 %5, %6
%8 = tail call i32 @shmget(i32 2556, i32 4, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
%14 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%15 = tail call i32 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @IPC_RMID
%17 = tail call i64 @shmctl(i32 %8, i32 %16, i32 0)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %13
%23 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %8)
%24 = tail call i32 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = tail call i32 @exit(i32 0)
unreachable
}