#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 size_t ssize_t;

/* Variables and functions */
size_t send(int, char const *, size_t, int /*<<< orphan*/);
int tracker_sendall(int sockfd, const char *buff, size_t len) {
  ssize_t tot_sent = 0;
  while (tot_sent < len) {
    ssize_t sent = send(sockfd, buff, len - tot_sent, 0);
    if (sent < 0)
      return -1;
    tot_sent += sent;
    buff += sent;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tracker_sendall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1187 <tracker_sendall+0x77>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    -0x20(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jae    116a <tracker_sendall+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    118e <tracker_sendall+0x7e>
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    112b <tracker_sendall+0x1b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tracker_sendall>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdx,%rdx
je     114e <tracker_sendall+0x3e>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdx
sub    %rbp,%rdx
mov    %r15d,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1030 <send@plt>
add    %rax,%rbx
add    %rax,%rbp
cmp    %r14,%rbp
jb     1130 <tracker_sendall+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @tracker_sendall(i32 %0, i8* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %13, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %11, %5 ], [ 0, %3 ]
%7 = phi i8* [ %10, %5 ], [ %1, %3 ]
%8 = sub i64 %2, %6
%9 = tail call i64 @send(i32 %0, i8* %7, i64 %8, i32 0)
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = add i64 %9, %6
%12 = icmp ult i64 %11, %2
br i1 %12, label %5, label %13
13: ; preds = %5, %3
ret i32 0
}