#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Usage: cp <src> <dest>\n");
    exit(1);
  }
  FILE *src, *dest;
  if ((src = fopen(argv[1], "r")) == NULL) {
    printf("Unable to open file '%s'\n", argv[1]);
    exit(1);
  }
  if ((dest = fopen(argv[2], "w")) == NULL) {
    printf("Unable to open/write file '%s'\n", argv[2]);
    exit(1);
  }
  char curr;
  while ((curr = getc(src)) != EOF) {
    putc(curr, dest);
  }
  if (src != NULL) {
    fclose(src);
  }
  if (dest != NULL) {
    fclose(dest);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1198 <main+0x38>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe71(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11da <main+0x7a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe4b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    121c <main+0xbc>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1221 <main+0xc1>
mov    -0x18(%rbp),%rdi
call   1080 <getc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
mov    0x2db1(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1256 <main+0xf6>
mov    -0x21(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
jmp    1221 <main+0xc1>
cmpq   $0x0,-0x18(%rbp)
je     126a <main+0x10a>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     127e <main+0x11e>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x3,%edi
jne    1200 <main+0x90>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xe74(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1216 <main+0xa6>
mov    %rax,%r14
mov    0x10(%r15),%rdi
lea    0xe74(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1223 <main+0xb3>
mov    %rax,%rbx
mov    %r14,%rdi
call   1090 <getc@plt>
mov    0x2e24(%rip),%r15
cmp    (%r15),%al
je     11e8 <main+0x78>
nopl   0x0(%rax)
movsbl %al,%edi
mov    %rbx,%rsi
call   1060 <putc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
cmp    (%r15),%al
jne    11d0 <main+0x60>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe37(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x8(%r15),%rsi
lea    0xde1(%rip),%rdi
jmp    122e <main+0xbe>
mov    0x10(%r15),%rsi
lea    0xdf0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Usage: cp <src> <dest>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Unable to open file '%s'\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [32 x i8] c"Unable to open/write file '%s'\0A\00"
@EOF = global i8 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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
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 = icmp eq i32* %18, null
br i1 %19, label %20, label %26
20: ; preds = %14
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %14
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %30, i32** %7
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %38
32: ; preds = %26
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %26
br label %39
39: ; preds = %46, %38
%40 = load i32*, i32** %6
%41 = call signext i8 @getc(i32* %40)
store i8 %41, i8* %8
%42 = sext i8 %41 to i32
%43 = load i8, i8* @EOF
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %42, %44
br i1 %45, label %46, label %50
46: ; preds = %39
%47 = load i8, i8* %8
%48 = load i32*, i32** %7
%49 = call i32 @putc(i8 signext %47, i32* %48)
br label %39
50: ; preds = %39
%51 = load i32*, i32** %6
%52 = icmp ne i32* %51, null
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32*, i32** %6
%55 = call i32 @fclose(i32* %54)
br label %56
56: ; preds = %53, %50
%57 = load i32*, i32** %7
%58 = icmp ne i32* %57, null
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i32*, i32** %7
%61 = call i32 @fclose(i32* %60)
br label %62
62: ; preds = %59, %56
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Unable to open file '%s'\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [32 x i8] c"Unable to open/write file '%s'\0A\00"
@EOF = global i8 0
@str = [23 x i8] c"Usage: cp <src> <dest>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
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 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i8*, i8** %8
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %7
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %25, label %21
21: ; preds = %16
%22 = tail call signext i8 @getc(i32* %10)
%23 = load i8, i8* @EOF
%24 = icmp eq i8 %22, %23
br i1 %24, label %35, label %29
25: ; preds = %16
%26 = load i8*, i8** %17
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %21, %29
%30 = phi i8 [ %32, %29 ], [ %22, %21 ]
%31 = tail call i32 @putc(i8 signext %30, i32* %19)
%32 = tail call signext i8 @getc(i32* %10)
%33 = load i8, i8* @EOF
%34 = icmp eq i8 %32, %33
br i1 %34, label %35, label %29
35: ; preds = %29, %21
%36 = tail call i32 @fclose(i32* %10)
%37 = tail call i32 @fclose(i32* %19)
ret i32 0
}