#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_in {
  int dummy;
};
struct msghdr {
  int msg_iovlen;
  int msg_namelen;
  struct sockaddr_in *msg_name;
  struct iovec *msg_iov;
};
struct iovec {
  size_t iov_len;
  void *iov_base;
};
typedef int ssize_t;
typedef int socklen_t;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ memset(struct msghdr *, int /*<<< orphan*/, int);
int sendmsg(int, struct msghdr *, int /*<<< orphan*/);
ssize_t sendmbuff(int sd, void *bufdata, size_t lendata, void *bufhdr,
                  size_t lenhdr, struct sockaddr_in *dst_addr) {
  ssize_t ret = 0;
  socklen_t alen = sizeof(struct sockaddr_in);
  struct msghdr msg;
  struct iovec io[2];
  memset(&msg, 0, sizeof(struct msghdr));
  if (lenhdr > 0 && bufhdr != NULL) {
    io[0].iov_base = bufhdr;
    io[0].iov_len = lenhdr;
    io[1].iov_base = bufdata;
    io[1].iov_len = lendata;
    msg.msg_iov = io;
    msg.msg_iovlen = 2;
  } else {
    io[0].iov_base = bufdata;
    io[0].iov_len = lendata;
    msg.msg_iov = io;
    msg.msg_iovlen = 1;
  }
  msg.msg_name = dst_addr;
  msg.msg_namelen = alen;
  while (1) {
    ret = sendmsg(sd, &msg, 0);
    if (ret > 0 || (ret == -1 && errno != EINTR))
      break;
  }
  return ret;
}


x86 assembly (clang, -O0):
<sendmbuff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x4,-0x38(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
cmpq   $0x0,-0x28(%rbp)
jbe    11a7 <sendmbuff+0x87>
cmpq   $0x0,-0x20(%rbp)
je     11a7 <sendmbuff+0x87>
mov    -0x20(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x2,-0x50(%rbp)
jmp    11c6 <sendmbuff+0xa6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x1,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
xor    %edx,%edx
call   1030 <sendmsg@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jg     1213 <sendmbuff+0xf3>
cmpl   $0xffffffff,-0x34(%rbp)
jne    1218 <sendmbuff+0xf8>
mov    0x2de0(%rip),%rax
mov    (%rax),%rax
mov    0x2dce(%rip),%rcx
cmp    (%rcx),%rax
je     1218 <sendmbuff+0xf8>
jmp    121d <sendmbuff+0xfd>
jmp    11d4 <sendmbuff+0xb4>
mov    -0x34(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendmbuff>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9,%r14
mov    %r8,%r12
mov    %rcx,%r15
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    $0x1,%eax
test   %r15,%r15
je     1170 <sendmbuff+0x50>
test   %r12,%r12
je     1170 <sendmbuff+0x50>
mov    %rbp,0x38(%rsp)
mov    %r13,0x30(%rsp)
mov    $0x2,%eax
jmp    1176 <sendmbuff+0x56>
mov    %rbp,%r15
mov    %r13,%r12
mov    %r15,0x28(%rsp)
mov    %r12,0x20(%rsp)
lea    0x20(%rsp),%rcx
mov    %rcx,0x18(%rsp)
mov    %eax,0x8(%rsp)
mov    %r14,0x10(%rsp)
movl   $0x4,0xc(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sendmsg@plt>
test   %eax,%eax
jle    11bc <sendmbuff+0x9c>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e1d(%rip),%r15
mov    0x2e0e(%rip),%rbp
lea    0x8(%rsp),%r14
jmp    11f0 <sendmbuff+0xd0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sendmsg@plt>
test   %eax,%eax
jg     11ad <sendmbuff+0x8d>
cmp    $0xffffffff,%eax
jne    11e0 <sendmbuff+0xc0>
mov    (%r15),%rax
cmp    0x0(%rbp),%rax
je     11e0 <sendmbuff+0xc0>
mov    $0xffffffff,%eax
jmp    11ad <sendmbuff+0x8d>

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

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