#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*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int read_big_block(int fd, char *buf) {
  int i, rc;
  if ((rc = read(fd, buf, (2 * 1024 * 1024))) != (2 * 1024 * 1024)) {
    if (rc) {
      if (rc == -1)
        perror("read() failed");
      else
        fprintf(stderr, "read(%u) returned %u bytes\n", (2 * 1024 * 1024), rc);
    } else {
      fputs("read() hit EOF - device too small\n", stderr);
    }
    return 1;
  }
  for (i = 0; i < (2 * 1024 * 1024); i += 512)
    buf[i] &= 1;
  return 0;
}


x86 assembly (clang, -O0):
<read_big_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x200000,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x200000,%eax
je     11d6 <read_big_block+0x96>
cmpl   $0x0,-0x18(%rbp)
je     11b5 <read_big_block+0x75>
cmpl   $0xffffffff,-0x18(%rbp)
jne    1193 <read_big_block+0x53>
lea    0xe77(%rip),%rdi
call   1060 <perror@plt>
jmp    11b0 <read_big_block+0x70>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%ecx
lea    0xe68(%rip),%rsi
mov    $0x200000,%edx
call   1050 <fprintf@plt>
jmp    11ca <read_big_block+0x8a>
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rdi
call   1030 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    1213 <read_big_block+0xd3>
movl   $0x0,-0x14(%rbp)
cmpl   $0x200000,-0x14(%rbp)
jge    120c <read_big_block+0xcc>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
and    $0x1,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x200,%eax
mov    %eax,-0x14(%rbp)
jmp    11dd <read_big_block+0x9d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_big_block>:
push   %rbx
mov    %rsi,%rbx
mov    $0x200000,%edx
call   1040 <read@plt>
test   %eax,%eax
je     117c <read_big_block+0x3c>
cmp    $0x200000,%eax
je     1198 <read_big_block+0x58>
cmp    $0xffffffff,%eax
je     11d2 <read_big_block+0x92>
mov    0x2e7b(%rip),%rcx
mov    (%rcx),%edi
lea    0xea0(%rip),%rsi
mov    $0x200000,%edx
mov    %eax,%ecx
call   1050 <fprintf@plt>
jmp    1191 <read_big_block+0x51>
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
lea    0xe9e(%rip),%rdi
call   1030 <fputs@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    $0xfffffffffffffe00,%rax
nop
andb   $0x1,0x200(%rbx,%rax,1)
01
andb   $0x1,0x400(%rbx,%rax,1)
01
andb   $0x1,0x600(%rbx,%rax,1)
01
andb   $0x1,0x800(%rbx,%rax,1)
01
add    $0x800,%rax
cmp    $0x1ffe00,%rax
jb     11a0 <read_big_block+0x60>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe27(%rip),%rdi
call   1060 <perror@plt>
jmp    1191 <read_big_block+0x51>

LLVM IR (-O0):
@.str = [14 x i8] c"read() failed\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"read(%u) returned %u bytes\0A\00"
@.str.2 = [35 x i8] c"read() hit EOF - device too small\0A\00"
define i32 @read_big_block(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = load i32, i32* %4
%9 = load i8*, i8** %5
%10 = call i32 @read(i32 %8, i8* %9, i32 2097152)
store i32 %10, i32* %7
%11 = icmp ne i32 %10, 2097152
br i1 %11, label %12, label %29
12: ; preds = %2
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %24
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i32, i32* %7
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 2097152, i32 %22)
br label %24
24: ; preds = %20, %18
br label %28
25: ; preds = %12
%26 = load i32, i32* @stderr
%27 = call i32 @fputs(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25, %24
store i32 1, i32* %3
br label %46
29: ; preds = %2
store i32 0, i32* %6
br label %30
30: ; preds = %42, %29
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 2097152
br i1 %32, label %33, label %45
33: ; preds = %30
%34 = load i8*, i8** %5
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = and i32 %39, 1
%41 = trunc i32 %40 to i8
store i8 %41, i8* %37
br label %42
42: ; preds = %33
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 512
store i32 %44, i32* %6
br label %30
45: ; preds = %30
store i32 0, i32* %3
br label %46
46: ; preds = %45, %28
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [14 x i8] c"read() failed\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"read(%u) returned %u bytes\0A\00"
@.str.2 = [35 x i8] c"read() hit EOF - device too small\0A\00"
define i32 @read_big_block(i32 %0, i8* nocapture %1) {
%3 = tail call i32 @read(i32 %0, i8* %1, i32 2097152)
switch i32 %3, label %6 [
i32 2097152, label %12
i32 0, label %9
i32 -1, label %4
]
4: ; preds = %2
%5 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %31
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 2097152, i32 %3)
br label %31
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fputs(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %31
12: ; preds = %2, %12
%13 = phi i64 [ %29, %12 ], [ 0, %2 ]
%14 = getelementptr inbounds i8, i8* %1, i64 %13
%15 = load i8, i8* %14
%16 = and i8 %15, 1
store i8 %16, i8* %14
%17 = or i64 %13, 512
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = load i8, i8* %18
%20 = and i8 %19, 1
store i8 %20, i8* %18
%21 = or i64 %13, 1024
%22 = getelementptr inbounds i8, i8* %1, i64 %21
%23 = load i8, i8* %22
%24 = and i8 %23, 1
store i8 %24, i8* %22
%25 = or i64 %13, 1536
%26 = getelementptr inbounds i8, i8* %1, i64 %25
%27 = load i8, i8* %26
%28 = and i8 %27, 1
store i8 %28, i8* %26
%29 = add nuw nsw i64 %13, 2048
%30 = icmp ult i64 %25, 2096640
br i1 %30, label %12, label %31
31: ; preds = %12, %9, %6, %4
%32 = phi i32 [ 1, %4 ], [ 1, %6 ], [ 1, %9 ], [ 0, %12 ]
ret i32 %32
}