#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;

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int mq_send(int /*<<< orphan*/, char *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stdout;
scalar_t__ strlen(char *);
void msg_snd(mqd_t mqdes, int i) {
  char buf[16];
  sprintf(buf, "%d", i);
  errno = 0;
  if (mq_send(mqdes, buf, strlen(buf) + 1, 0) == -1) {
    perror("mq_send failed");
    fflush(stdout);
    sleep(1);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<msg_snd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe74(%rip),%rsi
call   1070 <sprintf@plt>
mov    0x2e48(%rip),%rax
movq   $0x0,(%rax)
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
xor    %ecx,%ecx
call   1040 <mq_send@plt>
cmp    $0xffffffff,%eax
jne    1202 <msg_snd+0x92>
lea    0xe28(%rip),%rdi
call   1060 <perror@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msg_snd>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%edx
mov    %edi,%ebp
lea    0xe7f(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
mov    0x2e4d(%rip),%rax
movq   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1040 <mq_send@plt>
cmp    $0xffffffff,%eax
je     11be <msg_snd+0x4e>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe3e(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@errno = global i64 0
@.str.1 = [15 x i8] c"mq_send failed\00"
@stdout = global i32 0
define void @msg_snd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [16 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* %4
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %7)
store i64 0, i64* @errno
%9 = load i32, i32* %3
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%12 = call i64 @strlen(i8* %11)
%13 = add nsw i64 %12, 1
%14 = call i32 @mq_send(i32 %9, i8* %10, i64 %13, i32 0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%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 = %2
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@errno = global i64 0
@.str.1 = [15 x i8] c"mq_send failed\00"
@stdout = global i32 0
define void @msg_snd(i32 %0, i32 %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
store i64 0, i64* @errno
%6 = call i64 @strlen(i8* %4)
%7 = add nsw i64 %6, 1
%8 = call i32 @mq_send(i32 %0, i8* %4, i64 %7, i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, 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
ret void
}