#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 *convert_path(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char *path1;
  char *path2;
  FILE *in;
  FILE *out;
  char *buf;
  int n_in;
  int n_out;
  if (argc != 3) {
    fprintf(stderr, "Too many arguments\n");
    exit(1);
  }
  path1 = convert_path(argv[1]);
  path2 = convert_path(argv[2]);
  in = fopen(path1, "rb");
  if (in == NULL) {
    perror("Cannot open input file");
    exit(1);
  }
  out = fopen(path2, "wb");
  if (out == NULL) {
    perror("Cannot open output file");
    fclose(in);
    exit(1);
  }
  buf = malloc((65536));
  while (!feof(in)) {
    n_in = fread(buf, 1, (65536), in);
    n_out = fwrite(buf, 1, n_in, out);
    if (n_in != n_out) {
      perror("Failed to write to output file\n");
      free(buf);
      fclose(in);
      fclose(out);
      exit(1);
    }
  }
  exit(0);
}


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)
cmpl   $0x3,-0x8(%rbp)
je     11ef <main+0x3f>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <convert_path@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <convert_path@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1246 <main+0x96>
lea    0xde0(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xddd(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1284 <main+0xd4>
lea    0xdc5(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x10000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12b0 <main+0x100>
jmp    1324 <main+0x174>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000,%edx
call   1040 <fread@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
je     131f <main+0x16f>
lea    0xd54(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1292 <main+0xe2>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    1201 <main+0x51>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   10d0 <convert_path@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
call   10d0 <convert_path@plt>
mov    %rax,%rbx
lea    0xe36(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
jne    1220 <main+0x70>
lea    0xe25(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %rax,%r15
lea    0xe04(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
jne    1248 <main+0x98>
lea    0xdf3(%rip),%rdi
call   10a0 <perror@plt>
mov    %r15,%rdi
jmp    12b8 <main+0x108>
mov    %rax,%r14
mov    $0x10000,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    12c7 <main+0x117>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x10000,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
cmp    %eax,%ebp
je     1260 <main+0xb0>
lea    0xda9(%rip),%rdi
call   10a0 <perror@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"Too many arguments\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [23 x i8] c"Cannot open input file\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [24 x i8] c"Cannot open output file\00"
@.str.5 = [32 x i8] c"Failed to write to output file\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%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 i8* @convert_path(i8* %22)
store i8* %23, i8** %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i8* @convert_path(i8* %26)
store i8* %27, i8** %7
%28 = load i8*, i8** %6
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %8
%30 = load i32*, i32** %8
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %19
%33 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %19
%36 = load i8*, i8** %7
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %37, i32** %9
%38 = load i32*, i32** %9
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%42 = load i32*, i32** %8
%43 = call i32 @fclose(i32* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %35
%46 = call i8* @malloc(i32 65536)
store i8* %46, i8** %10
br label %47
47: ; preds = %72, %45
%48 = load i32*, i32** %8
%49 = call i32 @feof(i32* %48)
%50 = icmp ne i32 %49, 0
%51 = xor i1 %50, true
br i1 %51, label %52, label %73
52: ; preds = %47
%53 = load i8*, i8** %10
%54 = load i32*, i32** %8
%55 = call i32 @fread(i8* %53, i32 1, i32 65536, i32* %54)
store i32 %55, i32* %11
%56 = load i8*, i8** %10
%57 = load i32, i32* %11
%58 = load i32*, i32** %9
%59 = call i32 @fwrite(i8* %56, i32 1, i32 %57, i32* %58)
store i32 %59, i32* %12
%60 = load i32, i32* %11
%61 = load i32, i32* %12
%62 = icmp ne i32 %60, %61
br i1 %62, label %63, label %72
63: ; preds = %52
%64 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%65 = load i8*, i8** %10
%66 = call i32 @free(i8* %65)
%67 = load i32*, i32** %8
%68 = call i32 @fclose(i32* %67)
%69 = load i32*, i32** %9
%70 = call i32 @fclose(i32* %69)
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %52
br label %47
73: ; preds = %47
%74 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"Too many arguments\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [23 x i8] c"Cannot open input file\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [24 x i8] c"Cannot open output file\00"
@.str.5 = [32 x i8] c"Failed to write to output file\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i8* @convert_path(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i8* @convert_path(i8* %13)
%15 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %8
%18 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %8
%21 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%25 = tail call i32 @fclose(i32* %15)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = tail call dereferenceable_or_null(65536) i8* @malloc(i32 65536)
br label %29
29: ; preds = %32, %27
%30 = tail call i32 @feof(i32* %15)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %29
%33 = tail call i32 @fread(i8* %28, i32 1, i32 65536, i32* %15)
%34 = tail call i32 @fwrite(i8* %28, i32 1, i32 %33, i32* %21)
%35 = icmp eq i32 %33, %34
br i1 %35, label %29, label %36
36: ; preds = %32
%37 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%38 = tail call i32 @free(i8* %28)
%39 = tail call i32 @fclose(i32* %15)
%40 = tail call i32 @fclose(i32* %21)
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %29
%43 = tail call i32 @exit(i32 0)
unreachable
}