#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__ msgsnd(int, struct msgbuf *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main() {
  int msqid;
  char pathname[] = "temp2";
  key_t key;
  int i, len;
  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);
  }
  len = sizeof(mybuf.content);
  for (i = 1; i <= 5; i++) {
    mybuf.mtype = 1;
    mybuf.content.i_info = i * 5;
    mybuf.content.d_info = 3.1415 * i;
    if (msgsnd(msqid, (struct msgbuf *)&mybuf, len, 0) < 0) {
      printf("Can\'t send message to queue\n");
      msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
      exit(-1);
    }
  }
  mybuf.mtype = 255;
  len = 0;
  if (msgsnd(msqid, (struct msgbuf *)&mybuf, len, 0) < 0) {
    printf("Can\'t send message to queue\n");
    msgctl(msqid, IPC_RMID, (struct msqid_ds *)NULL);
    exit(-1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe93(%rip),%eax
mov    %eax,-0xe(%rbp)
mov    0xe8d(%rip),%ax
mov    %ax,-0xa(%rbp)
lea    -0xe(%rbp),%rdi
xor    %esi,%esi
call   1080 <ftok@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11b0 <main+0x50>
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
call   1030 <msgget@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11e9 <main+0x89>
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
movl   $0x10,-0x1c(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x5,-0x18(%rbp)
jg     127f <main+0x11f>
movq   $0x1,-0x38(%rbp)
imul   $0x5,-0x18(%rbp),%eax
mov    %eax,-0x30(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm1
movsd  0xde3(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1050 <msgsnd@plt>
cmp    $0x0,%rax
jge    126c <main+0x10c>
lea    0xdeb(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2d89(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <msgctl@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    1271 <main+0x111>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11f7 <main+0x97>
movq   $0xff,-0x38(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1050 <msgsnd@plt>
cmp    $0x0,%rax
jge    12d4 <main+0x174>
lea    0xd83(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2d21(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <msgctl@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movw   $0x32,0x1c(%rsp)
movl   $0x706d6574,0x18(%rsp)
70
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1080 <ftok@plt>
test   %eax,%eax
js     1307 <main+0x1a7>
mov    0x2e49(%rip),%rcx
mov    $0x1b6,%esi
or     (%rcx),%esi
mov    %eax,%edi
call   1030 <msgget@plt>
test   %eax,%eax
js     1310 <main+0x1b0>
mov    %eax,%ebx
movq   $0x1,(%rsp)
movl   $0x5,0x8(%rsp)
movabs $0x400921cac083126f,%rax
21 09 40
mov    %rax,0x10(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1050 <msgsnd@plt>
test   %rax,%rax
js     12df <main+0x17f>
movq   $0x1,(%rsp)
movl   $0xa,0x8(%rsp)
movabs $0x401921cac083126f,%rax
21 19 40
mov    %rax,0x10(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1050 <msgsnd@plt>
test   %rax,%rax
js     12df <main+0x17f>
movq   $0x1,(%rsp)
movl   $0xf,0x8(%rsp)
movabs $0x4022d95810624dd3,%rax
d9 22 40
mov    %rax,0x10(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1050 <msgsnd@plt>
test   %rax,%rax
js     12df <main+0x17f>
movq   $0x1,(%rsp)
movl   $0x14,0x8(%rsp)
movabs $0x402921cac083126f,%rax
21 29 40
mov    %rax,0x10(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1050 <msgsnd@plt>
test   %rax,%rax
js     12df <main+0x17f>
movq   $0x1,(%rsp)
movl   $0x19,0x8(%rsp)
movabs $0x402f6a3d70a3d70b,%rax
6a 2f 40
mov    %rax,0x10(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1050 <msgsnd@plt>
test   %rax,%rax
js     12df <main+0x17f>
movq   $0xff,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <msgsnd@plt>
test   %rax,%rax
js     12df <main+0x17f>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xd20(%rip),%rdi
call   1040 <puts@plt>
mov    0x2cee(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1060 <msgctl@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    0xd24(%rip),%rdi
jmp    1317 <main+0x1b7>
lea    0xd0b(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%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 = [29 x i8] c"Can't send message to queue\0A\00"
@IPC_RMID = global i32 0
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 @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 @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
store i32 16, i32* %6
store i32 1, i32* %5
br label %25
25: ; preds = %51, %24
%26 = load i32, i32* %5
%27 = icmp sle i32 %26, 5
br i1 %27, label %28, label %54
28: ; preds = %25
%29 = getelementptr inbounds %struct.mymsgbuf, %struct.mymsgbuf* %7, i32 0, i32 0
store i64 1, i64* %29
%30 = load i32, i32* %5
%31 = mul nsw i32 %30, 5
%32 = getelementptr inbounds %struct.mymsgbuf, %struct.mymsgbuf* %7, i32 0, i32 1
%33 = getelementptr inbounds %struct.anon, %struct.anon* %32, i32 0, i32 0
store i32 %31, i32* %33
%34 = load i32, i32* %5
%35 = sitofp i32 %34 to double
%36 = fmul double 3.141500e+00, %35
%37 = getelementptr inbounds %struct.mymsgbuf, %struct.mymsgbuf* %7, i32 0, i32 1
%38 = getelementptr inbounds %struct.anon, %struct.anon* %37, i32 0, i32 1
store double %36, double* %38
%39 = load i32, i32* %2
%40 = bitcast %struct.mymsgbuf* %7 to %struct.msgbuf*
%41 = load i32, i32* %6
%42 = call i64 @msgsnd(i32 %39, %struct.msgbuf* %40, i32 %41, i32 0)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %28
%45 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%46 = load i32, i32* %2
%47 = load i32, i32* @IPC_RMID
%48 = call i32 @msgctl(i32 %46, i32 %47, %struct.msqid_ds* null)
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %28
br label %51
51: ; preds = %50
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
br label %25
54: ; preds = %25
%55 = getelementptr inbounds %struct.mymsgbuf, %struct.mymsgbuf* %7, i32 0, i32 0
store i64 255, i64* %55
store i32 0, i32* %6
%56 = load i32, i32* %2
%57 = bitcast %struct.mymsgbuf* %7 to %struct.msgbuf*
%58 = load i32, i32* %6
%59 = call i64 @msgsnd(i32 %56, %struct.msgbuf* %57, i32 %58, i32 0)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %67
61: ; preds = %54
%62 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%63 = load i32, i32* %2
%64 = load i32, i32* @IPC_RMID
%65 = call i32 @msgctl(i32 %63, i32 %64, %struct.msqid_ds* null)
%66 = call i32 @exit(i32 -1)
unreachable
67: ; preds = %54
ret i32 0
}

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 = [28 x i8] c"Can't send message to 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 %22, label %15
15: ; preds = %10
%16 = getelementptr inbounds %struct.mymsgbuf, %struct.mymsgbuf* %2, i64 0, i32 0
%17 = getelementptr inbounds %struct.mymsgbuf, %struct.mymsgbuf* %2, i64 0, i32 1, i32 0
%18 = getelementptr inbounds %struct.mymsgbuf, %struct.mymsgbuf* %2, i64 0, i32 1, i32 1
%19 = bitcast %struct.mymsgbuf* %2 to %struct.msgbuf*
store i64 1, i64* %16
store i32 5, i32* %17
store double 3.141500e+00, double* %18
%20 = call i64 @msgsnd(i32 %13, %struct.msgbuf* %19, i32 16, i32 0)
%21 = icmp slt i64 %20, 0
br i1 %21, label %40, label %25
22: ; preds = %10
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0))
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %15
store i64 1, i64* %16
store i32 10, i32* %17
store double 6.283000e+00, double* %18
%26 = call i64 @msgsnd(i32 %13, %struct.msgbuf* %19, i32 16, i32 0)
%27 = icmp slt i64 %26, 0
br i1 %27, label %40, label %28
28: ; preds = %25
store i64 1, i64* %16
store i32 15, i32* %17
store double 9.424500e+00, double* %18
%29 = call i64 @msgsnd(i32 %13, %struct.msgbuf* %19, i32 16, i32 0)
%30 = icmp slt i64 %29, 0
br i1 %30, label %40, label %31
31: ; preds = %28
store i64 1, i64* %16
store i32 20, i32* %17
store double 1.256600e+01, double* %18
%32 = call i64 @msgsnd(i32 %13, %struct.msgbuf* %19, i32 16, i32 0)
%33 = icmp slt i64 %32, 0
br i1 %33, label %40, label %34
34: ; preds = %31
store i64 1, i64* %16
store i32 25, i32* %17
store double 0x402F6A3D70A3D70B, double* %18
%35 = call i64 @msgsnd(i32 %13, %struct.msgbuf* %19, i32 16, i32 0)
%36 = icmp slt i64 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %34
store i64 255, i64* %16
%38 = call i64 @msgsnd(i32 %13, %struct.msgbuf* %19, i32 0, i32 0)
%39 = icmp slt i64 %38, 0
br i1 %39, label %45, label %50
40: ; preds = %34, %31, %28, %25, %15
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.3, i64 0, i64 0))
%42 = load i32, i32* @IPC_RMID
%43 = call i32 @msgctl(i32 %13, i32 %42, %struct.msqid_ds* null)
%44 = call i32 @exit(i32 -1)
unreachable
45: ; preds = %37
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.3, i64 0, i64 0))
%47 = load i32, i32* @IPC_RMID
%48 = call i32 @msgctl(i32 %13, i32 %47, %struct.msqid_ds* null)
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %37
ret i32 0
}