#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  FILE *fp;
  int i;
  char buf[819200];
  printf("BUFSIZ = %d\n", BUFSIZ);
  fp = fopen("test_2.txt", "rb");
  if (fp == NULL) {
    printf("fopen error!\n");
    return -1;
  }
  printf("fread start\n");
  fread(buf, 819200, 1, fp);
  printf("fread end\n");
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc8020,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe9d(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a5 <main+0x65>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <main+0xab>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc8020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0xc8000,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc8020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0xc8008,%rsp
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe94(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c4 <main+0x74>
mov    %rax,%rbx
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    $0xc8000,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    11d5 <main+0x85>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0xc8008,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"BUFSIZ = %d\0A\00"
@BUFSIZ = global i32 0
@.str.1 = [11 x i8] c"test_2.txt\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [14 x i8] c"fopen error!\0A\00"
@.str.4 = [13 x i8] c"fread start\0A\00"
@.str.5 = [11 x i8] c"fread end\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [819200 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @BUFSIZ
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %20
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%14 = getelementptr inbounds [819200 x i8], [819200 x i8]* %4, i64 0, i64 0
%15 = load i32*, i32** %2
%16 = call i32 @fread(i8* %14, i32 819200, i32 1, i32* %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
store i32 0, i32* %1
br label %20
20: ; preds = %12, %10
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [13 x i8] c"BUFSIZ = %d\0A\00"
@BUFSIZ = global i32 0
@.str.1 = [11 x i8] c"test_2.txt\00"
@.str.2 = [3 x i8] c"rb\00"
@str = [12 x i8] c"fread start\00"
@str.6 = [10 x i8] c"fread end\00"
@str.7 = [13 x i8] c"fopen error!\00"
define i32 @main() {
%1 = alloca [819200 x i8]
%2 = getelementptr inbounds [819200 x i8], [819200 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @BUFSIZ
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
br label %14
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%11 = call i32 @fread(i8* %2, i32 819200, i32 1, i32* %5)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.6, i64 0, i64 0))
%13 = tail call i32 @fclose(i32* %5)
br label %14
14: ; preds = %9, %7
%15 = phi i32 [ -1, %7 ], [ 0, %9 ]
ret i32 %15
}