#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 dummy;
};
struct msgbuf {
  int dummy;
};
typedef int /*<<< orphan*/ key_t;

/* Variables and functions */
int IPC_CREAT;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ ftok(char *, int /*<<< orphan*/);
int /*<<< orphan*/ msgctl(int, int /*<<< orphan*/, struct msqid_ds *);
int msgget(int /*<<< orphan*/, int);
scalar_t__ msgrcv(int, struct msgbuf *, int, int /*<<< orphan*/,
                  int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int msqid;
  char pathname[] = "temp2";
  key_t key;
  int len, maxlen;
  struct mymsgbuf {
    long mtype;
    struct {
      int i_info;
      double d_info;
    } content;
  } mybuf;
  if ((key = ftok(pathname, 0)) < 0) {
    printf("Can\'t generate key\n");
    exit(-1);
  }
  if ((msqid = msgget(key, 0666 | IPC_CREAT)) < 0) {
    printf("Can\'t get msqid\n");
    exit(-1);
  }
  while (1) {
    maxlen = 16;
    if (len = msgrcv(msqid, (struct msgbuf *)&mybuf, maxlen, 0, 0) < 0) {
      printf("Can\'t receive message from queue\n");
      exit(-1);
    }
    if (mybuf.mtype == 255) {
      msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
      exit(0);
    }
    printf("message type = %ld, i_info = %d, d_info= %f\n", mybuf.mtype,
           mybuf.content.i_info, mybuf.content.d_info);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8b(%rip),%eax
mov    %eax,-0xe(%rbp)
mov    0xe85(%rip),%ax
mov    %ax,-0xa(%rbp)
lea    -0xe(%rbp),%rdi
xor    %esi,%esi
call   1070 <ftok@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11b2 <main+0x52>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
call   1030 <msgget@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11ed <main+0x8d>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jmp    11f2 <main+0x92>
movl   $0x10,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1080 <msgrcv@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x18(%rbp)
test   $0x1,%al
jne    122d <main+0xcd>
jmp    1245 <main+0xe5>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
cmpq   $0xff,-0x38(%rbp)
jne    126f <main+0x10f>
mov    -0x8(%rbp),%edi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <msgctl@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%edx
movsd  -0x28(%rbp),%xmm0
lea    0xdcb(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    11f2 <main+0x92>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movw   $0x32,0x4(%rsp)
movl   $0x706d6574,(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1080 <ftok@plt>
test   %eax,%eax
jns    11a1 <main+0x31>
lea    0xec8(%rip),%rdi
jmp    1232 <main+0xc2>
mov    0x2e30(%rip),%rcx
mov    $0x1b6,%esi
or     (%rcx),%esi
mov    %eax,%edi
call   1030 <msgget@plt>
test   %eax,%eax
jns    11c3 <main+0x53>
lea    0xe93(%rip),%rdi
jmp    1232 <main+0xc2>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x10,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <msgrcv@plt>
test   %rax,%rax
js     122b <main+0xbb>
lea    0xe1f(%rip),%r14
lea    0x8(%rsp),%r15
nopl   0x0(%rax)
mov    0x8(%rsp),%rsi
cmp    $0xff,%rsi
je     1241 <main+0xd1>
mov    0x10(%rsp),%edx
movsd  0x18(%rsp),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <msgrcv@plt>
test   %rax,%rax
jns    11f0 <main+0x80>
lea    0xe01(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1060 <msgctl@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.mymsgbuf = type { i64, %struct.anon }
%struct.anon = type { i32, double }
%struct.msgbuf = type { i32 }
%struct.msqid_ds = type { i32 }
@__const.main.pathname = [6 x i8] c"temp2\00"
@.str = [20 x i8] c"Can't generate key\0A\00"
@IPC_CREAT = global i32 0
@.str.1 = [17 x i8] c"Can't get msqid\0A\00"
@.str.2 = [34 x i8] c"Can't receive message from queue\0A\00"
@IPC_RMID = global i32 0
@.str.3 = [45 x i8] c"message type = %ld, i_info = %d, d_info= %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [6 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.mymsgbuf
store i32 0, i32* %1
%8 = bitcast [6 x i8]* %3 to i8*
%9 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%10 = call i32 @ftok(i8* %9, i32 0)
store i32 %10, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %0
%16 = load i32, i32* %4
%17 = load i32, i32* @IPC_CREAT
%18 = or i32 438, %17
%19 = call i32 @msgget(i32 %16, i32 %18)
store i32 %19, i32* %2
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %15
br label %25
25: ; preds = %24, %44
store i32 16, i32* %6
%26 = load i32, i32* %2
%27 = bitcast %struct.mymsgbuf* %7 to %struct.msgbuf*
%28 = load i32, i32* %6
%29 = call i64 @msgrcv(i32 %26, %struct.msgbuf* %27, i32 %28, i32 0, i32 0)
%30 = icmp slt i64 %29, 0
%31 = zext i1 %30 to i32
store i32 %31, i32* %5
br i1 %30, label %32, label %35
32: ; preds = %25
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %25
%36 = getelementptr inbounds %struct.mymsgbuf, %struct.mymsgbuf* %7, i32 0, i32 0
%37 = load i64, i64* %36
%38 = icmp eq i64 %37, 255
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i32, i32* %2
%41 = load i32, i32* @IPC_RMID
%42 = call i32 @msgctl(i32 %40, i32 %41, %struct.msqid_ds* null)
%43 = call i32 @exit(i32 0)
unreachable
44: ; preds = %35
%45 = getelementptr inbounds %struct.mymsgbuf, %struct.mymsgbuf* %7, i32 0, i32 0
%46 = load i64, i64* %45
%47 = getelementptr inbounds %struct.mymsgbuf, %struct.mymsgbuf* %7, i32 0, i32 1
%48 = getelementptr inbounds %struct.anon, %struct.anon* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.mymsgbuf, %struct.mymsgbuf* %7, i32 0, i32 1
%51 = getelementptr inbounds %struct.anon, %struct.anon* %50, i32 0, i32 1
%52 = load double, double* %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i64 %46, i32 %49, double %52)
br label %25
}

LLVM IR (-O2):
%struct.mymsgbuf = type { i64, %struct.anon }
%struct.anon = type { i32, double }
%struct.msgbuf = type { i32 }
%struct.msqid_ds = type { i32 }
@__const.main.pathname = [6 x i8] c"temp2\00"
@IPC_CREAT = global i32 0
@IPC_RMID = global i32 0
@.str.3 = [45 x i8] c"message type = %ld, i_info = %d, d_info= %f\0A\00"
@str = [33 x i8] c"Can't receive message from queue\00"
@str.4 = [16 x i8] c"Can't get msqid\00"
@str.5 = [19 x i8] c"Can't generate key\00"
define i32 @main() {
%1 = alloca [6 x i8]
%2 = alloca %struct.mymsgbuf
%3 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.mymsgbuf* %2 to i8*
%5 = call i32 @ftok(i8* %3, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
%9 = call i32 @exit(i32 -1)
unreachable
10: ; preds = %0
%11 = load i32, i32* @IPC_CREAT
%12 = or i32 %11, 438
%13 = call i32 @msgget(i32 %5, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %10
%16 = bitcast %struct.mymsgbuf* %2 to %struct.msgbuf*
%17 = call i64 @msgrcv(i32 %13, %struct.msgbuf* %16, i32 16, i32 0, i32 0)
%18 = icmp slt i64 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %15
%20 = getelementptr inbounds %struct.mymsgbuf, %struct.mymsgbuf* %2, i64 0, i32 0
%21 = getelementptr inbounds %struct.mymsgbuf, %struct.mymsgbuf* %2, i64 0, i32 1, i32 0
%22 = getelementptr inbounds %struct.mymsgbuf, %struct.mymsgbuf* %2, i64 0, i32 1, i32 1
br label %29
23: ; preds = %10
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0))
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %36, %15
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %19, %36
%30 = load i64, i64* %20
%31 = icmp eq i64 %30, 255
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32, i32* @IPC_RMID
%34 = call i32 @msgctl(i32 %13, i32 %33, %struct.msqid_ds* null)
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %29
%37 = load i32, i32* %21
%38 = load double, double* %22
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i64 %30, i32 %37, double %38)
%40 = call i64 @msgrcv(i32 %13, %struct.msgbuf* %16, i32 16, i32 0, i32 0)
%41 = icmp slt i64 %40, 0
br i1 %41, label %26, label %29
}