#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 EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *source_fp, *dest_fp;
  int ch;
  if (argc != 3) {
    fprintf(stderr, "usage: fcopy source dest\n");
    exit(EXIT_FAILURE);
  }
  if ((source_fp = fopen(argv[1], "rb")) == NULL) {
    fprintf(stderr, "Can't open %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  if ((dest_fp = fopen(argv[2], "wb")) == NULL) {
    fprintf(stderr, "Can't open %s\n", argv[2]);
    fclose(source_fp);
    exit(EXIT_FAILURE);
  }
  while ((ch = getc(source_fp)) != EOF)
    putc(ch, dest_fp);
  fclose(source_fp);
  fclose(dest_fp);
  return 0;
}


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     11a5 <main+0x45>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe66(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f4 <main+0x94>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe29(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    124c <main+0xec>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1251 <main+0xf1>
mov    -0x18(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d84(%rip),%rcx
cmp    (%rcx),%eax
je     127d <main+0x11d>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1040 <putc@plt>
jmp    1251 <main+0xf1>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x3,%edi
jne    11ef <main+0x8f>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1208 <main+0xa8>
mov    %rax,%r14
mov    0x10(%r15),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1225 <main+0xc5>
mov    %rax,%rbx
mov    %r14,%rdi
call   1080 <getc@plt>
mov    0x2e30(%rip),%r15
cmp    (%r15),%eax
je     11d7 <main+0x77>
nopl   (%rax)
mov    %eax,%edi
mov    %rbx,%rsi
call   1040 <putc@plt>
mov    %r14,%rdi
call   1080 <getc@plt>
cmp    (%r15),%eax
jne    11c0 <main+0x60>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1248 <main+0xe8>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xe01(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1248 <main+0xe8>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r15),%rdx
lea    0xde4(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"usage: fcopy source dest\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [15 x i8] c"Can't open %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@EOF = 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 i32
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 %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
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 ([3 x i8], [3 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 %30
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %16
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %7
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %46
36: ; preds = %30
%37 = load i32, i32* @stderr
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = load i32*, i32** %6
%43 = call i32 @fclose(i32* %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %30
br label %47
47: ; preds = %52, %46
%48 = load i32*, i32** %6
%49 = call i32 @getc(i32* %48)
store i32 %49, i32* %8
%50 = load i32, i32* @EOF
%51 = icmp ne i32 %49, %50
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = load i32, i32* %8
%54 = load i32*, i32** %7
%55 = call i32 @putc(i32 %53, i32* %54)
br label %47
56: ; preds = %47
%57 = load i32*, i32** %6
%58 = call i32 @fclose(i32* %57)
%59 = load i32*, i32** %7
%60 = call i32 @fclose(i32* %59)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"usage: fcopy source dest\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [15 x i8] c"Can't open %s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %10
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %9
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %29, label %25
25: ; preds = %20
%26 = tail call i32 @getc(i32* %12)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %42, label %36
29: ; preds = %20
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %21
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = tail call i32 @fclose(i32* %12)
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %25, %36
%37 = phi i32 [ %39, %36 ], [ %26, %25 ]
%38 = tail call i32 @putc(i32 %37, i32* %23)
%39 = tail call i32 @getc(i32* %12)
%40 = load i32, i32* @EOF
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %36
42: ; preds = %36, %25
%43 = tail call i32 @fclose(i32* %12)
%44 = tail call i32 @fclose(i32* %23)
ret i32 0
}