#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*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main(void) {
  char *buf;
  int file;
  int number = 1;
  file = open("./chota2.txt", O_RDONLY);
  if (file == -1) {
    printf("error open\n");
    exit(1);
  }
  buf = (char *)malloc(600000000);
  while (number != 0) {
    if (number == -1) {
      printf("read error\n");
      exit(1);
    }
    number = read(file, buf, 600000000);
    printf("read %d bytes\n", number);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x18(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11a0 <main+0x50>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x23c34600,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1204 <main+0xb4>
cmpl   $0xffffffff,-0x18(%rbp)
jne    11da <main+0x8a>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x23c34600,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ae <main+0x5e>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0xe89(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11fa <main+0x9a>
mov    %eax,%r15d
mov    $0x23c34600,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x1,%ebp
lea    0xe70(%rip),%r14
test   %ebp,%ebp
je     11d7 <main+0x77>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0xffffffff,%ebp
je     11e4 <main+0x84>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x23c34600,%edx
call   1050 <read@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jne    11b0 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe26(%rip),%rdi
jmp    11eb <main+0x8b>

LLVM IR (-O0):
@.str = [13 x i8] c"./chota2.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [12 x i8] c"error open\0A\00"
@.str.2 = [12 x i8] c"read error\0A\00"
@.str.3 = [15 x i8] c"read %d bytes\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %4
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = call i64 @malloc(i32 600000000)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %2
br label %15
15: ; preds = %24, %12
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %15
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %18
%25 = load i32, i32* %3
%26 = load i8*, i8** %2
%27 = call i32 @read(i32 %25, i8* %26, i32 600000000)
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %28)
br label %15
30: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"./chota2.txt\00"
@O_RDONLY = global i32 0
@.str.3 = [15 x i8] c"read %d bytes\0A\00"
@str = [11 x i8] c"read error\00"
@str.4 = [11 x i8] c"error open\00"
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.4, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i64 @malloc(i32 600000000)
%9 = inttoptr i64 %8 to i8*
br label %10
10: ; preds = %15, %7
%11 = phi i32 [ 1, %7 ], [ %16, %15 ]
switch i32 %11, label %15 [
i32 0, label %18
i32 -1, label %12
]
12: ; preds = %10
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %10
%16 = tail call i32 @read(i32 %2, i8* %9, i32 600000000)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %16)
br label %10
18: ; preds = %10
ret i32 0
}