#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 /*<<< orphan*/ msg;
typedef int mqd_t;

/* Variables and functions */
int O_APPEND;
int O_NONBLOCK;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ help(char *);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc < 2) {
    help(argv[0]);
    return -1;
  }
  int mq = open("/tmp/telemetryd.command", O_WRONLY | O_APPEND | O_NONBLOCK);
  if (mq == (mqd_t)-1) {
    perror("mq_open");
    return -1;
  }
  char msg[128];
  snprintf(msg, sizeof(msg), "command %s\n", argv[1]);
  int r = write(mq, msg, strlen(msg));
  if (r < 0) {
    perror("mq_send");
    return -1;
  }
  close(mq);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ab <main+0x3b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <help@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1288 <main+0x118>
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
mov    0x2e0d(%rip),%rax
or     (%rax),%esi
mov    0x2e24(%rip),%rax
or     (%rax),%esi
lea    0xe33(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f7 <main+0x87>
lea    0xe32(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1288 <main+0x118>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x80,%esi
lea    0xe0e(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xb4(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
jge    1279 <main+0x109>
lea    0xdc4(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1288 <main+0x118>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     1190 <main+0x20>
mov    (%rbx),%rdi
call   1090 <help@plt>
mov    $0xffffffff,%eax
jmp    11fa <main+0x8a>
mov    0x2e39(%rip),%rax
mov    0x2e2a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e3f(%rip),%rax
or     (%rax),%esi
lea    0xe4e(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1204 <main+0x94>
mov    %eax,%ebp
mov    0x8(%rbx),%rcx
lea    0xe57(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %eax,%eax
js     120d <main+0x9d>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe0d(%rip),%rdi
jmp    1214 <main+0xa4>
lea    0xe18(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%eax
jmp    11fa <main+0x8a>

LLVM IR (-O0):
@.str = [24 x i8] c"/tmp/telemetryd.command\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [8 x i8] c"mq_open\00"
@.str.2 = [12 x i8] c"command %s\0A\00"
@.str.3 = [8 x i8] c"mq_send\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [128 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @help(i8* %14)
store i32 -1, i32* %3
br label %45
16: ; preds = %2
%17 = load i32, i32* @O_WRONLY
%18 = load i32, i32* @O_APPEND
%19 = or i32 %17, %18
%20 = load i32, i32* @O_NONBLOCK
%21 = or i32 %19, %20
%22 = call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %16
%26 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %45
27: ; preds = %16
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @snprintf(i8* %28, i32 128, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i32, i32* %6
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = call i32 @write(i32 %33, i8* %34, i32 %36)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %27
%41 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %45
42: ; preds = %27
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
store i32 0, i32* %3
br label %45
45: ; preds = %42, %40, %25, %11
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [24 x i8] c"/tmp/telemetryd.command\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [8 x i8] c"mq_open\00"
@.str.2 = [12 x i8] c"command %s\0A\00"
@.str.3 = [8 x i8] c"mq_send\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @help(i8* %6)
br label %32
8: ; preds = %2
%9 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_APPEND
%11 = or i32 %10, %9
%12 = load i32, i32* @O_NONBLOCK
%13 = or i32 %11, %12
%14 = tail call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %32
18: ; preds = %8
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @snprintf(i8* %19, i32 128, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = call i32 @strlen(i8* %19)
%24 = call i32 @write(i32 %14, i8* %19, i32 %23)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %30
28: ; preds = %18
%29 = call i32 @close(i32 %14)
br label %30
30: ; preds = %28, %26
%31 = phi i32 [ -1, %26 ], [ 0, %28 ]
br label %32
32: ; preds = %16, %30, %5
%33 = phi i32 [ -1, %5 ], [ -1, %16 ], [ %31, %30 ]
ret i32 %33
}