#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 EXIT_SUCCESS;
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ IPC_RMID;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ shmdt(char *);
int shmget(int /*<<< orphan*/, int const, int);
int /*<<< orphan*/ sprintf(char *, char *);
int main(int argc, char *argv[]) {
  int segment_id;
  char *shared_memory;
  const int size = 1024;
  segment_id = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
  shared_memory = (char *)shmat(segment_id, NULL, 0);
  sprintf(shared_memory, "Interprocesso Communication - IPC");
  printf("*%s\n", shared_memory);
  shmdt(shared_memory);
  shmctl(segment_id, IPC_RMID, NULL);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x400,-0x24(%rbp)
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
mov    0x2e4a(%rip),%rax
or     (%rax),%edx
mov    $0x400,%esi
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    0xe3e(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <shmdt@plt>
mov    -0x14(%rbp),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <shmctl@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
mov    0x2e65(%rip),%rax
mov    0x2e76(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    $0x400,%esi
call   1070 <shmget@plt>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <shmat@plt>
mov    %rax,%rbx
movups 0xe71(%rip),%xmm0
movups %xmm0,(%rax)
movups 0xe77(%rip),%xmm0
movups %xmm0,0x10(%rax)
movw   $0x43,0x20(%rax)
lea    0xe78(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <shmdt@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <shmctl@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@IPC_PRIVATE = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [34 x i8] c"Interprocesso Communication - IPC\00"
@.str.1 = [5 x i8] c"*%s\0A\00"
@IPC_RMID = global i32 0
@EXIT_SUCCESS = 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*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1024, i32* %8
%9 = load i32, i32* @IPC_PRIVATE
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %10, %11
%13 = call i32 @shmget(i32 %9, i32 1024, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = call i64 @shmat(i32 %14, i32* null, i32 0)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %7
%20 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %7
%22 = call i32 @shmdt(i8* %21)
%23 = load i32, i32* %6
%24 = load i32, i32* @IPC_RMID
%25 = call i32 @shmctl(i32 %23, i32 %24, i32* null)
%26 = load i32, i32* @EXIT_SUCCESS
ret i32 %26
}

LLVM IR (-O2):
@IPC_PRIVATE = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [34 x i8] c"Interprocesso Communication - IPC\00"
@.str.1 = [5 x i8] c"*%s\0A\00"
@IPC_RMID = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @IPC_PRIVATE
%4 = load i32, i32* @S_IRUSR
%5 = load i32, i32* @S_IWUSR
%6 = or i32 %5, %4
%7 = tail call i32 @shmget(i32 %3, i32 1024, i32 %6)
%8 = tail call i64 @shmat(i32 %7, i32* null, i32 0)
%9 = inttoptr i64 %8 to i8*
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(34) %9, i8* align 1 dereferenceable(34) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 34, i1 false)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = tail call i32 @shmdt(i8* %9)
%12 = load i32, i32* @IPC_RMID
%13 = tail call i32 @shmctl(i32 %7, i32 %12, i32* null)
%14 = load i32, i32* @EXIT_SUCCESS
ret i32 %14
}