#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 ssize_t;
typedef int mqd_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ mq_close(int);
int mq_open(char *, int /*<<< orphan*/);
int mq_receive(int, char *, int, unsigned int *);
int /*<<< orphan*/ mq_unlink(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned int, char *);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int main() {
  mqd_t queue = mq_open("/is141315", O_RDONLY);
  if (queue == -1) {
    perror("/is141315");
    return 1;
  }
  char line[256];
  do {
    unsigned int prio = 0;
    ssize_t len = mq_receive(queue, line, 256, &prio);
    if (len == -1) {
      perror("/is141315");
      mq_close(queue);
      return 1;
    }
    line[256 - 1] = 0;
    printf("prio: %u, msg:'%s' \n", prio, line);
    fflush(stdout);
  } while (strcmp(line, "quit"));
  mq_close(queue);
  mq_unlink("/is141315");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    0xe5e(%rip),%rdi
call   1060 <mq_open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11cc <main+0x4c>
lea    0xe45(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    128c <main+0x10c>
jmp    11d1 <main+0x51>
movl   $0x0,-0x114(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
lea    -0x114(%rbp),%rcx
call   1080 <mq_receive@plt>
mov    %eax,-0x118(%rbp)
cmpl   $0xffffffff,-0x118(%rbp)
jne    1229 <main+0xa9>
lea    0xdf0(%rip),%rdi
call   1090 <perror@plt>
mov    -0x8(%rbp),%edi
call   1040 <mq_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    128c <main+0x10c>
movb   $0x0,-0x11(%rbp)
mov    -0x114(%rbp),%esi
lea    -0x110(%rbp),%rdx
lea    0xdc9(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    -0x110(%rbp),%rdi
lea    0xdbd(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11d1 <main+0x51>
mov    -0x8(%rbp),%edi
call   1040 <mq_close@plt>
lea    0xd80(%rip),%rdi
call   10a0 <mq_unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
lea    0xe5f(%rip),%rdi
call   1060 <mq_open@plt>
cmp    $0xffffffff,%eax
je     1246 <main+0xc6>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r14
lea    0xe48(%rip),%r15
mov    0x2e0f(%rip),%r13
lea    0xe4f(%rip),%r12
movl   $0x0,0xc(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
mov    %r14,%rcx
call   1080 <mq_receive@plt>
cmp    $0xffffffff,%eax
je     1259 <main+0xd9>
movb   $0x0,0x10f(%rsp)
mov    0xc(%rsp),%esi
mov    %r15,%rdi
mov    %rbx,%rdx
call   1030 <printf@plt>
mov    0x0(%r13),%edi
call   1070 <fflush@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11d0 <main+0x50>
mov    %ebp,%edi
call   1040 <mq_close@plt>
lea    0xdd3(%rip),%rdi
call   10a0 <mq_unlink@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb3(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%eax
jmp    1234 <main+0xb4>
lea    0xda0(%rip),%rdi
call   1090 <perror@plt>
mov    %ebp,%edi
call   1040 <mq_close@plt>
mov    $0x1,%eax
jmp    1234 <main+0xb4>

LLVM IR (-O0):
@.str = [10 x i8] c"/is141315\00"
@O_RDONLY = global i32 0
@.str.1 = [21 x i8] c"prio: %u, msg:'%s' \0A\00"
@stdout = global i32 0
@.str.2 = [5 x i8] c"quit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @mq_open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %38
12: ; preds = %0
br label %13
13: ; preds = %30, %12
store i32 0, i32* %4
%14 = load i32, i32* %2
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%16 = call i32 @mq_receive(i32 %14, i8* %15, i32 256, i32* %4)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* %2
%22 = call i32 @mq_close(i32 %21)
store i32 1, i32* %1
br label %38
23: ; preds = %13
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 255
store i8 0, i8* %24
%25 = load i32, i32* %4
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %25, i8* %26)
%28 = load i32, i32* @stdout
%29 = call i32 @fflush(i32 %28)
br label %30
30: ; preds = %23
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp ne i64 %32, 0
br i1 %33, label %13, label %34
34: ; preds = %30
%35 = load i32, i32* %2
%36 = call i32 @mq_close(i32 %35)
%37 = call i32 @mq_unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %38
38: ; preds = %34, %19, %10
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str = [10 x i8] c"/is141315\00"
@O_RDONLY = global i32 0
@.str.1 = [21 x i8] c"prio: %u, msg:'%s' \0A\00"
@stdout = global i32 0
@.str.2 = [5 x i8] c"quit\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @mq_open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %30
8: ; preds = %0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%10 = bitcast i32* %2 to i8*
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 255
br label %12
12: ; preds = %18, %8
store i32 0, i32* %2
%13 = call i32 @mq_receive(i32 %4, i8* %9, i32 256, i32* %2)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @mq_close(i32 %4)
br label %28
18: ; preds = %12
store i8 0, i8* %11
%19 = load i32, i32* %2
%20 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %19, i8* %9)
%21 = load i32, i32* @stdout
%22 = call i32 @fflush(i32 %21)
%23 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %12
25: ; preds = %18
%26 = call i32 @mq_close(i32 %4)
%27 = call i32 @mq_unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %15, %25
%29 = phi i32 [ 0, %25 ], [ 1, %15 ]
br label %30
30: ; preds = %28, %6
%31 = phi i32 [ 1, %6 ], [ %29, %28 ]
ret i32 %31
}