#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef scalar_t__ uid_t;
typedef int /*<<< orphan*/ u_long;
struct TYPE_2__ {
  int uid;
  int gid;
  int cuid;
  int cgid;
  int mode;
};
struct msqid_ds {
  TYPE_1__ msg_perm;
  int /*<<< orphan*/ msg_ctime;
  int /*<<< orphan*/ msg_rtime;
  int /*<<< orphan*/ msg_stime;
  int /*<<< orphan*/ msg_lrpid;
  int /*<<< orphan*/ msg_lspid;
  scalar_t__ msg_qbytes;
  int /*<<< orphan*/ msg_qnum;
};
typedef int mode_t;
typedef scalar_t__ gid_t;

/* Variables and functions */
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ errx(int, char *);
scalar_t__ getegid();
scalar_t__ geteuid();
int /*<<< orphan*/ printf(char *, ...);
void print_msqid_ds(struct msqid_ds *mp, mode_t mode) {
  uid_t uid = geteuid();
  gid_t gid = getegid();
  printf("PERM: uid %d, gid %d, cuid %d, cgid %d, mode 0%o\n", mp->msg_perm.uid,
         mp->msg_perm.gid, mp->msg_perm.cuid, mp->msg_perm.cgid,
         mp->msg_perm.mode & 0777);
  printf("qnum %lu, qbytes %lu, lspid %d, lrpid %d\n", mp->msg_qnum,
         (u_long)mp->msg_qbytes, mp->msg_lspid, mp->msg_lrpid);
  printf("stime: %s", ctime(&mp->msg_stime));
  printf("rtime: %s", ctime(&mp->msg_rtime));
  printf("ctime: %s", ctime(&mp->msg_ctime));
  if (mp->msg_perm.uid != uid || mp->msg_perm.cuid != uid)
    errx(1, "uid mismatch");
  if (mp->msg_perm.gid != gid || mp->msg_perm.cgid != gid)
    errx(1, "gid mismatch");
  if ((mp->msg_perm.mode & 0777) != mode)
    errx(1, "mode mismatch");
}


