#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 BUFSIZ;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int main(void) {
  int fd;
  int i;
  char buf[819200];
  printf("BUFSIZ = %d\n", BUFSIZ);
  fd = open("test_2.txt", O_RDONLY);
  if (fd == -1) {
    printf("open error!\n");
    return -1;
  }
  printf("read start\n");
  read(fd, buf, 819200);
  printf("read end\n");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc8010,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11a5 <main+0x65>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <main+0xa4>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0xc8010(%rbp),%rsi
mov    $0xc8000,%edx
call   1050 <read@plt>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc8010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0xc8008,%rsp
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11be <main+0x6e>
mov    %eax,%ebp
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc8000,%edx
call   1060 <read@plt>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11cf <main+0x7f>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%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"
@O_RDONLY = global i32 0
@.str.2 = [13 x i8] c"open error!\0A\00"
@.str.3 = [12 x i8] c"read start\0A\00"
@.str.4 = [10 x i8] c"read 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 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %21
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%15 = load i32, i32* %2
%16 = getelementptr inbounds [819200 x i8], [819200 x i8]* %4, i64 0, i64 0
%17 = call i32 @read(i32 %15, i8* %16, i32 819200)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%19 = load i32, i32* %2
%20 = call i32 @close(i32 %19)
store i32 0, i32* %1
br label %21
21: ; preds = %13, %11
%22 = load i32, i32* %1
ret i32 %22
}

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"
@O_RDONLY = global i32 0
@str = [11 x i8] c"read start\00"
@str.5 = [9 x i8] c"read end\00"
@str.6 = [12 x i8] c"open 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 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
br label %15
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%12 = call i32 @read(i32 %6, i8* %2, i32 819200)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.5, i64 0, i64 0))
%14 = tail call i32 @close(i32 %6)
br label %15
15: ; preds = %10, %8
%16 = phi i32 [ -1, %8 ], [ 0, %10 ]
ret i32 %16
}