#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 */
#define EINTR 131
#define ENOTCONN 130
#define EPIPE 129
#define EWOULDBLOCK 128
int errno;
int write(int, char *, int);
int m_senddata(int socket, char *sendbp, int count) {
  int slen;
retry:
  if ((slen = write(socket, sendbp, count)) < 0) {
    switch (errno) {
    case ENOTCONN:
    case EWOULDBLOCK:
      return (-2);
    case EPIPE:
      return (-3);
    case EINTR:
      goto retry;
    default:
      return (-1);
    }
  }
  if (slen > count) {
    return (-1);
  }
  return slen;
}


x86 assembly (clang, -O0):
<m_senddata>:
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 <write@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1195 <m_senddata+0x85>
mov    0x2e9c(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     1189 <m_senddata+0x79>
mov    -0x20(%rbp),%rax
lea    0xe9d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xfffffffe,-0x4(%rbp)
jmp    11b3 <m_senddata+0xa3>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11b3 <m_senddata+0xa3>
jmp    1122 <m_senddata+0x12>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <m_senddata+0xa3>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11ad <m_senddata+0x9d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <m_senddata+0xa3>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_senddata>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2eba(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    1167 <m_senddata+0x57>
mov    (%r15),%eax
cmp    $0x83,%eax
je     1130 <m_senddata+0x20>
cmp    $0x80,%eax
je     1160 <m_senddata+0x50>
cmp    $0x81,%eax
je     1176 <m_senddata+0x66>
cmp    $0x82,%eax
jne    117d <m_senddata+0x6d>
mov    $0xfffffffe,%eax
jmp    1182 <m_senddata+0x72>
mov    %eax,%ecx
cmp    %r14d,%eax
mov    $0xffffffff,%eax
cmovle %ecx,%eax
jmp    1182 <m_senddata+0x72>
mov    $0xfffffffd,%eax
jmp    1182 <m_senddata+0x72>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @m_senddata(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
br label %9
9: ; preds = %19, %3
%10 = load i32, i32* %5
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = call i32 @write(i32 %10, i8* %11, i32 %12)
store i32 %13, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = load i32, i32* @errno
switch i32 %16, label %20 [
i32 130, label %17
i32 128, label %17
i32 129, label %18
i32 131, label %19
]
17: ; preds = %15, %15
store i32 -2, i32* %4
br label %28
18: ; preds = %15
store i32 -3, i32* %4
br label %28
19: ; preds = %15
br label %9
20: ; preds = %15
store i32 -1, i32* %4
br label %28
21: ; preds = %9
%22 = load i32, i32* %8
%23 = load i32, i32* %7
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 -1, i32* %4
br label %28
26: ; preds = %21
%27 = load i32, i32* %8
store i32 %27, i32* %4
br label %28
28: ; preds = %26, %25, %20, %18, %17
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @m_senddata(i32 %0, i8* nocapture %1, i32 %2) {
br label %4
4: ; preds = %7, %3
%5 = tail call i32 @write(i32 %0, i8* %1, i32 %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = load i32, i32* @errno
switch i32 %8, label %14 [
i32 130, label %12
i32 128, label %12
i32 129, label %13
i32 131, label %4
]
9: ; preds = %4
%10 = icmp sgt i32 %5, %2
%11 = select i1 %10, i32 -1, i32 %5
br label %14
12: ; preds = %7, %7
br label %14
13: ; preds = %7
br label %14
14: ; preds = %7, %13, %12, %9
%15 = phi i32 [ %11, %9 ], [ -2, %12 ], [ -3, %13 ], [ -1, %7 ]
ret i32 %15
}