#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 */

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int msgsnd(int, void const *, size_t, int);
int sca_msgsnd(int MessageQueueID, const void *MessagePointer,
               size_t MessageSize, int MessageFlag) {
  int value;
  value = -1;
  while (value == -1) {
    value = msgsnd(MessageQueueID, MessagePointer, MessageSize, MessageFlag);
    if (value == -1 && errno != EINTR)
      return value;
  }
  return value;
}


x86 assembly (clang, -O0):
<sca_msgsnd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1181 <sca_msgsnd+0x71>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <msgsnd@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    117c <sca_msgsnd+0x6c>
mov    0x2e82(%rip),%rax
mov    (%rax),%rax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
je     117c <sca_msgsnd+0x6c>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1187 <sca_msgsnd+0x77>
jmp    112d <sca_msgsnd+0x1d>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sca_msgsnd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x2eb3(%rip),%r12
mov    0x2ea4(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1030 <msgsnd@plt>
cmp    $0xffffffff,%eax
jne    115f <sca_msgsnd+0x4f>
mov    (%r12),%rcx
cmp    0x0(%r13),%rcx
je     1140 <sca_msgsnd+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i32 @sca_msgsnd(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
store i32 -1, i32* %10
br label %11
11: ; preds = %28, %4
%12 = load i32, i32* %10
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = load i32, i32* %6
%16 = load i8*, i8** %7
%17 = load i64, i64* %8
%18 = load i32, i32* %9
%19 = call i32 @msgsnd(i32 %15, i8* %16, i64 %17, i32 %18)
store i32 %19, i32* %10
%20 = load i32, i32* %10
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %28
22: ; preds = %14
%23 = load i64, i64* @errno
%24 = load i64, i64* @EINTR
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = load i32, i32* %10
store i32 %27, i32* %5
br label %31
28: ; preds = %22, %14
br label %11
29: ; preds = %11
%30 = load i32, i32* %10
store i32 %30, i32* %5
br label %31
31: ; preds = %29, %26
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @sca_msgsnd(i32 %0, i8* %1, i64 %2, i32 %3) {
br label %5
5: ; preds = %8, %4
%6 = tail call i32 @msgsnd(i32 %0, i8* %1, i64 %2, i32 %3)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
br i1 %11, label %5, label %12
12: ; preds = %5, %8
ret i32 %6
}