#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 O_CREAT;
int O_EXCL;
int O_RDWR;
int /*<<< orphan*/ *SEM_FAILED;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ ftruncate(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sem_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *sem_open(char *, int, int, int);
int shm_open(char *, int, int);
void create_it(void) {
  int shm_fd;
  sem_t *mysem;
  if ((shm_fd = shm_open("/my_shm", O_RDWR | O_CREAT | O_EXCL, 0666)) == -1) {
    perror("shm_open");
    exit(errno);
  };
  ftruncate(shm_fd, 8196);
  printf("Shared Memory Region successfully created\n");
  if ((mysem = sem_open("/my_sem", O_CREAT | O_EXCL, 0666, 1)) == SEM_FAILED) {
    perror("sem_open");
    exit(errno);
  };
  if ((sem_close(mysem)) == -1) {
    perror("sem_close");
    exit(errno);
  };
  printf("Semaphore successfully created and initialized\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<create_it>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    0x2e70(%rip),%rax
or     (%rax),%esi
mov    0x2e37(%rip),%rax
or     (%rax),%esi
lea    0xe66(%rip),%rdi
mov    $0x1b6,%edx
call   1090 <shm_open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    11ca <create_it+0x5a>
lea    0xe51(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x4(%rbp),%edi
mov    $0x2004,%esi
call   1040 <ftruncate@plt>
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
mov    0x2dd5(%rip),%rax
or     (%rax),%esi
lea    0xe40(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x1,%ecx
call   1050 <sem_open@plt>
mov    %rax,-0x10(%rbp)
mov    0x2dc2(%rip),%rcx
cmp    (%rcx),%rax
jne    1239 <create_it+0xc9>
lea    0xe1e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1060 <sem_close@plt>
cmp    $0xffffffff,%eax
jne    1265 <create_it+0xf5>
lea    0xdfb(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xdeb(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<create_it>:
push   %r14
push   %rbx
push   %rax
mov    0x2e65(%rip),%rax
mov    0x2e76(%rip),%r14
mov    (%r14),%esi
or     (%rax),%esi
mov    0x2e3a(%rip),%rbx
or     (%rbx),%esi
lea    0xe69(%rip),%rdi
mov    $0x1b6,%edx
call   1090 <shm_open@plt>
cmp    $0xffffffff,%eax
jne    11af <create_it+0x3f>
lea    0xe5b(%rip),%rdi
jmp    120b <create_it+0x9b>
mov    %eax,%edi
mov    $0x2004,%esi
call   1040 <ftruncate@plt>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%esi
or     (%r14),%esi
lea    0xe3e(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x1,%ecx
call   1050 <sem_open@plt>
mov    0x2def(%rip),%rcx
cmp    (%rcx),%rax
jne    11f7 <create_it+0x87>
lea    0xe24(%rip),%rdi
jmp    120b <create_it+0x9b>
mov    %rax,%rdi
call   1060 <sem_close@plt>
cmp    $0xffffffff,%eax
jne    121e <create_it+0xae>
lea    0xe17(%rip),%rdi
call   1070 <perror@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

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

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