#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 O_NONBLOCK;
int O_WRONLY;
int errno;
int /*<<< orphan*/ mq_close(int);
int mq_open(char *, int);
scalar_t__ mq_send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  mqd_t fd;
  if (argc != 2) {
    printf("usage: %s </mqueue name> \n", argv[0]);
    return 2;
  }
  fd = mq_open(argv[1], O_WRONLY | O_NONBLOCK);
  if (fd == -1) {
    printf("mqsnd: mq_open: errno = %d\n", errno);
    return 2;
  }
  if (mq_send(fd, "TEST MESSAGE", strlen("TEST MESSAGE"), 0)) {
    printf("mqsnd: mq_send: errno = %d\n", errno);
    return 2;
  }
  mq_close(fd);
  return 0;
}


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)
cmpl   $0x2,-0x8(%rbp)
je     1191 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1241 <main+0xf1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    0x2e3f(%rip),%rax
or     (%rax),%esi
call   1070 <mq_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11e0 <main+0x90>
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1241 <main+0xf1>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    0xe4a(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%edx
lea    0xe39(%rip),%rsi
xor    %ecx,%ecx
call   1060 <mq_send@plt>
cmp    $0x0,%rax
je     1232 <main+0xe2>
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1241 <main+0xf1>
mov    -0x14(%rbp),%edi
call   1050 <mq_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11b1 <main+0x61>
mov    0x8(%rsi),%rdi
mov    0x2e64(%rip),%rax
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1070 <mq_open@plt>
cmp    $0xffffffff,%eax
je     11c9 <main+0x79>
mov    %eax,%ebp
lea    0xeb5(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <mq_send@plt>
test   %rax,%rax
je     11e7 <main+0x97>
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
jmp    11d9 <main+0x89>
mov    (%rsi),%rsi
lea    0xe45(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%ebx
jmp    11ee <main+0x9e>
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
lea    0xe42(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%ebx
jmp    11ee <main+0x9e>
mov    %ebp,%edi
call   1050 <mq_close@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"usage: %s </mqueue name> \0A\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [28 x i8] c"mqsnd: mq_open: errno = %d\0A\00"
@errno = global i32 0
@.str.2 = [13 x i8] c"TEST MESSAGE\00"
@.str.3 = [28 x i8] c"mqsnd: mq_send: errno = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 2, i32* %3
br label %38
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_WRONLY
%19 = load i32, i32* @O_NONBLOCK
%20 = or i32 %18, %19
%21 = call i32 @mq_open(i8* %17, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %14
%25 = load i32, i32* @errno
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %25)
store i32 2, i32* %3
br label %38
27: ; preds = %14
%28 = load i32, i32* %6
%29 = call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%30 = call i64 @mq_send(i32 %28, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 0)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* @errno
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %33)
store i32 2, i32* %3
br label %38
35: ; preds = %27
%36 = load i32, i32* %6
%37 = call i32 @mq_close(i32 %36)
store i32 0, i32* %3
br label %38
38: ; preds = %35, %32, %24, %9
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [27 x i8] c"usage: %s </mqueue name> \0A\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [28 x i8] c"mqsnd: mq_open: errno = %d\0A\00"
@errno = global i32 0
@.str.2 = [13 x i8] c"TEST MESSAGE\00"
@.str.3 = [28 x i8] c"mqsnd: mq_send: errno = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %27
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_WRONLY
%11 = load i32, i32* @O_NONBLOCK
%12 = or i32 %11, %10
%13 = tail call i32 @mq_open(i8* %9, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %7
%16 = load i32, i32* @errno
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %27
18: ; preds = %7
%19 = tail call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i64 @mq_send(i32 %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i32, i32* @errno
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %27
25: ; preds = %18
%26 = tail call i32 @mq_close(i32 %13)
br label %27
27: ; preds = %25, %22, %15, %4
%28 = phi i32 [ 2, %4 ], [ 2, %15 ], [ 2, %22 ], [ 0, %25 ]
ret i32 %28
}