#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_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
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[1300];
  fd = open(argv[1], O_RDWR);
  if (fd < 0) {
    perror("Error");
    exit(1);
  }
  ret = read(fd, buff, 1300);
  while (ret != 0) {
    if (write(1, buff, ret) < 0) {
      perror(" Write  Error");
      exit(1);
    }
    if (ret = read(fd, buff, 1300) < 0) {
      perror(" Read Error");
      exit(1);
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x530,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b2 <main+0x52>
lea    0xe65(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x530(%rbp),%rsi
mov    $0x514,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1254 <main+0xf4>
lea    -0x530(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1207 <main+0xa7>
lea    0xe08(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x530(%rbp),%rsi
mov    $0x514,%edx
call   1050 <read@plt>
cmp    $0x0,%eax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x18(%rbp)
test   $0x1,%al
jne    1239 <main+0xd9>
jmp    124f <main+0xef>
lea    0xdce(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11c9 <main+0x69>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x530,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x518,%rsp
mov    0x8(%rsi),%rdi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     1200 <main+0xa0>
mov    %eax,%ebp
mov    %rsp,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x514,%edx
call   1050 <read@plt>
mov    %eax,%edx
nopl   0x0(%rax)
test   %edx,%edx
je     11d7 <main+0x77>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
test   %rax,%rax
js     11ea <main+0x8a>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x514,%edx
call   1050 <read@plt>
mov    %eax,%edx
shr    $0x1f,%edx
test   %eax,%eax
jns    11a0 <main+0x40>
lea    0xe39(%rip),%rdi
jmp    11f1 <main+0x91>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x518,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe0f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe01(%rip),%rdi
jmp    11f1 <main+0x91>

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [6 x i8] c"Error\00"
@.str.1 = [14 x i8] c" Write Error\00"
@.str.2 = [12 x i8] c" Read 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 [1300 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i32, i32* %6
%22 = getelementptr inbounds [1300 x i8], [1300 x i8]* %9, i64 0, i64 0
%23 = call i32 @read(i32 %21, i8* %22, i32 1300)
store i32 %23, i32* %7
br label %24
24: ; preds = %44, %20
%25 = load i32, i32* %7
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %45
27: ; preds = %24
%28 = getelementptr inbounds [1300 x i8], [1300 x i8]* %9, i64 0, i64 0
%29 = load i32, i32* %7
%30 = call i64 @write(i32 1, i8* %28, i32 %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %27
%36 = load i32, i32* %6
%37 = getelementptr inbounds [1300 x i8], [1300 x i8]* %9, i64 0, i64 0
%38 = call i32 @read(i32 %36, i8* %37, i32 1300)
%39 = icmp slt i32 %38, 0
%40 = zext i1 %39 to i32
store i32 %40, i32* %7
br i1 %39, label %41, label %44
41: ; preds = %35
%42 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %35
br label %24
45: ; preds = %24
%46 = load i32, i32* %6
%47 = call i32 @close(i32 %46)
ret i32 0
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [6 x i8] c"Error\00"
@.str.1 = [14 x i8] c" Write Error\00"
@.str.2 = [12 x i8] c" Read Error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1300 x i8]
%4 = getelementptr inbounds [1300 x i8], [1300 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDWR
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i32 @read(i32 %8, i8* %4, i32 1300)
br label %15
15: ; preds = %24, %13
%16 = phi i32 [ %14, %13 ], [ %27, %24 ]
%17 = icmp eq i32 %16, 0
br i1 %17, label %31, label %18
18: ; preds = %15
%19 = call i64 @write(i32 1, i8* %4, i32 %16)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %18
%25 = call i32 @read(i32 %8, i8* %4, i32 1300)
%26 = icmp slt i32 %25, 0
%27 = lshr i32 %25, 31
br i1 %26, label %28, label %15
28: ; preds = %24
%29 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %15
%32 = tail call i32 @close(i32 %8)
ret i32 0
}