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

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ *SEM_FAILED;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *sem_open(char *, int /*<<< orphan*/);
int sem_unlink(char *);
int shm_open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ shm_unlink(char *);
void remove_it(void) {
  int shm_fd;
  sem_t *mysem;
  if ((shm_fd = shm_open("/my_shm", O_RDWR, 0) == -1)) {
    perror("shm_open");
    exit(errno);
  };
  if (shm_unlink("/my_shm")) {
    perror("shm_unlink");
    exit(errno);
  };
  printf("Shared Memory Region successfully destroyed\n");
  if ((mysem = sem_open("/my_sem", 0)) == SEM_FAILED) {
    perror("sem_open");
    exit(errno);
  };
  if ((sem_unlink("/my_sem")) == -1) {
    perror("sem_unlink");
    exit(errno);
  };
  printf("Semaphore successfully deleted\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<remove_it>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
xor    %edx,%edx
call   1070 <shm_open@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x4(%rbp)
test   $0x1,%al
jne    11ad <remove_it+0x3d>
jmp    11c7 <remove_it+0x57>
lea    0xe54(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    0xe32(%rip),%rdi
call   1080 <shm_unlink@plt>
cmp    $0x0,%rax
je     11f7 <remove_it+0x87>
lea    0xe2d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
lea    0xe3f(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    %rax,-0x10(%rbp)
mov    0x2dc4(%rip),%rcx
cmp    (%rcx),%rax
jne    123f <remove_it+0xcf>
lea    0xe25(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    0xe03(%rip),%rdi
call   1090 <sem_unlink@plt>
cmp    $0xffffffff,%eax
jne    126e <remove_it+0xfe>
lea    0xdff(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    0xdf0(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<remove_it>:
push   %rax
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
lea    0xe7f(%rip),%rdi
xor    %edx,%edx
call   1070 <shm_open@plt>
cmp    $0xffffffff,%eax
jne    1196 <remove_it+0x26>
lea    0xe74(%rip),%rdi
jmp    11f7 <remove_it+0x87>
lea    0xe63(%rip),%rdi
call   1080 <shm_unlink@plt>
test   %rax,%rax
jne    11d6 <remove_it+0x66>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
lea    0xe62(%rip),%rdi
xor    %esi,%esi
call   1040 <sem_open@plt>
mov    0x2e18(%rip),%rcx
cmp    (%rcx),%rax
jne    11df <remove_it+0x6f>
lea    0xe50(%rip),%rdi
jmp    11f7 <remove_it+0x87>
lea    0xe34(%rip),%rdi
jmp    11f7 <remove_it+0x87>
lea    0xe36(%rip),%rdi
call   1090 <sem_unlink@plt>
cmp    $0xffffffff,%eax
jne    120a <remove_it+0x9a>
lea    0xe36(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"/my_shm\00"
@O_RDWR = global i32 0
@.str.1 = [9 x i8] c"shm_open\00"
@errno = global i32 0
@.str.2 = [11 x i8] c"shm_unlink\00"
@.str.3 = [45 x i8] c"Shared Memory Region successfully destroyed\0A\00"
@.str.4 = [8 x i8] c"/my_sem\00"
@SEM_FAILED = global i32* null
@.str.5 = [9 x i8] c"sem_open\00"
@.str.6 = [11 x i8] c"sem_unlink\00"
@.str.7 = [32 x i8] c"Semaphore successfully deleted\0A\00"
@EXIT_SUCCESS = global i32 0
define void @remove_it() {
%1 = alloca i32
%2 = alloca i32*
%3 = load i32, i32* @O_RDWR
%4 = call i32 @shm_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
%6 = zext i1 %5 to i32
store i32 %6, i32* %1
br i1 %5, label %7, label %11
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @errno
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = call i64 @shm_unlink(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @errno
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %11
%19 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32* @sem_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 0)
store i32* %20, i32** %2
%21 = load i32*, i32** @SEM_FAILED
%22 = icmp eq i32* %20, %21
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%25 = load i32, i32* @errno
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %18
%28 = call i32 @sem_unlink(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%32 = load i32, i32* @errno
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %27
%35 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
%36 = load i32, i32* @EXIT_SUCCESS
%37 = call i32 @exit(i32 %36)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"/my_shm\00"
@O_RDWR = global i32 0
@.str.1 = [9 x i8] c"shm_open\00"
@errno = global i32 0
@.str.2 = [11 x i8] c"shm_unlink\00"
@.str.4 = [8 x i8] c"/my_sem\00"
@SEM_FAILED = global i32* null
@.str.5 = [9 x i8] c"sem_open\00"
@.str.6 = [11 x i8] c"sem_unlink\00"
@EXIT_SUCCESS = global i32 0
@str = [44 x i8] c"Shared Memory Region successfully destroyed\00"
@str.8 = [31 x i8] c"Semaphore successfully deleted\00"
define void @remove_it() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @shm_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %1, i32 0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @errno
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %0
%9 = tail call i64 @shm_unlink(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @errno
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %8
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%17 = tail call i32* @sem_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 0)
%18 = load i32*, i32** @SEM_FAILED
%19 = icmp eq i32* %17, %18
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%22 = load i32, i32* @errno
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %15
%25 = tail call i32 @sem_unlink(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%29 = load i32, i32* @errno
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %24
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.8, i64 0, i64 0))
%33 = load i32, i32* @EXIT_SUCCESS
%34 = tail call i32 @exit(i32 %33)
unreachable
}