#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 /*<<< orphan*/ assert(int);
void *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int /*<<< orphan*/, unsigned int, int);
void *mkmap(unsigned sz) {
  int shmid = shmget(IPC_PRIVATE, sz, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  assert(shmid != -1);
  void *addr = shmat(shmid, NULL, 0);
  assert(addr != (void *)-1);
  return addr;
}


x86 assembly (clang, -O0):
<mkmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
mov    0x2e99(%rip),%rax
or     (%rax),%edx
mov    0x2e68(%rip),%rax
or     (%rax),%edx
mov    0x2e6f(%rip),%rax
or     (%rax),%edx
call   1050 <shmget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
mov    %rax,-0x10(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkmap>:
push   %rbx
mov    %edi,%esi
mov    0x2e86(%rip),%rax
mov    0x2eaf(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e94(%rip),%rax
mov    0x2e75(%rip),%rcx
or     (%rcx),%edx
mov    (%rax),%edi
mov    0x2e7a(%rip),%rax
or     (%rax),%edx
call   1050 <shmget@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1030 <assert@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
mov    %rax,%rbx
xor    %edi,%edi
cmp    $0xffffffffffffffff,%rax
setne  %dil
call   1030 <assert@plt>
mov    %rbx,%rax
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
define i8* @mkmap(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %2
%5 = load i32, i32* @IPC_PRIVATE
%6 = load i32, i32* %2
%7 = load i32, i32* @IPC_CREAT
%8 = load i32, i32* @IPC_EXCL
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRUSR
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IWUSR
%13 = or i32 %11, %12
%14 = call i32 @shmget(i32 %5, i32 %6, i32 %13)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, -1
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* %3
%20 = call i8* @shmat(i32 %19, i32* null, i32 0)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = icmp ne i8* %21, inttoptr (i64 -1 to i8*)
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i8*, i8** %4
ret i8* %25
}

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
define i8* @mkmap(i32 %0) {
%2 = load i32, i32* @IPC_PRIVATE
%3 = load i32, i32* @IPC_CREAT
%4 = load i32, i32* @IPC_EXCL
%5 = or i32 %4, %3
%6 = load i32, i32* @S_IRUSR
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %7, %8
%10 = tail call i32 @shmget(i32 %2, i32 %0, i32 %9)
%11 = icmp ne i32 %10, -1
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i8* @shmat(i32 %10, i32* null, i32 0)
%15 = icmp ne i8* %14, inttoptr (i64 -1 to i8*)
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
ret i8* %14
}