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

/* Variables and functions */
scalar_t__ recv(int, int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
bool recvUntilDone(int sock, uint8_t *buffer, size_t bytesToRead) {
  size_t curRead = 0;
  while (curRead < bytesToRead) {
    ssize_t recvResult = recv(sock, buffer + curRead, bytesToRead - curRead, 0);
    if (recvResult <= 0) {
      return (false);
    }
    curRead += (size_t)recvResult;
  }
  return (true);
}


x86 assembly (clang, -O0):
<recvUntilDone>:
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    1186 <recvUntilDone+0x76>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
sub    -0x20(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jg     1175 <recvUntilDone+0x65>
movl   $0x0,-0x4(%rbp)
jmp    118d <recvUntilDone+0x7d>
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    112b <recvUntilDone+0x1b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recvUntilDone>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %r12,%rbx
jae    1153 <recvUntilDone+0x43>
lea    (%r14,%rbx,4),%rsi
mov    %r12,%rdx
sub    %rbx,%rdx
mov    %r15d,%edi
xor    %ecx,%ecx
call   1030 <recv@plt>
add    %rax,%rbx
test   %rax,%rax
jg     1130 <recvUntilDone+0x20>
jmp    1158 <recvUntilDone+0x48>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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