#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;
};
typedef scalar_t__ mqd_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
int errno;
int /*<<< orphan*/ exit(int);
scalar_t__ mq_open(char *, int, int, struct mq_attr *);
int mq_unlink(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
mqd_t serverUp(void) {
  int rc;
  mqd_t svrHndl;
  struct mq_attr mqAttr;
  printf("Bringing up server.\n");
  rc = mq_unlink("/pax");
  if (rc < 0) {
    printf("   Warning %d (%s) on server mq_unlink.\n", errno, strerror(errno));
  }
  mqAttr.mq_maxmsg = 10;
  mqAttr.mq_msgsize = 1024;
  svrHndl = mq_open("/pax", O_RDWR | O_CREAT, S_IWUSR | S_IRUSR, &mqAttr);
  if (svrHndl < 0) {
    printf("   Error %d (%s) on server mq_open.\n", errno, strerror(errno));
    exit(1);
  }
  printf("   Server opened mqd_t of %d.\n", svrHndl);
  return svrHndl;
}


x86 assembly (clang, -O0):
<serverUp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea8(%rip),%rdi
call   1060 <mq_unlink@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11ad <serverUp+0x5d>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x1c(%rbp),%esi
mov    %rax,%rdx
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xa,-0x18(%rbp)
movl   $0x400,-0x14(%rbp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
mov    0x2e2d(%rip),%rax
or     (%rax),%esi
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
mov    0x2de3(%rip),%rax
or     (%rax),%edx
lea    0xe2f(%rip),%rdi
lea    -0x18(%rbp),%rcx
call   1040 <mq_open@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1236 <serverUp+0xe6>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%esi
mov    %rax,%rdx
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serverUp>:
push   %rbx
sub    $0x10,%rsp
lea    0xf06(%rip),%rdi
call   1030 <puts@plt>
lea    0xe88(%rip),%rdi
call   1070 <mq_unlink@plt>
test   %eax,%eax
jns    11a4 <serverUp+0x44>
mov    0x2e40(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1080 <strerror@plt>
lea    0xe6d(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
movabs $0x4000000000a,%rax
mov    %rax,0x8(%rsp)
mov    0x2e26(%rip),%rax
mov    0x2e37(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e0c(%rip),%rax
mov    0x2ded(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe22(%rip),%rdi
lea    0x8(%rsp),%rcx
call   1050 <mq_open@plt>
test   %rax,%rax
js     120a <serverUp+0xaa>
mov    %rax,%rbx
lea    0xe5c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2db7(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1080 <strerror@plt>
lea    0xe0d(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32 }
@.str = [21 x i8] c"Bringing up server.\0A\00"
@.str.1 = [5 x i8] c"/pax\00"
@.str.2 = [41 x i8] c" Warning %d (%s) on server mq_unlink.\0A\00"
@errno = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@.str.3 = [37 x i8] c" Error %d (%s) on server mq_open.\0A\00"
@.str.4 = [31 x i8] c" Server opened mqd_t of %d.\0A\00"
define i64 @serverUp() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca %struct.mq_attr
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @mq_unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = load i32, i32* @errno
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %9, i8* %11)
br label %13
13: ; preds = %8, %0
%14 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i32 0, i32 0
store i32 10, i32* %14
%15 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i32 0, i32 1
store i32 1024, i32* %15
%16 = load i32, i32* @O_RDWR
%17 = load i32, i32* @O_CREAT
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IWUSR
%20 = load i32, i32* @S_IRUSR
%21 = or i32 %19, %20
%22 = call i64 @mq_open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %21, %struct.mq_attr* %3)
store i64 %22, i64* %2
%23 = load i64, i64* %2
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %13
%26 = load i32, i32* @errno
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %26, i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %13
%32 = load i64, i64* %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i64 %32)
%34 = load i64, i64* %2
ret i64 %34
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32 }
@.str.1 = [5 x i8] c"/pax\00"
@.str.2 = [41 x i8] c" Warning %d (%s) on server mq_unlink.\0A\00"
@errno = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@.str.3 = [37 x i8] c" Error %d (%s) on server mq_open.\0A\00"
@.str.4 = [31 x i8] c" Server opened mqd_t of %d.\0A\00"
@str = [20 x i8] c"Bringing up server.\00"
define i64 @serverUp() {
%1 = alloca %struct.mq_attr
%2 = bitcast %struct.mq_attr* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @mq_unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %7, i8* %8)
br label %10
10: ; preds = %6, %0
%11 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %1, i64 0, i32 0
store i32 10, i32* %11
%12 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %1, i64 0, i32 1
store i32 1024, i32* %12
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_CREAT
%15 = or i32 %14, %13
%16 = load i32, i32* @S_IWUSR
%17 = load i32, i32* @S_IRUSR
%18 = or i32 %17, %16
%19 = call i64 @mq_open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %18, %struct.mq_attr* %1)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %10
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %22, i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %10
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i64 %19)
ret i64 %19
}