#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 /*<<< orphan*/ hot_sys_Panic(char *);
int /*<<< orphan*/ perror(char *);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ trace(char *, int, char *, int);
int tcp_send(int s, void *buf_void, int len) {
  int result, ofs;
  char *buf = buf_void;
  trace("tcpsend: %d 0x%x %d", s, buf, len);
  for (ofs = 0; ofs < len; ofs += result) {
    result = send(s, buf + ofs, len - ofs, 0);
    if (result == -1) {
      perror("send");
      hot_sys_Panic("lost connection to outboard");
    }
  }
  return len;
}


x86 assembly (clang, -O0):
<tcp_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe95(%rip),%rdi
call   1050 <trace@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d6 <tcp_send+0x96>
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11c3 <tcp_send+0x83>
lea    0xe62(%rip),%rdi
call   1060 <perror@plt>
lea    0xe5b(%rip),%rdi
call   1040 <hot_sys_Panic@plt>
jmp    11c8 <tcp_send+0x88>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1177 <tcp_send+0x37>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp_send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%r13d
lea    0xea6(%rip),%rdi
mov    %r13d,%esi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1050 <trace@plt>
test   %ebx,%ebx
jle    11ba <tcp_send+0x7a>
xor    %r15d,%r15d
lea    0xea4(%rip),%r12
jmp    1188 <tcp_send+0x48>
nopw   0x0(%rax,%rax,1)
add    %ebp,%r15d
cmp    %ebx,%r15d
jge    11ba <tcp_send+0x7a>
movslq %r15d,%rax
lea    (%r14,%rax,1),%rsi
mov    %ebx,%edx
sub    %eax,%edx
mov    %r13d,%edi
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1180 <tcp_send+0x40>
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
mov    %r12,%rdi
call   1040 <hot_sys_Panic@plt>
jmp    1180 <tcp_send+0x40>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"tcpsend: %d 0x%x %d\00"
@.str.1 = [5 x i8] c"send\00"
@.str.2 = [28 x i8] c"lost connection to outboard\00"
define i32 @tcp_send(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
store i8* %10, i8** %9
%11 = load i32, i32* %4
%12 = load i8*, i8** %9
%13 = load i32, i32* %6
%14 = call i32 @trace(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %12, i32 %13)
store i32 0, i32* %8
br label %15
15: ; preds = %35, %3
%16 = load i32, i32* %8
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %39
19: ; preds = %15
%20 = load i32, i32* %4
%21 = load i8*, i8** %9
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i32, i32* %6
%26 = load i32, i32* %8
%27 = sub nsw i32 %25, %26
%28 = call i32 @send(i32 %20, i8* %24, i32 %27, i32 0)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %19
%32 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @hot_sys_Panic(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %31, %19
br label %35
35: ; preds = %34
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = add nsw i32 %37, %36
store i32 %38, i32* %8
br label %15
39: ; preds = %15
%40 = load i32, i32* %6
ret i32 %40
}

LLVM IR (-O2):
@.str = [20 x i8] c"tcpsend: %d 0x%x %d\00"
@.str.1 = [5 x i8] c"send\00"
@.str.2 = [28 x i8] c"lost connection to outboard\00"
define i32 @tcp_send(i32 %0, i8* %1, i32 returned %2) {
%4 = tail call i32 @trace(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %1, i32 %2)
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %19
6: ; preds = %3, %16
%7 = phi i32 [ %17, %16 ], [ 0, %3 ]
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = sub nsw i32 %2, %7
%11 = tail call i32 @send(i32 %0, i8* %9, i32 %10, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %6
%14 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @hot_sys_Panic(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %6, %13
%17 = add nsw i32 %11, %7
%18 = icmp slt i32 %17, %2
br i1 %18, label %6, label %19
19: ; preds = %16, %3
ret i32 %2
}