#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ stderr;
int getblk(unsigned char *blk) {
  int len;
  len = read(0, blk, (1024 * 1024));
  if (!len)
    return (EOF);
  if (len < 0) {
    fprintf(stderr, "getbyte: read error\n");
    exit(1);
  }
  return (len);
}


x86 assembly (clang, -O0):
<getblk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
mov    $0x100000,%edx
call   1030 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    116a <getblk+0x3a>
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1199 <getblk+0x69>
cmpl   $0x0,-0x14(%rbp)
jge    1193 <getblk+0x63>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getblk>:
push   %rax
mov    %rdi,%rsi
xor    %edi,%edi
mov    $0x100000,%edx
call   1030 <read@plt>
test   %eax,%eax
je     1148 <getblk+0x18>
js     1153 <getblk+0x23>
pop    %rcx
ret
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"getbyte: read error\0A\00"
define i32 @getblk(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @read(i32 0, i8* %5, i32 1048576)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = load i32, i32* @EOF
store i32 %10, i32* %2
br label %20
11: ; preds = %1
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = load i32, i32* %4
store i32 %19, i32* %2
br label %20
20: ; preds = %18, %9
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"getbyte: read error\0A\00"
define i32 @getblk(i8* nocapture %0) {
%2 = tail call i32 @read(i32 0, i8* %0, i32 1048576)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = load i32, i32* @EOF
br label %12
6: ; preds = %1
%7 = icmp slt i32 %2, 0
br i1 %7, label %8, label %12
8: ; preds = %6
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %6, %4
%13 = phi i32 [ %5, %4 ], [ %2, %6 ]
ret i32 %13
}