#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 */
typedef int mqd_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int O_CREAT;
int O_EXCL;
int O_RDWR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getopt(int, char **, char *);
int mq_close(int);
int mq_open(char *, int, int, int /*<<< orphan*/ *);
int optind;
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int c, flags;
  mqd_t mqd;
  flags = O_RDWR | O_CREAT;
  while (-1 != (c = getopt(argc, argv, "e"))) {
    switch (c) {
    case 'e':
      flags |= O_EXCL;
      break;
    }
  }
  if (optind != argc - 1) {
    printf("usage: %s [-e] <name>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  mqd = mq_open(argv[optind], flags, (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH),
                NULL);
  if (-1 == mqd) {
    printf("mq_open error: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (-1 == mq_close(mqd)) {
    printf("mq_close error: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    0x2e72(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe67(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     11d5 <main+0x75>
mov    -0x14(%rbp),%eax
sub    $0x65,%eax
jne    11d0 <main+0x70>
jmp    11c1 <main+0x61>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    118b <main+0x2b>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     120d <main+0xad>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe08(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x2db8(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%esi
mov    0x2d6f(%rip),%rax
mov    (%rax),%edx
mov    0x2da6(%rip),%rax
or     (%rax),%edx
mov    0x2d75(%rip),%rax
or     (%rax),%edx
mov    0x2d64(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <mq_open@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x1c(%rbp),%eax
jne    128b <main+0x12b>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xda1(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1040 <mq_close@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    12cd <main+0x16d>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xd72(%rip),%rdi
call   1030 <printf@plt>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e6c(%rip),%rax
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%r14d
or     (%rax),%r14d
lea    0xe78(%rip),%r15
mov    0x2e31(%rip),%r12
jmp    11a0 <main+0x40>
or     (%r12),%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1060 <getopt@plt>
cmp    $0x65,%eax
je     1191 <main+0x31>
cmp    $0xffffffff,%eax
jne    11a0 <main+0x40>
mov    0x2e12(%rip),%rax
movslq (%rax),%rax
add    $0xffffffff,%ebp
cmp    %ebp,%eax
jne    1216 <main+0xb6>
mov    0x2dc9(%rip),%rcx
mov    0x2e02(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2dcf(%rip),%rcx
or     (%rcx),%edx
mov    (%rbx,%rax,8),%rdi
mov    0x2dba(%rip),%rax
or     (%rax),%edx
mov    %r14d,%esi
xor    %ecx,%ecx
call   1050 <mq_open@plt>
cmp    $0xffffffff,%eax
jne    1222 <main+0xc2>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe05(%rip),%rdi
jmp    1243 <main+0xe3>
mov    (%rbx),%rsi
lea    0xde2(%rip),%rdi
jmp    1246 <main+0xe6>
mov    %eax,%edi
call   1040 <mq_close@plt>
cmp    $0xffffffff,%eax
jne    1259 <main+0xf9>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xde9(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [2 x i8] c"e\00"
@O_EXCL = global i32 0
@optind = global i32 0
@.str.1 = [23 x i8] c"usage: %s [-e] <name>\0A\00"
@EXIT_FAILURE = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.2 = [19 x i8] c"mq_open error: %s\0A\00"
@errno = global i32 0
@.str.3 = [20 x i8] c"mq_close error: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_CREAT
%11 = or i32 %9, %10
store i32 %11, i32* %7
br label %12
12: ; preds = %23, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %6
%16 = icmp ne i32 -1, %15
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = load i32, i32* %6
switch i32 %18, label %23 [
i32 101, label %19
]
19: ; preds = %17
%20 = load i32, i32* @O_EXCL
%21 = load i32, i32* %7
%22 = or i32 %21, %20
store i32 %22, i32* %7
br label %23
23: ; preds = %17, %19
br label %12
24: ; preds = %12
%25 = load i32, i32* @optind
%26 = load i32, i32* %4
%27 = sub nsw i32 %26, 1
%28 = icmp ne i32 %25, %27
br i1 %28, label %29, label %36
29: ; preds = %24
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %24
%37 = load i8**, i8*** %5
%38 = load i32, i32* @optind
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = load i32, i32* %7
%43 = load i32, i32* @S_IRUSR
%44 = load i32, i32* @S_IWUSR
%45 = or i32 %43, %44
%46 = load i32, i32* @S_IRGRP
%47 = or i32 %45, %46
%48 = load i32, i32* @S_IROTH
%49 = or i32 %47, %48
%50 = call i32 @mq_open(i8* %41, i32 %42, i32 %49, i32* null)
store i32 %50, i32* %8
%51 = load i32, i32* %8
%52 = icmp eq i32 -1, %51
br i1 %52, label %53, label %59
53: ; preds = %36
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %55)
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %36
%60 = load i32, i32* %8
%61 = call i32 @mq_close(i32 %60)
%62 = icmp eq i32 -1, %61
br i1 %62, label %63, label %69
63: ; preds = %59
%64 = load i32, i32* @errno
%65 = call i8* @strerror(i32 %64)
%66 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %65)
%67 = load i32, i32* @EXIT_FAILURE
%68 = call i32 @exit(i32 %67)
unreachable
69: ; preds = %59
%70 = load i32, i32* @EXIT_SUCCESS
%71 = call i32 @exit(i32 %70)
unreachable
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [2 x i8] c"e\00"
@O_EXCL = global i32 0
@optind = global i32 0
@.str.1 = [23 x i8] c"usage: %s [-e] <name>\0A\00"
@EXIT_FAILURE = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.2 = [19 x i8] c"mq_open error: %s\0A\00"
@errno = global i32 0
@.str.3 = [20 x i8] c"mq_close error: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
br label %6
6: ; preds = %10, %2
%7 = phi i32 [ %12, %10 ], [ %5, %2 ]
br label %8
8: ; preds = %6, %8
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
switch i32 %9, label %8 [
i32 -1, label %13
i32 101, label %10
]
10: ; preds = %8
%11 = load i32, i32* @O_EXCL
%12 = or i32 %11, %7
br label %6
13: ; preds = %8
%14 = load i32, i32* @optind
%15 = add nsw i32 %0, -1
%16 = icmp eq i32 %14, %15
br i1 %16, label %22, label %17
17: ; preds = %13
%18 = load i8*, i8** %1
%19 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %13
%23 = sext i32 %14 to i64
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
%26 = load i32, i32* @S_IRUSR
%27 = load i32, i32* @S_IWUSR
%28 = or i32 %27, %26
%29 = load i32, i32* @S_IRGRP
%30 = or i32 %28, %29
%31 = load i32, i32* @S_IROTH
%32 = or i32 %30, %31
%33 = tail call i32 @mq_open(i8* %25, i32 %7, i32 %32, i32* null)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %41
35: ; preds = %22
%36 = load i32, i32* @errno
%37 = tail call i8* @strerror(i32 %36)
%38 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %22
%42 = tail call i32 @mq_close(i32 %33)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %50
44: ; preds = %41
%45 = load i32, i32* @errno
%46 = tail call i8* @strerror(i32 %45)
%47 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
%49 = tail call i32 @exit(i32 %48)
unreachable
50: ; preds = %41
%51 = load i32, i32* @EXIT_SUCCESS
%52 = tail call i32 @exit(i32 %51)
unreachable
}