#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_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int write(int, char *, int);
int main(int argc, char **argv) {
  int fd_from, fd_to;
  if (argc != 3) {
    fprintf(stderr, "Uage: %s <file_src> <file_dest>", argv[0]);
    exit(-1);
  }
  if ((fd_from = open(argv[1], O_RDONLY)) == -1) {
    fprintf(stderr, "open %s fail: %s\n", argv[1], strerror(errno));
    exit(-1);
  }
  if ((fd_to = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) {
    fprintf(stderr, "open %s fail: %s\n", argv[2], strerror(errno));
    exit(-1);
  }
  char buf[32];
  char *bp;
  int bytes_read, bytes_written;
  while (1) {
    while (((bytes_read = read(fd_from, buf, 32)) == -1) && (errno == EINTR))
      ;
    if (bytes_read <= 0)
      break;
    bp = buf;
    while (bytes_read > 0) {
      while (((bytes_written = write(fd_to, bp, bytes_read)) == -1) &&
             (errno == EINTR))
        ;
      if (bytes_written <= 0) {
        perror("write failed");
        break;
      }
      bytes_read -= bytes_written;
      bp += bytes_written;
    }
  }
  close(fd_from);
  close(fd_to);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11c8 <main+0x48>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1235 <main+0xb5>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x58(%rbp)
mov    0x2db5(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
mov    0x2dab(%rip),%rax
or     (%rax),%esi
mov    0x2d9a(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    12b9 <main+0x139>
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x68(%rbp)
mov    0x2d31(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xd78(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    12be <main+0x13e>
jmp    12c3 <main+0x143>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1050 <read@plt>
mov    %eax,%ecx
mov    %ecx,-0x4c(%rbp)
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x6d(%rbp)
jne    1301 <main+0x181>
mov    0x2cd2(%rip),%rax
mov    (%rax),%rax
mov    0x2cc0(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x6d(%rbp)
mov    -0x6d(%rbp),%al
test   $0x1,%al
jne    1311 <main+0x191>
jmp    1316 <main+0x196>
jmp    12c3 <main+0x143>
cmpl   $0x0,-0x4c(%rbp)
jg     1325 <main+0x1a5>
jmp    13ce <main+0x24e>
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jle    13c9 <main+0x249>
jmp    133c <main+0x1bc>
mov    -0x18(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    %ecx,-0x50(%rbp)
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x6e(%rbp)
jne    1378 <main+0x1f8>
mov    0x2c5b(%rip),%rax
mov    (%rax),%rax
mov    0x2c49(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x6e(%rbp)
mov    -0x6e(%rbp),%al
test   $0x1,%al
jne    1388 <main+0x208>
jmp    138d <main+0x20d>
jmp    133c <main+0x1bc>
cmpl   $0x0,-0x50(%rbp)
jg     13a8 <main+0x228>
lea    0xc94(%rip),%rdi
call   1080 <perror@plt>
jmp    13c9 <main+0x249>
mov    -0x50(%rbp),%ecx
mov    -0x4c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x50(%rbp),%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
jmp    132d <main+0x1ad>
jmp    12be <main+0x13e>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    128a <main+0x10a>
mov    0x8(%r14),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     12ae <main+0x12e>
mov    %eax,%r12d
mov    0x2de7(%rip),%rax
mov    0x2e30(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%r14),%rdi
mov    0x2e19(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
xor    %eax,%eax
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     12bd <main+0x13d>
mov    %eax,%r13d
mov    0x2dc8(%rip),%r15
mov    0x2db9(%rip),%r14
jmp    1210 <main+0x90>
lea    0xe2a(%rip),%rdi
call   1080 <perror@plt>
nopl   (%rax)
mov    %r12d,%edi
mov    %rsp,%rsi
mov    $0x20,%edx
call   1050 <read@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    122f <main+0xaf>
mov    (%r14),%rax
cmp    %rax,(%r15)
je     1210 <main+0x90>
test   %ebx,%ebx
jle    1269 <main+0xe9>
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    125a <main+0xda>
mov    (%r14),%rcx
cmp    %rcx,(%r15)
je     1240 <main+0xc0>
test   %eax,%eax
jle    1201 <main+0x81>
mov    %eax,%ecx
add    %rcx,%rbp
sub    %eax,%ebx
jg     1240 <main+0xc0>
jmp    1210 <main+0x90>
mov    %r12d,%edi
call   1040 <close@plt>
mov    %r13d,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd63(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r14),%rbp
jmp    12ca <main+0x14a>
mov    0x2d04(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%r14),%rbp
mov    0x2cef(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
lea    0xd40(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Uage: %s <file_src> <file_dest>\00"
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"open %s fail: %s\0A\00"
@errno = global i64 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@EINTR = global i64 0
@.str.2 = [13 x i8] c"write failed\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 [32 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
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 ([32 x i8], [32 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 ([18 x i8], [18 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* @O_TRUNC
%45 = or i32 %43, %44
%46 = call i32 (i8*, i32, ...) @open(i8* %40, i32 %45, i32 420)
store i32 %46, i32* %7
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %57
48: ; preds = %37
%49 = load i32, i32* @stderr
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = load i64, i64* @errno
%54 = call i8* @strerror(i64 %53)
%55 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %52, i8* %54)
%56 = call i32 @exit(i32 -1)
unreachable
57: ; preds = %37
br label %58
58: ; preds = %57, %107
br label %59
59: ; preds = %70, %58
%60 = load i32, i32* %6
%61 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%62 = call i32 @read(i32 %60, i8* %61, i32 32)
store i32 %62, i32* %10
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %68
64: ; preds = %59
%65 = load i64, i64* @errno
%66 = load i64, i64* @EINTR
%67 = icmp eq i64 %65, %66
br label %68
68: ; preds = %64, %59
%69 = phi i1 [ false, %59 ], [ %67, %64 ]
br i1 %69, label %70, label %71
70: ; preds = %68
br label %59
71: ; preds = %68
%72 = load i32, i32* %10
%73 = icmp sle i32 %72, 0
br i1 %73, label %74, label %75
74: ; preds = %71
br label %108
75: ; preds = %71
%76 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
store i8* %76, i8** %9
br label %77
77: ; preds = %99, %75
%78 = load i32, i32* %10
%79 = icmp sgt i32 %78, 0
br i1 %79, label %80, label %107
80: ; preds = %77
br label %81
81: ; preds = %93, %80
%82 = load i32, i32* %7
%83 = load i8*, i8** %9
%84 = load i32, i32* %10
%85 = call i32 @write(i32 %82, i8* %83, i32 %84)
store i32 %85, i32* %11
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %91
87: ; preds = %81
%88 = load i64, i64* @errno
%89 = load i64, i64* @EINTR
%90 = icmp eq i64 %88, %89
br label %91
91: ; preds = %87, %81
%92 = phi i1 [ false, %81 ], [ %90, %87 ]
br i1 %92, label %93, label %94
93: ; preds = %91
br label %81
94: ; preds = %91
%95 = load i32, i32* %11
%96 = icmp sle i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %94
%98 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %107
99: ; preds = %94
%100 = load i32, i32* %11
%101 = load i32, i32* %10
%102 = sub nsw i32 %101, %100
store i32 %102, i32* %10
%103 = load i32, i32* %11
%104 = load i8*, i8** %9
%105 = sext i32 %103 to i64
%106 = getelementptr inbounds i8, i8* %104, i64 %105
store i8* %106, i8** %9
br label %77
107: ; preds = %97, %77
br label %58
108: ; preds = %74
%109 = load i32, i32* %6
%110 = call i32 @close(i32 %109)
%111 = load i32, i32* %7
%112 = call i32 @close(i32 %111)
ret i32 0
}

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