#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct msghdr {
  int msg_flags;
  TYPE_1__ *msg_iov;
};
struct TYPE_2__ {
  int iov_len;
};

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ EMSGSIZE;
scalar_t__ ENOMEM;
scalar_t__ errno;
int /*<<< orphan*/ error(int, scalar_t__, char *, ...);
int sendmsg(int, struct msghdr *, int);
bool __send_one(int fd, struct msghdr *msg, int flags) {
  int ret;
  ret = sendmsg(fd, msg, flags);
  if (ret == -1 && (errno == EMSGSIZE || errno == ENOMEM || errno == EINVAL))
    return false;
  if (ret == -1)
    error(1, errno, "sendmsg");
  if (ret != msg->msg_iov->iov_len)
    error(1, 0, "sendto: %d != %llu", ret,
          (unsigned long long)msg->msg_iov->iov_len);
  if (msg->msg_flags)
    error(1, 0, "sendmsg: return flags 0x%x\n", msg->msg_flags);
  return true;
}


x86 assembly (clang, -O0):
<__send_one>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <sendmsg@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11a8 <__send_one+0x88>
mov    0x2e7b(%rip),%rax
mov    (%rax),%rax
mov    0x2e89(%rip),%rcx
cmp    (%rcx),%rax
je     119c <__send_one+0x7c>
mov    0x2e61(%rip),%rax
mov    (%rax),%rax
mov    0x2e5f(%rip),%rcx
cmp    (%rcx),%rax
je     119c <__send_one+0x7c>
mov    0x2e47(%rip),%rax
mov    (%rax),%rax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
jne    11a8 <__send_one+0x88>
movl   $0x0,-0x4(%rbp)
jmp    1238 <__send_one+0x118>
cmpl   $0xffffffff,-0x18(%rbp)
jne    11cf <__send_one+0xaf>
mov    0x2e17(%rip),%rax
mov    (%rax),%rsi
mov    $0x1,%edi
lea    0xe38(%rip),%rdx
mov    $0x0,%al
call   1040 <error@plt>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
cmp    (%rcx),%eax
je     1207 <__send_one+0xe7>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq (%rax),%r8
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xe08(%rip),%rdx
mov    $0x0,%al
call   1040 <error@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
je     1231 <__send_one+0x111>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xdf1(%rip),%rdx
mov    $0x0,%al
call   1040 <error@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__send_one>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
call   1030 <sendmsg@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1177 <__send_one+0x57>
mov    0x2e96(%rip),%rax
mov    (%rax),%rsi
mov    0x2ea4(%rip),%rax
xor    %r14d,%r14d
cmp    (%rax),%rsi
je     11c3 <__send_one+0xa3>
mov    0x2e85(%rip),%rax
cmp    (%rax),%rsi
je     11c3 <__send_one+0xa3>
mov    0x2e69(%rip),%rax
cmp    (%rax),%rsi
je     11c3 <__send_one+0xa3>
lea    0xe95(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <error@plt>
mov    0x8(%rbx),%rax
movslq (%rax),%r8
cmp    %r8d,%ebp
je     119a <__send_one+0x7a>
lea    0xe7e(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <error@plt>
mov    (%rbx),%ecx
test   %ecx,%ecx
je     11bd <__send_one+0x9d>
lea    0xe74(%rip),%rdx
mov    $0x1,%r14d
mov    $0x1,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <error@plt>
jmp    11c3 <__send_one+0xa3>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.msghdr = type { i32, %struct.TYPE_2__* }
%struct.TYPE_2__ = type { i32 }
@errno = global i64 0
@EMSGSIZE = global i64 0
@ENOMEM = global i64 0
@EINVAL = global i64 0
@.str = [8 x i8] c"sendmsg\00"
@.str.1 = [19 x i8] c"sendto: %d != %llu\00"
@.str.2 = [28 x i8] c"sendmsg: return flags 0x%x\0A\00"
define i32 @__send_one(i32 %0, %struct.msghdr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.msghdr*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store %struct.msghdr* %1, %struct.msghdr** %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = load %struct.msghdr*, %struct.msghdr** %6
%11 = load i32, i32* %7
%12 = call i32 @sendmsg(i32 %9, %struct.msghdr* %10, i32 %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %28
15: ; preds = %3
%16 = load i64, i64* @errno
%17 = load i64, i64* @EMSGSIZE
%18 = icmp eq i64 %16, %17
br i1 %18, label %27, label %19
19: ; preds = %15
%20 = load i64, i64* @errno
%21 = load i64, i64* @ENOMEM
%22 = icmp eq i64 %20, %21
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = load i64, i64* @errno
%25 = load i64, i64* @EINVAL
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23, %19, %15
store i32 0, i32* %4
br label %62
28: ; preds = %23, %3
%29 = load i32, i32* %8
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i64, i64* @errno
%33 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %31, %28
%35 = load i32, i32* %8
%36 = load %struct.msghdr*, %struct.msghdr** %6
%37 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %36, i32 0, i32 1
%38 = load %struct.TYPE_2__*, %struct.TYPE_2__** %37
%39 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = icmp ne i32 %35, %40
br i1 %41, label %42, label %51
42: ; preds = %34
%43 = load i32, i32* %8
%44 = load %struct.msghdr*, %struct.msghdr** %6
%45 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %44, i32 0, i32 1
%46 = load %struct.TYPE_2__*, %struct.TYPE_2__** %45
%47 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = sext i32 %48 to i64
%50 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %43, i64 %49)
br label %51
51: ; preds = %42, %34
%52 = load %struct.msghdr*, %struct.msghdr** %6
%53 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %51
%57 = load %struct.msghdr*, %struct.msghdr** %6
%58 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %57, i32 0, i32 0
%59 = load i32, i32* %58
%60 = call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %56, %51
store i32 1, i32* %4
br label %62
62: ; preds = %61, %27
%63 = load i32, i32* %4
ret i32 %63
}

LLVM IR (-O2):
%struct.msghdr = type { i32, %struct.TYPE_2__* }
%struct.TYPE_2__ = type { i32 }
@errno = global i64 0
@EMSGSIZE = global i64 0
@ENOMEM = global i64 0
@EINVAL = global i64 0
@.str = [8 x i8] c"sendmsg\00"
@.str.1 = [19 x i8] c"sendto: %d != %llu\00"
@.str.2 = [28 x i8] c"sendmsg: return flags 0x%x\0A\00"
define i32 @__send_one(i32 %0, %struct.msghdr* %1, i32 %2) {
%4 = tail call i32 @sendmsg(i32 %0, %struct.msghdr* %1, i32 %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = load i64, i64* @errno
%8 = load i64, i64* @EMSGSIZE
%9 = icmp eq i64 %7, %8
%10 = load i64, i64* @ENOMEM
%11 = icmp eq i64 %7, %10
%12 = select i1 %9, i1 true, i1 %11
%13 = load i64, i64* @EINVAL
%14 = icmp eq i64 %7, %13
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %33, label %16
16: ; preds = %6
%17 = tail call i32 (i32, i64, i8*, ...) @error(i32 1, i64 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %3, %16
%19 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %1, i64 0, i32 1
%20 = load %struct.TYPE_2__*, %struct.TYPE_2__** %19
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i64 0, i32 0
%22 = load i32, i32* %21
%23 = icmp eq i32 %4, %22
br i1 %23, label %27, label %24
24: ; preds = %18
%25 = sext i32 %22 to i64
%26 = tail call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %4, i64 %25)
br label %27
27: ; preds = %24, %18
%28 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %1, i64 0, i32 0
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %27
%32 = tail call i32 (i32, i64, i8*, ...) @error(i32 1, i64 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %33
33: ; preds = %27, %31, %6
%34 = phi i32 [ 0, %6 ], [ 1, %31 ], [ 1, %27 ]
ret i32 %34
}