#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*/ IPC_RMID;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ logmsg(int /*<<< orphan*/, char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/);
scalar_t__ msgctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void release_message_queue(int msgid) {
  if (msgid < 0)
    return;
  if (msgctl(msgid, IPC_RMID, NULL) < 0) {
    logmsg(0, "failed to delete message queue (%x): %s (errno=%d)\n", msgid,
           strerror(errno), errno);
  }
  msgid = -1;
}


x86 assembly (clang, -O0):
<release_message_queue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    114a <release_message_queue+0x1a>
jmp    11a1 <release_message_queue+0x71>
mov    -0x4(%rbp),%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <msgctl@plt>
cmp    $0x0,%rax
jge    119a <release_message_queue+0x6a>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x8(%rbp),%edx
mov    %eax,%ecx
mov    0x2e57(%rip),%rax
mov    (%rax),%r8d
xor    %edi,%edi
lea    0xe6b(%rip),%rsi
call   1040 <logmsg@plt>
movl   $0xffffffff,-0x4(%rbp)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<release_message_queue>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
js     114f <release_message_queue+0x1f>
mov    %edi,%ebx
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <msgctl@plt>
test   %rax,%rax
js     1157 <release_message_queue+0x27>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e82(%rip),%r14
mov    (%r14),%edi
call   1050 <strerror@plt>
mov    (%r14),%r8d
lea    0xe90(%rip),%rsi
xor    %edi,%edi
mov    %ebx,%edx
mov    %eax,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <logmsg@plt>

LLVM IR (-O0):
@IPC_RMID = global i32 0
@.str = [52 x i8] c"failed to delete message queue (%x): %s (errno=%d)\0A\00"
@errno = global i32 0
define void @release_message_queue(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %1
br label %18
6: ; preds = %1
%7 = load i32, i32* %2
%8 = load i32, i32* @IPC_RMID
%9 = call i64 @msgctl(i32 %7, i32 %8, i32* null)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = load i32, i32* %2
%13 = load i32, i32* @errno
%14 = call i32 @strerror(i32 %13)
%15 = load i32, i32* @errno
%16 = call i32 @logmsg(i32 0, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %14, i32 %15)
br label %17
17: ; preds = %11, %6
store i32 -1, i32* %2
br label %18
18: ; preds = %17, %5
ret void
}

LLVM IR (-O2):
@IPC_RMID = global i32 0
@.str = [52 x i8] c"failed to delete message queue (%x): %s (errno=%d)\0A\00"
@errno = global i32 0
define void @release_message_queue(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = load i32, i32* @IPC_RMID
%5 = tail call i64 @msgctl(i32 %0, i32 %4, i32* null)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = load i32, i32* @errno
%11 = tail call i32 @logmsg(i32 0, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %9, i32 %10)
br label %12
12: ; preds = %3, %7, %1
ret void
}