#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 */
int tcpSelect(int, int, int);
int write(int, char *, int);
int tcpSend(int fd, char *buffer, int size, int timeout) {
  int ret;
  ret = tcpSelect(fd, 1, timeout);
  if (ret == (-1))
    return -2;
  if (ret == 0)
    return -3;
  ret = write(fd, buffer, size);
  if (ret != size) {
    return -4;
  }
  return ret;
}


x86 assembly (clang, -O0):
<tcpSend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%edx
mov    $0x1,%esi
call   1040 <tcpSelect@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    115e <tcpSend+0x3e>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11a4 <tcpSend+0x84>
cmpl   $0x0,-0x1c(%rbp)
jne    1174 <tcpSend+0x54>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11a4 <tcpSend+0x84>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     119e <tcpSend+0x7e>
movl   $0xfffffffc,-0x4(%rbp)
jmp    11a4 <tcpSend+0x84>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcpSend>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x1,%esi
mov    %ecx,%edx
call   1040 <tcpSelect@plt>
cmp    $0xffffffff,%eax
je     1147 <tcpSend+0x27>
test   %eax,%eax
jne    114e <tcpSend+0x2e>
mov    $0xfffffffd,%eax
jmp    1166 <tcpSend+0x46>
mov    $0xfffffffe,%eax
jmp    1166 <tcpSend+0x46>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
mov    %eax,%ecx
cmp    %ebx,%eax
mov    $0xfffffffc,%eax
cmove  %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @tcpSend(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i32, i32* %6
%12 = load i32, i32* %9
%13 = call i32 @tcpSelect(i32 %11, i32 1, i32 %12)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -2, i32* %5
br label %32
17: ; preds = %4
%18 = load i32, i32* %10
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 -3, i32* %5
br label %32
21: ; preds = %17
%22 = load i32, i32* %6
%23 = load i8*, i8** %7
%24 = load i32, i32* %8
%25 = call i32 @write(i32 %22, i8* %23, i32 %24)
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = load i32, i32* %8
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %21
store i32 -4, i32* %5
br label %32
30: ; preds = %21
%31 = load i32, i32* %10
store i32 %31, i32* %5
br label %32
32: ; preds = %30, %29, %20, %16
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
define i32 @tcpSend(i32 %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32 @tcpSelect(i32 %0, i32 1, i32 %3)
switch i32 %5, label %7 [
i32 -1, label %11
i32 0, label %6
]
6: ; preds = %4
br label %11
7: ; preds = %4
%8 = tail call i32 @write(i32 %0, i8* %1, i32 %2)
%9 = icmp eq i32 %8, %2
%10 = select i1 %9, i32 %8, i32 -4
br label %11
11: ; preds = %7, %4, %6
%12 = phi i32 [ -3, %6 ], [ -2, %4 ], [ %10, %7 ]
ret i32 %12
}