#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 int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int send(int, int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
int send_block(int sock, uint8_t *src, size_t len) {
  while (len) {
    int r = send(sock, src, len, 0);
    if (r < 0)
      break;
    src += r;
    len -= r;
  }
  return (len ? -1 : 0);
}


x86 assembly (clang, -O0):
<send_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     117b <send_block+0x6b>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1152 <send_block+0x42>
jmp    117b <send_block+0x6b>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movslq -0x1c(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1123 <send_block+0x13>
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_block>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
nopw   0x0(%rax,%rax,1)
mov    %rdx,%rbp
test   %rdx,%rdx
je     1148 <send_block+0x38>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %ecx,%ecx
call   1030 <send@plt>
cltq
mov    %rbp,%rdx
sub    %rax,%rdx
lea    (%rbx,%rax,4),%rbx
test   %eax,%eax
jns    1120 <send_block+0x10>
neg    %rbp
sbb    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @send_block(i32 %0, i32* %1, i64 %2) {
br label %4
4: ; preds = %8, %3
%5 = phi i64 [ %2, %3 ], [ %13, %8 ]
%6 = phi i32* [ %1, %3 ], [ %12, %8 ]
%7 = icmp eq i64 %5, 0
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = tail call i32 @send(i32 %0, i32* %6, i64 %5, i32 0)
%10 = icmp slt i32 %9, 0
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds i32, i32* %6, i64 %11
%13 = sub i64 %5, %11
br i1 %10, label %14, label %4
14: ; preds = %8, %4
%15 = xor i1 %7, true
%16 = sext i1 %15 to i32
ret i32 %16
}