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

/* Variables and functions */
int atoi(char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int mq_receive(int /*<<< orphan*/, char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
void msg_rcv(mqd_t mqdes, int i) {
  char buf[10000];
  errno = 0;
  if (mq_receive(mqdes, buf, sizeof(buf), NULL) == -1) {
    perror("mq_receive failed");
    fflush(stdout);
    sleep(1);
    exit(1);
  }
  if (i != atoi(buf)) {
    printf("Msg mismatch: expected: %d, got: %s\n", i, buf);
    fflush(stdout);
    sleep(1);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<msg_rcv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2730,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2e58(%rip),%rax
movq   $0x0,(%rax)
mov    -0x4(%rbp),%edi
lea    -0x2720(%rbp),%rsi
mov    $0x2710,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <mq_receive@plt>
cmp    $0xffffffff,%eax
jne    11de <msg_rcv+0x6e>
lea    0xe49(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x2724(%rbp)
lea    -0x2720(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x2724(%rbp),%eax
cmp    %ecx,%eax
je     123b <msg_rcv+0xcb>
mov    -0x8(%rbp),%esi
lea    -0x2720(%rbp),%rdx
lea    0xdfe(%rip),%rdi
call   1030 <printf@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
add    $0x2730,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msg_rcv>:
push   %rbx
sub    $0x2710,%rsp
mov    %esi,%ebx
mov    0x2e5f(%rip),%rax
movq   $0x0,(%rax)
mov    %rsp,%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
call   1050 <mq_receive@plt>
cmp    $0xffffffff,%eax
je     11b1 <msg_rcv+0x41>
mov    %rsp,%rdi
call   1070 <atoi@plt>
cmp    %ebx,%eax
jne    11bf <msg_rcv+0x4f>
add    $0x2710,%rsp
pop    %rbx
ret
lea    0xe48(%rip),%rdi
call   1060 <perror@plt>
jmp    11d0 <msg_rcv+0x60>
lea    0xe4c(%rip),%rdi
mov    %rsp,%rdx
mov    %ebx,%esi
call   1030 <printf@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@.str = [18 x i8] c"mq_receive failed\00"
@stdout = global i32 0
@.str.1 = [37 x i8] c"Msg mismatch: expected: %d, got: %s\0A\00"
define void @msg_rcv(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [10000 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
store i64 0, i64* @errno
%6 = load i32, i32* %3
%7 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%8 = call i32 @mq_receive(i32 %6, i8* %7, i32 10000, i32* null)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @stdout
%13 = call i32 @fflush(i32 %12)
%14 = call i32 @sleep(i32 1)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* %4
%18 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%19 = call i32 @atoi(i8* %18)
%20 = icmp ne i32 %17, %19
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = load i32, i32* %4
%23 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %22, i8* %23)
%25 = load i32, i32* @stdout
%26 = call i32 @fflush(i32 %25)
%27 = call i32 @sleep(i32 1)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %16
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [18 x i8] c"mq_receive failed\00"
@stdout = global i32 0
@.str.1 = [37 x i8] c"Msg mismatch: expected: %d, got: %s\0A\00"
define void @msg_rcv(i32 %0, i32 %1) {
%3 = alloca [10000 x i8]
%4 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
store i64 0, i64* @errno
%5 = call i32 @mq_receive(i32 %0, i8* %4, i32 10000, i32* null)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stdout
%10 = call i32 @fflush(i32 %9)
%11 = call i32 @sleep(i32 1)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i32 @atoi(i8* %4)
%15 = icmp eq i32 %14, %1
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %4)
%18 = load i32, i32* @stdout
%19 = call i32 @fflush(i32 %18)
%20 = call i32 @sleep(i32 1)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %13
ret void
}