#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 /*<<< orphan*/ printf(char *, ...);
int send(int, void *, unsigned int, int /*<<< orphan*/);
char *strerror(scalar_t__);
int nlmsg_do_send(int nlfd, void *req, unsigned int size) {
  int r;
  if (size > (1024 * 32) || req == NULL)
    return -1;
  while (1) {
    errno = 0;
    r = send(nlfd, req, size, 0);
    if (r == -1 && errno == EINTR)
      continue;
    else if ((unsigned int)r == size)
      return 0;
    else if (r <= 0) {
      printf("rtnl send: %s\n", strerror(errno));
      return -1;
    } else {
      printf("rtnl send returned unexpected size\n");
      return -1;
    }
  }
}


x86 assembly (clang, -O0):
<nlmsg_do_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x8000,-0x14(%rbp)
ja     115a <nlmsg_do_send+0x2a>
cmpq   $0x0,-0x10(%rbp)
jne    1166 <nlmsg_do_send+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <nlmsg_do_send+0xe9>
jmp    116b <nlmsg_do_send+0x3b>
mov    0x2e6e(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11b6 <nlmsg_do_send+0x86>
mov    0x2e42(%rip),%rax
mov    (%rax),%rax
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%rax
jne    11b6 <nlmsg_do_send+0x86>
jmp    116b <nlmsg_do_send+0x3b>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11ce <nlmsg_do_send+0x9e>
movl   $0x0,-0x4(%rbp)
jmp    1219 <nlmsg_do_send+0xe9>
cmpl   $0x0,-0x18(%rbp)
jg     1204 <nlmsg_do_send+0xd4>
mov    0x2e01(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <nlmsg_do_send+0xe9>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nlmsg_do_send>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%eax
test   %rsi,%rsi
je     11e5 <nlmsg_do_send+0xa5>
mov    %edx,%ebp
cmp    $0x8000,%edx
ja     11e5 <nlmsg_do_send+0xa5>
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x2e6f(%rip),%r15
mov    0x2e60(%rip),%r12
nopl   0x0(%rax,%rax,1)
movq   $0x0,(%r15)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
jne    11ad <nlmsg_do_send+0x6d>
mov    (%r15),%rdi
cmp    (%r12),%rdi
je     1180 <nlmsg_do_send+0x40>
cmp    $0xffffffff,%ebp
jne    11ca <nlmsg_do_send+0x8a>
xor    %eax,%eax
jmp    11e5 <nlmsg_do_send+0xa5>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ebp,%ecx
je     11e5 <nlmsg_do_send+0xa5>
test   %ecx,%ecx
jle    11c7 <nlmsg_do_send+0x87>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
jmp    11e0 <nlmsg_do_send+0xa0>
mov    (%r15),%rdi
call   1060 <strerror@plt>
lea    0xe2a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [15 x i8] c"rtnl send: %s\0A\00"
@.str.1 = [36 x i8] c"rtnl send returned unexpected size\0A\00"
define i32 @nlmsg_do_send(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = icmp ugt i32 %9, 32768
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11, %3
store i32 -1, i32* %4
br label %42
15: ; preds = %11
br label %16
16: ; preds = %15, %27
store i64 0, i64* @errno
%17 = load i32, i32* %5
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = call i32 @send(i32 %17, i8* %18, i32 %19, i32 0)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = load i64, i64* @errno
%25 = load i64, i64* @EINTR
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23
br label %16
28: ; preds = %23, %16
%29 = load i32, i32* %8
%30 = load i32, i32* %7
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 0, i32* %4
br label %42
33: ; preds = %28
%34 = load i32, i32* %8
%35 = icmp sle i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i64, i64* @errno
%38 = call i8* @strerror(i64 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %38)
store i32 -1, i32* %4
br label %42
40: ; preds = %33
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %42
42: ; preds = %40, %36, %32, %14
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [15 x i8] c"rtnl send: %s\0A\00"
@str = [35 x i8] c"rtnl send returned unexpected size\00"
define i32 @nlmsg_do_send(i32 %0, i8* %1, i32 %2) {
%4 = icmp ugt i32 %2, 32768
%5 = icmp eq i8* %1, null
%6 = or i1 %5, %4
br i1 %6, label %28, label %7
7: ; preds = %3, %10
store i64 0, i64* @errno
%8 = tail call i32 @send(i32 %0, i8* %1, i32 %2, i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i64, i64* @errno
%12 = load i64, i64* @EINTR
%13 = icmp eq i64 %11, %12
br i1 %13, label %7, label %16
14: ; preds = %7
%15 = icmp eq i32 %8, %2
br i1 %15, label %28, label %18
16: ; preds = %10
%17 = icmp eq i32 %2, -1
br i1 %17, label %28, label %22
18: ; preds = %14
%19 = icmp slt i32 %8, 1
br i1 %19, label %20, label %26
20: ; preds = %18
%21 = load i64, i64* @errno
br label %22
22: ; preds = %20, %16
%23 = phi i64 [ %21, %20 ], [ %11, %16 ]
%24 = tail call i8* @strerror(i64 %23)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %28
26: ; preds = %18
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %28
28: ; preds = %16, %14, %3, %26, %22
%29 = phi i32 [ -1, %22 ], [ -1, %26 ], [ -1, %3 ], [ 0, %14 ], [ 0, %16 ]
ret i32 %29
}