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


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)
jl     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     11d7 <main+0x67>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
mov    0x2e09(%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    1223 <main+0xb3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <perror@plt>
mov    $0x2,%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>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x4,%edi
jl     11e3 <main+0x73>
mov    0x10(%rbx),%rdi
lea    0xe7a(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    11e3 <main+0x73>
mov    0x8(%rbx),%rdi
mov    0x2e28(%rip),%rax
mov    0x2e51(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1b6,%edx
xor    %ecx,%ecx
call   1060 <mq_open@plt>
cmp    $0xffffffff,%eax
je     1205 <main+0x95>
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>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe0d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x8(%rbx),%rdi
call   1080 <perror@plt>
mov    $0x2,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"usage: %s mq prio message\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = 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 slt 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 %23
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 ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %10
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_WRONLY
%28 = load i32, i32* @O_CREAT
%29 = or i32 %27, %28
%30 = call i32 @mq_open(i8* %26, i32 %29, i32 438, i32* null)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %39
33: ; preds = %23
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @perror(i8* %36)
%38 = call i32 @exit(i32 2)
unreachable
39: ; preds = %23
%40 = load i32, i32* %6
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 3
%46 = load i8*, i8** %45
%47 = call i32 @strlen(i8* %46)
%48 = load i32, i32* %7
%49 = call i32 @mq_send(i32 %40, i8* %43, i32 %47, i32 %48)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"usage: %s mq prio message\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 4
br i1 %5, label %11, label %6
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 %16, 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 ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %6
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_WRONLY
%20 = load i32, i32* @O_CREAT
%21 = or i32 %20, %19
%22 = call i32 @mq_open(i8* %18, i32 %21, i32 438, i32* null)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %16
%25 = load i8*, i8** %17
%26 = call i32 @perror(i8* %25)
%27 = call i32 @exit(i32 2)
unreachable
28: ; preds = %16
%29 = getelementptr inbounds i8*, i8** %1, i64 3
%30 = load i8*, i8** %29
%31 = call i32 @strlen(i8* %30)
%32 = load i32, i32* %3
%33 = call i32 @mq_send(i32 %22, i8* %30, i32 %31, i32 %32)
ret i32 0
}