#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 */

/* Variables and functions */
int read(int, char *, int);
int lineFileLongNetRead(int fd, char *buf, int size) {
  int oneSize, totalRead = 0;
  while (size > 0) {
    oneSize = read(fd, buf, size);
    if (oneSize <= 0)
      break;
    totalRead += oneSize;
    buf += oneSize;
    size -= oneSize;
  }
  return totalRead;
}


x86 assembly (clang, -O0):
<lineFileLongNetRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    117e <lineFileLongNetRead+0x6e>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     1154 <lineFileLongNetRead+0x44>
jmp    117e <lineFileLongNetRead+0x6e>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <lineFileLongNetRead+0x19>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lineFileLongNetRead>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    114f <lineFileLongNetRead+0x3f>
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r15d
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    1152 <lineFileLongNetRead+0x42>
add    %eax,%r14d
mov    %eax,%ecx
add    %rcx,%rbx
sub    %eax,%ebp
jg     1130 <lineFileLongNetRead+0x20>
jmp    1152 <lineFileLongNetRead+0x42>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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