#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*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
main(int argc, char *argv[]) {
  FILE *in, *out;
  int ch;
  if (argc != 3) {
    fprintf(stderr, "usage: copy in_file out_file\n");
    exit(EXIT_FAILURE);
  }
  if ((in = fopen(argv[1], "rb")) == NULL) {
    fprintf(stderr, "Can't open %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  if ((out = fopen(argv[2], "wb")) == NULL) {
    fprintf(stderr, "Can't open %s\n", argv[2]);
    fclose(in);
    exit(EXIT_FAILURE);
  }
  while ((ch = getc(in)) != EOF)
    if (putc(ch, out) == EOF)
      break;
  if (ferror(in))
    printf("Error while reading source file.\n");
  if (ferror(out))
    printf("Error while writing into dest file.\n");
  fclose(in);
  fclose(out);
  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     11c5 <main+0x45>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1214 <main+0x94>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe0d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    126c <main+0xec>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1271 <main+0xf1>
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d64(%rip),%rcx
cmp    (%rcx),%eax
je     12b1 <main+0x131>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <putc@plt>
mov    0x2d49(%rip),%rcx
cmp    (%rcx),%eax
jne    12ac <main+0x12c>
jmp    12b1 <main+0x131>
jmp    1271 <main+0xf1>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12d0 <main+0x150>
lea    0xd68(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12ef <main+0x16f>
lea    0xd6b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    124a <main+0xca>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1263 <main+0xe3>
mov    %rax,%r14
mov    0x10(%r15),%rdi
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1280 <main+0x100>
mov    %rax,%r12
mov    0x2e15(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   10a0 <getc@plt>
cmp    (%rbx),%eax
je     11fa <main+0x7a>
mov    %eax,%edi
mov    %r12,%rsi
call   1060 <putc@plt>
cmp    (%rbx),%eax
jne    11e0 <main+0x60>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     1213 <main+0x93>
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     122c <main+0xac>
lea    0xe0c(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12a3 <main+0x123>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xdaa(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12a3 <main+0x123>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r15),%rdx
lea    0xd8d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"usage: copy in_file out_file\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
@.str.4 = [34 x i8] c"Error while reading source file.\0A\00"
@.str.5 = [37 x i8] c"Error while writing into dest file.\0A\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 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 ([30 x i8], [30 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 = %59, %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 %60
52: ; preds = %47
%53 = load i32, i32* %8
%54 = load i32*, i32** %7
%55 = call i32 @putc(i32 %53, i32* %54)
%56 = load i32, i32* @EOF
%57 = icmp eq i32 %55, %56
br i1 %57, label %58, label %59
58: ; preds = %52
br label %60
59: ; preds = %52
br label %47
60: ; preds = %58, %47
%61 = load i32*, i32** %6
%62 = call i64 @ferror(i32* %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %66
66: ; preds = %64, %60
%67 = load i32*, i32** %7
%68 = call i64 @ferror(i32* %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %66
%71 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %72
72: ; preds = %70, %66
%73 = load i32*, i32** %6
%74 = call i32 @fclose(i32* %73)
%75 = load i32*, i32** %7
%76 = call i32 @fclose(i32* %75)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"usage: copy in_file out_file\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
@str = [36 x i8] c"Error while writing into dest file.\00"
@str.6 = [33 x i8] c"Error while reading source file.\00"
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 ([30 x i8], [30 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 %25, label %32
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %21
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = tail call i32 @fclose(i32* %12)
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %20, %36
%33 = tail call i32 @getc(i32* %12)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %40, label %36
36: ; preds = %32
%37 = tail call i32 @putc(i32 %33, i32* %23)
%38 = load i32, i32* @EOF
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %32
40: ; preds = %36, %32
%41 = tail call i64 @ferror(i32* %12)
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.6, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
%46 = tail call i64 @ferror(i32* %23)
%47 = icmp eq i64 %46, 0
br i1 %47, label %50, label %48
48: ; preds = %45
%49 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %50
50: ; preds = %48, %45
%51 = tail call i32 @fclose(i32* %12)
%52 = tail call i32 @fclose(i32* %23)
ret i32 0
}