#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 /*<<< orphan*/ O_WRONLY;
void *atoi(char *);
void *calloc(size_t, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int mq_open(char *, int /*<<< orphan*/);
int mq_send(int, void *, size_t, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  mqd_t mqd;
  void *ptr;
  size_t len;
  unsigned prio;
  if (4 != argc) {
    printf("usage: %s <name>  <bytes> <priority>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  len = atoi(argv[2]);
  prio = atoi(argv[3]);
  mqd = mq_open(argv[1], O_WRONLY);
  if (-1 == mqd) {
    printf("mq_open error: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  ptr = calloc(len, sizeof(char));
  if (NULL == ptr) {
    printf("calloc error\n");
    exit(EXIT_FAILURE);
  }
  if (-1 == mq_send(mqd, ptr, len, prio)) {
    printf("mq_send error: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  exit(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)
mov    $0x4,%eax
cmp    -0x8(%rbp),%eax
je     11b7 <main+0x47>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
call   1060 <mq_open@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    122c <main+0xbc>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1266 <main+0xf6>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1040 <mq_send@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    12b5 <main+0x145>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
cmp    $0x4,%edi
jne    11d2 <main+0x52>
mov    0x10(%rbp),%rdi
call   1080 <atoi@plt>
mov    %rax,%rbx
mov    0x18(%rbp),%rdi
call   1080 <atoi@plt>
mov    %rax,%r14
mov    0x8(%rbp),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
call   1070 <mq_open@plt>
cmp    $0xffffffff,%eax
jne    11df <main+0x5f>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe56(%rip),%rdi
jmp    122b <main+0xab>
mov    0x0(%rbp),%rsi
lea    0xe23(%rip),%rdi
jmp    122e <main+0xae>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
test   %rax,%rax
jne    1201 <main+0x81>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
jmp    1235 <main+0xb5>
mov    %ebp,%edi
mov    %rax,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1050 <mq_send@plt>
cmp    $0xffffffff,%eax
jne    1243 <main+0xc3>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe0e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"usage: %s <name> <bytes> <priority>\0A\00"
@EXIT_FAILURE = global i32 0
@O_WRONLY = global i32 0
@.str.1 = [19 x i8] c"mq_open error: %s\0A\00"
@errno = global i32 0
@.str.2 = [14 x i8] c"calloc error\0A\00"
@.str.3 = [19 x i8] c"mq_send 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 i8*
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 4, %10
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i8* @atoi(i8* %22)
%24 = ptrtoint i8* %23 to i64
store i64 %24, i64* %8
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 3
%27 = load i8*, i8** %26
%28 = call i8* @atoi(i8* %27)
%29 = ptrtoint i8* %28 to i32
store i32 %29, i32* %9
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i32, i32* @O_WRONLY
%34 = call i32 @mq_open(i8* %32, i32 %33)
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = icmp eq i32 -1, %35
br i1 %36, label %37, label %43
37: ; preds = %19
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %19
%44 = load i64, i64* %8
%45 = call i8* @calloc(i64 %44, i32 1)
store i8* %45, i8** %7
%46 = load i8*, i8** %7
%47 = icmp eq i8* null, %46
br i1 %47, label %48, label %52
48: ; preds = %43
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %43
%53 = load i32, i32* %6
%54 = load i8*, i8** %7
%55 = load i64, i64* %8
%56 = load i32, i32* %9
%57 = call i32 @mq_send(i32 %53, i8* %54, i64 %55, i32 %56)
%58 = icmp eq i32 -1, %57
br i1 %58, label %59, label %65
59: ; preds = %52
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %61)
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %52
%66 = load i32, i32* @EXIT_SUCCESS
%67 = call i32 @exit(i32 %66)
unreachable
}

LLVM IR (-O2):
@.str = [38 x i8] c"usage: %s <name> <bytes> <priority>\0A\00"
@EXIT_FAILURE = global i32 0
@O_WRONLY = global i32 0
@.str.1 = [19 x i8] c"mq_open error: %s\0A\00"
@errno = global i32 0
@.str.3 = [19 x i8] c"mq_send error: %s\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [13 x i8] c"calloc error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i8* @atoi(i8* %11)
%13 = ptrtoint i8* %12 to i64
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call i8* @atoi(i8* %15)
%17 = ptrtoint i8* %16 to i64
%18 = trunc i64 %17 to i32
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_WRONLY
%22 = tail call i32 @mq_open(i8* %20, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %30
24: ; preds = %9
%25 = load i32, i32* @errno
%26 = tail call i8* @strerror(i32 %25)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %9
%31 = tail call i8* @calloc(i64 %13, i32 1)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = tail call i32 @exit(i32 %35)
unreachable
37: ; preds = %30
%38 = tail call i32 @mq_send(i32 %22, i8* %31, i64 %13, i32 %18)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %46
40: ; preds = %37
%41 = load i32, i32* @errno
%42 = tail call i8* @strerror(i32 %41)
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = tail call i32 @exit(i32 %44)
unreachable
46: ; preds = %37
%47 = load i32, i32* @EXIT_SUCCESS
%48 = tail call i32 @exit(i32 %47)
unreachable
}