#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 */
struct shmid_ds {
  int dummy;
};

/* Variables and functions */
int IPC_CREAT;
int IPC_EXCL;
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ IPC_STAT;
int S_IRUSR;
int S_IWUSR;
scalar_t__ shmat(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ shmctl(int, int /*<<< orphan*/, struct shmid_ds *);
int shmget(int /*<<< orphan*/, int, int);
void sharemem() {
  struct shmid_ds mem_stat;
  int mem_id =
      shmget(IPC_PRIVATE, 4096, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  char *mem_access = (char *)shmat(mem_id, 0, 0);
  shmctl(mem_id, IPC_STAT, &mem_stat);
}


x86 assembly (clang, -O0):
<sharemem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
mov    0x2e9f(%rip),%rax
or     (%rax),%edx
mov    0x2e66(%rip),%rax
or     (%rax),%edx
mov    0x2e75(%rip),%rax
or     (%rax),%edx
mov    $0x1000,%esi
call   1050 <shmget@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1040 <shmat@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1030 <shmctl@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sharemem>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e7c(%rip),%rax
mov    0x2ead(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e92(%rip),%rax
mov    0x2e6b(%rip),%rcx
or     (%rcx),%edx
mov    (%rax),%edi
mov    0x2e78(%rip),%rax
or     (%rax),%edx
mov    $0x1000,%esi
call   1050 <shmget@plt>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <shmat@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1030 <shmctl@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.shmid_ds = type { i32 }
@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
@IPC_STAT = global i32 0
define void @sharemem() {
%1 = alloca %struct.shmid_ds
%2 = alloca i32
%3 = alloca i8*
%4 = load i32, i32* @IPC_PRIVATE
%5 = load i32, i32* @IPC_CREAT
%6 = load i32, i32* @IPC_EXCL
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IRUSR
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IWUSR
%11 = or i32 %9, %10
%12 = call i32 @shmget(i32 %4, i32 4096, i32 %11)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = call i64 @shmat(i32 %13, i32 0, i32 0)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %3
%16 = load i32, i32* %2
%17 = load i32, i32* @IPC_STAT
%18 = call i32 @shmctl(i32 %16, i32 %17, %struct.shmid_ds* %1)
ret void
}

LLVM IR (-O2):
%struct.shmid_ds = type { i32 }
@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
@IPC_STAT = global i32 0
define void @sharemem() {
%1 = alloca %struct.shmid_ds
%2 = bitcast %struct.shmid_ds* %1 to i8*
%3 = load i32, i32* @IPC_PRIVATE
%4 = load i32, i32* @IPC_CREAT
%5 = load i32, i32* @IPC_EXCL
%6 = or i32 %5, %4
%7 = load i32, i32* @S_IRUSR
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %8, %9
%11 = tail call i32 @shmget(i32 %3, i32 4096, i32 %10)
%12 = tail call i64 @shmat(i32 %11, i32 0, i32 0)
%13 = load i32, i32* @IPC_STAT
%14 = call i32 @shmctl(i32 %11, i32 %13, %struct.shmid_ds* %1)
ret void
}