#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 /*<<< orphan*/ copy(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("parameters missing\n");
    exit(10);
  }
  if (!strcmp(argv[1], argv[2])) {
    printf("filenames need to be different\n");
    exit(10);
  }
  FILE *fp_in = fopen(argv[1], "r");
  if (!fp_in) {
    printf("can't open file %s\n", argv[1]);
    exit(10);
  }
  FILE *fp_out = fopen(argv[2], "w");
  if (!fp_out) {
    printf("can't open file %s\n", argv[2]);
    exit(10);
  }
  copy(fp_in, fp_out);
  if (ferror(fp_in) || ferror(fp_out)) {
    printf("read/write error\n");
    exit(10);
  }
  if (fclose(fp_in) || fclose(fp_out)) {
    printf("can't close\n");
    exit(10);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a8 <main+0x38>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11de <main+0x6e>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe47(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1221 <main+0xb1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe1a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1264 <main+0xf4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <copy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
jne    1297 <main+0x127>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12af <main+0x13f>
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
jne    12d5 <main+0x165>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     12ed <main+0x17d>
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1090 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x3,%edi
jne    1239 <main+0xb9>
mov    %rsi,%r14
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
je     1242 <main+0xc2>
lea    0xea0(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1258 <main+0xd8>
mov    %rax,%r15
mov    0x10(%r14),%rdi
lea    0xe45(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     125e <main+0xde>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1070 <copy@plt>
mov    %r15,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1227 <main+0xa7>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1227 <main+0xa7>
mov    %r15,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
jne    1230 <main+0xb0>
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
jne    1230 <main+0xb0>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe13(%rip),%rdi
jmp    1249 <main+0xc9>
lea    0xdfe(%rip),%rdi
jmp    1249 <main+0xc9>
lea    0xe12(%rip),%rdi
jmp    1249 <main+0xc9>
lea    0xdcd(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%edi
call   10a0 <exit@plt>
mov    0x8(%r14),%rsi
jmp    1262 <main+0xe2>
mov    0x10(%r14),%rsi
lea    0xd97(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"parameters missing\0A\00"
@.str.1 = [32 x i8] c"filenames need to be different\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [20 x i8] c"can't open file %s\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [18 x i8] c"read/write error\0A\00"
@.str.6 = [13 x i8] c"can't close\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 10)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @strcmp(i8* %16, i8* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %13
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 10)
unreachable
25: ; preds = %13
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %29, i32** %6
%30 = load i32*, i32** %6
%31 = icmp ne i32* %30, null
br i1 %31, label %38, label %32
32: ; preds = %25
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 10)
unreachable
38: ; preds = %25
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %42, i32** %7
%43 = load i32*, i32** %7
%44 = icmp ne i32* %43, null
br i1 %44, label %51, label %45
45: ; preds = %38
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %48)
%50 = call i32 @exit(i32 10)
unreachable
51: ; preds = %38
%52 = load i32*, i32** %6
%53 = load i32*, i32** %7
%54 = call i32 @copy(i32* %52, i32* %53)
%55 = load i32*, i32** %6
%56 = call i64 @ferror(i32* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %62, label %58
58: ; preds = %51
%59 = load i32*, i32** %7
%60 = call i64 @ferror(i32* %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %58, %51
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%64 = call i32 @exit(i32 10)
unreachable
65: ; preds = %58
%66 = load i32*, i32** %6
%67 = call i64 @fclose(i32* %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %73, label %69
69: ; preds = %65
%70 = load i32*, i32** %7
%71 = call i64 @fclose(i32* %70)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %69, %65
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%75 = call i32 @exit(i32 10)
unreachable
76: ; preds = %69
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [20 x i8] c"can't open file %s\0A\00"
@.str.4 = [2 x i8] c"w\00"
@str = [31 x i8] c"filenames need to be different\00"
@str.7 = [12 x i8] c"can't close\00"
@str.8 = [17 x i8] c"read/write error\00"
@str.9 = [19 x i8] c"parameters missing\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 ([19 x i8], [19 x i8]* @str.9, i64 0, i64 0))
%6 = tail call i32 @exit(i32 10)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(1) %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %7
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 10)
unreachable
17: ; preds = %7
%18 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i8*, i8** %8
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = tail call i32 @exit(i32 10)
unreachable
24: ; preds = %17
%25 = load i8*, i8** %10
%26 = tail call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i8*, i8** %10
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = tail call i32 @exit(i32 10)
unreachable
32: ; preds = %24
%33 = tail call i32 @copy(i32* %18, i32* %26)
%34 = tail call i64 @ferror(i32* %18)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = tail call i64 @ferror(i32* %26)
%38 = icmp eq i64 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %36, %32
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
%41 = tail call i32 @exit(i32 10)
unreachable
42: ; preds = %36
%43 = tail call i64 @fclose(i32* %18)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = tail call i64 @fclose(i32* %26)
%47 = icmp eq i64 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %45, %42
%49 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0))
%50 = tail call i32 @exit(i32 10)
unreachable
51: ; preds = %45
ret i32 0
}