#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 /*<<< orphan*/ EXIT_SUCCESS;
int O_CREAT;
int O_EXCL;
int O_RDWR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ ftruncate(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int shm_open(char *, int, int);
void create_it(void) {
  int shm_fd;
  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");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<create_it>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
or     (%rax),%esi
mov    0x2e5f(%rip),%rax
or     (%rax),%esi
lea    0xe86(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <shm_open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    11aa <create_it+0x5a>
lea    0xe71(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
mov    $0x2004,%esi
call   1040 <ftruncate@plt>
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<create_it>:
push   %rax
mov    0x2e88(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e66(%rip),%rax
or     (%rax),%esi
lea    0xe8d(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <shm_open@plt>
cmp    $0xffffffff,%eax
jne    119c <create_it+0x4c>
lea    0xe7f(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    %eax,%edi
mov    $0x2004,%esi
call   1040 <ftruncate@plt>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e05(%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
@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"
@EXIT_SUCCESS = global i32 0
define void @create_it() {
%1 = alloca i32
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_CREAT
%4 = or i32 %2, %3
%5 = load i32, i32* @O_EXCL
%6 = or i32 %4, %5
%7 = call i32 @shm_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %6, i32 438)
store i32 %7, i32* %1
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @errno
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = load i32, i32* %1
%15 = call i32 @ftruncate(i32 %14, i32 8196)
%16 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @EXIT_SUCCESS
%18 = call i32 @exit(i32 %17)
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
@EXIT_SUCCESS = global i32 0
@str = [42 x i8] c"Shared Memory Region successfully created\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* @EXIT_SUCCESS
%16 = tail call i32 @exit(i32 %15)
unreachable
}