#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 sockaddr {
  int dummy;
};
struct msghdr {
  int msg_namelen;
  int msg_iovlen;
  struct iovec *msg_iov;
  struct sockaddr *msg_name;
};
struct iovec {
  int iov_len;
  void *iov_base;
};
typedef int /*<<< orphan*/ msg;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ memset(struct msghdr *, int /*<<< orphan*/, int);
int /*<<< orphan*/ nap(int);
int sendmsg(int, struct msghdr *, int /*<<< orphan*/);
int babel_send(int s, const void *buf1, int buflen1, const void *buf2,
               int buflen2, const struct sockaddr *sin, int slen) {
  struct iovec iovec[2];
  struct msghdr msg;
  int rc;
  iovec[0].iov_base = (void *)buf1;
  iovec[0].iov_len = buflen1;
  iovec[1].iov_base = (void *)buf2;
  iovec[1].iov_len = buflen2;
  memset(&msg, 0, sizeof(msg));
  msg.msg_name = (struct sockaddr *)sin;
  msg.msg_namelen = slen;
  msg.msg_iov = iovec;
  msg.msg_iovlen = 2;
again:
  rc = sendmsg(s, &msg, 0);
  if (rc < 0) {
    if (errno == EINTR)
      goto again;
    else if (errno == EAGAIN) {
      nap(10);
      rc = sendmsg(s, &msg, 0);
    }
  }
  return rc;
}


