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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char **, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Usage: cp source destination\n");
    return 1;
  }
  FILE *fp = fopen(argv[1], "r");
  FILE *fcp = fopen(argv[2], "w+");
  if (fp == NULL || fcp == NULL)
    return 1;
  char *buffer[(1024 * 1024)];
  size_t bytes;
  while ((bytes = fread(buffer, 1, sizeof(buffer), fp)) > 0)
    fwrite(buffer, 1, bytes, fcp);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x800030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118b <main+0x3b>
lea    0xe86(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123e <main+0xee>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe84(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe6e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d1 <main+0x81>
cmpq   $0x0,-0x20(%rbp)
jne    11dd <main+0x8d>
movl   $0x1,-0x4(%rbp)
jmp    123e <main+0xee>
jmp    11e2 <main+0x92>
lea    -0x800020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x800000,%edx
call   1030 <fread@plt>
mov    %rax,-0x800028(%rbp)
cmp    $0x0,%rax
jbe    122e <main+0xde>
lea    -0x800020(%rbp),%rdi
mov    -0x800028(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
jmp    11e2 <main+0x92>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x800030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x800000,%rsp
cmp    $0x3,%edi
jne    11f9 <main+0xa9>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
mov    $0x1,%eax
test   %r14,%r14
je     120a <main+0xba>
test   %r15,%r15
je     120a <main+0xba>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x800000,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     11ed <main+0x9d>
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r15,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x800000,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jne    11c0 <main+0x70>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    120a <main+0xba>
lea    0xe05(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x800000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Usage: cp source destination\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"w+\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 [1048576 x i8*]
%9 = alloca i64
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 %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %43
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %7
%23 = load i32*, i32** %6
%24 = icmp eq i32* %23, null
br i1 %24, label %28, label %25
25: ; preds = %14
%26 = load i32*, i32** %7
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %29
28: ; preds = %25, %14
store i32 1, i32* %3
br label %43
29: ; preds = %25
br label %30
30: ; preds = %35, %29
%31 = getelementptr inbounds [1048576 x i8*], [1048576 x i8*]* %8, i64 0, i64 0
%32 = load i32*, i32** %6
%33 = call i64 @fread(i8** %31, i32 1, i32 8388608, i32* %32)
store i64 %33, i64* %9
%34 = icmp ugt i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = getelementptr inbounds [1048576 x i8*], [1048576 x i8*]* %8, i64 0, i64 0
%37 = load i64, i64* %9
%38 = load i32*, i32** %7
%39 = call i32 @fwrite(i8** %36, i32 1, i64 %37, i32* %38)
br label %30
40: ; preds = %30
%41 = load i32*, i32** %6
%42 = call i32 @fclose(i32* %41)
store i32 0, i32* %3
br label %43
43: ; preds = %40, %28, %12
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"w+\00"
@str = [29 x i8] c"Usage: cp source destination\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1048576 x i8*]
%4 = icmp eq i32 %0, 3
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %29
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %10, null
%15 = icmp eq i32* %13, null
%16 = or i1 %14, %15
br i1 %16, label %29, label %17
17: ; preds = %7
%18 = bitcast [1048576 x i8*]* %3 to i8*
%19 = getelementptr inbounds [1048576 x i8*], [1048576 x i8*]* %3, i64 0, i64 0
%20 = call i64 @fread(i8** %19, i32 1, i32 8388608, i32* %10)
%21 = icmp eq i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %17, %22
%23 = phi i64 [ %25, %22 ], [ %20, %17 ]
%24 = call i32 @fwrite(i8** %19, i32 1, i64 %23, i32* %13)
%25 = call i64 @fread(i8** %19, i32 1, i32 8388608, i32* %10)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %22
27: ; preds = %22, %17
%28 = tail call i32 @fclose(i32* %10)
br label %29
29: ; preds = %27, %7, %5
%30 = phi i32 [ 1, %5 ], [ 0, %27 ], [ 1, %7 ]
ret i32 %30
}