#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_PRIVATE;
int S_IRUSR;
int S_IWUSR;
int dsCapToBytes(int);
int /*<<< orphan*/ pexit(char *);
int shmget(int /*<<< orphan*/, int, int);
int createSharedMem(int cap) {
  int id, size;
  size = dsCapToBytes(cap);
  id = shmget(IPC_PRIVATE, size, IPC_CREAT | IPC_EXCL | (S_IRUSR | S_IWUSR));
  if (id == -1)
    pexit("shmget");
  return id;
}


x86 assembly (clang, -O0):
<createSharedMem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <dsCapToBytes@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%esi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
mov    0x2e8e(%rip),%rax
or     (%rax),%edx
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    0x2e64(%rip),%rcx
or     (%rcx),%eax
or     %eax,%edx
call   1030 <shmget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1196 <createSharedMem+0x66>
lea    0xe6f(%rip),%rdi
call   1050 <pexit@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createSharedMem>:
push   %rbx
call   1040 <dsCapToBytes@plt>
mov    0x2ea3(%rip),%rcx
mov    (%rcx),%edi
mov    0x2e7a(%rip),%rcx
mov    0x2ea3(%rip),%rdx
mov    (%rdx),%edx
mov    0x2e72(%rip),%rsi
mov    0x2e7b(%rip),%rbx
or     (%rcx),%edx
or     (%rsi),%edx
or     (%rbx),%edx
mov    %eax,%esi
call   1030 <shmget@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    117d <createSharedMem+0x4d>
lea    0xe88(%rip),%rdi
call   1050 <pexit@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [7 x i8] c"shmget\00"
define i32 @createSharedMem(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @dsCapToBytes(i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* @IPC_PRIVATE
%8 = load i32, i32* %4
%9 = load i32, i32* @IPC_CREAT
%10 = load i32, i32* @IPC_EXCL
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IRUSR
%13 = load i32, i32* @S_IWUSR
%14 = or i32 %12, %13
%15 = or i32 %11, %14
%16 = call i32 @shmget(i32 %7, i32 %8, i32 %15)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %1
%20 = call i32 @pexit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %1
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [7 x i8] c"shmget\00"
define i32 @createSharedMem(i32 %0) {
%2 = tail call i32 @dsCapToBytes(i32 %0)
%3 = load i32, i32* @IPC_PRIVATE
%4 = load i32, i32* @IPC_CREAT
%5 = load i32, i32* @IPC_EXCL
%6 = load i32, i32* @S_IRUSR
%7 = load i32, i32* @S_IWUSR
%8 = or i32 %5, %4
%9 = or i32 %8, %6
%10 = or i32 %9, %7
%11 = tail call i32 @shmget(i32 %3, i32 %2, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = tail call i32 @pexit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
ret i32 %11
}