x86 assembly (clang, -O0):
<babel_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x40(%rbp)
lea    -0x68(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x10(%rbp),%eax
mov    %eax,-0x68(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
movl   $0x2,-0x64(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x68(%rbp),%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jge    1213 <babel_send+0xe3>
mov    0x2e24(%rip),%rax
mov    (%rax),%rax
mov    0x2e12(%rip),%rcx
cmp    (%rcx),%rax
jne    11d4 <babel_send+0xa4>
jmp    119a <babel_send+0x6a>
mov    0x2e05(%rip),%rax
mov    (%rax),%rax
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%rax
jne    1209 <babel_send+0xd9>
mov    $0xa,%edi
call   1030 <nap@plt>
mov    -0x4(%rbp),%edi
lea    -0x68(%rbp),%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
mov    %eax,-0x6c(%rbp)
jmp    120e <babel_send+0xde>
jmp    1213 <babel_send+0xe3>
mov    -0x6c(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<babel_send>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %r9,%r15
mov    %edi,%ebx
mov    0x70(%rsp),%ebp
mov    %rsi,0x28(%rsp)
mov    %edx,0x20(%rsp)
mov    %rcx,0x38(%rsp)
mov    %r8d,0x30(%rsp)
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    %r15,0x18(%rsp)
mov    %ebp,0x8(%rsp)
lea    0x20(%rsp),%rax
mov    %rax,0x10(%rsp)
movl   $0x2,0xc(%rsp)
mov    0x2e52(%rip),%r15
mov    0x2e43(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
test   %eax,%eax
jns    11dd <babel_send+0xad>
mov    (%r15),%rcx
cmp    (%r12),%rcx
je     11a0 <babel_send+0x70>
mov    0x2e08(%rip),%rdx
cmp    (%rdx),%rcx
jne    11dd <babel_send+0xad>
mov    $0xa,%edi
call   1030 <nap@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1040 <sendmsg@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.iovec = type { i32, i8* }
%struct.msghdr = type { i32, i32, %struct.iovec*, %struct.sockaddr* }
@errno = global i64 0
@EINTR = global i64 0
@EAGAIN = global i64 0
define i32 @babel_send(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4, %struct.sockaddr* %5, i32 %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca %struct.sockaddr*
%14 = alloca i32
%15 = alloca [2 x %struct.iovec]
%16 = alloca %struct.msghdr
%17 = alloca i32
store i32 %0, i32* %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store %struct.sockaddr* %5, %struct.sockaddr** %13
store i32 %6, i32* %14
%18 = load i8*, i8** %9
%19 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %15, i64 0, i64 0
%20 = getelementptr inbounds %struct.iovec, %struct.iovec* %19, i32 0, i32 1
store i8* %18, i8** %20
%21 = load i32, i32* %10
%22 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %15, i64 0, i64 0
%23 = getelementptr inbounds %struct.iovec, %struct.iovec* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load i8*, i8** %11
%25 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %15, i64 0, i64 1
%26 = getelementptr inbounds %struct.iovec, %struct.iovec* %25, i32 0, i32 1
store i8* %24, i8** %26
%27 = load i32, i32* %12
%28 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %15, i64 0, i64 1
%29 = getelementptr inbounds %struct.iovec, %struct.iovec* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = call i32 @memset(%struct.msghdr* %16, i32 0, i32 24)
%31 = load %struct.sockaddr*, %struct.sockaddr** %13
%32 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %16, i32 0, i32 3
store %struct.sockaddr* %31, %struct.sockaddr** %32
%33 = load i32, i32* %14
%34 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %16, i32 0, i32 0
store i32 %33, i32* %34
%35 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %15, i64 0, i64 0
%36 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %16, i32 0, i32 2
store %struct.iovec* %35, %struct.iovec** %36
%37 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %16, i32 0, i32 1
store i32 2, i32* %37
br label %38
38: ; preds = %47, %7
%39 = load i32, i32* %8
%40 = call i32 @sendmsg(i32 %39, %struct.msghdr* %16, i32 0)
store i32 %40, i32* %17
%41 = load i32, i32* %17
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %58
43: ; preds = %38
%44 = load i64, i64* @errno
%45 = load i64, i64* @EINTR
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %43
br label %38
48: ; preds = %43
%49 = load i64, i64* @errno
%50 = load i64, i64* @EAGAIN
%51 = icmp eq i64 %49, %50
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = call i32 @nap(i32 10)
%54 = load i32, i32* %8
%55 = call i32 @sendmsg(i32 %54, %struct.msghdr* %16, i32 0)
store i32 %55, i32* %17
br label %56
56: ; preds = %52, %48
br label %57
57: ; preds = %56
br label %58
58: ; preds = %57, %38
%59 = load i32, i32* %17
ret i32 %59
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.iovec = type { i32, i8* }
%struct.msghdr = type { i32, i32, %struct.iovec*, %struct.sockaddr* }
@errno = global i64 0
@EINTR = global i64 0
@EAGAIN = global i64 0
define i32 @babel_send(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4, %struct.sockaddr* %5, i32 %6) {
%8 = alloca [2 x %struct.iovec]
%9 = alloca %struct.msghdr
%10 = bitcast [2 x %struct.iovec]* %8 to i8*
%11 = bitcast %struct.msghdr* %9 to i8*
%12 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %8, i64 0, i64 0
%13 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %8, i64 0, i64 0, i32 1
store i8* %1, i8** %13
%14 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %8, i64 0, i64 0, i32 0
store i32 %2, i32* %14
%15 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %8, i64 0, i64 1, i32 1
store i8* %3, i8** %15
%16 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %8, i64 0, i64 1, i32 0
store i32 %4, i32* %16
%17 = call i32 @memset(%struct.msghdr* %9, i32 0, i32 24)
%18 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i64 0, i32 3
store %struct.sockaddr* %5, %struct.sockaddr** %18
%19 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i64 0, i32 0
store i32 %6, i32* %19
%20 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i64 0, i32 2
store %struct.iovec* %12, %struct.iovec** %20
%21 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i64 0, i32 1
store i32 2, i32* %21
br label %22
22: ; preds = %25, %7
%23 = call i32 @sendmsg(i32 %0, %struct.msghdr* %9, i32 0)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i64, i64* @errno
%27 = load i64, i64* @EINTR
%28 = icmp eq i64 %26, %27
br i1 %28, label %22, label %29
29: ; preds = %25
%30 = load i64, i64* @EAGAIN
%31 = icmp eq i64 %26, %30
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = call i32 @nap(i32 10)
%34 = call i32 @sendmsg(i32 %0, %struct.msghdr* %9, i32 0)
br label %35
35: ; preds = %22, %32, %29
%36 = phi i32 [ %34, %32 ], [ %23, %29 ], [ %23, %22 ]
ret i32 %36
}