#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 write(int, char const *, int);
void tcpSend(int fd, const char *data, int len) {
  int written;
  while (len > 0 && ((written = write(fd, data, len)) >= 0 || errno == EINTR)) {
    if (written > 0)
      data += written, len -= written;
  }
}


x86 assembly (clang, -O0):
<tcpSend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jle    1173 <tcpSend+0x63>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x1a(%rbp)
jge    116d <tcpSend+0x5d>
mov    0x2e86(%rip),%rax
mov    (%rax),%rax
mov    0x2e74(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1183 <tcpSend+0x73>
jmp    11ae <tcpSend+0x9e>
cmpl   $0x0,-0x18(%rbp)
jle    11a9 <tcpSend+0x99>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1122 <tcpSend+0x12>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcpSend>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1167 <tcpSend+0x57>
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x2eb2(%rip),%r15
mov    0x2ea3(%rip),%r12
xor    %r13d,%r13d
jmp    114d <tcpSend+0x3d>
nopw   0x0(%rax,%rax,1)
test   %eax,%eax
cmovs  %r13d,%eax
add    %rax,%rbx
sub    %eax,%ebp
jle    1167 <tcpSend+0x57>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    1140 <tcpSend+0x30>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1140 <tcpSend+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define void @tcpSend(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %36, %3
%9 = load i32, i32* %6
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = load i32, i32* %4
%13 = load i8*, i8** %5
%14 = load i32, i32* %6
%15 = call i32 @write(i32 %12, i8* %13, i32 %14)
store i32 %15, i32* %7
%16 = icmp sge i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %11
%18 = load i64, i64* @errno
%19 = load i64, i64* @EINTR
%20 = icmp eq i64 %18, %19
br label %21
21: ; preds = %17, %11
%22 = phi i1 [ true, %11 ], [ %20, %17 ]
br label %23
23: ; preds = %21, %8
%24 = phi i1 [ false, %8 ], [ %22, %21 ]
br i1 %24, label %25, label %37
25: ; preds = %23
%26 = load i32, i32* %7
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = load i32, i32* %7
%30 = load i8*, i8** %5
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8* %32, i8** %5
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = sub nsw i32 %34, %33
store i32 %35, i32* %6
br label %36
36: ; preds = %28, %25
br label %8
37: ; preds = %23
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define void @tcpSend(i32 %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %21
5: ; preds = %3, %14
%6 = phi i8* [ %19, %14 ], [ %1, %3 ]
%7 = phi i32 [ %17, %14 ], [ %2, %3 ]
%8 = tail call i32 @write(i32 %0, i8* %6, i32 %7)
%9 = icmp sgt i32 %8, -1
%10 = load i64, i64* @errno
%11 = load i64, i64* @EINTR
%12 = icmp eq i64 %10, %11
%13 = select i1 %9, i1 true, i1 %12
br i1 %13, label %14, label %21
14: ; preds = %5
%15 = icmp sgt i32 %8, 0
%16 = select i1 %15, i32 %8, i32 0
%17 = sub nsw i32 %7, %16
%18 = zext i32 %16 to i64
%19 = getelementptr i8, i8* %6, i64 %18
%20 = icmp sgt i32 %17, 0
br i1 %20, label %5, label %21
21: ; preds = %5, %14, %3
ret void
}