#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 mq_attr {
  int mq_maxmsg;
  int mq_msgsize;
  int mq_flags;
  long mq_curmsgs;
};

/* Variables and functions */
int O_NONBLOCK;
int /*<<< orphan*/ printf(char *, int, long);
int check_attrs(struct mq_attr *attr, int nonblock, long cnt) {
  int result = 0;
  if (attr->mq_maxmsg != 10 || attr->mq_msgsize != 1) {
    printf("attributes don't match those passed to mq_open\n"
           "mq_maxmsg %ld, mq_msgsize %ld\n",
           attr->mq_maxmsg, attr->mq_msgsize);
    result = 1;
  }
  if ((attr->mq_flags & O_NONBLOCK) != nonblock) {
    printf("mq_flags %lx != %x\n", (attr->mq_flags & O_NONBLOCK), nonblock);
    result = 1;
  }
  if (attr->mq_curmsgs != cnt) {
    printf("mq_curmsgs %ld != %ld\n", attr->mq_curmsgs, cnt);
    result = 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<check_attrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0xa,(%rax)
jne    1145 <check_attrs+0x35>
mov    -0x8(%rbp),%rax
cmpl   $0x1,0x4(%rax)
je     1166 <check_attrs+0x56>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rax
movslq 0x4(%rax),%rdx
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2e74(%rip),%rcx
and    (%rcx),%eax
cmp    -0xc(%rbp),%eax
je     11a6 <check_attrs+0x96>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%esi
mov    0x2e5b(%rip),%rax
and    (%rax),%esi
movslq -0xc(%rbp),%rdx
lea    0xeb4(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
cmp    -0x18(%rbp),%rax
je     11d9 <check_attrs+0xc9>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_attrs>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
mov    (%rdi),%esi
mov    0x4(%rdi),%ecx
cmp    $0xa,%esi
jne    112d <check_attrs+0x1d>
xor    %eax,%eax
cmp    $0x1,%ecx
je     1141 <check_attrs+0x31>
movslq %ecx,%rdx
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
mov    0x2ea0(%rip),%rcx
mov    (%rcx),%esi
and    0x8(%rbx),%esi
cmp    %ebp,%esi
je     1165 <check_attrs+0x55>
movslq %ebp,%rdx
lea    0xef3(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
mov    0x10(%rbx),%rsi
cmp    %r14,%rsi
je     1182 <check_attrs+0x72>
lea    0xeed(%rip),%rdi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32, i32, i64 }
@.str = [78 x i8] c"attributes don't match those passed to mq_open\0Amq_maxmsg %ld, mq_msgsize %ld\0A\00"
@O_NONBLOCK = global i32 0
@.str.1 = [20 x i8] c"mq_flags %lx != %x\0A\00"
@.str.2 = [23 x i8] c"mq_curmsgs %ld != %ld\0A\00"
define i32 @check_attrs(%struct.mq_attr* %0, i32 %1, i64 %2) {
%4 = alloca %struct.mq_attr*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
store %struct.mq_attr* %0, %struct.mq_attr** %4
store i32 %1, i32* %5
store i64 %2, i64* %6
store i32 0, i32* %7
%8 = load %struct.mq_attr*, %struct.mq_attr** %4
%9 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = icmp ne i32 %10, 10
br i1 %11, label %17, label %12
12: ; preds = %3
%13 = load %struct.mq_attr*, %struct.mq_attr** %4
%14 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %26
17: ; preds = %12, %3
%18 = load %struct.mq_attr*, %struct.mq_attr** %4
%19 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = load %struct.mq_attr*, %struct.mq_attr** %4
%22 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %21, i32 0, i32 1
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = call i32 @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str, i64 0, i64 0), i32 %20, i64 %24)
store i32 1, i32* %7
br label %26
26: ; preds = %17, %12
%27 = load %struct.mq_attr*, %struct.mq_attr** %4
%28 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %27, i32 0, i32 2
%29 = load i32, i32* %28
%30 = load i32, i32* @O_NONBLOCK
%31 = and i32 %29, %30
%32 = load i32, i32* %5
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %43
34: ; preds = %26
%35 = load %struct.mq_attr*, %struct.mq_attr** %4
%36 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %35, i32 0, i32 2
%37 = load i32, i32* %36
%38 = load i32, i32* @O_NONBLOCK
%39 = and i32 %37, %38
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %39, i64 %41)
store i32 1, i32* %7
br label %43
43: ; preds = %34, %26
%44 = load %struct.mq_attr*, %struct.mq_attr** %4
%45 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %44, i32 0, i32 3
%46 = load i64, i64* %45
%47 = load i64, i64* %6
%48 = icmp ne i64 %46, %47
br i1 %48, label %49, label %56
49: ; preds = %43
%50 = load %struct.mq_attr*, %struct.mq_attr** %4
%51 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %50, i32 0, i32 3
%52 = load i64, i64* %51
%53 = trunc i64 %52 to i32
%54 = load i64, i64* %6
%55 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %53, i64 %54)
store i32 1, i32* %7
br label %56
56: ; preds = %49, %43
%57 = load i32, i32* %7
ret i32 %57
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32, i32, i64 }
@.str = [78 x i8] c"attributes don't match those passed to mq_open\0Amq_maxmsg %ld, mq_msgsize %ld\0A\00"
@O_NONBLOCK = global i32 0
@.str.1 = [20 x i8] c"mq_flags %lx != %x\0A\00"
@.str.2 = [23 x i8] c"mq_curmsgs %ld != %ld\0A\00"
define i32 @check_attrs(%struct.mq_attr* nocapture %0, i32 %1, i64 %2) {
%4 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 10
%7 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %0, i64 0, i32 1
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 1
%10 = select i1 %6, i1 %9, i1 false
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = sext i32 %8 to i64
%13 = tail call i32 @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str, i64 0, i64 0), i32 %5, i64 %12)
br label %14
14: ; preds = %3, %11
%15 = phi i32 [ 1, %11 ], [ 0, %3 ]
%16 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %0, i64 0, i32 2
%17 = load i32, i32* %16
%18 = load i32, i32* @O_NONBLOCK
%19 = and i32 %18, %17
%20 = icmp eq i32 %19, %1
br i1 %20, label %24, label %21
21: ; preds = %14
%22 = sext i32 %1 to i64
%23 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %19, i64 %22)
br label %24
24: ; preds = %21, %14
%25 = phi i32 [ 1, %21 ], [ %15, %14 ]
%26 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %0, i64 0, i32 3
%27 = load i64, i64* %26
%28 = icmp eq i64 %27, %2
br i1 %28, label %32, label %29
29: ; preds = %24
%30 = trunc i64 %27 to i32
%31 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %30, i64 %2)
br label %32
32: ; preds = %29, %24
%33 = phi i32 [ 1, %29 ], [ %25, %24 ]
ret i32 %33
}