#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_qnum;
  int msg_qbytes;
  int msg_lspid;
  int msg_lrpid;
  int msg_stime;
  int msg_rtime;
  int msg_ctime;
  int /*<<< orphan*/ msg_perm;
};

/* Variables and functions */
int /*<<< orphan*/ IPC_STAT;
int /*<<< orphan*/ dump_perm(int /*<<< orphan*/ *);
int /*<<< orphan*/ err_sys(char *);
int msgctl(int, int /*<<< orphan*/, struct msqid_ds *);
int /*<<< orphan*/ printf(char *, char const *, int, int, int, int, int, int,
                          int, int);
void dump_queue(char const *prompt, int mid, int with_perm) {
  struct msqid_ds mbuf;
  int ret = msgctl(mid, IPC_STAT, &mbuf);
  if (ret < 0)
    err_sys("msgctl to stat queue failed");
  printf("%s queue %d: \n"
         "   qnum: %d\n"
         "   qbytes: %d\n"
         "   last send pid: %d\n"
         "   last recv pid: %d\n"
         "   last send time: %d\n"
         "   last recv time: %d\n"
         "   last change time: %d\n",
         prompt, mid, mbuf.msg_qnum, mbuf.msg_qbytes, mbuf.msg_lspid,
         mbuf.msg_lrpid, mbuf.msg_stime, mbuf.msg_rtime, mbuf.msg_ctime);
  if (with_perm)
    dump_perm(&mbuf.msg_perm);
}


x86 assembly (clang, -O0):
<dump_queue>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x58,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1060 <msgctl@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    1181 <dump_queue+0x41>
lea    0xe84(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x38(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    -0x30(%rbp),%r9d
mov    -0x2c(%rbp),%ebx
mov    -0x28(%rbp),%r11d
mov    -0x24(%rbp),%r10d
mov    -0x20(%rbp),%eax
lea    0xe74(%rip),%rdi
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
call   1040 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
je     11d5 <dump_queue+0x95>
lea    -0x38(%rbp),%rdi
add    $0x1c,%rdi
call   1050 <dump_perm@plt>
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_queue>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1060 <msgctl@plt>
test   %eax,%eax
jns    1177 <dump_queue+0x37>
lea    0xe8e(%rip),%rdi
call   1030 <err_sys@plt>
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    0x10(%rsp),%r9d
mov    0x14(%rsp),%r10d
mov    0x18(%rsp),%r11d
mov    0x1c(%rsp),%eax
mov    0x20(%rsp),%ebx
lea    0xe7e(%rip),%rdi
mov    %r15,%rsi
mov    %ebp,%edx
push   %rbx
push   %rax
push   %r11
push   %r10
call   1040 <printf@plt>
add    $0x20,%rsp
test   %r14d,%r14d
je     11c1 <dump_queue+0x81>
lea    0x24(%rsp),%rdi
call   1050 <dump_perm@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.msqid_ds = type { i32, i32, i32, i32, i32, i32, i32, i32 }
@IPC_STAT = global i32 0
@.str = [28 x i8] c"msgctl to stat queue failed\00"
@.str.1 = [151 x i8] c"%s queue %d: \0A qnum: %d\0A qbytes: %d\0A last send pid: %d\0A last recv pid: %d\0A last send time: %d\0A last recv time: %d\0A last change time: %d\0A\00"
define void @dump_queue(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.msqid_ds
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = load i32, i32* @IPC_STAT
%11 = call i32 @msgctl(i32 %9, i32 %10, %struct.msqid_ds* %7)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @err_sys(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %3
%17 = load i8*, i8** %4
%18 = load i32, i32* %5
%19 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %7, i32 0, i32 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %7, i32 0, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %7, i32 0, i32 2
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %7, i32 0, i32 3
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %7, i32 0, i32 4
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %7, i32 0, i32 5
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %7, i32 0, i32 6
%32 = load i32, i32* %31
%33 = call i32 @printf(i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i8* %17, i32 %18, i32 %20, i32 %22, i32 %24, i32 %26, i32 %28, i32 %30, i32 %32)
%34 = load i32, i32* %6
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %16
%37 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %7, i32 0, i32 7
%38 = call i32 @dump_perm(i32* %37)
br label %39
39: ; preds = %36, %16
ret void
}

LLVM IR (-O2):
%struct.msqid_ds = type { i32, i32, i32, i32, i32, i32, i32, i32 }
@IPC_STAT = global i32 0
@.str = [28 x i8] c"msgctl to stat queue failed\00"
@.str.1 = [151 x i8] c"%s queue %d: \0A qnum: %d\0A qbytes: %d\0A last send pid: %d\0A last recv pid: %d\0A last send time: %d\0A last recv time: %d\0A last change time: %d\0A\00"
define void @dump_queue(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.msqid_ds
%5 = bitcast %struct.msqid_ds* %4 to i8*
%6 = load i32, i32* @IPC_STAT
%7 = call i32 @msgctl(i32 %1, i32 %6, %struct.msqid_ds* %4)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = call i32 @err_sys(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %3
%12 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i64 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i64 0, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i64 0, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i64 0, i32 3
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i64 0, i32 4
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i64 0, i32 5
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i64 0, i32 6
%25 = load i32, i32* %24
%26 = call i32 @printf(i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %1, i32 %13, i32 %15, i32 %17, i32 %19, i32 %21, i32 %23, i32 %25)
%27 = icmp eq i32 %2, 0
br i1 %27, label %31, label %28
28: ; preds = %11
%29 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i64 0, i32 7
%30 = call i32 @dump_perm(i32* %29)
br label %31
31: ; preds = %28, %11
ret void
}