#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 */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  FILE *fi, *fo;
  char *buf;
  size_t n = (1024 * 4), i;
  if (argc != 3) {
    printf("E: Need 2 filenames as arguments.\n");
    return EXIT_FAILURE;
  }
  if ((fi = fopen(argv[1], "r")) == NULL) {
    perror("E: Can not open input file");
    return EXIT_FAILURE;
  }
  if ((fo = fopen(argv[2], "w")) == NULL) {
    perror("E: Can not open output file");
    return EXIT_FAILURE;
  }
  if ((buf = (char *)malloc(n)) == NULL) {
    perror("E: Can not make a buffer");
    exit(EXIT_FAILURE);
  }
  for (;;) {
    i = fread(buf, 1, n, fi);
    if (ferror(fi)) {
      perror("E: Error reading input file");
      exit(EXIT_FAILURE);
    } else if (i == 0) {
      break;
    } else {
      if (fwrite(buf, 1, i, fo) != i) {
        perror("E: Error writing output file");
        exit(EXIT_FAILURE);
      }
    }
  }
  if (fclose(fi)) {
    perror("E: Can not close input file");
    exit(EXIT_FAILURE);
  }
  if (fclose(fo)) {
    perror("E: Can not close output file");
    exit(EXIT_FAILURE);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1000,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11d5 <main+0x45>
lea    0xe41(%rip),%rdi
call   1060 <printf@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    138f <main+0x1ff>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1214 <main+0x84>
lea    0xe25(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    138f <main+0x1ff>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe1b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1253 <main+0xc3>
lea    0xe03(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    138f <main+0x1ff>
mov    -0x30(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1284 <main+0xf4>
lea    0xdeb(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1289 <main+0xf9>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12d0 <main+0x140>
lea    0xdb8(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x38(%rbp)
jne    12e0 <main+0x150>
jmp    1329 <main+0x199>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
cmp    -0x38(%rbp),%rax
je     131a <main+0x18a>
lea    0xd8a(%rip),%rdi
call   1090 <perror@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    131f <main+0x18f>
jmp    1324 <main+0x194>
jmp    1289 <main+0xf9>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     1356 <main+0x1c6>
lea    0xd6b(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     1383 <main+0x1f3>
lea    0xd5a(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2c4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    124f <main+0xbf>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xea1(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1293 <main+0x103>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xe50(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     129c <main+0x10c>
mov    %rax,%r14
mov    $0x1000,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     12cb <main+0x13b>
mov    %rax,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x1000,%edx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   1050 <fread@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    12b1 <main+0x121>
test   %rbx,%rbx
je     1264 <main+0xd4>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   10b0 <fwrite@plt>
cmp    %rbx,%rax
je     1200 <main+0x70>
lea    0xe21(%rip),%rdi
jmp    12b8 <main+0x128>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d7e(%rip),%rax
jmp    1285 <main+0xf5>
mov    %r15,%rdi
call   1060 <fclose@plt>
test   %rax,%rax
jne    12d4 <main+0x144>
mov    %r14,%rdi
call   1060 <fclose@plt>
test   %rax,%rax
jne    12dd <main+0x14d>
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd66(%rip),%rdi
jmp    12a3 <main+0x113>
lea    0xd7a(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d31(%rip),%rax
jmp    1285 <main+0xf5>
lea    0xd9a(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xd67(%rip),%rdi
jmp    12b8 <main+0x128>
lea    0xdb0(%rip),%rdi
jmp    12b8 <main+0x128>
lea    0xdc3(%rip),%rdi
jmp    12b8 <main+0x128>

LLVM IR (-O0):
@.str = [35 x i8] c"E: Need 2 filenames as arguments.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"E: Can not open input file\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [28 x i8] c"E: Can not open output file\00"
@.str.5 = [25 x i8] c"E: Can not make a buffer\00"
@.str.6 = [28 x i8] c"E: Error reading input file\00"
@.str.7 = [29 x i8] c"E: Error writing output file\00"
@.str.8 = [28 x i8] c"E: Can not close input file\00"
@.str.9 = [29 x i8] c"E: Can not close output file\00"
@EXIT_SUCCESS = global i32 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 i8*
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 4096, i64* %9
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %3
br label %92
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
store i32 %24, i32* %3
br label %92
25: ; preds = %16
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %29, i32** %7
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
store i32 %33, i32* %3
br label %92
34: ; preds = %25
%35 = load i64, i64* %9
%36 = call i64 @malloc(i64 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %8
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %34
br label %44
44: ; preds = %73, %43
%45 = load i8*, i8** %8
%46 = load i64, i64* %9
%47 = load i32*, i32** %6
%48 = call i64 @fread(i8* %45, i32 1, i64 %46, i32* %47)
store i64 %48, i64* %10
%49 = load i32*, i32** %6
%50 = call i64 @ferror(i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %44
%53 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %44
%57 = load i64, i64* %10
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %56
br label %74
60: ; preds = %56
%61 = load i8*, i8** %8
%62 = load i64, i64* %10
%63 = load i32*, i32** %7
%64 = call i64 @fwrite(i8* %61, i32 1, i64 %62, i32* %63)
%65 = load i64, i64* %10
%66 = icmp ne i64 %64, %65
br i1 %66, label %67, label %71
67: ; preds = %60
%68 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %60
br label %72
72: ; preds = %71
br label %73
73: ; preds = %72
br label %44
74: ; preds = %59
%75 = load i32*, i32** %6
%76 = call i64 @fclose(i32* %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %74
%79 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%80 = load i32, i32* @EXIT_FAILURE
%81 = call i32 @exit(i32 %80)
unreachable
82: ; preds = %74
%83 = load i32*, i32** %7
%84 = call i64 @fclose(i32* %83)
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %90
86: ; preds = %82
%87 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0))
%88 = load i32, i32* @EXIT_FAILURE
%89 = call i32 @exit(i32 %88)
unreachable
90: ; preds = %82
%91 = load i32, i32* @EXIT_SUCCESS
store i32 %91, i32* %3
br label %92
92: ; preds = %90, %31, %22, %13
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"E: Can not open input file\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [28 x i8] c"E: Can not open output file\00"
@.str.5 = [25 x i8] c"E: Can not make a buffer\00"
@.str.6 = [28 x i8] c"E: Error reading input file\00"
@.str.7 = [29 x i8] c"E: Error writing output file\00"
@.str.8 = [28 x i8] c"E: Can not close input file\00"
@.str.9 = [29 x i8] c"E: Can not close output file\00"
@EXIT_SUCCESS = global i32 0
@str = [34 x i8] c"E: Need 2 filenames as arguments.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %59
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %59
13: ; preds = %6
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %59
20: ; preds = %13
%21 = tail call i64 @malloc(i64 4096)
%22 = inttoptr i64 %21 to i8*
%23 = icmp eq i64 %21, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %20, %38
%29 = tail call i64 @fread(i8* %22, i32 1, i64 4096, i32* %9)
%30 = tail call i64 @ferror(i32* %9)
%31 = icmp eq i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %28
%37 = icmp eq i64 %29, 0
br i1 %37, label %45, label %38
38: ; preds = %36
%39 = tail call i64 @fwrite(i8* %22, i32 1, i64 %29, i32* %16)
%40 = icmp eq i64 %39, %29
br i1 %40, label %28, label %41
41: ; preds = %38
%42 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = tail call i32 @exit(i32 %43)
unreachable
45: ; preds = %36
%46 = tail call i64 @fclose(i32* %9)
%47 = icmp eq i64 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %45
%49 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = tail call i32 @exit(i32 %50)
unreachable
52: ; preds = %45
%53 = tail call i64 @fclose(i32* %16)
%54 = icmp eq i64 %53, 0
br i1 %54, label %59, label %55
55: ; preds = %52
%56 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
%58 = tail call i32 @exit(i32 %57)
unreachable
59: ; preds = %52, %18, %11, %4
%60 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_FAILURE, %11 ], [ @EXIT_FAILURE, %18 ], [ @EXIT_SUCCESS, %52 ]
%61 = load i32, i32* %60
ret i32 %61
}