#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 key_t;

/* Variables and functions */
int IPC_CREAT;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ printf(char *, int);
int *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ shmdt(int *);
int shmget(int, int, int);
int /*<<< orphan*/ sleep(int);
void main() {
  int *value;
  key_t key = 1234;
  int shmid = shmget(key, sizeof(int), IPC_CREAT | 0666);
  value = shmat(shmid, NULL, 0);
  *value = 10;
  printf("Program 1 : %d\n", *value);
  sleep(5);
  printf("Program 1: %d\n", *value);
  shmdt(value);
  shmctl(shmid, IPC_RMID, NULL);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x4d2,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x4,%esi
call   1070 <shmget@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movl   $0xa,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
mov    $0x5,%edi
call   1080 <sleep@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <shmdt@plt>
mov    -0x10(%rbp),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <shmctl@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e6e(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x4d2,%edi
mov    $0x4,%esi
call   1070 <shmget@plt>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
mov    %rax,%rbx
movl   $0xa,(%rax)
lea    0xe63(%rip),%rdi
mov    $0xa,%esi
call   1040 <printf@plt>
mov    $0x5,%edi
call   1080 <sleep@plt>
mov    (%rbx),%esi
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <shmdt@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <shmctl@plt>

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

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [16 x i8] c"Program 1 : %d\0A\00"
@.str.1 = [15 x i8] c"Program 1: %d\0A\00"
@IPC_RMID = global i32 0
define void @main() {
%1 = load i32, i32* @IPC_CREAT
%2 = or i32 %1, 438
%3 = tail call i32 @shmget(i32 1234, i32 4, i32 %2)
%4 = tail call i32* @shmat(i32 %3, i32* null, i32 0)
store i32 10, i32* %4
%5 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 10)
%6 = tail call i32 @sleep(i32 5)
%7 = load i32, i32* %4
%8 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i32 @shmdt(i32* %4)
%10 = load i32, i32* @IPC_RMID
%11 = tail call i32 @shmctl(i32 %3, i32 %10, i32* null)
ret void
}