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

/* Variables and functions */
scalar_t__ send(int, char *, size_t, int /*<<< orphan*/);
void pushToSocket(int socket, char *buffer, size_t length) {
  ssize_t bytesSent;
  size_t sentLength = 0;
  while (sentLength < length) {
    bytesSent = send(socket, buffer + sentLength, length - sentLength, 0);
    if (bytesSent <= 0)
      break;
    else
      sentLength += bytesSent;
  }
}


x86 assembly (clang, -O0):
<pushToSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1178 <pushToSocket+0x68>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    -0x28(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jg     1167 <pushToSocket+0x57>
jmp    1178 <pushToSocket+0x68>
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    112b <pushToSocket+0x1b>
add    $0x30,%rsp
pop    %rbp
ret

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

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

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