#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 /*<<< orphan*/ EXIT_SUCCESS;
int IPC_CREAT;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
void *shmat(int, void *, int /*<<< orphan*/);
int shmdt(void *);
int shmget(int /*<<< orphan*/, int, int);
void create_it(void) {
  int shmid;
  void *shm_area;
  if ((shmid = shmget((key_t)26, 8196, IPC_CREAT | 0666)) == -1) {
    perror("shmget");
    exit(errno);
  };
  if ((shm_area = shmat(shmid, (void *)0, 0)) == (void *)-1) {
    perror("shmat");
    exit(errno);
  };
  printf("CREATE: Memory attached at %lX\n", (unsigned long)shm_area);
  if (shmdt(shm_area) == -1) {
    perror("shmdt");
    exit(errno);
  };
  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    0x2e61(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x1a,%edi
mov    $0x2004,%esi
call   1070 <shmget@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    11ac <create_it+0x4c>
lea    0xe67(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
mov    %rax,-0x10(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    11e8 <create_it+0x88>
lea    0xe32(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <shmdt@plt>
cmp    $0xffffffff,%eax
jne    1226 <create_it+0xc6>
lea    0xe1a(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<create_it>:
push   %rbx
mov    0x2e58(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x1a,%edi
mov    $0x2004,%esi
call   1080 <shmget@plt>
cmp    $0xffffffff,%eax
jne    119c <create_it+0x2c>
lea    0xe66(%rip),%rdi
jmp    11de <create_it+0x6e>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
jne    11b6 <create_it+0x46>
lea    0xe53(%rip),%rdi
jmp    11de <create_it+0x6e>
mov    %rax,%rbx
lea    0xe4d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <shmdt@plt>
cmp    $0xffffffff,%eax
jne    11f1 <create_it+0x81>
lea    0xe4f(%rip),%rdi
call   1060 <perror@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@.str = [7 x i8] c"shmget\00"
@errno = global i32 0
@.str.1 = [6 x i8] c"shmat\00"
@.str.2 = [32 x i8] c"CREATE: Memory attached at %lX\0A\00"
@.str.3 = [6 x i8] c"shmdt\00"
@.str.4 = [43 x i8] c"Shared Memory Region successfully created\0A\00"
@EXIT_SUCCESS = global i32 0
define void @create_it() {
%1 = alloca i32
%2 = alloca i8*
%3 = load i32, i32* @IPC_CREAT
%4 = or i32 %3, 438
%5 = call i32 @shmget(i32 26, i32 8196, i32 %4)
store i32 %5, i32* %1
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @errno
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = load i32, i32* %1
%13 = call i8* @shmat(i32 %12, i8* null, i32 0)
store i8* %13, i8** %2
%14 = icmp eq i8* %13, inttoptr (i64 -1 to i8*)
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @errno
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %11
%20 = load i8*, i8** %2
%21 = ptrtoint i8* %20 to i64
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i64 %21)
%23 = load i8*, i8** %2
%24 = call i32 @shmdt(i8* %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %19
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @errno
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %19
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%32 = load i32, i32* @EXIT_SUCCESS
%33 = call i32 @exit(i32 %32)
unreachable
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [7 x i8] c"shmget\00"
@errno = global i32 0
@.str.1 = [6 x i8] c"shmat\00"
@.str.2 = [32 x i8] c"CREATE: Memory attached at %lX\0A\00"
@.str.3 = [6 x i8] c"shmdt\00"
@EXIT_SUCCESS = global i32 0
@str = [42 x i8] c"Shared Memory Region successfully created\00"
define void @create_it() {
%1 = load i32, i32* @IPC_CREAT
%2 = or i32 %1, 438
%3 = tail call i32 @shmget(i32 26, i32 8196, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @errno
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = tail call i8* @shmat(i32 %3, i8* null, i32 0)
%11 = icmp eq i8* %10, inttoptr (i64 -1 to i8*)
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @errno
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %9
%17 = ptrtoint i8* %10 to i64
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i64 %17)
%19 = tail call i32 @shmdt(i8* %10)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* @errno
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %16
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%27 = load i32, i32* @EXIT_SUCCESS
%28 = tail call i32 @exit(i32 %27)
unreachable
}