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

/* Variables and functions */
int /*<<< orphan*/ IPC_STAT;
char *ctime(int /*<<< orphan*/ *);
scalar_t__ msgctl(int, int /*<<< orphan*/, struct msqid_ds *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int msq_status(int msq_id) {
  struct msqid_ds buf = {0};
  if (msgctl(msq_id, IPC_STAT, &buf) < 0)
    do {
      perror("msgctl");
      return -1;
    } while (0);
  printf("--------status---------\n");
  printf("stime: %s", ctime(&buf.msg_stime));
  printf("rtime: %s", ctime(&buf.msg_rtime));
  printf("ctime: %s", ctime(&buf.msg_ctime));
  printf("msg_qnum: %lu\n", buf.msg_qnum);
  printf("msg_qbytes: %lu\n", buf.msg_qbytes);
  printf("lspid: %hu\n", buf.msg_lspid);
  printf("lrpid: %hu\n", buf.msg_lrpid);
  printf("--------status---over-------\n");
  return 0;
}


x86 assembly (clang, -O0):
<msq_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1060 <msgctl@plt>
cmp    $0x0,%rax
jge    11a7 <msq_status+0x57>
jmp    118f <msq_status+0x3f>
lea    0xe6a(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1268 <msq_status+0x118>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x28(%rbp),%rdi
add    $0x18,%rdi
call   1030 <ctime@plt>
mov    %rax,%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x28(%rbp),%rdi
add    $0x14,%rdi
call   1030 <ctime@plt>
mov    %rax,%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x28(%rbp),%rdi
add    $0x10,%rdi
call   1030 <ctime@plt>
mov    %rax,%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msq_status>:
push   %rbx
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1060 <msgctl@plt>
test   %rax,%rax
js     1235 <msq_status+0xe5>
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
lea    0x18(%rsp),%rdi
call   1040 <ctime@plt>
lea    0xe6f(%rip),%rdi
xor    %ebx,%ebx
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x14(%rsp),%rdi
call   1040 <ctime@plt>
lea    0xe5c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rsp),%rdi
call   1040 <ctime@plt>
lea    0xe4b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xe40(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xe3d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xe3c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%esi
lea    0xe37(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xdc4(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%ebx
jmp    122d <msq_status+0xdd>

LLVM IR (-O0):
%struct.msqid_ds = type { i32, i32, i32, i32, i32, i32, i32, i32 }
@IPC_STAT = global i32 0
@.str = [7 x i8] c"msgctl\00"
@.str.1 = [25 x i8] c"--------status---------\0A\00"
@.str.2 = [10 x i8] c"stime: %s\00"
@.str.3 = [10 x i8] c"rtime: %s\00"
@.str.4 = [10 x i8] c"ctime: %s\00"
@.str.5 = [15 x i8] c"msg_qnum: %lu\0A\00"
@.str.6 = [17 x i8] c"msg_qbytes: %lu\0A\00"
@.str.7 = [12 x i8] c"lspid: %hu\0A\00"
@.str.8 = [12 x i8] c"lrpid: %hu\0A\00"
@.str.9 = [30 x i8] c"--------status---over-------\0A\00"
define i32 @msq_status(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.msqid_ds
store i32 %0, i32* %3
%5 = bitcast %struct.msqid_ds* %4 to i8*
%6 = load i32, i32* %3
%7 = load i32, i32* @IPC_STAT
%8 = call i64 @msgctl(i32 %6, i32 %7, %struct.msqid_ds* %4)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
br label %11
11: ; preds = %10
%12 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %38
13: ; No predecessors!
br label %14
14: ; preds = %13, %1
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i32 0, i32 6
%17 = call i8* @ctime(i32* %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i32 0, i32 5
%20 = call i8* @ctime(i32* %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i32 0, i32 4
%23 = call i8* @ctime(i32* %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i32 0, i32 3
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i32 0, i32 2
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i32 0, i32 1
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %4, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %2
br label %38
38: ; preds = %14, %11
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
%struct.msqid_ds = type { i32, i32, i32, i32, i32, i32, i32, i32 }
@IPC_STAT = global i32 0
@.str = [7 x i8] c"msgctl\00"
@.str.2 = [10 x i8] c"stime: %s\00"
@.str.3 = [10 x i8] c"rtime: %s\00"
@.str.4 = [10 x i8] c"ctime: %s\00"
@.str.5 = [15 x i8] c"msg_qnum: %lu\0A\00"
@.str.6 = [17 x i8] c"msg_qbytes: %lu\0A\00"
@.str.7 = [12 x i8] c"lspid: %hu\0A\00"
@.str.8 = [12 x i8] c"lrpid: %hu\0A\00"
@str = [24 x i8] c"--------status---------\00"
@str.10 = [29 x i8] c"--------status---over-------\00"
define i32 @msq_status(i32 %0) {
%2 = alloca %struct.msqid_ds
%3 = bitcast %struct.msqid_ds* %2 to i8*
%4 = load i32, i32* @IPC_STAT
%5 = call i64 @msgctl(i32 %0, i32 %4, %struct.msqid_ds* %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %33
9: ; preds = %1
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%11 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 6
%12 = call i8* @ctime(i32* %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 5
%15 = call i8* @ctime(i32* %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 4
%18 = call i8* @ctime(i32* %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 3
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 2
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 1
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %30)
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.10, i64 0, i64 0))
br label %33
33: ; preds = %9, %7
%34 = phi i32 [ -1, %7 ], [ 0, %9 ]
ret i32 %34
}