#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 O_CREAT;
int O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
scalar_t__ write(int, char *, int);
int main(int argc, char **argv) {
  int fd, ret, i;
  char buff[1000];
  if (argc == 1) {
    ret = read(0, buff, 1000);
    write(1, buff, ret);
    exit(0);
  }
  i = 1;
  for (argc; (argc - 1) >= 1; argc--) {
    fd = open(argv[i], O_RDWR | O_CREAT, 0700);
    if (fd < 0) {
      perror(" FILE ONENING EROOR");
      exit(1);
    }
    while ((ret = read(fd, buff, 10)) != 0) {
      if (ret < 0) {
        perror(" Read Error");
        exit(1);
      }
      if (write(1, buff, ret) < 0) {
        perror(" Write  Error");
        exit(1);
      }
    }
    i++;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11b4 <main+0x54>
lea    -0x410(%rbp),%rsi
xor    %edi,%edi
mov    $0x3e8,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
lea    -0x410(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
xor    %edi,%edi
call   1080 <exit@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cmp    $0x1,%eax
jl     12aa <main+0x14a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
mov    0x2e12(%rip),%rax
or     (%rax),%esi
mov    $0x1c0,%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1215 <main+0xb5>
lea    0xdfa(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    121a <main+0xba>
mov    -0x14(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     1293 <main+0x133>
cmpl   $0x0,-0x18(%rbp)
jge    125a <main+0xfa>
lea    0xdc9(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x410(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
cmp    $0x0,%rax
jge    128e <main+0x12e>
lea    0xda1(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    121a <main+0xba>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    11bb <main+0x5b>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
cmp    $0x1,%edi
je     123c <main+0xdc>
mov    %rsi,%r14
mov    %edi,%r15d
mov    $0x1,%r12d
mov    0x2e6b(%rip),%r13
mov    %rsp,%rbx
jmp    11a9 <main+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r12
cmp    %r15,%r12
je     1202 <main+0xa2>
mov    (%r14,%r12,8),%rdi
mov    0x0(%r13),%esi
mov    0x2e28(%rip),%rax
or     (%rax),%esi
mov    $0x1c0,%edx
call   1060 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1233 <main+0xd3>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1050 <read@plt>
test   %eax,%eax
je     11a0 <main+0x40>
js     121d <main+0xbd>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
jns    11d0 <main+0x70>
lea    0xe20(%rip),%rdi
jmp    1224 <main+0xc4>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf0(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xdc6(%rip),%rdi
jmp    1224 <main+0xc4>
mov    %rsp,%rbx
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1050 <read@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [20 x i8] c" FILE ONENING EROOR\00"
@.str.1 = [12 x i8] c" Read Error\00"
@.str.2 = [14 x i8] c" Write Error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%14 = call i32 @read(i32 0, i8* %13, i32 1000)
store i32 %14, i32* %7
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%16 = load i32, i32* %7
%17 = call i64 @write(i32 1, i8* %15, i32 %16)
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %2
store i32 1, i32* %8
%20 = load i32, i32* %4
br label %21
21: ; preds = %64, %19
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 1
%24 = icmp sge i32 %23, 1
br i1 %24, label %25, label %67
25: ; preds = %21
%26 = load i8**, i8*** %5
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = load i32, i32* @O_RDWR
%32 = load i32, i32* @O_CREAT
%33 = or i32 %31, %32
%34 = call i32 @open(i8* %30, i32 %33, i32 448)
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %25
%38 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %25
br label %41
41: ; preds = %60, %40
%42 = load i32, i32* %6
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%44 = call i32 @read(i32 %42, i8* %43, i32 10)
store i32 %44, i32* %7
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %61
46: ; preds = %41
%47 = load i32, i32* %7
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %46
%53 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%54 = load i32, i32* %7
%55 = call i64 @write(i32 1, i8* %53, i32 %54)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %52
br label %41
61: ; preds = %41
%62 = load i32, i32* %8
%63 = add nsw i32 %62, 1
store i32 %63, i32* %8
br label %64
64: ; preds = %61
%65 = load i32, i32* %4
%66 = add nsw i32 %65, -1
store i32 %66, i32* %4
br label %21
67: ; preds = %21
%68 = load i32, i32* %6
%69 = call i32 @close(i32 %68)
ret i32 0
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [20 x i8] c" FILE ONENING EROOR\00"
@.str.1 = [12 x i8] c" Read Error\00"
@.str.2 = [14 x i8] c" Write Error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 1
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 1
%8 = zext i32 %0 to i64
br label %13
9: ; preds = %2
%10 = call i32 @read(i32 0, i8* %4, i32 1000)
%11 = call i64 @write(i32 1, i8* %4, i32 %10)
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %6, %39
%14 = phi i64 [ 1, %6 ], [ %40, %39 ]
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDWR
%18 = load i32, i32* @O_CREAT
%19 = or i32 %18, %17
%20 = tail call i32 @open(i8* %16, i32 %19, i32 448)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %13, %33
%26 = call i32 @read(i32 %20, i8* %4, i32 10)
%27 = icmp eq i32 %26, 0
br i1 %27, label %39, label %28
28: ; preds = %25
%29 = icmp slt i32 %26, 0
br i1 %29, label %30, label %33
30: ; preds = %28
%31 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %28
%34 = call i64 @write(i32 1, i8* %4, i32 %26)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %25
36: ; preds = %33
%37 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %25
%40 = add nuw nsw i64 %14, 1
%41 = icmp eq i64 %40, %8
br i1 %41, label %42, label %13
42: ; preds = %39
%43 = tail call i32 @close(i32 %20)
ret i32 0
}