#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*/ O_WRONLY;
int atoi(char *);
int /*<<< orphan*/ exit(int);
void *malloc(int);
int /*<<< orphan*/ mq_close(int);
int mq_open(char *, int /*<<< orphan*/);
int mq_send(int, void *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int main(int argc, char *argv[]) {
  mqd_t mqd;
  int r;
  int len;
  int prio;
  void *ptr;
  mqd = mq_open(argv[1], O_WRONLY);
  if (mqd == -1) {
    perror("mq_open");
    exit(-1);
  }
  len = atoi(argv[2]);
  prio = atoi(argv[3]);
  ptr = malloc(len);
  r = mq_send(mqd, ptr, len, prio);
  if (r == -1) {
    perror("mq_send");
    exit(0);
  }
  printf("%d len sent in %d prio\n", len, prio);
  mq_close(mqd);
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
call   1060 <mq_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11cf <main+0x4f>
lea    0xe40(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1050 <mq_send@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    122d <main+0xad>
lea    0xde7(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdd6(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <mq_close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   1060 <mq_open@plt>
cmp    $0xffffffff,%eax
je     11f1 <main+0x71>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
mov    0x18(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %r14d,%edi
mov    %rax,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1050 <mq_send@plt>
cmp    $0xffffffff,%eax
je     1207 <main+0x87>
lea    0xe37(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
mov    %r14d,%edi
call   1040 <mq_close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe08(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xdfa(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@.str = [8 x i8] c"mq_open\00"
@.str.1 = [8 x i8] c"mq_send\00"
@.str.2 = [24 x i8] c"%d len sent in %d prio\0A\00"
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
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_WRONLY
%15 = call i32 @mq_open(i8* %13, i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %8
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %9
%30 = load i32, i32* %8
%31 = call i8* @malloc(i32 %30)
store i8* %31, i8** %10
%32 = load i32, i32* %6
%33 = load i8*, i8** %10
%34 = load i32, i32* %8
%35 = load i32, i32* %9
%36 = call i32 @mq_send(i32 %32, i8* %33, i32 %34, i32 %35)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %21
%40 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%41 = call i32 @exit(i32 0)
unreachable
42: ; preds = %21
%43 = load i32, i32* %8
%44 = load i32, i32* %9
%45 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %43, i32 %44)
%46 = load i32, i32* %6
%47 = call i32 @mq_close(i32 %46)
ret i32 0
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@.str = [8 x i8] c"mq_open\00"
@.str.1 = [8 x i8] c"mq_send\00"
@.str.2 = [24 x i8] c"%d len sent in %d prio\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @mq_open(i8* %4, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = tail call i8* @malloc(i32 %14)
%19 = tail call i32 @mq_send(i32 %6, i8* %18, i32 %14, i32 %17)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %11
%22 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @exit(i32 0)
unreachable
24: ; preds = %11
%25 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %17)
%26 = tail call i32 @mq_close(i32 %6)
ret i32 0
}