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

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ errno;
int read(int, void *, size_t);
ssize_t readData(int file, void *data, size_t size, unsigned int tries) {
  ssize_t result;
  size_t offset = 0;
  if (size == 0)
    return 0;
  if (tries == 0)
    return 0;
  result = read(file, data, size);
  if (result == -1) {
    if (errno == EAGAIN) {
      return readData(file, data, size, tries - 1);
    }
    return -1;
  }
  offset = result;
  size -= offset;
  data = (char *)data + offset;
  result = readData(file, data, size, tries - 1);
  if (result == -1) {
    return -1;
  }
  offset += result;
  return offset;
}


x86 assembly (clang, -O0):
<readData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1155 <readData+0x35>
movl   $0x0,-0x4(%rbp)
jmp    1231 <readData+0x111>
cmpl   $0x0,-0x1c(%rbp)
jne    116b <readData+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    1231 <readData+0x111>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <read@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11cc <readData+0xac>
mov    0x2e51(%rip),%rax
mov    (%rax),%rax
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%rax
jne    11c0 <readData+0xa0>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
call   1030 <readData@plt>
mov    %eax,-0x4(%rbp)
jmp    1231 <readData+0x111>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <readData+0x111>
movslq -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
call   1030 <readData@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    121e <readData+0xfe>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <readData+0x111>
movslq -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readData>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
test   %rdx,%rdx
je     11ab <readData+0x8b>
test   %ecx,%ecx
je     11ab <readData+0x8b>
mov    %rdx,%r13
mov    %rsi,%r12
mov    %edi,%r15d
mov    $0x1,%ebp
sub    %ecx,%ebp
mov    0x2e83(%rip),%r14
nopl   (%rax)
mov    %r15d,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
jne    117e <readData+0x5e>
mov    0x2e76(%rip),%rax
mov    (%rax),%rax
cmp    (%r14),%rax
jne    11a6 <readData+0x86>
add    $0x1,%ebp
cmp    $0x1,%ebp
jne    1150 <readData+0x30>
xor    %eax,%eax
jmp    11ab <readData+0x8b>
mov    %eax,%ebx
cltq
sub    %rax,%r13
add    %rax,%r12
neg    %ebp
mov    %r15d,%edi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %ebp,%ecx
call   1030 <readData@plt>
add    %eax,%ebx
cmp    $0xffffffff,%eax
cmove  %eax,%ebx
mov    %ebx,%eax
jmp    11ab <readData+0x8b>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @readData(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
store i64 0, i64* %11
%12 = load i64, i64* %8
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %4
store i32 0, i32* %5
br label %63
15: ; preds = %4
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 0, i32* %5
br label %63
19: ; preds = %15
%20 = load i32, i32* %6
%21 = load i8*, i8** %7
%22 = load i64, i64* %8
%23 = call i32 @read(i32 %20, i8* %21, i64 %22)
store i32 %23, i32* %10
%24 = load i32, i32* %10
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %38
26: ; preds = %19
%27 = load i64, i64* @errno
%28 = load i64, i64* @EAGAIN
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %37
30: ; preds = %26
%31 = load i32, i32* %6
%32 = load i8*, i8** %7
%33 = load i64, i64* %8
%34 = load i32, i32* %9
%35 = sub i32 %34, 1
%36 = call i32 @readData(i32 %31, i8* %32, i64 %33, i32 %35)
store i32 %36, i32* %5
br label %63
37: ; preds = %26
store i32 -1, i32* %5
br label %63
38: ; preds = %19
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
store i64 %40, i64* %11
%41 = load i64, i64* %11
%42 = load i64, i64* %8
%43 = sub i64 %42, %41
store i64 %43, i64* %8
%44 = load i8*, i8** %7
%45 = load i64, i64* %11
%46 = getelementptr inbounds i8, i8* %44, i64 %45
store i8* %46, i8** %7
%47 = load i32, i32* %6
%48 = load i8*, i8** %7
%49 = load i64, i64* %8
%50 = load i32, i32* %9
%51 = sub i32 %50, 1
%52 = call i32 @readData(i32 %47, i8* %48, i64 %49, i32 %51)
store i32 %52, i32* %10
%53 = load i32, i32* %10
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %56
55: ; preds = %38
store i32 -1, i32* %5
br label %63
56: ; preds = %38
%57 = load i32, i32* %10
%58 = sext i32 %57 to i64
%59 = load i64, i64* %11
%60 = add i64 %59, %58
store i64 %60, i64* %11
%61 = load i64, i64* %11
%62 = trunc i64 %61 to i32
store i32 %62, i32* %5
br label %63
63: ; preds = %56, %55, %37, %30, %18, %14
%64 = load i32, i32* %5
ret i32 %64
}

LLVM IR (-O2):
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @readData(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = icmp eq i64 %2, 0
%6 = icmp eq i32 %3, 0
%7 = or i1 %5, %6
br i1 %7, label %19, label %8
8: ; preds = %4, %16
%9 = phi i32 [ %17, %16 ], [ %3, %4 ]
%10 = tail call i32 @read(i32 %0, i8* %1, i64 %2)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = load i64, i64* @errno
%14 = load i64, i64* @EAGAIN
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = add i32 %9, -1
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %8
19: ; preds = %12, %16, %4, %21
%20 = phi i32 [ %29, %21 ], [ 0, %4 ], [ -1, %12 ], [ 0, %16 ]
ret i32 %20
21: ; preds = %8
%22 = sext i32 %10 to i64
%23 = sub i64 %2, %22
%24 = getelementptr inbounds i8, i8* %1, i64 %22
%25 = add i32 %9, -1
%26 = tail call i32 @readData(i32 %0, i8* %24, i64 %23, i32 %25)
%27 = icmp eq i32 %26, -1
%28 = add i32 %26, %10
%29 = select i1 %27, i32 -1, i32 %28
br label %19
}