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

/* Variables and functions */
int O_NONBLOCK;
int O_WRONLY;
char *calloc(int, size_t);
int /*<<< orphan*/ ctime_r(int /*<<< orphan*/ const *, char *);
int getopt(int, char **, char *);
int mq_open(char *, int);
scalar_t__ mq_send(int, char *, size_t, unsigned int);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, char *);
void *strtoul(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  char *path;
  int oflags = O_WRONLY;
  mqd_t mqd;
  unsigned int msg_prio = 0;
  size_t msglen = 64;
  int count = 1;
  char *msgptr;
  int c;
  while (-1 != (c = getopt(argc, argv, "p:b:c:n"))) {
    switch (c) {
    case 'p':
      msg_prio = strtoul(optarg, NULL, 0);
      break;
    case 'b':
      msglen = strtoul(optarg, NULL, 0);
      if (msglen < 32)
        msglen = 32;
      break;
    case 'c':
      count = strtoul(optarg, NULL, 0);
      if (count > 99999)
        count = 99999;
      break;
    case 'n':
      oflags |= O_NONBLOCK;
      break;
    default:
      return -1;
    }
  }
  if (optind < argc)
    path = argv[optind];
  else {
    printf("Queue pathname required\n");
    return -1;
  }
  msgptr = calloc(1, msglen);
  mqd = mq_open(path, oflags);
  if (-1 != mqd) {
    char stime[26];
    const time_t tm = time(NULL);
    (void)ctime_r(&tm, stime);
    stime[24] = '\0';
    for (c = 1; c <= count; ++c) {
      sprintf(msgptr, "%05d %s", c, stime);
      if (mq_send(mqd, msgptr, msglen, msg_prio)) {
        perror("mq_send()");
        break;
      }
    }
  } else
    perror("mq_open(O_WRONLY)");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x40,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe56(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,%ecx
mov    %ecx,-0x44(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     12c7 <main+0x127>
mov    -0x44(%rbp),%eax
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x70(%rbp)
sub    $0xe,%eax
ja     12b6 <main+0x116>
mov    -0x70(%rbp),%rax
lea    0xde3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <strtoul@plt>
mov    %eax,-0x24(%rbp)
jmp    12c2 <main+0x122>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <strtoul@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x20,-0x30(%rbp)
jae    126d <main+0xcd>
movq   $0x20,-0x30(%rbp)
jmp    12c2 <main+0x122>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <strtoul@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x1869f,-0x34(%rbp)
jle    129d <main+0xfd>
movl   $0x1869f,-0x34(%rbp)
jmp    12c2 <main+0x122>
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    12c2 <main+0x122>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d4 <main+0x234>
jmp    11d8 <main+0x38>
mov    0x2d0a(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    12f4 <main+0x154>
mov    -0x10(%rbp),%rax
mov    0x2cf4(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
jmp    130c <main+0x16c>
lea    0xd49(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d4 <main+0x234>
mov    -0x30(%rbp),%rsi
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <mq_open@plt>
mov    %eax,-0x20(%rbp)
mov    $0xffffffff,%eax
cmp    -0x20(%rbp),%eax
je     13c8 <main+0x228>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x64(%rbp)
lea    -0x60(%rbp),%rsi
lea    -0x64(%rbp),%rdi
call   1080 <ctime_r@plt>
movb   $0x0,-0x48(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x34(%rbp),%eax
jg     13c3 <main+0x223>
mov    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%edx
lea    -0x60(%rbp),%rcx
lea    0xce0(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x20(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1040 <mq_send@plt>
cmp    $0x0,%rax
je     13b0 <main+0x210>
lea    0xcbf(%rip),%rdi
call   1090 <perror@plt>
jmp    13c3 <main+0x223>
jmp    13b5 <main+0x215>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    135f <main+0x1bf>
jmp    13d4 <main+0x234>
lea    0xca0(%rip),%rdi
call   1090 <perror@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r13
mov    %edi,%ebp
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    $0x1,%ebx
mov    $0x40,%eax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
mov    %rax,0x18(%rsp)
lea    0xe23(%rip),%r12
mov    0x2e14(%rip),%r14
mov    $0x1869f,%r15d
jmp    1209 <main+0x69>
nopl   0x0(%rax)
mov    (%r14),%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <strtoul@plt>
mov    %rax,%rbx
cmp    $0x1869f,%ebx
cmovge %r15d,%ebx
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r12,%rdx
call   10a0 <getopt@plt>
cmp    $0x63,%eax
je     11f0 <main+0x50>
cmp    $0x6d,%eax
jg     124e <main+0xae>
cmp    $0xffffffff,%eax
je     1282 <main+0xe2>
cmp    $0x62,%eax
jne    1350 <main+0x1b0>
mov    (%r14),%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <strtoul@plt>
cmp    $0x21,%rax
mov    $0x20,%ecx
cmovb  %rcx,%rax
mov    %rax,0x8(%rsp)
jmp    1209 <main+0x69>
cmp    $0x6e,%eax
je     126f <main+0xcf>
cmp    $0x70,%eax
jne    1350 <main+0x1b0>
mov    (%r14),%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <strtoul@plt>
mov    %rax,0x18(%rsp)
jmp    1209 <main+0x69>
mov    0x4(%rsp),%eax
mov    0x2d66(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x4(%rsp)
jmp    1209 <main+0x69>
mov    0x2d4f(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    1344 <main+0x1a4>
mov    0x0(%r13,%rax,8),%r14
mov    $0x1,%edi
mov    0x8(%rsp),%rsi
call   1050 <calloc@plt>
mov    %rax,%rbp
mov    %r14,%rdi
mov    0x4(%rsp),%esi
call   1060 <mq_open@plt>
cmp    $0xffffffff,%eax
je     1364 <main+0x1c4>
mov    %eax,%r13d
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0x14(%rsp)
lea    0x14(%rsp),%rdi
lea    0x20(%rsp),%rsi
call   1080 <ctime_r@plt>
movb   $0x0,0x38(%rsp)
test   %ebx,%ebx
jle    1340 <main+0x1a0>
neg    %ebx
mov    $0x1,%r15d
lea    0xd13(%rip),%r12
lea    0x20(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
mov    %r14,%rcx
call   10c0 <sprintf@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    0x8(%rsp),%rdx
mov    0x18(%rsp),%rcx
call   1040 <mq_send@plt>
test   %rax,%rax
jne    1374 <main+0x1d4>
lea    (%rbx,%r15,1),%eax
add    $0x1,%eax
mov    %r15d,%ecx
add    $0x1,%ecx
mov    %ecx,%r15d
cmp    $0x1,%eax
jne    1300 <main+0x160>
xor    %eax,%eax
jmp    1355 <main+0x1b5>
lea    0xce1(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcaf(%rip),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
jmp    1355 <main+0x1b5>
lea    0xc95(%rip),%rdi
call   1090 <perror@plt>
jmp    1340 <main+0x1a0>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@.str = [8 x i8] c"p:b:c:n\00"
@optarg = global i32 0
@O_NONBLOCK = global i32 0
@optind = global i32 0
@.str.1 = [25 x i8] c"Queue pathname required\0A\00"
@.str.2 = [8 x i8] c"%05d %s\00"
@.str.3 = [10 x i8] c"mq_send()\00"
@.str.4 = [18 x i8] c"mq_open(O_WRONLY)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca [26 x i8]
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* @O_WRONLY
store i32 %16, i32* %7
store i32 0, i32* %9
store i64 64, i64* %10
store i32 1, i32* %11
br label %17
17: ; preds = %49, %2
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @getopt(i32 %18, i8** %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 %20, i32* %13
%21 = icmp ne i32 -1, %20
br i1 %21, label %22, label %50
22: ; preds = %17
%23 = load i32, i32* %13
switch i32 %23, label %48 [
i32 112, label %24
i32 98, label %28
i32 99, label %36
i32 110, label %44
]
24: ; preds = %22
%25 = load i32, i32* @optarg
%26 = call i8* @strtoul(i32 %25, i32* null, i32 0)
%27 = ptrtoint i8* %26 to i32
store i32 %27, i32* %9
br label %49
28: ; preds = %22
%29 = load i32, i32* @optarg
%30 = call i8* @strtoul(i32 %29, i32* null, i32 0)
%31 = ptrtoint i8* %30 to i64
store i64 %31, i64* %10
%32 = load i64, i64* %10
%33 = icmp ult i64 %32, 32
br i1 %33, label %34, label %35
34: ; preds = %28
store i64 32, i64* %10
br label %35
35: ; preds = %34, %28
br label %49
36: ; preds = %22
%37 = load i32, i32* @optarg
%38 = call i8* @strtoul(i32 %37, i32* null, i32 0)
%39 = ptrtoint i8* %38 to i32
store i32 %39, i32* %11
%40 = load i32, i32* %11
%41 = icmp sgt i32 %40, 99999
br i1 %41, label %42, label %43
42: ; preds = %36
store i32 99999, i32* %11
br label %43
43: ; preds = %42, %36
br label %49
44: ; preds = %22
%45 = load i32, i32* @O_NONBLOCK
%46 = load i32, i32* %7
%47 = or i32 %46, %45
store i32 %47, i32* %7
br label %49
48: ; preds = %22
store i32 -1, i32* %3
br label %99
49: ; preds = %44, %43, %35, %24
br label %17
50: ; preds = %17
%51 = load i32, i32* @optind
%52 = load i32, i32* %4
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %60
54: ; preds = %50
%55 = load i8**, i8*** %5
%56 = load i32, i32* @optind
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
store i8* %59, i8** %6
br label %62
60: ; preds = %50
%61 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %99
62: ; preds = %54
%63 = load i64, i64* %10
%64 = call i8* @calloc(i32 1, i64 %63)
store i8* %64, i8** %12
%65 = load i8*, i8** %6
%66 = load i32, i32* %7
%67 = call i32 @mq_open(i8* %65, i32 %66)
store i32 %67, i32* %8
%68 = load i32, i32* %8
%69 = icmp ne i32 -1, %68
br i1 %69, label %70, label %97
70: ; preds = %62
%71 = call i32 @time(i32* null)
store i32 %71, i32* %15
%72 = getelementptr inbounds [26 x i8], [26 x i8]* %14, i64 0, i64 0
%73 = call i32 @ctime_r(i32* %15, i8* %72)
%74 = getelementptr inbounds [26 x i8], [26 x i8]* %14, i64 0, i64 24
store i8 0, i8* %74
store i32 1, i32* %13
br label %75
75: ; preds = %93, %70
%76 = load i32, i32* %13
%77 = load i32, i32* %11
%78 = icmp sle i32 %76, %77
br i1 %78, label %79, label %96
79: ; preds = %75
%80 = load i8*, i8** %12
%81 = load i32, i32* %13
%82 = getelementptr inbounds [26 x i8], [26 x i8]* %14, i64 0, i64 0
%83 = call i32 @sprintf(i8* %80, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %81, i8* %82)
%84 = load i32, i32* %8
%85 = load i8*, i8** %12
%86 = load i64, i64* %10
%87 = load i32, i32* %9
%88 = call i64 @mq_send(i32 %84, i8* %85, i64 %86, i32 %87)
%89 = icmp ne i64 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %79
%91 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %96
92: ; preds = %79
br label %93
93: ; preds = %92
%94 = load i32, i32* %13
%95 = add nsw i32 %94, 1
store i32 %95, i32* %13
br label %75
96: ; preds = %90, %75
br label %99
97: ; preds = %62
%98 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %99
99: ; preds = %48, %60, %97, %96
%100 = load i32, i32* %3
ret i32 %100
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@.str = [8 x i8] c"p:b:c:n\00"
@optarg = global i32 0
@O_NONBLOCK = global i32 0
@optind = global i32 0
@.str.2 = [8 x i8] c"%05d %s\00"
@.str.3 = [10 x i8] c"mq_send()\00"
@.str.4 = [18 x i8] c"mq_open(O_WRONLY)\00"
@str = [24 x i8] c"Queue pathname required\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [26 x i8]
%4 = alloca i32
%5 = load i32, i32* @O_WRONLY
br label %6
6: ; preds = %39, %2
%7 = phi i32 [ %41, %39 ], [ %5, %2 ]
%8 = phi i32 [ %12, %39 ], [ 0, %2 ]
%9 = phi i64 [ %16, %39 ], [ 64, %2 ]
%10 = phi i32 [ %19, %39 ], [ 1, %2 ]
br label %11
11: ; preds = %6, %21
%12 = phi i32 [ %8, %6 ], [ %25, %21 ]
%13 = phi i64 [ %9, %6 ], [ %16, %21 ]
%14 = phi i32 [ %10, %6 ], [ %19, %21 ]
br label %15
15: ; preds = %11, %26
%16 = phi i64 [ %13, %11 ], [ %31, %26 ]
%17 = phi i32 [ %14, %11 ], [ %19, %26 ]
br label %18
18: ; preds = %15, %32
%19 = phi i32 [ %38, %32 ], [ %17, %15 ]
%20 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
switch i32 %20, label %74 [
i32 -1, label %42
i32 112, label %21
i32 98, label %26
i32 99, label %32
i32 110, label %39
]
21: ; preds = %18
%22 = load i32, i32* @optarg
%23 = tail call i8* @strtoul(i32 %22, i32* null, i32 0)
%24 = ptrtoint i8* %23 to i64
%25 = trunc i64 %24 to i32
br label %11
26: ; preds = %18
%27 = load i32, i32* @optarg
%28 = tail call i8* @strtoul(i32 %27, i32* null, i32 0)
%29 = ptrtoint i8* %28 to i64
%30 = icmp ugt i64 %29, 32
%31 = select i1 %30, i64 %29, i64 32
br label %15
32: ; preds = %18
%33 = load i32, i32* @optarg
%34 = tail call i8* @strtoul(i32 %33, i32* null, i32 0)
%35 = ptrtoint i8* %34 to i64
%36 = trunc i64 %35 to i32
%37 = icmp slt i32 %36, 99999
%38 = select i1 %37, i32 %36, i32 99999
br label %18
39: ; preds = %18
%40 = load i32, i32* @O_NONBLOCK
%41 = or i32 %40, %7
br label %6
42: ; preds = %18
%43 = load i32, i32* @optind
%44 = icmp slt i32 %43, %0
br i1 %44, label %45, label %52
45: ; preds = %42
%46 = sext i32 %43 to i64
%47 = getelementptr inbounds i8*, i8** %1, i64 %46
%48 = load i8*, i8** %47
%49 = tail call i8* @calloc(i32 1, i64 %16)
%50 = tail call i32 @mq_open(i8* %48, i32 %7)
%51 = icmp eq i32 %50, -1
br i1 %51, label %72, label %54
52: ; preds = %42
%53 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %74
54: ; preds = %45
%55 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%56 = bitcast i32* %4 to i8*
%57 = tail call i32 @time(i32* null)
store i32 %57, i32* %4
%58 = call i32 @ctime_r(i32* %4, i8* %55)
%59 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 24
store i8 0, i8* %59
%60 = icmp slt i32 %19, 1
br i1 %60, label %71, label %64
61: ; preds = %64
%62 = add nuw i32 %65, 1
%63 = icmp eq i32 %65, %19
br i1 %63, label %71, label %64
64: ; preds = %54, %61
%65 = phi i32 [ %62, %61 ], [ 1, %54 ]
%66 = call i32 @sprintf(i8* dereferenceable(1) %49, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %65, i8* %55)
%67 = call i64 @mq_send(i32 %50, i8* %49, i64 %16, i32 %12)
%68 = icmp eq i64 %67, 0
br i1 %68, label %61, label %69
69: ; preds = %64
%70 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %71
71: ; preds = %61, %54, %69
br label %74
72: ; preds = %45
%73 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %74
74: ; preds = %18, %71, %72, %52
%75 = phi i32 [ -1, %52 ], [ 0, %72 ], [ 0, %71 ], [ -1, %18 ]
ret i32 %75
}