#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ fread(char *, int, size_t, int /*<<< orphan*/ *);
ssize_t receiveData(void *d, size_t dataSize, FILE *f) {
  char *data = (char *)d;
  size_t nread = 0;
  ssize_t ret = 0;
  while (nread < dataSize) {
    ret = fread(data + nread, 1, dataSize - nread, f);
    if (ret <= 0)
      return -1;
    nread += ret;
  }
  return nread;
}


x86 assembly (clang, -O0):
<receiveData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1195 <receiveData+0x85>
mov    -0x28(%rbp),%rdi
add    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
sub    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jg     1184 <receiveData+0x74>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    119d <receiveData+0x8d>
mov    -0x38(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    113c <receiveData+0x2c>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receiveData>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     1156 <receiveData+0x46>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbx,1),%rdi
mov    %r15,%rdx
sub    %rbx,%rdx
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jle    115a <receiveData+0x4a>
add    %rax,%rbx
cmp    %r15,%rbx
jb     1130 <receiveData+0x20>
jmp    1161 <receiveData+0x51>
xor    %ebx,%ebx
jmp    1161 <receiveData+0x51>
mov    $0xffffffffffffffff,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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