#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ msgctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int msgget(int /*<<< orphan*/, int);
int /*<<< orphan*/ msgrcv(int, void *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ msgsnd(int, void *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  int msgid;
  struct {
    long my_msg_type;
    char some_text[132];
  } some_data;
  some_data.my_msg_type = 1;
  msgid = msgget((key_t)1234, 0666 | IPC_CREAT);
  strcpy(some_data.some_text, "A MESSAGE");
  printf("You are sending: %s\n", some_data.some_text);
  msgsnd(msgid, (void *)&some_data, 132, 0);
  memset(some_data.some_text, 0, 132);
  printf("Message is cleared, is now: %s\n", some_data.some_text);
  sleep(5);
  msgrcv(msgid, (void *)&some_data, 132, 0, 0);
  printf("You received: %s\n", some_data.some_text);
  msgctl(msgid, IPC_RMID, 0);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1,-0xa8(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
mov    $0x4d2,%edi
call   1030 <msgget@plt>
mov    %eax,-0x14(%rbp)
lea    -0xa8(%rbp),%rdi
add    $0x8,%rdi
lea    0xe1e(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0xa8(%rbp),%rsi
add    $0x8,%rsi
lea    0xe11(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0xa8(%rbp),%rsi
mov    $0x84,%edx
xor    %ecx,%ecx
call   1070 <msgsnd@plt>
lea    -0xa8(%rbp),%rdi
add    $0x8,%rdi
xor    %esi,%esi
mov    $0x84,%edx
call   1060 <memset@plt>
lea    -0xa8(%rbp),%rsi
add    $0x8,%rsi
lea    0xde2(%rip),%rdi
call   1050 <printf@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    -0x14(%rbp),%edi
lea    -0xa8(%rbp),%rsi
mov    $0x84,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   10b0 <msgrcv@plt>
lea    -0xa8(%rbp),%rsi
add    $0x8,%rsi
lea    0xdc7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2d59(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <msgctl@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
movq   $0x1,(%rsp)
mov    0x2e2d(%rip),%rax
mov    $0x1b6,%esi
or     (%rax),%esi
mov    $0x4d2,%edi
call   1030 <msgget@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
lea    0xe36(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
lea    0xe31(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %rsp,%r15
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x84,%edx
xor    %ecx,%ecx
call   1070 <msgsnd@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x84,%edx
call   1060 <memset@plt>
lea    0xe14(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x84,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <msgrcv@plt>
lea    0xe07(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1080 <msgctl@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.anon = type { i64, [132 x i8] }
@IPC_CREAT = global i32 0
@.str = [10 x i8] c"A MESSAGE\00"
@.str.1 = [21 x i8] c"You are sending: %s\0A\00"
@.str.2 = [32 x i8] c"Message is cleared, is now: %s\0A\00"
@.str.3 = [18 x i8] c"You received: %s\0A\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 %struct.anon
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = getelementptr inbounds %struct.anon, %struct.anon* %7, i32 0, i32 0
store i64 1, i64* %8
%9 = load i32, i32* @IPC_CREAT
%10 = or i32 438, %9
%11 = call i32 @msgget(i32 1234, i32 %10)
store i32 %11, i32* %6
%12 = getelementptr inbounds %struct.anon, %struct.anon* %7, i32 0, i32 1
%13 = getelementptr inbounds [132 x i8], [132 x i8]* %12, i64 0, i64 0
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds %struct.anon, %struct.anon* %7, i32 0, i32 1
%16 = getelementptr inbounds [132 x i8], [132 x i8]* %15, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %6
%19 = bitcast %struct.anon* %7 to i8*
%20 = call i32 @msgsnd(i32 %18, i8* %19, i32 132, i32 0)
%21 = getelementptr inbounds %struct.anon, %struct.anon* %7, i32 0, i32 1
%22 = getelementptr inbounds [132 x i8], [132 x i8]* %21, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 132)
%24 = getelementptr inbounds %struct.anon, %struct.anon* %7, i32 0, i32 1
%25 = getelementptr inbounds [132 x i8], [132 x i8]* %24, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = call i32 @sleep(i32 5)
%28 = load i32, i32* %6
%29 = bitcast %struct.anon* %7 to i8*
%30 = call i32 @msgrcv(i32 %28, i8* %29, i32 132, i32 0, i32 0)
%31 = getelementptr inbounds %struct.anon, %struct.anon* %7, i32 0, i32 1
%32 = getelementptr inbounds [132 x i8], [132 x i8]* %31, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = load i32, i32* %6
%35 = load i32, i32* @IPC_RMID
%36 = call i32 @msgctl(i32 %34, i32 %35, i32 0)
%37 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.anon = type { i64, [132 x i8] }
@IPC_CREAT = global i32 0
@.str = [10 x i8] c"A MESSAGE\00"
@.str.1 = [21 x i8] c"You are sending: %s\0A\00"
@.str.2 = [32 x i8] c"Message is cleared, is now: %s\0A\00"
@.str.3 = [18 x i8] c"You received: %s\0A\00"
@IPC_RMID = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.anon
%4 = bitcast %struct.anon* %3 to i8*
%5 = getelementptr inbounds %struct.anon, %struct.anon* %3, i64 0, i32 0
store i64 1, i64* %5
%6 = load i32, i32* @IPC_CREAT
%7 = or i32 %6, 438
%8 = tail call i32 @msgget(i32 1234, i32 %7)
%9 = getelementptr inbounds %struct.anon, %struct.anon* %3, i64 0, i32 1, i64 0
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%12 = call i32 @msgsnd(i32 %8, i8* %4, i32 132, i32 0)
%13 = call i32 @memset(i8* %9, i32 0, i32 132)
%14 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%15 = call i32 @sleep(i32 5)
%16 = call i32 @msgrcv(i32 %8, i8* %4, i32 132, i32 0, i32 0)
%17 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%18 = load i32, i32* @IPC_RMID
%19 = call i32 @msgctl(i32 %8, i32 %18, i32 0)
%20 = call i32 @exit(i32 0)
unreachable
}