#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 */
struct mq_attr {
  int member_1;
  int member_2;
  int /*<<< orphan*/ member_3;
  int /*<<< orphan*/ member_0;
};
typedef int mqd_t;

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mq_close(int);
int mq_open(char *, int, int, struct mq_attr *);
int mq_send(int, char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int main() {
  struct mq_attr attr = {0, 10, 256, 0};
  mqd_t queue = mq_open("/is141315q", O_WRONLY | O_CREAT, 0644, &attr);
  if (queue == -1) {
    perror("/is141315q");
    return 1;
  }
  char line[256];
  do {
    int len;
    printf("> ");
    fgets(line, 256, stdin);
    len = strlen(line);
    if (len > 0 && line[len - 1] == '\n') {
      line[len - 1] = '\0';
      len--;
    }
    if (!strcmp(line, "sleep")) {
      sleep(20);
    }
    if (mq_send(queue, line, len + 1, 7) == -1) {
      perror("/is141315q");
      mq_close(queue);
      return 1;
    }
  } while (strcmp(line, "quit"));
  mq_close(queue);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe57(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe54(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
mov    0x2e30(%rip),%rax
or     (%rax),%esi
lea    0xe3f(%rip),%rdi
mov    $0x1a4,%edx
lea    -0x18(%rbp),%rcx
call   1090 <mq_open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1204 <main+0x74>
lea    0xe1d(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    132a <main+0x19a>
jmp    1209 <main+0x79>
lea    0xe0b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    0x2dbd(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1070 <fgets@plt>
lea    -0x120(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
jle    128c <main+0xfc>
mov    -0x124(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    128c <main+0xfc>
mov    -0x124(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x120(%rbp,%rax,1)
mov    -0x124(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x124(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xd84(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12b3 <main+0x123>
mov    $0x14,%edi
call   10b0 <sleep@plt>
mov    -0x1c(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x124(%rbp),%edx
add    $0x1,%edx
mov    $0x7,%ecx
call   1060 <mq_send@plt>
cmp    $0xffffffff,%eax
jne    12f9 <main+0x169>
lea    0xd30(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1050 <mq_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    132a <main+0x19a>
jmp    12fe <main+0x16e>
lea    -0x120(%rbp),%rdi
lea    0xd18(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1209 <main+0x79>
mov    -0x1c(%rbp),%edi
call   1050 <mq_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
movups 0xe58(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    0x2e15(%rip),%rax
mov    0x2e3e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe4b(%rip),%rdi
mov    %rsp,%rcx
mov    $0x1a4,%edx
call   1090 <mq_open@plt>
cmp    $0xffffffff,%eax
je     12a5 <main+0x115>
mov    %eax,%r13d
lea    0xe36(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xe2d(%rip),%r15
lea    0xe2c(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <printf@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    123f <main+0xaf>
mov    %ebp,%eax
add    $0xffffffff,%eax
cmpb   $0xa,0x10(%rsp,%rax,1)
jne    123f <main+0xaf>
movb   $0x0,0x10(%rsp,%rax,1)
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1259 <main+0xc9>
mov    $0x14,%edi
call   10b0 <sleep@plt>
add    $0x1,%ebp
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    $0x7,%ecx
call   1060 <mq_send@plt>
cmp    $0xffffffff,%eax
je     12b8 <main+0x128>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1200 <main+0x70>
xor    %ebx,%ebx
mov    %r13d,%edi
call   1050 <mq_close@plt>
mov    %ebx,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd64(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%ebx
jmp    1291 <main+0x101>
lea    0xd51(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%ebx
jmp    1289 <main+0xf9>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32, i32, i32 }
@__const.main.attr = %struct.mq_attr { i32 0, i32 10, i32 256, i32 0 }
@.str = [11 x i8] c"/is141315q\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.2 = [6 x i8] c"sleep\00"
@.str.3 = [5 x i8] c"quit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.mq_attr
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast %struct.mq_attr* %2 to i8*
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = call i32 @mq_open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %9, i32 420, %struct.mq_attr* %2)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %65
15: ; preds = %0
br label %16
16: ; preds = %58, %15
%17 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %18, i32 256, i32 %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %40
25: ; preds = %16
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 10
br i1 %32, label %33, label %40
33: ; preds = %25
%34 = load i32, i32* %5
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %36
store i8 0, i8* %37
%38 = load i32, i32* %5
%39 = add nsw i32 %38, -1
store i32 %39, i32* %5
br label %40
40: ; preds = %33, %25, %16
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%43 = icmp ne i64 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %40
%45 = call i32 @sleep(i32 20)
br label %46
46: ; preds = %44, %40
%47 = load i32, i32* %3
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
%51 = call i32 @mq_send(i32 %47, i8* %48, i32 %50, i32 7)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %57
53: ; preds = %46
%54 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%55 = load i32, i32* %3
%56 = call i32 @mq_close(i32 %55)
store i32 1, i32* %1
br label %65
57: ; preds = %46
br label %58
58: ; preds = %57
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%61 = icmp ne i64 %60, 0
br i1 %61, label %16, label %62
62: ; preds = %58
%63 = load i32, i32* %3
%64 = call i32 @mq_close(i32 %63)
store i32 0, i32* %1
br label %65
65: ; preds = %62, %53, %13
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32, i32, i32 }
@__const.main.attr = %struct.mq_attr { i32 0, i32 10, i32 256, i32 0 }
@.str = [11 x i8] c"/is141315q\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.2 = [6 x i8] c"sleep\00"
@.str.3 = [5 x i8] c"quit\00"
define i32 @main() {
%1 = alloca %struct.mq_attr
%2 = alloca [256 x i8]
%3 = bitcast %struct.mq_attr* %1 to i8*
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = call i32 @mq_open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6, i32 420, %struct.mq_attr* %1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %44
11: ; preds = %0
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
br label %13
13: ; preds = %38, %11
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %12, i32 256, i32 %15)
%17 = call i32 @strlen(i8* %12)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %13
%20 = add nsw i32 %17, -1
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 10
br i1 %24, label %25, label %26
25: ; preds = %19
store i8 0, i8* %22
br label %26
26: ; preds = %25, %19, %13
%27 = phi i32 [ %20, %25 ], [ %17, %19 ], [ %17, %13 ]
%28 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @sleep(i32 20)
br label %32
32: ; preds = %30, %26
%33 = add nsw i32 %27, 1
%34 = call i32 @mq_send(i32 %7, i8* %12, i32 %33, i32 7)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %41
38: ; preds = %32
%39 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %13
41: ; preds = %38, %36
%42 = phi i32 [ 1, %36 ], [ 0, %38 ]
%43 = call i32 @mq_close(i32 %7)
br label %44
44: ; preds = %41, %9
%45 = phi i32 [ 1, %9 ], [ %42, %41 ]
ret i32 %45
}