#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  char f1[1024], f2[1024];
  char *filename1 = NULL;
  char *filename2 = NULL;
  FILE *fp1 = NULL;
  FILE *fp2 = NULL;
  int bytes;
  char c, d;
  if (argc < 3) {
    printf("Usage: %s <file-to-read> <file-to-write>\n", argv[0]);
    return argc;
  }
  filename1 = argv[1];
  filename2 = argv[2];
  printf("Reading file %s\n", filename1);
  printf("Writing file %s\n", filename2);
  fp1 = fopen(filename1, "r");
  fp2 = fopen(filename2, "w");
  if (!fp1) {
    printf("cannot open %s for read\n", filename1);
    return -1;
  }
  if (!fp2) {
    printf("cannot open %s for write\n", filename2);
    return -2;
  }
  while ((c = fgetc(fp1)) != EOF) {
    bytes++;
    printf("%c", c);
    if ((d = fputc(c, fp2)) == EOF) {
      printf("write error to file %s\n", filename2);
      return -3;
    }
  }
  c = EOF;
  printf("\nsup: EOF is %d, %u, %x\n", c, c, c);
  fclose(fp1);
  fclose(fp2);
  printf("Copied %d bytes from %s to %s\n", bytes, filename1, filename2);
  sprintf(f1, "shasum %s", filename1);
  sprintf(f2, "shasum %s", filename2);
  system(f1);
  system(f2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x818(%rbp)
movq   $0x0,-0x820(%rbp)
movq   $0x0,-0x828(%rbp)
movq   $0x0,-0x830(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11df <main+0x6f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    141e <main+0x2ae>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x818(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x820(%rbp)
mov    -0x818(%rbp),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x820(%rbp),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x818(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x828(%rbp)
mov    -0x820(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x830(%rbp)
cmpq   $0x0,-0x828(%rbp)
jne    128a <main+0x11a>
mov    -0x818(%rbp),%rsi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    141e <main+0x2ae>
cmpq   $0x0,-0x830(%rbp)
jne    12b9 <main+0x149>
mov    -0x820(%rbp),%rsi
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    141e <main+0x2ae>
jmp    12be <main+0x14e>
mov    -0x828(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x835(%rbp)
movsbl %al,%eax
mov    0x2d0e(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     135f <main+0x1ef>
mov    -0x834(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x834(%rbp)
movsbl -0x835(%rbp),%esi
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x835(%rbp),%al
mov    -0x830(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
mov    %al,-0x836(%rbp)
movsbl %al,%eax
mov    0x2cba(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    135a <main+0x1ea>
mov    -0x820(%rbp),%rsi
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    141e <main+0x2ae>
jmp    12be <main+0x14e>
mov    0x2c82(%rip),%rax
mov    (%rax),%al
mov    %al,-0x835(%rbp)
movsbl -0x835(%rbp),%esi
movsbl -0x835(%rbp),%edx
movsbl -0x835(%rbp),%ecx
lea    0xd14(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x828(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x830(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x834(%rbp),%esi
mov    -0x818(%rbp),%rdx
mov    -0x820(%rbp),%rcx
lea    0xcf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x818(%rbp),%rdx
lea    0xcf6(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x810(%rbp),%rdi
mov    -0x820(%rbp),%rdx
lea    0xcdc(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x410(%rbp),%rdi
call   1040 <system@plt>
lea    -0x810(%rbp),%rdi
call   1040 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
cmp    $0x2,%edi
jg     11af <main+0x2f>
mov    %edi,%r12d
mov    (%rsi),%rsi
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1326 <main+0x1a6>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%r12
lea    0xe6c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6c(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%r15
lea    0xe5c(%rip),%rsi
mov    %r12,%rdi
call   1090 <fopen@plt>
test   %r15,%r15
je     1266 <main+0xe6>
mov    %rax,%r13
test   %rax,%rax
je     1282 <main+0x102>
mov    %rbx,0x8(%rsp)
mov    0x2dd5(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1070 <fgetc@plt>
movsbl %al,%r14d
cmp    (%rbx),%al
je     129e <main+0x11e>
add    $0x1,%ebp
mov    %r14d,%edi
call   1030 <putchar@plt>
mov    %r14d,%edi
mov    %r13,%rsi
call   1080 <fputc@plt>
cmp    (%rbx),%al
jne    1220 <main+0xa0>
lea    0xe32(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xfffffffd,%r12d
jmp    1326 <main+0x1a6>
lea    0xde3(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%r12d
jmp    1326 <main+0x1a6>
lea    0xde0(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xfffffffe,%r12d
jmp    1326 <main+0x1a6>
lea    0xdf6(%rip),%rdi
mov    %r12,%rbx
xor    %r12d,%r12d
mov    %r14d,%esi
mov    %r14d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
lea    0xde2(%rip),%rdi
mov    %ebp,%esi
mov    0x8(%rsp),%rbp
mov    %rbp,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xde6(%rip),%r13
lea    0x410(%rsp),%r14
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   10a0 <sprintf@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   10a0 <sprintf@plt>
mov    %r14,%rdi
call   1050 <system@plt>
mov    %r15,%rdi
call   1050 <system@plt>
mov    %r12d,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Usage: %s <file-to-read> <file-to-write>\0A\00"
@.str.1 = [17 x i8] c"Reading file %s\0A\00"
@.str.2 = [17 x i8] c"Writing file %s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [25 x i8] c"cannot open %s for read\0A\00"
@.str.6 = [26 x i8] c"cannot open %s for write\0A\00"
@EOF = global i8 0
@.str.7 = [3 x i8] c"%c\00"
@.str.8 = [24 x i8] c"write error to file %s\0A\00"
@.str.9 = [25 x i8] c"\0Asup: EOF is %d, %u, %x\0A\00"
@.str.10 = [31 x i8] c"Copied %d bytes from %s to %s\0A\00"
@.str.11 = [10 x i8] c"shasum %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i8
%14 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
store i8* null, i8** %9
store i32* null, i32** %10
store i32* null, i32** %11
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* %4
store i32 %22, i32* %3
br label %101
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %8
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
store i8* %29, i8** %9
%30 = load i8*, i8** %8
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %9
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %8
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %35, i32** %10
%36 = load i8*, i8** %9
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %37, i32** %11
%38 = load i32*, i32** %10
%39 = icmp ne i32* %38, null
br i1 %39, label %43, label %40
40: ; preds = %23
%41 = load i8*, i8** %8
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %41)
store i32 -1, i32* %3
br label %101
43: ; preds = %23
%44 = load i32*, i32** %11
%45 = icmp ne i32* %44, null
br i1 %45, label %49, label %46
46: ; preds = %43
%47 = load i8*, i8** %9
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %47)
store i32 -2, i32* %3
br label %101
49: ; preds = %43
br label %50
50: ; preds = %73, %49
%51 = load i32*, i32** %10
%52 = call signext i8 @fgetc(i32* %51)
store i8 %52, i8* %13
%53 = sext i8 %52 to i32
%54 = load i8, i8* @EOF
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %53, %55
br i1 %56, label %57, label %74
57: ; preds = %50
%58 = load i32, i32* %12
%59 = add nsw i32 %58, 1
store i32 %59, i32* %12
%60 = load i8, i8* %13
%61 = sext i8 %60 to i32
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %61)
%63 = load i8, i8* %13
%64 = load i32*, i32** %11
%65 = call signext i8 @fputc(i8 signext %63, i32* %64)
store i8 %65, i8* %14
%66 = sext i8 %65 to i32
%67 = load i8, i8* @EOF
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %66, %68
br i1 %69, label %70, label %73
70: ; preds = %57
%71 = load i8*, i8** %9
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* %71)
store i32 -3, i32* %3
br label %101
73: ; preds = %57
br label %50
74: ; preds = %50
%75 = load i8, i8* @EOF
store i8 %75, i8* %13
%76 = load i8, i8* %13
%77 = sext i8 %76 to i32
%78 = load i8, i8* %13
%79 = sext i8 %78 to i32
%80 = load i8, i8* %13
%81 = sext i8 %80 to i32
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %77, i32 %79, i32 %81)
%83 = load i32*, i32** %10
%84 = call i32 @fclose(i32* %83)
%85 = load i32*, i32** %11
%86 = call i32 @fclose(i32* %85)
%87 = load i32, i32* %12
%88 = load i8*, i8** %8
%89 = load i8*, i8** %9
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i32 %87, i8* %88, i8* %89)
%91 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%92 = load i8*, i8** %8
%93 = call i32 @sprintf(i8* %91, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* %92)
%94 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%95 = load i8*, i8** %9
%96 = call i32 @sprintf(i8* %94, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* %95)
%97 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%98 = call i32 @system(i8* %97)
%99 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%100 = call i32 @system(i8* %99)
store i32 0, i32* %3
br label %101
101: ; preds = %74, %70, %46, %40, %17
%102 = load i32, i32* %3
ret i32 %102
}

LLVM IR (-O2):
@.str = [42 x i8] c"Usage: %s <file-to-read> <file-to-write>\0A\00"
@.str.1 = [17 x i8] c"Reading file %s\0A\00"
@.str.2 = [17 x i8] c"Writing file %s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [25 x i8] c"cannot open %s for read\0A\00"
@.str.6 = [26 x i8] c"cannot open %s for write\0A\00"
@EOF = global i8 0
@.str.8 = [24 x i8] c"write error to file %s\0A\00"
@.str.9 = [25 x i8] c"\0Asup: EOF is %d, %u, %x\0A\00"
@.str.10 = [31 x i8] c"Copied %d bytes from %s to %s\0A\00"
@.str.11 = [10 x i8] c"shasum %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %50
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%18 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i32* %18, null
br i1 %20, label %21, label %23
21: ; preds = %11
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %13)
br label %50
23: ; preds = %11
%24 = icmp eq i32* %19, null
br i1 %24, label %25, label %27
25: ; preds = %23
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %15)
br label %50
27: ; preds = %23, %33
%28 = phi i32 [ %34, %33 ], [ undef, %23 ]
%29 = tail call signext i8 @fgetc(i32* %18)
%30 = load i8, i8* @EOF
%31 = icmp eq i8 %29, %30
%32 = sext i8 %29 to i32
br i1 %31, label %41, label %33
33: ; preds = %27
%34 = add nsw i32 %28, 1
%35 = tail call i32 @putchar(i32 %32)
%36 = tail call signext i8 @fputc(i8 signext %29, i32* %19)
%37 = load i8, i8* @EOF
%38 = icmp eq i8 %36, %37
br i1 %38, label %39, label %27
39: ; preds = %33
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* %15)
br label %50
41: ; preds = %27
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %32, i32 %32, i32 %32)
%43 = tail call i32 @fclose(i32* %18)
%44 = tail call i32 @fclose(i32* %19)
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i32 %28, i8* %13, i8* %15)
%46 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* %13)
%47 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* %15)
%48 = call i32 @system(i8* %5)
%49 = call i32 @system(i8* %6)
br label %50
50: ; preds = %41, %39, %25, %21, %8
%51 = phi i32 [ %0, %8 ], [ -3, %39 ], [ 0, %41 ], [ -2, %25 ], [ -1, %21 ]
ret i32 %51
}