x86 assembly (clang, -O0):
<print_msqid_ds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1070 <getegid@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%r8d
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%r9d
and    $0x1ff,%r9d
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x30(%rax),%esi
mov    -0x8(%rbp),%rax
mov    0x28(%rax),%rax
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    0x24(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    0x20(%rax),%r8d
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0x1c,%rdi
call   1030 <ctime@plt>
mov    %rax,%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0x18,%rdi
call   1030 <ctime@plt>
mov    %rax,%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0x14,%rdi
call   1030 <ctime@plt>
mov    %rax,%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
movslq (%rax),%rax
cmp    -0x18(%rbp),%rax
jne    1259 <print_msqid_ds+0x109>
mov    -0x8(%rbp),%rax
movslq 0x8(%rax),%rax
cmp    -0x18(%rbp),%rax
je     126a <print_msqid_ds+0x11a>
mov    $0x1,%edi
lea    0xe15(%rip),%rsi
call   1040 <errx@plt>
mov    -0x8(%rbp),%rax
movslq 0x4(%rax),%rax
cmp    -0x20(%rbp),%rax
jne    128e <print_msqid_ds+0x13e>
mov    -0x8(%rbp),%rax
movslq 0xc(%rax),%rax
cmp    -0x20(%rbp),%rax
je     129f <print_msqid_ds+0x14f>
mov    $0x1,%edi
lea    0xded(%rip),%rsi
call   1040 <errx@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%eax
and    $0x1ff,%eax
cmp    -0xc(%rbp),%eax
je     12c5 <print_msqid_ds+0x175>
mov    $0x1,%edi
lea    0xdd4(%rip),%rsi
call   1040 <errx@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_msqid_ds>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1070 <getegid@plt>
mov    %rax,%r15
mov    (%rbx),%esi
mov    0x4(%rbx),%edx
mov    0x8(%rbx),%ecx
mov    0xc(%rbx),%r8d
mov    $0x1ff,%r9d
and    0x10(%rbx),%r9d
lea    0xe72(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x30(%rbx),%esi
mov    0x28(%rbx),%edx
mov    0x20(%rbx),%r8d
mov    0x24(%rbx),%ecx
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x1c(%rbx),%rdi
call   1030 <ctime@plt>
lea    0xe9c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x18(%rbx),%rdi
call   1030 <ctime@plt>
lea    0xe8c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x14(%rbx),%rdi
call   1030 <ctime@plt>
lea    0xe7c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
movslq (%rbx),%rax
cmp    %rax,%rbp
jne    120f <print_msqid_ds+0xbf>
movslq 0x8(%rbx),%rax
cmp    %rax,%rbp
je     1220 <print_msqid_ds+0xd0>
lea    0xe64(%rip),%rsi
mov    $0x1,%edi
call   1040 <errx@plt>
movslq 0x4(%rbx),%rax
cmp    %rax,%r15
jne    1232 <print_msqid_ds+0xe2>
movslq 0xc(%rbx),%rax
cmp    %rax,%r15
je     1243 <print_msqid_ds+0xf3>
lea    0xe4e(%rip),%rsi
mov    $0x1,%edi
call   1040 <errx@plt>
mov    $0x1ff,%eax
and    0x10(%rbx),%eax
cmp    %r14d,%eax
jne    125b <print_msqid_ds+0x10b>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe32(%rip),%rsi
mov    $0x1,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <errx@plt>

LLVM IR (-O0):
%struct.msqid_ds = type { %struct.TYPE_2__, i32, i32, i32, i32, i32, i64, i32 }
%struct.TYPE_2__ = type { i32, i32, i32, i32, i32 }
@.str = [50 x i8] c"PERM: uid %d, gid %d, cuid %d, cgid %d, mode 0%o\0A\00"
@.str.1 = [42 x i8] c"qnum %lu, qbytes %lu, lspid %d, lrpid %d\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 = [13 x i8] c"uid mismatch\00"
@.str.6 = [13 x i8] c"gid mismatch\00"
@.str.7 = [14 x i8] c"mode mismatch\00"
define void @print_msqid_ds(%struct.msqid_ds* %0, i32 %1) {
%3 = alloca %struct.msqid_ds*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store %struct.msqid_ds* %0, %struct.msqid_ds** %3
store i32 %1, i32* %4
%7 = call i64 (...) @geteuid()
store i64 %7, i64* %5
%8 = call i64 (...) @getegid()
store i64 %8, i64* %6
%9 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%10 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %9, i32 0, i32 0
%11 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%14 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %13, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 1
%16 = load i32, i32* %15
%17 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%18 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %17, i32 0, i32 0
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 2
%20 = load i32, i32* %19
%21 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%22 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %21, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 3
%24 = load i32, i32* %23
%25 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%26 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %25, i32 0, i32 0
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 4
%28 = load i32, i32* %27
%29 = and i32 %28, 511
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %16, i32 %20, i32 %24, i32 %29)
%31 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%32 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %31, i32 0, i32 7
%33 = load i32, i32* %32
%34 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%35 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %34, i32 0, i32 6
%36 = load i64, i64* %35
%37 = trunc i64 %36 to i32
%38 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%39 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %38, i32 0, i32 5
%40 = load i32, i32* %39
%41 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%42 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %41, i32 0, i32 4
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %37, i32 %40, i32 %43)
%45 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%46 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %45, i32 0, i32 3
%47 = call i8* @ctime(i32* %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%50 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %49, i32 0, i32 2
%51 = call i8* @ctime(i32* %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %51)
%53 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%54 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %53, i32 0, i32 1
%55 = call i8* @ctime(i32* %54)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %55)
%57 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%58 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %57, i32 0, i32 0
%59 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %58, i32 0, i32 0
%60 = load i32, i32* %59
%61 = sext i32 %60 to i64
%62 = load i64, i64* %5
%63 = icmp ne i64 %61, %62
br i1 %63, label %72, label %64
64: ; preds = %2
%65 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%66 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %65, i32 0, i32 0
%67 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %66, i32 0, i32 2
%68 = load i32, i32* %67
%69 = sext i32 %68 to i64
%70 = load i64, i64* %5
%71 = icmp ne i64 %69, %70
br i1 %71, label %72, label %74
72: ; preds = %64, %2
%73 = call i32 @errx(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %74
74: ; preds = %72, %64
%75 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%76 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %75, i32 0, i32 0
%77 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %76, i32 0, i32 1
%78 = load i32, i32* %77
%79 = sext i32 %78 to i64
%80 = load i64, i64* %6
%81 = icmp ne i64 %79, %80
br i1 %81, label %90, label %82
82: ; preds = %74
%83 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%84 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %83, i32 0, i32 0
%85 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %84, i32 0, i32 3
%86 = load i32, i32* %85
%87 = sext i32 %86 to i64
%88 = load i64, i64* %6
%89 = icmp ne i64 %87, %88
br i1 %89, label %90, label %92
90: ; preds = %82, %74
%91 = call i32 @errx(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %92
92: ; preds = %90, %82
%93 = load %struct.msqid_ds*, %struct.msqid_ds** %3
%94 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %93, i32 0, i32 0
%95 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %94, i32 0, i32 4
%96 = load i32, i32* %95
%97 = and i32 %96, 511
%98 = load i32, i32* %4
%99 = icmp ne i32 %97, %98
br i1 %99, label %100, label %102
100: ; preds = %92
%101 = call i32 @errx(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %102
102: ; preds = %100, %92
ret void
}

LLVM IR (-O2):
%struct.msqid_ds = type { %struct.TYPE_2__, i32, i32, i32, i32, i32, i64, i32 }
%struct.TYPE_2__ = type { i32, i32, i32, i32, i32 }
@.str = [50 x i8] c"PERM: uid %d, gid %d, cuid %d, cgid %d, mode 0%o\0A\00"
@.str.1 = [42 x i8] c"qnum %lu, qbytes %lu, lspid %d, lrpid %d\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 = [13 x i8] c"uid mismatch\00"
@.str.6 = [13 x i8] c"gid mismatch\00"
@.str.7 = [14 x i8] c"mode mismatch\00"
define void @print_msqid_ds(%struct.msqid_ds* %0, i32 %1) {
%3 = tail call i64 (...) @geteuid()
%4 = tail call i64 (...) @getegid()
%5 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %0, i64 0, i32 0, i32 0
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %0, i64 0, i32 0, i32 1
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %0, i64 0, i32 0, i32 2
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %0, i64 0, i32 0, i32 3
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %0, i64 0, i32 0, i32 4
%14 = load i32, i32* %13
%15 = and i32 %14, 511
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %8, i32 %10, i32 %12, i32 %15)
%17 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %0, i64 0, i32 7
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %0, i64 0, i32 6
%20 = load i64, i64* %19
%21 = trunc i64 %20 to i32
%22 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %0, i64 0, i32 5
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %0, i64 0, i32 4
%25 = load i32, i32* %24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %21, i32 %23, i32 %25)
%27 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %0, i64 0, i32 3
%28 = tail call i8* @ctime(i32* %27)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %0, i64 0, i32 2
%31 = tail call i8* @ctime(i32* %30)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds %struct.msqid_ds, %struct.msqid_ds* %0, i64 0, i32 1
%34 = tail call i8* @ctime(i32* %33)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = icmp eq i64 %3, %37
br i1 %38, label %39, label %43
39: ; preds = %2
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = icmp eq i64 %3, %41
br i1 %42, label %45, label %43
43: ; preds = %39, %2
%44 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %45
45: ; preds = %43, %39
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = icmp eq i64 %4, %47
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = load i32, i32* %11
%51 = sext i32 %50 to i64
%52 = icmp eq i64 %4, %51
br i1 %52, label %55, label %53
53: ; preds = %49, %45
%54 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %55
55: ; preds = %53, %49
%56 = load i32, i32* %13
%57 = and i32 %56, 511
%58 = icmp eq i32 %57, %1
br i1 %58, label %61, label %59
59: ; preds = %55
%60 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %61
61: ; preds = %59, %55
ret void
}