#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 ipc_perm {
  int uid;
  int gid;
  int cuid;
  int cgid;
  int mode;
};
struct msqid_ds {
  scalar_t__ msg_ctime;
  scalar_t__ msg_rtime;
  scalar_t__ msg_stime;
  int /*<<< orphan*/ msg_lrpid;
  int /*<<< orphan*/ msg_lspid;
  scalar_t__ msg_qnum;
  scalar_t__ msg_qbytes;
  scalar_t__ msg_cbytes;
  struct ipc_perm msg_perm;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ IPC_STAT;
char *ctime(scalar_t__ *);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int msgctl(int, int /*<<< orphan*/, struct msqid_ds *);
int /*<<< orphan*/ printf(char *, ...);
void print_msg(int msqid) {
  struct msqid_ds buf;
  struct ipc_perm *ipcp = &buf.msg_perm;
  if (msgctl(msqid, IPC_STAT, &buf) == -1)
    err(EXIT_FAILURE, ("msgctl failed"));
  printf(("\nMessage Queue msqid=%d\n"), msqid);
  printf(("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"), ipcp->uid, ipcp->gid,
         ipcp->cuid, ipcp->cgid, ipcp->mode);
  printf(("cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n"),
         (long)buf.msg_cbytes, (long)buf.msg_qbytes, (long)buf.msg_qnum,
         buf.msg_lspid, buf.msg_lrpid);
  printf(("send_time=%-26.24s\n"),
         buf.msg_stime ? ctime(&buf.msg_stime) : ("Not set"));
  printf(("rcv_time=%-26.24s\n"),
         buf.msg_rtime ? ctime(&buf.msg_rtime) : ("Not set"));
  printf(("change_time=%-26.24s\n"),
         buf.msg_ctime ? ctime(&buf.msg_ctime) : ("Not set"));
  printf("\n");
  return;
}


x86 assembly (clang, -O0):
<print_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x58(%rbp),%rax
add    $0x38,%rax
mov    %rax,-0x60(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdx
call   1060 <msgctl@plt>
cmp    $0xffffffff,%eax
jne    118d <print_msg+0x4d>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1050 <err@plt>
mov    -0x4(%rbp),%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x60(%rbp),%rax
mov    (%rax),%esi
mov    -0x60(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x60(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x60(%rbp),%rax
mov    0xc(%rax),%r8d
mov    -0x60(%rbp),%rax
mov    0x10(%rax),%r9d
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x3c(%rbp),%r8d
mov    -0x40(%rbp),%r9d
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x48(%rbp)
je     1213 <print_msg+0xd3>
lea    -0x58(%rbp),%rdi
add    $0x10,%rdi
call   1030 <ctime@plt>
mov    %rax,-0x68(%rbp)
jmp    1223 <print_msg+0xe3>
lea    0xe7b(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    1223 <print_msg+0xe3>
mov    -0x68(%rbp),%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x50(%rbp)
je     1256 <print_msg+0x116>
lea    -0x58(%rbp),%rdi
add    $0x8,%rdi
call   1030 <ctime@plt>
mov    %rax,-0x70(%rbp)
jmp    1266 <print_msg+0x126>
lea    0xe38(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    1266 <print_msg+0x126>
mov    -0x70(%rbp),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x58(%rbp)
je     1295 <print_msg+0x155>
lea    -0x58(%rbp),%rdi
call   1030 <ctime@plt>
mov    %rax,-0x78(%rbp)
jmp    12a5 <print_msg+0x165>
lea    0xdf9(%rip),%rax
mov    %rax,-0x78(%rbp)
jmp    12a5 <print_msg+0x165>
mov    -0x78(%rbp),%rsi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_msg>:
push   %rbx
sub    $0x50,%rsp
mov    %edi,%ebx
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1070 <msgctl@plt>
cmp    $0xffffffff,%eax
jne    1182 <print_msg+0x32>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1060 <err@plt>
lea    0xe85(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x38(%rsp),%esi
mov    0x3c(%rsp),%edx
mov    0x40(%rsp),%ecx
mov    0x44(%rsp),%r8d
mov    0x48(%rsp),%r9d
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x30(%rsp),%rsi
mov    0x28(%rsp),%rdx
mov    0x20(%rsp),%rcx
mov    0x18(%rsp),%r9d
mov    0x1c(%rsp),%r8d
lea    0xe79(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb1(%rip),%rbx
cmpq   $0x0,0x10(%rsp)
mov    %rbx,%rsi
je     11fc <print_msg+0xac>
lea    0x10(%rsp),%rdi
call   1040 <ctime@plt>
mov    %rax,%rsi
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpq   $0x0,0x8(%rsp)
mov    %rbx,%rsi
je     1222 <print_msg+0xd2>
lea    0x8(%rsp),%rdi
call   1040 <ctime@plt>
mov    %rax,%rsi
lea    0xe74(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpq   $0x0,(%rsp)
je     1242 <print_msg+0xf2>
mov    %rsp,%rdi
call   1040 <ctime@plt>
mov    %rax,%rbx
lea    0xe67(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.msqid_ds = type { i64, i64, i64, i32, i32, i64, i64, i64, %struct.ipc_perm }
%struct.ipc_perm = type { i32, i32, i32, i32, i32 }
@IPC_STAT = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [14 x i8] c"msgctl failed\00"
@.str.1 = [25 x i8] c"\0AMessage Queue msqid=%d\0A\00"
@.str.2 = [40 x i8] c"uid=%d\09gid=%d\09cuid=%d\09cgid=%d\09mode=%#o\0A\00"
@.str.3 = [50 x i8] c"cbytes=%ld\09qbytes=%ld\09qnum=%ld\09lspid=%d\09lrpid=%d\0A\00"
@.str.4 = [20 x i8] c"send_time=%-26.24s\0A\00"
@.str.5 = [8 x i8] c"Not set\00"
@.str.6 = [19 x i8] c"rcv_time=%-26.24s\0A\00"
@.str.7 = [22 x i8] c"change_time=%-26.24s\0A\00"
@.str.8 = [2 x i8] c"\0A\00"
define void @print_msg(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.msqid_ds
%4 = alloca %struct.ipc_perm*
store i32 %0, i32* %2
%5 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %3, i32 0, i32 8
store %struct.ipc_perm* %5, %struct.ipc_perm** %4
%6 = load i32, i32* %2
%7 = load i32, i32* @IPC_STAT
%8 = call i32 @msgctl(i32 %6, i32 %7, %struct.msqid_ds* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @err(i32 %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %1
%14 = load i32, i32* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%17 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%20 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%23 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %22, i32 0, i32 2
%24 = load i32, i32* %23
%25 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%26 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %25, i32 0, i32 3
%27 = load i32, i32* %26
%28 = load %struct.ipc_perm*, %struct.ipc_perm** %4
%29 = getelementptr inbounds %struct.ipc_perm, %struct.ipc_perm* %28, i32 0, i32 4
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %21, i32 %24, i32 %27, i32 %30)
%32 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %3, i32 0, i32 7
%33 = load i64, i64* %32
%34 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %3, i32 0, i32 6
%35 = load i64, i64* %34
%36 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %3, i32 0, i32 5
%37 = load i64, i64* %36
%38 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %3, i32 0, i32 4
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %3, i32 0, i32 3
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i64 %33, i64 %35, i64 %37, i32 %39, i32 %41)
%43 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %3, i32 0, i32 2
%44 = load i64, i64* %43
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %13
%47 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %3, i32 0, i32 2
%48 = call i8* @ctime(i64* %47)
br label %50
49: ; preds = %13
br label %50
50: ; preds = %49, %46
%51 = phi i8* [ %48, %46 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %49 ]
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %51)
%53 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %3, i32 0, i32 1
%54 = load i64, i64* %53
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %50
%57 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %3, i32 0, i32 1
%58 = call i8* @ctime(i64* %57)
br label %60
59: ; preds = %50
br label %60
60: ; preds = %59, %56
%61 = phi i8* [ %58, %56 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %59 ]
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %61)
%63 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %3, i32 0, i32 0
%64 = load i64, i64* %63
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %60
%67 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %3, i32 0, i32 0
%68 = call i8* @ctime(i64* %67)
br label %70
69: ; preds = %60
br label %70
70: ; preds = %69, %66
%71 = phi i8* [ %68, %66 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %69 ]
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %71)
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.msqid_ds = type { i64, i64, i64, i32, i32, i64, i64, i64, %struct.ipc_perm }
%struct.ipc_perm = type { i32, i32, i32, i32, i32 }
@IPC_STAT = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [14 x i8] c"msgctl failed\00"
@.str.1 = [25 x i8] c"\0AMessage Queue msqid=%d\0A\00"
@.str.2 = [40 x i8] c"uid=%d\09gid=%d\09cuid=%d\09cgid=%d\09mode=%#o\0A\00"
@.str.3 = [50 x i8] c"cbytes=%ld\09qbytes=%ld\09qnum=%ld\09lspid=%d\09lrpid=%d\0A\00"
@.str.4 = [20 x i8] c"send_time=%-26.24s\0A\00"
@.str.5 = [8 x i8] c"Not set\00"
@.str.6 = [19 x i8] c"rcv_time=%-26.24s\0A\00"
@.str.7 = [22 x i8] c"change_time=%-26.24s\0A\00"
define void @print_msg(i32 %0) {
%2 = alloca %struct.msqid_ds
%3 = bitcast %struct.msqid_ds* %2 to i8*
%4 = load i32, i32* @IPC_STAT
%5 = call i32 @msgctl(i32 %0, i32 %4, %struct.msqid_ds* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @EXIT_FAILURE
%9 = call i32 @err(i32 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %1
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%12 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 8, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 8, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 8, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 8, i32 3
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 8, i32 4
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %15, i32 %17, i32 %19, i32 %21)
%23 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 7
%24 = load i64, i64* %23
%25 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 6
%26 = load i64, i64* %25
%27 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 5
%28 = load i64, i64* %27
%29 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 4
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 3
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i64 %24, i64 %26, i64 %28, i32 %30, i32 %32)
%34 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 2
%35 = load i64, i64* %34
%36 = icmp eq i64 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %10
%38 = call i8* @ctime(i64* %34)
br label %39
39: ; preds = %10, %37
%40 = phi i8* [ %38, %37 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %10 ]
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 1
%43 = load i64, i64* %42
%44 = icmp eq i64 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %39
%46 = call i8* @ctime(i64* %42)
br label %47
47: ; preds = %39, %45
%48 = phi i8* [ %46, %45 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %39 ]
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %48)
%50 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %2, i64 0, i32 0
%51 = load i64, i64* %50
%52 = icmp eq i64 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %47
%54 = call i8* @ctime(i64* %50)
br label %55
55: ; preds = %47, %53
%56 = phi i8* [ %54, %53 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %47 ]
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %56)
%58 = call i32 @putchar(i32 10)
ret void
}