#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 EXIT_SUCCESS;
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int mq_open(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ mq_send(int, char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  mqd_t mq;
  int priority;
  if ((argc != 4) || (sscanf(argv[2], "%d", &priority) != 1)) {
    fprintf(stderr, "usage: %s mq_name priority message\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  mq = mq_open(argv[1], O_CREAT | O_WRONLY, 0666, NULL);
  if (mq == -1) {
    perror(argv[1]);
    exit(EXIT_FAILURE);
  }
  if (mq_send(mq, argv[3], strlen(argv[3]), priority) != 0) {
    perror("mq_send");
    exit(EXIT_FAILURE);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    11b1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe61(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
je     11db <main+0x6b>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3b(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
mov    0x2dc5(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <mq_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    122b <main+0xbb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <perror@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
mov    -0x18(%rbp),%ecx
call   1040 <mq_send@plt>
cmp    $0x0,%rax
je     127f <main+0x10f>
lea    0xdbb(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    11ef <main+0x7f>
mov    0x10(%rbx),%rdi
lea    0xe7a(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    11ef <main+0x7f>
mov    0x8(%rbx),%rdi
mov    0x2e58(%rip),%rax
mov    0x2e11(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1b6,%edx
xor    %ecx,%ecx
call   1060 <mq_open@plt>
cmp    $0xffffffff,%eax
je     1209 <main+0x99>
mov    %eax,%ebp
mov    0x18(%rbx),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    0x4(%rsp),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <mq_send@plt>
test   %rax,%rax
jne    120f <main+0x9f>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe01(%rip),%rsi
call   1050 <fprintf@plt>
jmp    121b <main+0xab>
mov    0x8(%rbx),%rdi
jmp    1216 <main+0xa6>
lea    0xe11(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"usage: %s mq_name priority message\0A\00"
@EXIT_FAILURE = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str.2 = [8 x i8] c"mq_send\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 4
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 2
%13 = load i8*, i8** %12
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%15 = icmp ne i32 %14, 1
br i1 %15, label %16, label %24
16: ; preds = %10, %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %10
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_CREAT
%29 = load i32, i32* @O_WRONLY
%30 = or i32 %28, %29
%31 = call i32 @mq_open(i8* %27, i32 %30, i32 438, i32* null)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %41
34: ; preds = %24
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @perror(i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %24
%42 = load i32, i32* %6
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 3
%45 = load i8*, i8** %44
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 3
%48 = load i8*, i8** %47
%49 = call i32 @strlen(i8* %48)
%50 = load i32, i32* %7
%51 = call i64 @mq_send(i32 %42, i8* %45, i32 %49, i32 %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %41
%54 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %41
%58 = load i32, i32* @EXIT_SUCCESS
ret i32 %58
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"usage: %s mq_name priority message\0A\00"
@EXIT_FAILURE = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str.2 = [8 x i8] c"mq_send\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 4
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%10 = icmp eq i32 %9, 1
br i1 %10, label %17, label %11
11: ; preds = %6, %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %6
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_CREAT
%21 = load i32, i32* @O_WRONLY
%22 = or i32 %21, %20
%23 = call i32 @mq_open(i8* %19, i32 %22, i32 438, i32* null)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %17
%26 = load i8*, i8** %18
%27 = call i32 @perror(i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %17
%31 = getelementptr inbounds i8*, i8** %1, i64 3
%32 = load i8*, i8** %31
%33 = call i32 @strlen(i8* %32)
%34 = load i32, i32* %3
%35 = call i64 @mq_send(i32 %23, i8* %32, i32 %33, i32 %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %30
%38 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %30
%42 = load i32, i32* @EXIT_SUCCESS
ret i32 %42
}