#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 */
scalar_t__ EINTR;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int open(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int write(int, char *, int);
int main(int argc, char **argv) {
  int from_fd, to_fd;
  int bytes_read, bytes_write;
  char buffer[10];
  char *ptr;
  if (argc != 3) {
    fprintf(stderr, "Usage:%s fromfile tofile/n/a", argv[0]);
    exit(1);
  }
  if ((from_fd = open(argv[1], O_RDONLY)) == -1) {
    fprintf(stderr, "Open %s Error:%s/n", argv[1], strerror(errno));
    exit(1);
  }
  if ((to_fd = open(argv[2], O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) == -1) {
    fprintf(stderr, "Open %s Error:%s/n", argv[2], strerror(errno));
    exit(1);
  }
  while (bytes_read = read(from_fd, buffer, 10)) {
    if ((bytes_read == -1) && (errno != EINTR))
      break;
    else if (bytes_read > 0) {
      ptr = buffer;
      while (bytes_write = write(to_fd, ptr, bytes_read)) {
        if ((bytes_write == -1) && (errno != EINTR))
          break;
        else if (bytes_write == bytes_read)
          break;
        else if (bytes_write > 0) {
          ptr += bytes_write;
          bytes_read -= bytes_write;
        }
      }
      if (bytes_write == -1)
        break;
    }
  }
  close(from_fd);
  close(to_fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b8 <main+0x48>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1225 <main+0xb5>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
mov    0x2dbb(%rip),%rax
or     (%rax),%esi
mov    0x2d6a(%rip),%rax
mov    (%rax),%edx
mov    0x2d89(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    12ad <main+0x13d>
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2d3d(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xd81(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    12b2 <main+0x142>
mov    -0x14(%rbp),%edi
lea    -0x2a(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     13b2 <main+0x242>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12f8 <main+0x188>
mov    0x2ce0(%rip),%rax
mov    (%rax),%rax
mov    0x2cce(%rip),%rcx
cmp    (%rcx),%rax
je     12f8 <main+0x188>
jmp    13b2 <main+0x242>
cmpl   $0x0,-0x1c(%rbp)
jle    13a8 <main+0x238>
lea    -0x2a(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     1394 <main+0x224>
cmpl   $0xffffffff,-0x20(%rbp)
jne    134e <main+0x1de>
mov    0x2c8a(%rip),%rax
mov    (%rax),%rax
mov    0x2c78(%rip),%rcx
cmp    (%rcx),%rax
je     134e <main+0x1de>
jmp    1394 <main+0x224>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    135f <main+0x1ef>
jmp    1394 <main+0x224>
cmpl   $0x0,-0x20(%rbp)
jle    1385 <main+0x215>
mov    -0x20(%rbp),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    138a <main+0x21a>
jmp    138f <main+0x21f>
jmp    130a <main+0x19a>
cmpl   $0xffffffff,-0x20(%rbp)
jne    13a3 <main+0x233>
jmp    13b2 <main+0x242>
jmp    13a8 <main+0x238>
jmp    13ad <main+0x23d>
jmp    12b2 <main+0x142>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11ae <main+0x3e>
mov    0x8(%rbx),%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1070 <open@plt>
cmp    $0xffffffff,%eax
jne    11d2 <main+0x62>
mov    0x2e22(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
jmp    1218 <main+0xa8>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe3f(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
mov    0x2dc1(%rip),%rax
mov    0x2e12(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dbf(%rip),%rax
mov    0x2de0(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
xor    %r13d,%r13d
xor    %eax,%eax
call   1070 <open@plt>
cmp    $0xffffffff,%eax
jne    1247 <main+0xd7>
mov    0x2db6(%rip),%rax
mov    (%rax),%ebp
mov    0x10(%rbx),%rbx
mov    0x2da1(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
lea    0xdef(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %eax,%r12d
mov    %ebp,0x8(%rsp)
mov    0x2d6b(%rip),%r14
mov    0x2d5c(%rip),%r15
jmp    1268 <main+0xf8>
xchg   %ax,%ax
mov    (%r14),%rax
cmp    (%r15),%rax
jne    12cd <main+0x15d>
mov    0x8(%rsp),%edi
lea    0xe(%rsp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     1260 <main+0xf0>
mov    %eax,%ebx
test   %eax,%eax
je     12cd <main+0x15d>
jle    1268 <main+0xf8>
lea    0xe(%rsp),%rbp
jmp    129b <main+0x12b>
nop
test   %eax,%eax
cmovs  %r13d,%eax
sub    %eax,%ebx
add    %rax,%rbp
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     12c0 <main+0x150>
test   %eax,%eax
je     1268 <main+0xf8>
cmp    %eax,%ebx
jne    1290 <main+0x120>
jmp    1268 <main+0xf8>
nopw   0x0(%rax,%rax,1)
cmp    $0xffffffff,%ebx
je     12cd <main+0x15d>
mov    (%r15),%rcx
cmp    %rcx,(%r14)
je     1290 <main+0x120>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    %r12d,%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Usage:%s fromfile tofile/n/a\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"Open %s Error:%s/n\00"
@errno = global i64 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@EINTR = global i64 0
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 i32
%10 = alloca [10 x i8]
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDONLY
%26 = call i32 (i8*, i32, ...) @open(i8* %24, i32 %25)
store i32 %26, i32* %6
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %37
28: ; preds = %21
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i64, i64* @errno
%34 = call i8* @strerror(i64 %33)
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %32, i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %21
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = load i32, i32* @O_WRONLY
%42 = load i32, i32* @O_CREAT
%43 = or i32 %41, %42
%44 = load i32, i32* @S_IRUSR
%45 = load i32, i32* @S_IWUSR
%46 = or i32 %44, %45
%47 = call i32 (i8*, i32, ...) @open(i8* %40, i32 %43, i32 %46)
store i32 %47, i32* %7
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %58
49: ; preds = %37
%50 = load i32, i32* @stderr
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = load i64, i64* @errno
%55 = call i8* @strerror(i64 %54)
%56 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %53, i8* %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %37
br label %59
59: ; preds = %116, %58
%60 = load i32, i32* %6
%61 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%62 = call i32 @read(i32 %60, i8* %61, i32 10)
store i32 %62, i32* %8
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %117
64: ; preds = %59
%65 = load i32, i32* %8
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %72
67: ; preds = %64
%68 = load i64, i64* @errno
%69 = load i64, i64* @EINTR
%70 = icmp ne i64 %68, %69
br i1 %70, label %71, label %72
71: ; preds = %67
br label %117
72: ; preds = %67, %64
%73 = load i32, i32* %8
%74 = icmp sgt i32 %73, 0
br i1 %74, label %75, label %115
75: ; preds = %72
%76 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
store i8* %76, i8** %11
br label %77
77: ; preds = %109, %75
%78 = load i32, i32* %7
%79 = load i8*, i8** %11
%80 = load i32, i32* %8
%81 = call i32 @write(i32 %78, i8* %79, i32 %80)
store i32 %81, i32* %9
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %110
83: ; preds = %77
%84 = load i32, i32* %9
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %91
86: ; preds = %83
%87 = load i64, i64* @errno
%88 = load i64, i64* @EINTR
%89 = icmp ne i64 %87, %88
br i1 %89, label %90, label %91
90: ; preds = %86
br label %110
91: ; preds = %86, %83
%92 = load i32, i32* %9
%93 = load i32, i32* %8
%94 = icmp eq i32 %92, %93
br i1 %94, label %95, label %96
95: ; preds = %91
br label %110
96: ; preds = %91
%97 = load i32, i32* %9
%98 = icmp sgt i32 %97, 0
br i1 %98, label %99, label %107
99: ; preds = %96
%100 = load i32, i32* %9
%101 = load i8*, i8** %11
%102 = sext i32 %100 to i64
%103 = getelementptr inbounds i8, i8* %101, i64 %102
store i8* %103, i8** %11
%104 = load i32, i32* %9
%105 = load i32, i32* %8
%106 = sub nsw i32 %105, %104
store i32 %106, i32* %8
br label %107
107: ; preds = %99, %96
br label %108
108: ; preds = %107
br label %109
109: ; preds = %108
br label %77
110: ; preds = %95, %90, %77
%111 = load i32, i32* %9
%112 = icmp eq i32 %111, -1
br i1 %112, label %113, label %114
113: ; preds = %110
br label %117
114: ; preds = %110
br label %115
115: ; preds = %114, %72
br label %116
116: ; preds = %115
br label %59
117: ; preds = %113, %71, %59
%118 = load i32, i32* %6
%119 = call i32 @close(i32 %118)
%120 = load i32, i32* %7
%121 = call i32 @close(i32 %120)
%122 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Usage:%s fromfile tofile/n/a\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"Open %s Error:%s/n\00"
@errno = global i64 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@EINTR = global i64 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 (i8*, i32, ...) @open(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %24
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %12
%20 = load i64, i64* @errno
%21 = tail call i8* @strerror(i64 %20)
%22 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %21)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %11
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_WRONLY
%28 = load i32, i32* @O_CREAT
%29 = or i32 %28, %27
%30 = load i32, i32* @S_IRUSR
%31 = load i32, i32* @S_IWUSR
%32 = or i32 %31, %30
%33 = tail call i32 (i8*, i32, ...) @open(i8* %26, i32 %29, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %42
35: ; preds = %24
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %25
%38 = load i64, i64* @errno
%39 = tail call i8* @strerror(i64 %38)
%40 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %37, i8* %39)
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %24, %48
%43 = call i32 @read(i32 %15, i8* %4, i32 10)
switch i32 %43, label %49 [
i32 0, label %69
i32 -1, label %44
]
44: ; preds = %42
%45 = load i64, i64* @errno
%46 = load i64, i64* @EINTR
%47 = icmp eq i64 %45, %46
br i1 %47, label %48, label %69
48: ; preds = %51, %61, %44, %49
br label %42
49: ; preds = %42
%50 = icmp sgt i32 %43, 0
br i1 %50, label %51, label %48
51: ; preds = %49, %63
%52 = phi i32 [ %66, %63 ], [ %43, %49 ]
%53 = phi i8* [ %68, %63 ], [ %4, %49 ]
%54 = call i32 @write(i32 %33, i8* %53, i32 %52)
switch i32 %54, label %61 [
i32 -1, label %55
i32 0, label %48
]
55: ; preds = %51
%56 = load i64, i64* @errno
%57 = load i64, i64* @EINTR
%58 = icmp ne i64 %56, %57
%59 = icmp eq i32 %52, -1
%60 = or i1 %59, %58
br i1 %60, label %69, label %63
61: ; preds = %51
%62 = icmp eq i32 %52, %54
br i1 %62, label %48, label %63
63: ; preds = %55, %61
%64 = icmp sgt i32 %54, 0
%65 = select i1 %64, i32 %54, i32 0
%66 = sub nsw i32 %52, %65
%67 = zext i32 %65 to i64
%68 = getelementptr i8, i8* %53, i64 %67
br label %51
69: ; preds = %42, %44, %55
%70 = tail call i32 @close(i32 %15)
%71 = tail call i32 @close(i32 %33)
%72 = tail call i32 @exit(i32 0)
unreachable
}