#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 msqid_ds {
  int msg_lspid;
};
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ IPC_NOWAIT;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ SIGUSR2;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int msgctl(int, int /*<<< orphan*/, struct msqid_ds *);
int msgget(int, int);
int msgrcv(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int msgQId, retFromRcv, retFromCtl;
  int key = 1234;
  char receivedMsg[100];
  struct msqid_ds myq;
  pid_t pid_sender;
  msgQId = msgget(key, 0666);
  printf("%d\n", msgQId);
  if (msgQId < 0) {
    printf("Error in msgqid!\n");
    exit(0);
  }
  retFromRcv = msgrcv(msgQId, receivedMsg, 100, 0, IPC_NOWAIT);
  printf("%d\n", retFromRcv);
  printf("%s\n", receivedMsg);
  if (retFromRcv < 0) {
    printf("Error in retFromRcv!\n");
    exit(0);
  }
  retFromCtl = msgctl(msgQId, IPC_RMID, &myq);
  printf("%d\n", retFromCtl);
  if (retFromCtl < 0) {
    printf("Error in retFromCtl!\n");
    exit(0);
  }
  pid_sender = myq.msg_lspid;
  printf("%d\n", pid_sender);
  kill(pid_sender, SIGUSR2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4d2,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1b6,%esi
call   1030 <msgget@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    11b9 <main+0x59>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    0x2e29(%rip),%rax
mov    (%rax),%r8d
mov    $0x64,%edx
xor    %ecx,%ecx
call   1080 <msgrcv@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jge    121b <main+0xbb>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
lea    -0x88(%rbp),%rdx
call   1060 <msgctl@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
jge    1266 <main+0x106>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x88(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%esi
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8c(%rbp),%edi
mov    0x2d45(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    $0x4d2,%edi
mov    $0x1b6,%esi
call   1030 <msgget@plt>
mov    %eax,%ebx
lea    0xe6d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
js     123f <main+0xcf>
mov    0x2e45(%rip),%rax
mov    (%rax),%r8d
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1090 <msgrcv@plt>
mov    %eax,%ebp
lea    0xe33(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
test   %ebp,%ebp
js     1248 <main+0xd8>
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1070 <msgctl@plt>
mov    %eax,%ebx
lea    0xe00(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
js     1251 <main+0xe1>
mov    0x8(%rsp),%ebx
lea    0xde8(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1060 <kill@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xde8(%rip),%rdi
jmp    1258 <main+0xe8>
lea    0xdca(%rip),%rdi
jmp    1258 <main+0xe8>
lea    0xdac(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.msqid_ds = type { i32 }
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [18 x i8] c"Error in msgqid!\0A\00"
@IPC_NOWAIT = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [22 x i8] c"Error in retFromRcv!\0A\00"
@IPC_RMID = global i32 0
@.str.4 = [22 x i8] c"Error in retFromCtl!\0A\00"
@SIGUSR2 = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = alloca %struct.msqid_ds
%8 = alloca i32
store i32 0, i32* %1
store i32 1234, i32* %5
%9 = load i32, i32* %5
%10 = call i32 @msgget(i32 %9, i32 438)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %0
%19 = load i32, i32* %2
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%21 = load i32, i32* @IPC_NOWAIT
%22 = call i32 @msgrcv(i32 %19, i8* %20, i32 100, i32 0, i32 %21)
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %18
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %18
%33 = load i32, i32* %2
%34 = load i32, i32* @IPC_RMID
%35 = call i32 @msgctl(i32 %33, i32 %34, %struct.msqid_ds* %7)
store i32 %35, i32* %4
%36 = load i32, i32* %4
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %4
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %32
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %32
%44 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %7, i32 0, i32 0
%45 = load i32, i32* %44
store i32 %45, i32* %8
%46 = load i32, i32* %8
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %8
%49 = load i32, i32* @SIGUSR2
%50 = call i32 @kill(i32 %48, i32 %49)
ret i32 0
}

LLVM IR (-O2):
%struct.msqid_ds = type { i32 }
@.str = [4 x i8] c"%d\0A\00"
@IPC_NOWAIT = global i32 0
@IPC_RMID = global i32 0
@SIGUSR2 = global i32 0
@str = [21 x i8] c"Error in retFromCtl!\00"
@str.5 = [21 x i8] c"Error in retFromRcv!\00"
@str.6 = [17 x i8] c"Error in msgqid!\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca %struct.msqid_ds
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.msqid_ds* %2 to i8*
%5 = tail call i32 @msgget(i32 1234, i32 438)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %5, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %0
%12 = load i32, i32* @IPC_NOWAIT
%13 = call i32 @msgrcv(i32 %5, i8* %3, i32 100, i32 0, i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @puts(i8* %3)
%16 = icmp slt i32 %13, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %11
%21 = load i32, i32* @IPC_RMID
%22 = call i32 @msgctl(i32 %5, i32 %21, %struct.msqid_ds* %2)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = icmp slt i32 %22, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %20
%29 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @SIGUSR2
%33 = call i32 @kill(i32 %30, i32 %32)
ret i32 0
}