#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ IPC_RMID;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int msgctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int msgget(int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  int id = 0;
  int perms = S_IRUSR | S_IWUSR | S_IWGRP;
  id = msgget(IPC_PRIVATE, perms);
  if (id == -1)
    do {
      perror("Create message queue failed");
      exit(EXIT_FAILURE);
    } while (0);
  printf("Message queue id: %d\n", id);
  if (msgctl(id, IPC_RMID, NULL) == -1)
    do {
      perror("Delete message queue id failed");
      exit(EXIT_FAILURE);
    } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    0x2e5b(%rip),%rcx
or     (%rcx),%eax
mov    0x2e62(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%esi
call   1030 <msgget@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c8 <main+0x78>
jmp    11ae <main+0x5e>
lea    0xe4b(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%esi
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <msgctl@plt>
cmp    $0xffffffff,%eax
jne    1214 <main+0xc4>
jmp    11fa <main+0xaa>
lea    0xe31(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e60(%rip),%rax
mov    0x2e79(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e7e(%rip),%rax
or     (%rax),%esi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
call   1030 <msgget@plt>
cmp    $0xffffffff,%eax
je     11aa <main+0x5a>
mov    %eax,%ebx
lea    0xe94(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <msgctl@plt>
cmp    $0xffffffff,%eax
je     11b3 <main+0x63>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe4f(%rip),%rdi
jmp    11ba <main+0x6a>
lea    0xe78(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IWGRP = global i32 0
@IPC_PRIVATE = global i32 0
@.str = [28 x i8] c"Create message queue failed\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [22 x i8] c"Message queue id: %d\0A\00"
@IPC_RMID = global i32 0
@.str.2 = [31 x i8] c"Delete message queue id failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IWGRP
%12 = or i32 %10, %11
store i32 %12, i32* %7
%13 = load i32, i32* @IPC_PRIVATE
%14 = load i32, i32* %7
%15 = call i32 @msgget(i32 %13, i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %2
br label %19
19: ; preds = %18
%20 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; No predecessors!
br label %24
24: ; preds = %23, %2
%25 = load i32, i32* %6
%26 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %6
%28 = load i32, i32* @IPC_RMID
%29 = call i32 @msgctl(i32 %27, i32 %28, i32* null)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %37
31: ; preds = %24
br label %32
32: ; preds = %31
%33 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; No predecessors!
br label %37
37: ; preds = %36, %24
ret i32 0
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IWGRP = global i32 0
@IPC_PRIVATE = global i32 0
@.str = [28 x i8] c"Create message queue failed\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [22 x i8] c"Message queue id: %d\0A\00"
@IPC_RMID = global i32 0
@.str.2 = [31 x i8] c"Delete message queue id failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @S_IRUSR
%4 = load i32, i32* @S_IWUSR
%5 = or i32 %4, %3
%6 = load i32, i32* @S_IWGRP
%7 = or i32 %5, %6
%8 = load i32, i32* @IPC_PRIVATE
%9 = tail call i32 @msgget(i32 %8, i32 %7)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%17 = load i32, i32* @IPC_RMID
%18 = tail call i32 @msgctl(i32 %9, i32 %17, i32* null)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %15
ret i32 0
}