#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 send(int const, char const *, int, int /*<<< orphan*/);
int /*<<< orphan*/ warning(char *, int, int const);
void send_bytes(const int fd, const char *data, int bytes) {
  int res;
  int offset = 0;
  while (1) {
    res = send(fd, data + offset, bytes, 0);
    if (res == -1) {
      warning("Sending %i bytes to %i.", bytes, fd);
      break;
    }
    if (res == bytes)
      break;
    offset += res;
    bytes -= res;
  }
}


x86 assembly (clang, -O0):
<send_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1175 <send_bytes+0x55>
mov    -0x14(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xe95(%rip),%rdi
call   1030 <warning@plt>
jmp    119f <send_bytes+0x7f>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1186 <send_bytes+0x66>
jmp    119f <send_bytes+0x7f>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <send_bytes+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_bytes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r15
mov    %edi,%r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     115f <send_bytes+0x3f>
sub    %eax,%ebx
je     117a <send_bytes+0x5a>
add    %eax,%ebp
movslq %ebp,%rsi
add    %r15,%rsi
mov    %r14d,%edi
mov    %ebx,%edx
jmp    1140 <send_bytes+0x20>
lea    0xe9a(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <warning@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Sending %i bytes to %i.\00"
define void @send_bytes(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %8
br label %9
9: ; preds = %3, %28
%10 = load i32, i32* %4
%11 = load i8*, i8** %5
%12 = load i32, i32* %8
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i32, i32* %6
%16 = call i32 @send(i32 %10, i8* %14, i32 %15, i32 0)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %9
%20 = load i32, i32* %6
%21 = load i32, i32* %4
%22 = call i32 @warning(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21)
br label %35
23: ; preds = %9
%24 = load i32, i32* %7
%25 = load i32, i32* %6
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23
br label %35
28: ; preds = %23
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = add nsw i32 %30, %29
store i32 %31, i32* %8
%32 = load i32, i32* %7
%33 = load i32, i32* %6
%34 = sub nsw i32 %33, %32
store i32 %34, i32* %6
br label %9
35: ; preds = %27, %19
ret void
}

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