#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 /*<<< orphan*/ die(char *);
int read(int, unsigned char *, int);
void read_bytes(int fd, unsigned char *buf, int maxlen) {
  while (maxlen) {
    int bytes = read(fd, buf, maxlen);
    if (bytes <= 0)
      die("EOF or read error on tty\n");
    maxlen -= bytes;
    buf += bytes;
  }
}


x86 assembly (clang, -O0):
<read_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1185 <read_bytes+0x65>
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     1164 <read_bytes+0x44>
lea    0xea1(%rip),%rdi
call   1040 <die@plt>
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1132 <read_bytes+0x12>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_bytes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
je     1169 <read_bytes+0x49>
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0xec5(%rip),%r15
jmp    114b <read_bytes+0x2b>
nopl   (%rax)
movslq %r12d,%rax
add    %rax,%rbx
sub    %r12d,%ebp
je     1169 <read_bytes+0x49>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <read@plt>
mov    %eax,%r12d
test   %eax,%eax
jg     1140 <read_bytes+0x20>
mov    %r15,%rdi
call   1040 <die@plt>
jmp    1140 <read_bytes+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"EOF or read error on tty\0A\00"
define void @read_bytes(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %20, %3
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = load i32, i32* %4
%13 = load i8*, i8** %5
%14 = load i32, i32* %6
%15 = call i32 @read(i32 %12, i8* %13, i32 %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp sle i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %11
%21 = load i32, i32* %7
%22 = load i32, i32* %6
%23 = sub nsw i32 %22, %21
store i32 %23, i32* %6
%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
br label %8
28: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"EOF or read error on tty\0A\00"
define void @read_bytes(i32 %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %17, label %5
5: ; preds = %3, %12
%6 = phi i8* [ %15, %12 ], [ %1, %3 ]
%7 = phi i32 [ %13, %12 ], [ %2, %3 ]
%8 = tail call i32 @read(i32 %0, i8* %6, i32 %7)
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %5
%13 = sub nsw i32 %7, %8
%14 = sext i32 %8 to i64
%15 = getelementptr inbounds i8, i8* %6, i64 %14
%16 = icmp eq i32 %13, 0
br i1 %16, label %17, label %5
17: ; preds = %12, %3
ret void
}