#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, char *, int, int /*<<< orphan*/);
bool sendResponse(int fileDescriptor, char *buffer, int length) {
  int totalBytesSent = 0;
  int bytesRemaining = length;
  while (totalBytesSent < length) {
    int bytesSent = 0;
    if ((bytesSent = send(fileDescriptor, buffer + totalBytesSent,
                          bytesRemaining, 0)) == -1) {
      break;
    } else {
      totalBytesSent += bytesSent;
      bytesRemaining -= bytesSent;
    }
  }
  return totalBytesSent == length;
}


x86 assembly (clang, -O0):
<sendResponse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1184 <sendResponse+0x74>
movl   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    116b <sendResponse+0x5b>
jmp    1184 <sendResponse+0x74>
mov    -0x20(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    112f <sendResponse+0x1f>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendResponse>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ecx,%ecx
mov    %edx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,%ebp
cmp    %r12d,%ecx
jge    1153 <sendResponse+0x43>
movslq %ebp,%rsi
add    %r14,%rsi
mov    %r15d,%edi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
lea    (%rax,%rbp,1),%ecx
sub    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1130 <sendResponse+0x20>
xor    %eax,%eax
cmp    %r12d,%ebp
sete   %al
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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