#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EINTR;
int EOF;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int main(int argc, char **argv) {
  FILE *fp_from, *fp_to;
  if (argc != 3) {
    fprintf(stderr, "Uage: %s <file_src> <file_dest>", argv[0]);
    exit(-1);
  }
  if ((fp_from = fopen(argv[1], "r+")) == NULL) {
    fprintf(stderr, "fopen %s fail: %s\n", argv[1], strerror(errno));
    exit(-1);
  }
  if ((fp_to = fopen(argv[2], "w+")) == NULL) {
    fprintf(stderr, "fopen %s fail: %s\n", argv[2], strerror(errno));
    exit(-1);
  }
  int ret_fgetc, ret_fputc;
  while (1) {
    ret_fgetc = fgetc(fp_from);
    if ((ret_fgetc == EOF) && (ferror(fp_from)) && (errno == EINTR))
      continue;
    else if ((ret_fgetc == EOF) && (ferror(fp_from)) && (errno != EINTR)) {
      perror("fgetc failed");
      exit(-1);
    } else if ((ret_fgetc == EOF) && (feof(fp_from)))
      break;
    else {
      while (1) {
        ret_fputc = fputc(ret_fgetc, fp_to);
        if ((ret_fputc == EOF) && (errno == EINTR))
          continue;
        else if ((ret_fputc == EOF) && (errno != EINTR)) {
          perror("fputc failed");
          exit(-2);
        }
        break;
      }
    }
  }
  fclose(fp_from);
  fclose(fp_to);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11e8 <main+0x48>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe29(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1253 <main+0xb3>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2da7(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdd4(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12be <main+0x11e>
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d3c(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xd76(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
jmp    12c3 <main+0x123>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2d0f(%rip),%rcx
cmp    (%rcx),%eax
jne    1313 <main+0x173>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1313 <main+0x173>
mov    0x2cd5(%rip),%rax
mov    (%rax),%rax
mov    0x2cc3(%rip),%rcx
cmp    (%rcx),%rax
jne    1313 <main+0x173>
jmp    12c3 <main+0x123>
mov    -0x24(%rbp),%eax
mov    0x2ccb(%rip),%rcx
cmp    (%rcx),%eax
jne    1368 <main+0x1c8>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1368 <main+0x1c8>
mov    0x2c91(%rip),%rax
mov    (%rax),%rax
mov    0x2c7f(%rip),%rcx
cmp    (%rcx),%rax
je     1368 <main+0x1c8>
lea    0xce0(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0x24(%rbp),%eax
mov    0x2c76(%rip),%rcx
cmp    (%rcx),%eax
jne    1392 <main+0x1f2>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     1392 <main+0x1f2>
jmp    1437 <main+0x297>
jmp    1397 <main+0x1f7>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <fputc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2c38(%rip),%rcx
cmp    (%rcx),%eax
jne    13d7 <main+0x237>
mov    0x2c11(%rip),%rax
mov    (%rax),%rax
mov    0x2bff(%rip),%rcx
cmp    (%rcx),%rax
jne    13d7 <main+0x237>
jmp    1397 <main+0x1f7>
mov    -0x28(%rbp),%eax
mov    0x2c07(%rip),%rcx
cmp    (%rcx),%eax
jne    1419 <main+0x279>
mov    0x2be0(%rip),%rax
mov    (%rax),%rax
mov    0x2bce(%rip),%rcx
cmp    (%rcx),%rax
je     1419 <main+0x279>
lea    0xc3c(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xfffffffe,%edi
call   10b0 <exit@plt>
jmp    141e <main+0x27e>
jmp    1423 <main+0x283>
jmp    1428 <main+0x288>
jmp    142d <main+0x28d>
jmp    1432 <main+0x292>
jmp    12c3 <main+0x123>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    12c6 <main+0x126>
mov    0x8(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12eb <main+0x14b>
mov    %rax,%r14
mov    0x10(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12fa <main+0x15a>
mov    %rax,%rbx
mov    0x2df2(%rip),%r15
mov    0x2dd3(%rip),%r12
mov    0x2dc4(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
jne    1260 <main+0xc0>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1236 <main+0x96>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1210 <main+0x70>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     124d <main+0xad>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
jne    12b0 <main+0x110>
mov    %r14,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    128f <main+0xef>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
cmp    (%r15),%eax
jne    1210 <main+0x70>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1260 <main+0xc0>
lea    0xdc6(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xfffffffe,%edi
call   10b0 <exit@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd82(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xd26(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rbp),%rbp
jmp    1307 <main+0x167>
mov    0x2cd7(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%rbp),%rbp
mov    0x2cc2(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xd06(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

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

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