#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;
  scalar_t__ mq_curmsgs;
};
typedef int /*<<< orphan*/ pid_t;
typedef int /*<<< orphan*/ name;
typedef scalar_t__ mqd_t;
typedef int /*<<< orphan*/ attr2;

/* Variables and functions */
scalar_t__ EBADF;
int O_CREAT;
int O_EXCL;
int O_NONBLOCK;
int O_WRONLY;
int /*<<< orphan*/ add_temp_mq(char *);
int do_one_test(scalar_t__, char *, int);
scalar_t__ errno;
int getpid();
int /*<<< orphan*/ memset(struct mq_attr *, int, int);
int mq_close(scalar_t__);
scalar_t__ mq_getattr(scalar_t__, struct mq_attr *);
scalar_t__ mq_open(char *, int, ...);
scalar_t__ mq_setattr(scalar_t__, struct mq_attr *, struct mq_attr *);
scalar_t__ mq_unlink(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int do_test(void) {
  int result = 0;
  char name[sizeof "/tst-mqueue1-" + sizeof(pid_t) * 3];
  snprintf(name, sizeof(name), "/tst-mqueue1-%u", getpid());
  struct mq_attr attr = {.mq_maxmsg = 10, .mq_msgsize = 1};
  mqd_t q = mq_open(name, O_CREAT | O_EXCL | O_WRONLY, 0600, &attr);
  if (q == (mqd_t)-1) {
    printf("mq_open failed with: %m\n");
    return result;
  } else
    add_temp_mq(name);
  result |= do_one_test(q, name, 0);
  mqd_t q2 = mq_open(name, O_WRONLY | O_NONBLOCK);
  if (q2 == (mqd_t)-1) {
    printf("mq_open failed with: %m\n");
    q2 = q;
    result = 1;
  } else {
    if (mq_close(q) != 0) {
      printf("mq_close in parent failed: %m\n");
      result = 1;
    }
    q = q2;
    result |= do_one_test(q, name, O_NONBLOCK);
    if (mq_getattr(q, &attr) != 0) {
      printf("mq_getattr failed: %m\n");
      result = 1;
    } else {
      attr.mq_flags ^= O_NONBLOCK;
      struct mq_attr attr2;
      memset(&attr2, 0x55, sizeof(attr2));
      if (mq_setattr(q, &attr, &attr2) != 0) {
        printf("mq_setattr failed: %m\n");
        result = 1;
      } else if (attr.mq_flags != (attr2.mq_flags ^ O_NONBLOCK) ||
                 attr.mq_maxmsg != attr2.mq_maxmsg ||
                 attr.mq_msgsize != attr2.mq_msgsize || attr.mq_curmsgs != 0 ||
                 attr2.mq_curmsgs != 0) {
        puts("mq_setattr returned unexpected values in *omqstat");
        result = 1;
      } else {
        result |= do_one_test(q, name, 0);
        if (mq_setattr(q, &attr2, NULL) != 0) {
          printf("mq_setattr failed: %m\n");
          result = 1;
        } else
          result |= do_one_test(q, name, O_NONBLOCK);
      }
    }
  }
  if (mq_unlink(name) != 0) {
    printf("mq_unlink failed: %m\n");
    result = 1;
  }
  if (mq_close(q) != 0) {
    printf("mq_close in parent failed: %m\n");
    result = 1;
  }
  if (mq_close(q) != -1) {
    puts("second mq_close did not fail");
    result = 1;
  } else if (errno != EBADF) {
    printf("second mq_close did not fail with EBADF: %m\n");
    result = 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x8(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%ecx
mov    $0x1a,%esi
lea    0xe0d(%rip),%rdx
call   1080 <snprintf@plt>
mov    0xf09(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xf06(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xf03(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
mov    0x2da3(%rip),%rax
or     (%rax),%esi
mov    0x2d7a(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
lea    -0x48(%rbp),%rcx
mov    $0x0,%al
call   10b0 <mq_open@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0xffffffffffffffff,-0x50(%rbp)
jne    126e <do_test+0xae>
lea    0xdb2(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1527 <do_test+0x367>
lea    -0x30(%rbp),%rdi
call   10d0 <add_temp_mq@plt>
mov    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1050 <do_one_test@plt>
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
mov    0x2d19(%rip),%rax
mov    (%rax),%esi
mov    0x2d40(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   10b0 <mq_open@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0xffffffffffffffff,-0x58(%rbp)
jne    12d8 <do_test+0x118>
lea    0xd51(%rip),%rdi
call   1060 <printf@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x1,-0x8(%rbp)
jmp    147a <do_test+0x2ba>
mov    -0x50(%rbp),%rdi
call   10a0 <mq_close@plt>
cmp    $0x0,%eax
je     12fd <do_test+0x13d>
lea    0xd38(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    0x2ccc(%rip),%rax
mov    (%rax),%edx
call   1050 <do_one_test@plt>
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   10e0 <mq_getattr@plt>
cmp    $0x0,%rax
je     1350 <do_test+0x190>
lea    0xd09(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    1475 <do_test+0x2b5>
mov    0x2c89(%rip),%rax
mov    (%rax),%eax
xor    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x55,%esi
mov    $0x18,%edx
call   1090 <memset@plt>
mov    -0x50(%rbp),%rdi
lea    -0x48(%rbp),%rsi
lea    -0x70(%rbp),%rdx
call   1070 <mq_setattr@plt>
cmp    $0x0,%rax
je     13a5 <do_test+0x1e5>
lea    0xccb(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    1470 <do_test+0x2b0>
mov    -0x40(%rbp),%eax
mov    -0x68(%rbp),%ecx
mov    0x2c2e(%rip),%rdx
xor    (%rdx),%ecx
cmp    %ecx,%eax
jne    13ea <do_test+0x22a>
mov    -0x48(%rbp),%eax
cmp    -0x70(%rbp),%eax
jne    13ea <do_test+0x22a>
mov    -0x44(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jne    13ea <do_test+0x22a>
cmpq   $0x0,-0x38(%rbp)
jne    13ea <do_test+0x22a>
cmpq   $0x0,-0x60(%rbp)
je     1402 <do_test+0x242>
lea    0xc85(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x8(%rbp)
jmp    146b <do_test+0x2ab>
mov    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1050 <do_one_test@plt>
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x70(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <mq_setattr@plt>
cmp    $0x0,%rax
je     144a <do_test+0x28a>
lea    0xc26(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    1466 <do_test+0x2a6>
mov    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    0x2b87(%rip),%rax
mov    (%rax),%edx
call   1050 <do_one_test@plt>
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    146b <do_test+0x2ab>
jmp    1470 <do_test+0x2b0>
jmp    1475 <do_test+0x2b5>
jmp    147a <do_test+0x2ba>
lea    -0x30(%rbp),%rdi
call   10c0 <mq_unlink@plt>
cmp    $0x0,%rax
je     14a0 <do_test+0x2e0>
lea    0xc14(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x50(%rbp),%rdi
call   10a0 <mq_close@plt>
cmp    $0x0,%eax
je     14c5 <do_test+0x305>
lea    0xb70(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x50(%rbp),%rdi
call   10a0 <mq_close@plt>
cmp    $0xffffffff,%eax
je     14ef <do_test+0x32f>
lea    0xbe0(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x8(%rbp)
jmp    1521 <do_test+0x361>
mov    0x2ad2(%rip),%rax
mov    (%rax),%rax
mov    0x2ac0(%rip),%rcx
cmp    (%rcx),%rax
je     151c <do_test+0x35c>
lea    0xbcb(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    1521 <do_test+0x361>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe22(%rip),%rdx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1a,%esi
mov    %eax,%ecx
call   1080 <snprintf@plt>
mov    0xf1f(%rip),%rax
mov    %rax,0x10(%rsp)
movups 0xf03(%rip),%xmm0
mov    0x2dec(%rip),%rax
mov    0x2dbd(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
movaps %xmm0,(%rsp)
mov    0x2d8e(%rip),%r14
or     (%r14),%esi
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    $0x180,%edx
xor    %eax,%eax
call   10b0 <mq_open@plt>
cmp    $0xffffffffffffffff,%rax
je     12cd <do_test+0x10d>
mov    %rax,%rbx
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
call   10d0 <add_temp_mq@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %edx,%edx
call   1050 <do_one_test@plt>
mov    %eax,%r12d
mov    0x2d78(%rip),%r13
mov    0x0(%r13),%esi
or     (%r14),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   10b0 <mq_open@plt>
cmp    $0xffffffffffffffff,%rax
je     12de <do_test+0x11e>
mov    %rax,%r15
mov    %rbx,%rdi
call   10a0 <mq_close@plt>
test   %eax,%eax
je     12a0 <do_test+0xe0>
lea    0xd94(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%r12d
mov    0x0(%r13),%edx
lea    0x30(%rsp),%rsi
mov    %r15,%rdi
call   1050 <do_one_test@plt>
mov    %eax,%r14d
mov    %rsp,%rsi
mov    %r15,%rdi
call   10e0 <mq_getattr@plt>
test   %rax,%rax
je     12f4 <do_test+0x134>
lea    0xd7d(%rip),%rdi
jmp    1331 <do_test+0x171>
lea    0xd3c(%rip),%rdi
call   1060 <printf@plt>
jmp    13ba <do_test+0x1fa>
lea    0xd2b(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%ebp
mov    %rbx,%r15
jmp    133b <do_test+0x17b>
mov    0x0(%r13),%eax
xor    %eax,0x8(%rsp)
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x55,%esi
mov    $0x18,%edx
call   1090 <memset@plt>
mov    %rsp,%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
call   1070 <mq_setattr@plt>
test   %rax,%rax
je     13cb <do_test+0x20b>
lea    0xd2e(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%ebp
lea    0x30(%rsp),%rdi
call   10c0 <mq_unlink@plt>
test   %rax,%rax
je     135b <do_test+0x19b>
lea    0xd57(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%ebp
mov    %r15,%rdi
call   10a0 <mq_close@plt>
test   %eax,%eax
je     1378 <do_test+0x1b8>
lea    0xcbb(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%ebp
mov    %r15,%rdi
call   10a0 <mq_close@plt>
cmp    $0xffffffff,%eax
je     1393 <do_test+0x1d3>
lea    0xd32(%rip),%rdi
call   1030 <puts@plt>
jmp    13b5 <do_test+0x1f5>
mov    0x2c2e(%rip),%rax
mov    (%rax),%rax
mov    0x2c1c(%rip),%rcx
cmp    (%rcx),%rax
je     13ba <do_test+0x1fa>
lea    0xd2b(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%r13),%eax
xor    0x20(%rsp),%eax
cmp    %eax,0x8(%rsp)
jne    1446 <do_test+0x286>
mov    (%rsp),%eax
cmp    0x18(%rsp),%eax
jne    1446 <do_test+0x286>
mov    0x4(%rsp),%eax
cmp    0x1c(%rsp),%eax
jne    1446 <do_test+0x286>
cmpq   $0x0,0x10(%rsp)
jne    1446 <do_test+0x286>
cmpq   $0x0,0x28(%rsp)
jne    1446 <do_test+0x286>
lea    0x30(%rsp),%rsi
mov    %r15,%rdi
xor    %edx,%edx
call   1050 <do_one_test@plt>
mov    %eax,%ebx
lea    0x18(%rsp),%rsi
mov    %r15,%rdi
xor    %edx,%edx
call   1070 <mq_setattr@plt>
test   %rax,%rax
jne    132a <do_test+0x16a>
or     %r12d,%r14d
or     %ebx,%r14d
mov    0x0(%r13),%edx
lea    0x30(%rsp),%rsi
mov    %r15,%rdi
call   1050 <do_one_test@plt>
mov    %eax,%ebp
or     %r14d,%ebp
jmp    133b <do_test+0x17b>
lea    0xc29(%rip),%rdi
call   1030 <puts@plt>
jmp    1336 <do_test+0x176>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32, i32, i64 }
@.str = [16 x i8] c"/tst-mqueue1-%u\00"
@__const.do_test.attr = %struct.mq_attr { i32 10, i32 1, i32 0, i64 0 }
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_WRONLY = global i32 0
@.str.1 = [25 x i8] c"mq_open failed with: %m\0A\00"
@O_NONBLOCK = global i32 0
@.str.2 = [31 x i8] c"mq_close in parent failed: %m\0A\00"
@.str.3 = [23 x i8] c"mq_getattr failed: %m\0A\00"
@.str.4 = [23 x i8] c"mq_setattr failed: %m\0A\00"
@.str.5 = [50 x i8] c"mq_setattr returned unexpected values in *omqstat\00"
@.str.6 = [22 x i8] c"mq_unlink failed: %m\0A\00"
@.str.7 = [29 x i8] c"second mq_close did not fail\00"
@errno = global i64 0
@EBADF = global i64 0
@.str.8 = [45 x i8] c"second mq_close did not fail with EBADF: %m\0A\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [26 x i8]
%4 = alloca %struct.mq_attr
%5 = alloca i64
%6 = alloca i64
%7 = alloca %struct.mq_attr
store i32 0, i32* %2
%8 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%9 = call i32 (...) @getpid()
%10 = call i32 @snprintf(i8* %8, i32 26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = bitcast %struct.mq_attr* %4 to i8*
%12 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* @O_CREAT
%14 = load i32, i32* @O_EXCL
%15 = or i32 %13, %14
%16 = load i32, i32* @O_WRONLY
%17 = or i32 %15, %16
%18 = call i64 (i8*, i32, ...) @mq_open(i8* %12, i32 %17, i32 384, %struct.mq_attr* %4)
store i64 %18, i64* %5
%19 = load i64, i64* %5
%20 = icmp eq i64 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %0
%22 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %2
store i32 %23, i32* %1
br label %152
24: ; preds = %0
%25 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%26 = call i32 @add_temp_mq(i8* %25)
br label %27
27: ; preds = %24
%28 = load i64, i64* %5
%29 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%30 = call i32 @do_one_test(i64 %28, i8* %29, i32 0)
%31 = load i32, i32* %2
%32 = or i32 %31, %30
store i32 %32, i32* %2
%33 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%34 = load i32, i32* @O_WRONLY
%35 = load i32, i32* @O_NONBLOCK
%36 = or i32 %34, %35
%37 = call i64 (i8*, i32, ...) @mq_open(i8* %33, i32 %36)
store i64 %37, i64* %6
%38 = load i64, i64* %6
%39 = icmp eq i64 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %27
%41 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%42 = load i64, i64* %5
store i64 %42, i64* %6
store i32 1, i32* %2
br label %125
43: ; preds = %27
%44 = load i64, i64* %5
%45 = call i32 @mq_close(i64 %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %49
49: ; preds = %47, %43
%50 = load i64, i64* %6
store i64 %50, i64* %5
%51 = load i64, i64* %5
%52 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%53 = load i32, i32* @O_NONBLOCK
%54 = call i32 @do_one_test(i64 %51, i8* %52, i32 %53)
%55 = load i32, i32* %2
%56 = or i32 %55, %54
store i32 %56, i32* %2
%57 = load i64, i64* %5
%58 = call i64 @mq_getattr(i64 %57, %struct.mq_attr* %4)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %49
%61 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %2
br label %124
62: ; preds = %49
%63 = load i32, i32* @O_NONBLOCK
%64 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %4, i32 0, i32 2
%65 = load i32, i32* %64
%66 = xor i32 %65, %63
store i32 %66, i32* %64
%67 = call i32 @memset(%struct.mq_attr* %7, i32 85, i32 24)
%68 = load i64, i64* %5
%69 = call i64 @mq_setattr(i64 %68, %struct.mq_attr* %4, %struct.mq_attr* %7)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %62
%72 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %123
73: ; preds = %62
%74 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %4, i32 0, i32 2
%75 = load i32, i32* %74
%76 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 2
%77 = load i32, i32* %76
%78 = load i32, i32* @O_NONBLOCK
%79 = xor i32 %77, %78
%80 = icmp ne i32 %75, %79
br i1 %80, label %101, label %81
81: ; preds = %73
%82 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %4, i32 0, i32 0
%83 = load i32, i32* %82
%84 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 0
%85 = load i32, i32* %84
%86 = icmp ne i32 %83, %85
br i1 %86, label %101, label %87
87: ; preds = %81
%88 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %4, i32 0, i32 1
%89 = load i32, i32* %88
%90 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 1
%91 = load i32, i32* %90
%92 = icmp ne i32 %89, %91
br i1 %92, label %101, label %93
93: ; preds = %87
%94 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %4, i32 0, i32 3
%95 = load i64, i64* %94
%96 = icmp ne i64 %95, 0
br i1 %96, label %101, label %97
97: ; preds = %93
%98 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 3
%99 = load i64, i64* %98
%100 = icmp ne i64 %99, 0
br i1 %100, label %101, label %103
101: ; preds = %97, %93, %87, %81, %73
%102 = call i32 @puts(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %2
br label %122
103: ; preds = %97
%104 = load i64, i64* %5
%105 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%106 = call i32 @do_one_test(i64 %104, i8* %105, i32 0)
%107 = load i32, i32* %2
%108 = or i32 %107, %106
store i32 %108, i32* %2
%109 = load i64, i64* %5
%110 = call i64 @mq_setattr(i64 %109, %struct.mq_attr* %7, %struct.mq_attr* null)
%111 = icmp ne i64 %110, 0
br i1 %111, label %112, label %114
112: ; preds = %103
%113 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %121
114: ; preds = %103
%115 = load i64, i64* %5
%116 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%117 = load i32, i32* @O_NONBLOCK
%118 = call i32 @do_one_test(i64 %115, i8* %116, i32 %117)
%119 = load i32, i32* %2
%120 = or i32 %119, %118
store i32 %120, i32* %2
br label %121
121: ; preds = %114, %112
br label %122
122: ; preds = %121, %101
br label %123
123: ; preds = %122, %71
br label %124
124: ; preds = %123, %60
br label %125
125: ; preds = %124, %40
%126 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%127 = call i64 @mq_unlink(i8* %126)
%128 = icmp ne i64 %127, 0
br i1 %128, label %129, label %131
129: ; preds = %125
%130 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %2
br label %131
131: ; preds = %129, %125
%132 = load i64, i64* %5
%133 = call i32 @mq_close(i64 %132)
%134 = icmp ne i32 %133, 0
br i1 %134, label %135, label %137
135: ; preds = %131
%136 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %137
137: ; preds = %135, %131
%138 = load i64, i64* %5
%139 = call i32 @mq_close(i64 %138)
%140 = icmp ne i32 %139, -1
br i1 %140, label %141, label %143
141: ; preds = %137
%142 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %2
br label %150
143: ; preds = %137
%144 = load i64, i64* @errno
%145 = load i64, i64* @EBADF
%146 = icmp ne i64 %144, %145
br i1 %146, label %147, label %149
147: ; preds = %143
%148 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %2
br label %149
149: ; preds = %147, %143
br label %150
150: ; preds = %149, %141
%151 = load i32, i32* %2
store i32 %151, i32* %1
br label %152
152: ; preds = %150, %21
%153 = load i32, i32* %1
ret i32 %153
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32, i32, i64 }
@.str = [16 x i8] c"/tst-mqueue1-%u\00"
@__const.do_test.attr = %struct.mq_attr { i32 10, i32 1, i32 0, i64 0 }
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_WRONLY = global i32 0
@.str.1 = [25 x i8] c"mq_open failed with: %m\0A\00"
@O_NONBLOCK = global i32 0
@.str.2 = [31 x i8] c"mq_close in parent failed: %m\0A\00"
@.str.3 = [23 x i8] c"mq_getattr failed: %m\0A\00"
@.str.4 = [23 x i8] c"mq_setattr failed: %m\0A\00"
@.str.5 = [50 x i8] c"mq_setattr returned unexpected values in *omqstat\00"
@.str.6 = [22 x i8] c"mq_unlink failed: %m\0A\00"
@.str.7 = [29 x i8] c"second mq_close did not fail\00"
@errno = global i64 0
@EBADF = global i64 0
@.str.8 = [45 x i8] c"second mq_close did not fail with EBADF: %m\0A\00"
define i32 @do_test() {
%1 = alloca [26 x i8]
%2 = alloca %struct.mq_attr
%3 = alloca %struct.mq_attr
%4 = getelementptr inbounds [26 x i8], [26 x i8]* %1, i64 0, i64 0
%5 = tail call i32 (...) @getpid()
%6 = call i32 @snprintf(i8* %4, i32 26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = bitcast %struct.mq_attr* %2 to i8*
%8 = load i32, i32* @O_CREAT
%9 = load i32, i32* @O_EXCL
%10 = or i32 %9, %8
%11 = load i32, i32* @O_WRONLY
%12 = or i32 %10, %11
%13 = call i64 (i8*, i32, ...) @mq_open(i8* %4, i32 %12, i32 384, %struct.mq_attr* %2)
%14 = icmp eq i64 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %119
17: ; preds = %0
%18 = call i32 @add_temp_mq(i8* %4)
%19 = call i32 @do_one_test(i64 %13, i8* %4, i32 0)
%20 = load i32, i32* @O_WRONLY
%21 = load i32, i32* @O_NONBLOCK
%22 = or i32 %21, %20
%23 = call i64 (i8*, i32, ...) @mq_open(i8* %4, i32 %22)
%24 = icmp eq i64 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %94
27: ; preds = %17
%28 = call i32 @mq_close(i64 %13)
%29 = icmp eq i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
%33 = phi i32 [ 1, %30 ], [ %19, %27 ]
%34 = load i32, i32* @O_NONBLOCK
%35 = call i32 @do_one_test(i64 %23, i8* %4, i32 %34)
%36 = or i32 %35, %33
%37 = call i64 @mq_getattr(i64 %23, %struct.mq_attr* %2)
%38 = icmp eq i64 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %32
%40 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %94
41: ; preds = %32
%42 = load i32, i32* @O_NONBLOCK
%43 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %2, i64 0, i32 2
%44 = load i32, i32* %43
%45 = xor i32 %44, %42
store i32 %45, i32* %43
%46 = bitcast %struct.mq_attr* %3 to i8*
%47 = call i32 @memset(%struct.mq_attr* %3, i32 85, i32 24)
%48 = call i64 @mq_setattr(i64 %23, %struct.mq_attr* %2, %struct.mq_attr* %3)
%49 = icmp eq i64 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %41
%51 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %92
52: ; preds = %41
%53 = load i32, i32* %43
%54 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 2
%55 = load i32, i32* %54
%56 = load i32, i32* @O_NONBLOCK
%57 = xor i32 %56, %55
%58 = icmp eq i32 %53, %57
br i1 %58, label %59, label %79
59: ; preds = %52
%60 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %2, i64 0, i32 0
%61 = load i32, i32* %60
%62 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 0
%63 = load i32, i32* %62
%64 = icmp eq i32 %61, %63
br i1 %64, label %65, label %79
65: ; preds = %59
%66 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %2, i64 0, i32 1
%67 = load i32, i32* %66
%68 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 1
%69 = load i32, i32* %68
%70 = icmp ne i32 %67, %69
%71 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %2, i64 0, i32 3
%72 = load i64, i64* %71
%73 = icmp ne i64 %72, 0
%74 = select i1 %70, i1 true, i1 %73
%75 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 3
%76 = load i64, i64* %75
%77 = icmp ne i64 %76, 0
%78 = select i1 %74, i1 true, i1 %77
br i1 %78, label %79, label %81
79: ; preds = %65, %59, %52
%80 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
br label %92
81: ; preds = %65
%82 = call i32 @do_one_test(i64 %23, i8* %4, i32 0)
%83 = call i64 @mq_setattr(i64 %23, %struct.mq_attr* %3, %struct.mq_attr* null)
%84 = icmp eq i64 %83, 0
br i1 %84, label %87, label %85
85: ; preds = %81
%86 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %92
87: ; preds = %81
%88 = or i32 %36, %82
%89 = load i32, i32* @O_NONBLOCK
%90 = call i32 @do_one_test(i64 %23, i8* %4, i32 %89)
%91 = or i32 %88, %90
br label %92
92: ; preds = %79, %87, %85, %50
%93 = phi i32 [ 1, %50 ], [ 1, %79 ], [ 1, %85 ], [ %91, %87 ]
br label %94
94: ; preds = %39, %92, %25
%95 = phi i32 [ 1, %25 ], [ 1, %39 ], [ %93, %92 ]
%96 = phi i64 [ %13, %25 ], [ %23, %39 ], [ %23, %92 ]
%97 = call i64 @mq_unlink(i8* %4)
%98 = icmp eq i64 %97, 0
br i1 %98, label %101, label %99
99: ; preds = %94
%100 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
br label %101
101: ; preds = %99, %94
%102 = phi i32 [ 1, %99 ], [ %95, %94 ]
%103 = call i32 @mq_close(i64 %96)
%104 = icmp eq i32 %103, 0
br i1 %104, label %107, label %105
105: ; preds = %101
%106 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %107
107: ; preds = %105, %101
%108 = phi i32 [ 1, %105 ], [ %102, %101 ]
%109 = call i32 @mq_close(i64 %96)
%110 = icmp eq i32 %109, -1
br i1 %110, label %113, label %111
111: ; preds = %107
%112 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
br label %119
113: ; preds = %107
%114 = load i64, i64* @errno
%115 = load i64, i64* @EBADF
%116 = icmp eq i64 %114, %115
br i1 %116, label %119, label %117
117: ; preds = %113
%118 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0))
br label %119
119: ; preds = %111, %117, %113, %15
%120 = phi i32 [ 0, %15 ], [ 1, %111 ], [ 1, %117 ], [ %108, %113 ]
ret i32 %120
}