#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__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int read(int /*<<< orphan*/, int /*<<< orphan*/ *, scalar_t__);
void ReadData(uint8_t *pDest, uint32_t dataLen) {
  uint32_t readRemaining = dataLen;
  uint32_t readPos = 0;
  while (readRemaining > 0) {
    int data_read = read(0, pDest + readPos, readRemaining);
    if (data_read <= 0) {
      exit(-1);
    }
    readPos += data_read;
    readRemaining -= data_read;
  }
}


x86 assembly (clang, -O0):
<ReadData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    119c <ReadData+0x7c>
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
xor    %edi,%edi
call   1030 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jg     117c <ReadData+0x5c>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
movslq -0x24(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
movslq -0x24(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1140 <ReadData+0x20>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadData>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
jle    115c <ReadData+0x3c>
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%r14,%rbx,4),%rsi
xor    %edi,%edi
mov    %r15,%rdx
call   1030 <read@plt>
test   %eax,%eax
jle    1162 <ReadData+0x42>
mov    %eax,%eax
add    %rax,%rbx
sub    %rax,%r15
jg     1140 <ReadData+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0xffffffff,%edi
call   1040 <exit@plt>

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

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