#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*/ close(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("para error\n");
    return -1;
  }
  int fd;
  fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    perror("open");
    return -1;
  }
  char buff[1024] = {0};
  int ret;
  while (ret = read(fd, buff, 1023)) {
    printf("%s", buff);
    memset(buff, 0, 1024);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119d <main+0x3d>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124a <main+0xea>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d8 <main+0x78>
lea    0xe45(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124a <main+0xea>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x3ff,%edx
call   1060 <read@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
je     123b <main+0xdb>
lea    -0x420(%rbp),%rsi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
jmp    11eb <main+0x8b>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
cmp    $0x2,%edi
jne    1218 <main+0xa8>
mov    0x8(%rsi),%rdi
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     123b <main+0xcb>
mov    %eax,%ebp
mov    %rsp,%rbx
xor    %r14d,%r14d
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1070 <read@plt>
test   %eax,%eax
je     120f <main+0x9f>
lea    0xe34(%rip),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1070 <read@plt>
test   %eax,%eax
jne    11e0 <main+0x70>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    122a <main+0xba>
lea    0xde9(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdbe(%rip),%rdi
call   1090 <perror@plt>
jmp    1224 <main+0xb4>

LLVM IR (-O0):
@.str = [12 x i8] c"para error\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %38
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %16, i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %38
23: ; preds = %13
%24 = bitcast [1024 x i8]* %7 to i8*
br label %25
25: ; preds = %30, %23
%26 = load i32, i32* %6
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%28 = call i32 @read(i32 %26, i8* %27, i32 1023)
store i32 %28, i32* %8
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%34 = call i32 @memset(i8* %33, i32 0, i32 1024)
br label %25
35: ; preds = %25
%36 = load i32, i32* %6
%37 = call i32 @close(i32 %36)
store i32 0, i32* %3
br label %38
38: ; preds = %35, %21, %11
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [3 x i8] c"%s\00"
@str = [11 x i8] c"para error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %26
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %26
15: ; preds = %7
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = call i32 @read(i32 %11, i8* %16, i32 1023)
%18 = icmp eq i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %15, %19
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%21 = call i32 @memset(i8* %16, i32 0, i32 1024)
%22 = call i32 @read(i32 %11, i8* %16, i32 1023)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %19
24: ; preds = %19, %15
%25 = call i32 @close(i32 %11)
br label %26
26: ; preds = %13, %24, %5
%27 = phi i32 [ -1, %5 ], [ -1, %13 ], [ 0, %24 ]
ret i32 %27
}