#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 */
typedef char uint8_t;
typedef int uint32_t;
typedef int ssize_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EBADF;
scalar_t__ EINTR;
scalar_t__ EWOULDBLOCK;
int /*<<< orphan*/ SHUT_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int senddata(int ssock, uint8_t *bf, uint32_t len) {
  ssize_t status;
  printf("msg len= %d (%s)\n", len, bf);
  fflush(stdout);
  status = send(ssock, bf, len, 0);
  if (status != len) {
    if (status > -1) {
      printf("short write client with %lu bytes\n", status);
      return 0;
    } else if (errno == EAGAIN || errno == EINTR) {
      printf("client errro.\n");
      return 0;
    } else if (errno == EBADF)
      printf("client has vanished.\n");
    else if (errno == EWOULDBLOCK)
      printf("client timed out.\n");
    else
      printf("client write error\n");
    (void)shutdown(ssock, SHUT_RDWR);
    (void)close(ssock);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<senddata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     12b6 <senddata+0x166>
cmpl   $0xffffffff,-0x18(%rbp)
jle    11cc <senddata+0x7c>
mov    -0x18(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12bd <senddata+0x16d>
mov    0x2e05(%rip),%rax
mov    (%rax),%rax
mov    0x2dcb(%rip),%rcx
cmp    (%rcx),%rax
je     1200 <senddata+0xb0>
mov    0x2deb(%rip),%rax
mov    (%rax),%rax
mov    0x2dd1(%rip),%rcx
cmp    (%rcx),%rax
jne    121a <senddata+0xca>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12bd <senddata+0x16d>
mov    0x2db7(%rip),%rax
mov    (%rax),%rax
mov    0x2d8d(%rip),%rcx
cmp    (%rcx),%rax
jne    1247 <senddata+0xf7>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1287 <senddata+0x137>
mov    0x2d8a(%rip),%rax
mov    (%rax),%rax
mov    0x2d78(%rip),%rcx
cmp    (%rcx),%rax
jne    1274 <senddata+0x124>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1282 <senddata+0x132>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1287 <senddata+0x137>
jmp    128c <senddata+0x13c>
jmp    1291 <senddata+0x141>
mov    -0x8(%rbp),%edi
mov    0x2d55(%rip),%rax
mov    (%rax),%esi
call   1030 <shutdown@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bd <senddata+0x16d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<senddata>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%rbp
mov    %edi,%r14d
lea    0xe8a(%rip),%rdi
xor    %r15d,%r15d
mov    %edx,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    %ebx,%eax
je     124b <senddata+0xeb>
test   %eax,%eax
js     11c6 <senddata+0x66>
lea    0xe5d(%rip),%rdi
xor    %r15d,%r15d
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    124b <senddata+0xeb>
mov    0x2e0b(%rip),%rax
mov    (%rax),%rax
mov    0x2dd1(%rip),%rcx
cmp    (%rcx),%rax
je     123f <senddata+0xdf>
mov    0x2de5(%rip),%rcx
cmp    (%rcx),%rax
je     123f <senddata+0xdf>
mov    0x2dc9(%rip),%rcx
mov    0x2dda(%rip),%rdx
cmp    (%rdx),%rax
lea    0xe48(%rip),%rdx
lea    0xe2e(%rip),%rsi
cmove  %rdx,%rsi
cmp    (%rcx),%rax
lea    0xe45(%rip),%rdi
cmovne %rsi,%rdi
call   1030 <puts@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1040 <shutdown@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    $0x1,%r15d
jmp    124b <senddata+0xeb>
lea    0xe29(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"msg len= %d (%s)\0A\00"
@stdout = global i32 0
@.str.1 = [35 x i8] c"short write client with %lu bytes\0A\00"
@errno = global i64 0
@EAGAIN = global i64 0
@EINTR = global i64 0
@.str.2 = [15 x i8] c"client errro.\0A\00"
@EBADF = global i64 0
@.str.3 = [22 x i8] c"client has vanished.\0A\00"
@EWOULDBLOCK = global i64 0
@.str.4 = [19 x i8] c"client timed out.\0A\00"
@.str.5 = [20 x i8] c"client write error\0A\00"
@SHUT_RDWR = global i32 0
define i32 @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
%9 = load i32, i32* %7
%10 = load i8*, i8** %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %9, i8* %10)
%12 = load i32, i32* @stdout
%13 = call i32 @fflush(i32 %12)
%14 = load i32, i32* %5
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = call i32 @send(i32 %14, i8* %15, i32 %16, i32 0)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = load i32, i32* %7
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %60
21: ; preds = %3
%22 = load i32, i32* %8
%23 = icmp sgt i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %8
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %25)
store i32 0, i32* %4
br label %61
27: ; preds = %21
%28 = load i64, i64* @errno
%29 = load i64, i64* @EAGAIN
%30 = icmp eq i64 %28, %29
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i64, i64* @errno
%33 = load i64, i64* @EINTR
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31, %27
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %61
37: ; preds = %31
%38 = load i64, i64* @errno
%39 = load i64, i64* @EBADF
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %52
43: ; preds = %37
%44 = load i64, i64* @errno
%45 = load i64, i64* @EWOULDBLOCK
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %51
49: ; preds = %43
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %51
51: ; preds = %49, %47
br label %52
52: ; preds = %51, %41
br label %53
53: ; preds = %52
br label %54
54: ; preds = %53
%55 = load i32, i32* %5
%56 = load i32, i32* @SHUT_RDWR
%57 = call i32 @shutdown(i32 %55, i32 %56)
%58 = load i32, i32* %5
%59 = call i32 @close(i32 %58)
store i32 1, i32* %4
br label %61
60: ; preds = %3
store i32 0, i32* %4
br label %61
61: ; preds = %60, %54, %35, %24
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
@.str = [18 x i8] c"msg len= %d (%s)\0A\00"
@stdout = global i32 0
@.str.1 = [35 x i8] c"short write client with %lu bytes\0A\00"
@errno = global i64 0
@EAGAIN = global i64 0
@EINTR = global i64 0
@EBADF = global i64 0
@EWOULDBLOCK = global i64 0
@SHUT_RDWR = global i32 0
@str = [19 x i8] c"client write error\00"
@str.6 = [18 x i8] c"client timed out.\00"
@str.7 = [21 x i8] c"client has vanished.\00"
@str.8 = [14 x i8] c"client errro.\00"
define i32 @senddata(i32 %0, i8* %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %2, i8* %1)
%5 = load i32, i32* @stdout
%6 = tail call i32 @fflush(i32 %5)
%7 = tail call i32 @send(i32 %0, i8* %1, i32 %2, i32 0)
%8 = icmp eq i32 %7, %2
br i1 %8, label %33, label %9
9: ; preds = %3
%10 = icmp sgt i32 %7, -1
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %33
13: ; preds = %9
%14 = load i64, i64* @errno
%15 = load i64, i64* @EAGAIN
%16 = icmp eq i64 %14, %15
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %14, %17
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.8, i64 0, i64 0))
br label %33
22: ; preds = %13
%23 = load i64, i64* @EBADF
%24 = icmp eq i64 %14, %23
%25 = load i64, i64* @EWOULDBLOCK
%26 = icmp eq i64 %14, %25
%27 = select i1 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0)
%28 = select i1 %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0), i8* %27
%29 = tail call i32 @puts(i8* dereferenceable(1) %28)
%30 = load i32, i32* @SHUT_RDWR
%31 = tail call i32 @shutdown(i32 %0, i32 %30)
%32 = tail call i32 @close(i32 %0)
br label %33
33: ; preds = %3, %22, %20, %11
%34 = phi i32 [ 0, %11 ], [ 0, %20 ], [ 1, %22 ], [ 0, %3 ]
ret i32 %34
}