#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*/ printf(char *);
int send(int, char *, int, int);
int hls_send(int sockfd, char *sendbuf, int len, int flags) {
  int sendlen = 0;
  int ret = -1;
  while (sendlen < len) {
    ret = send(sockfd, sendbuf + sendlen, len - sendlen, flags);
    if (-1 == ret) {
      printf("send error\n");
      return -1;
    } else {
      sendlen += ret;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<hls_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a2 <hls_send+0x82>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <send@plt>
mov    %eax,-0x20(%rbp)
mov    $0xffffffff,%eax
cmp    -0x20(%rbp),%eax
jne    1194 <hls_send+0x74>
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <hls_send+0x89>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1143 <hls_send+0x23>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hls_send>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
jle    1161 <hls_send+0x41>
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rsi,%r15
mov    %edi,%r12d
xor    %ebx,%ebx
nopl   0x0(%rax)
movslq %ebx,%rax
lea    (%r15,%rax,1),%rsi
mov    %ebp,%edx
sub    %eax,%edx
mov    %r12d,%edi
mov    %r14d,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     1165 <hls_send+0x45>
add    %eax,%ebx
cmp    %ebp,%ebx
jl     1140 <hls_send+0x20>
xor    %eax,%eax
jmp    1176 <hls_send+0x56>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"send error\0A\00"
define i32 @hls_send(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
%11 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 0, i32* %10
store i32 -1, i32* %11
br label %12
12: ; preds = %35, %4
%13 = load i32, i32* %10
%14 = load i32, i32* %8
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %36
16: ; preds = %12
%17 = load i32, i32* %6
%18 = load i8*, i8** %7
%19 = load i32, i32* %10
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i32, i32* %8
%23 = load i32, i32* %10
%24 = sub nsw i32 %22, %23
%25 = load i32, i32* %9
%26 = call i32 @send(i32 %17, i8* %21, i32 %24, i32 %25)
store i32 %26, i32* %11
%27 = load i32, i32* %11
%28 = icmp eq i32 -1, %27
br i1 %28, label %29, label %31
29: ; preds = %16
%30 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %37
31: ; preds = %16
%32 = load i32, i32* %11
%33 = load i32, i32* %10
%34 = add nsw i32 %33, %32
store i32 %34, i32* %10
br label %35
35: ; preds = %31
br label %12
36: ; preds = %12
store i32 0, i32* %5
br label %37
37: ; preds = %36, %29
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
@str = [11 x i8] c"send error\00"
define i32 @hls_send(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %8, label %18
6: ; preds = %8
%7 = icmp slt i32 %15, %2
br i1 %7, label %8, label %18
8: ; preds = %4, %6
%9 = phi i32 [ %15, %6 ], [ 0, %4 ]
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = sub nsw i32 %2, %9
%13 = tail call i32 @send(i32 %0, i8* %11, i32 %12, i32 %3)
%14 = icmp eq i32 %13, -1
%15 = add nsw i32 %13, %9
br i1 %14, label %16, label %6
16: ; preds = %8
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %6, %4, %16
%19 = phi i32 [ -1, %16 ], [ 0, %4 ], [ 0, %6 ]
ret i32 %19
}