#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 IPC_CREAT;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getpagesize();
void *shmat(int, void *, int /*<<< orphan*/);
int /*<<< orphan*/ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ shmdt(void *);
int shmget(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strcpy(void *, char *);
int main(int argc, char *argv[]) {
  int shmid;
  void *shared_mem;
  shmid = shmget((key_t)89, getpagesize(), 0666 | IPC_CREAT);
  shared_mem = shmat(shmid, (void *)0, 0);
  strcpy(shared_mem, "a string");
  sleep(5);
  shmdt(shared_mem);
  shmctl(shmid, IPC_RMID, 0);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <getpagesize@plt>
mov    %eax,%esi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x59,%edi
call   1070 <shmget@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    -0x20(%rbp),%rdi
call   1040 <shmdt@plt>
mov    -0x14(%rbp),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <shmctl@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <getpagesize@plt>
mov    0x2e47(%rip),%rcx
mov    $0x1b6,%edx
or     (%rcx),%edx
mov    $0x59,%edi
mov    %eax,%esi
call   1070 <shmget@plt>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
mov    %rax,%rbx
lea    0xe45(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    %rbx,%rdi
call   1040 <shmdt@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <shmctl@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@.str = [9 x i8] c"a string\00"
@IPC_RMID = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @getpagesize()
%9 = load i32, i32* @IPC_CREAT
%10 = or i32 438, %9
%11 = call i32 @shmget(i32 89, i32 %8, i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = call i8* @shmat(i32 %12, i8* null, i32 0)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @sleep(i32 5)
%17 = load i8*, i8** %7
%18 = call i32 @shmdt(i8* %17)
%19 = load i32, i32* %6
%20 = load i32, i32* @IPC_RMID
%21 = call i32 @shmctl(i32 %19, i32 %20, i32 0)
%22 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [9 x i8] c"a string\00"
@IPC_RMID = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @getpagesize()
%4 = load i32, i32* @IPC_CREAT
%5 = or i32 %4, 438
%6 = tail call i32 @shmget(i32 89, i32 %3, i32 %5)
%7 = tail call i8* @shmat(i32 %6, i8* null, i32 0)
%8 = tail call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @sleep(i32 5)
%10 = tail call i32 @shmdt(i8* %7)
%11 = load i32, i32* @IPC_RMID
%12 = tail call i32 @shmctl(i32 %6, i32 %11, i32 0)
%13 = tail call i32 @exit(i32 0)
unreachable
}