#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 sendmsg(int, struct msghdr *, int /*<<< orphan*/);
int wait_for_fd(int, int, int);
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, count = 0;
  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) {
      count++;
      if (count < 100)
        goto again;
    } else if (errno == EAGAIN) {
      int rc2;
      rc2 = wait_for_fd(1, s, 5);
      if (rc2 > 0) {
        count++;
        if (count < 100)
          goto again;
      }
      errno = EAGAIN;
    }
  }
  return rc;
}


x86 assembly (clang, -O0):
<babel_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%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)
movl   $0x0,-0x70(%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   1030 <sendmsg@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jge    126a <babel_send+0x13a>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rax
mov    0x2e08(%rip),%rcx
cmp    (%rcx),%rax
jne    11f6 <babel_send+0xc6>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
cmpl   $0x64,-0x70(%rbp)
jge    11f1 <babel_send+0xc1>
jmp    11a4 <babel_send+0x74>
jmp    1265 <babel_send+0x135>
mov    0x2de3(%rip),%rax
mov    (%rax),%rax
mov    0x2dc1(%rip),%rcx
cmp    (%rcx),%rax
jne    1260 <babel_send+0x130>
mov    -0x4(%rbp),%esi
mov    $0x1,%edi
mov    $0x5,%edx
call   1040 <wait_for_fd@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jle    124c <babel_send+0x11c>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
cmpl   $0x64,-0x70(%rbp)
jge    1247 <babel_send+0x117>
jmp    11a4 <babel_send+0x74>
jmp    124c <babel_send+0x11c>
mov    0x2d75(%rip),%rax
mov    (%rax),%rcx
mov    0x2d83(%rip),%rax
mov    %rcx,(%rax)
jmp    1265 <babel_send+0x135>
jmp    126a <babel_send+0x13a>
mov    -0x6c(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<babel_send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,%rbp
mov    %edi,%r15d
mov    0x80(%rsp),%r12d
mov    %rsi,0x28(%rsp)
mov    %edx,0x20(%rsp)
mov    %rcx,0x38(%rsp)
mov    %r8d,0x30(%rsp)
lea    0x8(%rsp),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    %rbp,0x18(%rsp)
mov    %r12d,0x8(%rsp)
lea    0x20(%rsp),%rax
mov    %rax,0x10(%rsp)
movl   $0x2,0xc(%rsp)
mov    %r15d,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sendmsg@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11b5 <babel_send+0x85>
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e24(%rip),%r12
mov    0x2e15(%rip),%r13
lea    0x8(%rsp),%r14
jmp    11eb <babel_send+0xbb>
nopw   0x0(%rax,%rax,1)
cmp    $0x62,%ebx
ja     11a4 <babel_send+0x74>
add    $0x1,%ebx
mov    %r15d,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sendmsg@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11a4 <babel_send+0x74>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     11d0 <babel_send+0xa0>
mov    0x2dcc(%rip),%rcx
cmp    (%rcx),%rax
jne    11a4 <babel_send+0x74>
mov    $0x1,%edi
mov    %r15d,%esi
mov    $0x5,%edx
call   1040 <wait_for_fd@plt>
test   %eax,%eax
jle    121c <babel_send+0xec>
cmp    $0x63,%ebx
jb     11d5 <babel_send+0xa5>
mov    0x2da5(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r12)
jmp    11a4 <babel_send+0x74>

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
%18 = alloca i32
%19 = 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
store i32 0, i32* %18
%20 = load i8*, i8** %9
%21 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %15, i64 0, i64 0
%22 = getelementptr inbounds %struct.iovec, %struct.iovec* %21, i32 0, i32 1
store i8* %20, i8** %22
%23 = load i32, i32* %10
%24 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %15, i64 0, i64 0
%25 = getelementptr inbounds %struct.iovec, %struct.iovec* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = load i8*, i8** %11
%27 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %15, i64 0, i64 1
%28 = getelementptr inbounds %struct.iovec, %struct.iovec* %27, i32 0, i32 1
store i8* %26, i8** %28
%29 = load i32, i32* %12
%30 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %15, i64 0, i64 1
%31 = getelementptr inbounds %struct.iovec, %struct.iovec* %30, i32 0, i32 0
store i32 %29, i32* %31
%32 = call i32 @memset(%struct.msghdr* %16, i32 0, i32 24)
%33 = load %struct.sockaddr*, %struct.sockaddr** %13
%34 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %16, i32 0, i32 3
store %struct.sockaddr* %33, %struct.sockaddr** %34
%35 = load i32, i32* %14
%36 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %16, i32 0, i32 0
store i32 %35, i32* %36
%37 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %15, i64 0, i64 0
%38 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %16, i32 0, i32 2
store %struct.iovec* %37, %struct.iovec** %38
%39 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %16, i32 0, i32 1
store i32 2, i32* %39
br label %40
40: ; preds = %70, %54, %7
%41 = load i32, i32* %8
%42 = call i32 @sendmsg(i32 %41, %struct.msghdr* %16, i32 0)
store i32 %42, i32* %17
%43 = load i32, i32* %17
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %76
45: ; preds = %40
%46 = load i64, i64* @errno
%47 = load i64, i64* @EINTR
%48 = icmp eq i64 %46, %47
br i1 %48, label %49, label %56
49: ; preds = %45
%50 = load i32, i32* %18
%51 = add nsw i32 %50, 1
store i32 %51, i32* %18
%52 = load i32, i32* %18
%53 = icmp slt i32 %52, 100
br i1 %53, label %54, label %55
54: ; preds = %49
br label %40
55: ; preds = %49
br label %75
56: ; preds = %45
%57 = load i64, i64* @errno
%58 = load i64, i64* @EAGAIN
%59 = icmp eq i64 %57, %58
br i1 %59, label %60, label %74
60: ; preds = %56
%61 = load i32, i32* %8
%62 = call i32 @wait_for_fd(i32 1, i32 %61, i32 5)
store i32 %62, i32* %19
%63 = load i32, i32* %19
%64 = icmp sgt i32 %63, 0
br i1 %64, label %65, label %72
65: ; preds = %60
%66 = load i32, i32* %18
%67 = add nsw i32 %66, 1
store i32 %67, i32* %18
%68 = load i32, i32* %18
%69 = icmp slt i32 %68, 100
br i1 %69, label %70, label %71
70: ; preds = %65
br label %40
71: ; preds = %65
br label %72
72: ; preds = %71, %60
%73 = load i64, i64* @EAGAIN
store i64 %73, i64* @errno
br label %74
74: ; preds = %72, %56
br label %75
75: ; preds = %74, %55
br label %76
76: ; preds = %75, %40
%77 = load i32, i32* %17
ret i32 %77
}

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
%22 = call i32 @sendmsg(i32 %0, %struct.msghdr* %9, i32 0)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %46
24: ; preds = %7, %32
%25 = phi i32 [ %34, %32 ], [ %22, %7 ]
%26 = phi i32 [ %33, %32 ], [ 0, %7 ]
%27 = load i64, i64* @errno
%28 = load i64, i64* @EINTR
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %36
30: ; preds = %24
%31 = icmp ult i32 %26, 99
br i1 %31, label %32, label %46
32: ; preds = %30, %39
%33 = add nuw nsw i32 %26, 1
%34 = call i32 @sendmsg(i32 %0, %struct.msghdr* %9, i32 0)
%35 = icmp slt i32 %34, 0
br i1 %35, label %24, label %46
36: ; preds = %24
%37 = load i64, i64* @EAGAIN
%38 = icmp eq i64 %27, %37
br i1 %38, label %39, label %46
39: ; preds = %36
%40 = call i32 @wait_for_fd(i32 1, i32 %0, i32 5)
%41 = icmp sgt i32 %40, 0
%42 = icmp ult i32 %26, 99
%43 = select i1 %41, i1 %42, i1 false
br i1 %43, label %32, label %44
44: ; preds = %39
%45 = load i64, i64* @EAGAIN
store i64 %45, i64* @errno
br label %46
46: ; preds = %32, %36, %30, %7, %44
%47 = phi i32 [ %25, %44 ], [ %22, %7 ], [ %34, %32 ], [ %25, %36 ], [ %25, %30 ]
ret i32 %47
}