#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(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  FILE *inFile, *outFile;
  int c;
  if (argc != 3) {
    printf("Incorrect number of arguments - exiting!\n");
    exit(1);
  }
  printf("first argument was  %s\n", argv[0]);
  printf("second argument was %s\n", argv[1]);
  printf("third argument was  %s\n", argv[2]);
  if ((inFile = fopen(argv[1], "r")) == NULL) {
    printf("Cannot open input file - exiting!\n");
    exit(1);
  }
  if ((outFile = fopen(argv[2], "w")) == NULL) {
    printf("Cannot open output file - exiting!\n");
    exit(1);
  }
  while ((c = getc(inFile)) != EOF)
    putc(c, outFile);
  fclose(inFile);
  fclose(outFile);
  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     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    (%rax),%rsi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1213 <main+0xb3>
lea    0xe72(%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    0xe75(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    124d <main+0xed>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1252 <main+0xf2>
mov    -0x18(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d83(%rip),%rcx
cmp    (%rcx),%eax
je     127e <main+0x11e>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <putc@plt>
jmp    1252 <main+0xf2>
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    122f <main+0xbf>
mov    %rsi,%r14
mov    (%rsi),%rsi
lea    0xe75(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r14),%rsi
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r14),%rsi
lea    0xe81(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r14),%rdi
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1238 <main+0xc8>
mov    %rax,%r15
mov    0x10(%r14),%rdi
lea    0xe71(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1241 <main+0xd1>
mov    %rax,%rbx
mov    %r15,%rdi
call   1090 <getc@plt>
mov    0x2df3(%rip),%r14
cmp    (%r14),%eax
je     1217 <main+0xa7>
nopw   0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <putc@plt>
mov    %r15,%rdi
call   1090 <getc@plt>
cmp    (%r14),%eax
jne    1200 <main+0x90>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe5b(%rip),%rdi
jmp    1248 <main+0xd8>
lea    0xe30(%rip),%rdi
jmp    1248 <main+0xd8>
lea    0xe04(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"Incorrect number of arguments - exiting!\0A\00"
@.str.1 = [24 x i8] c"first argument was %s\0A\00"
@.str.2 = [24 x i8] c"second argument was %s\0A\00"
@.str.3 = [24 x i8] c"third argument was %s\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [35 x i8] c"Cannot open input file - exiting!\0A\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [36 x i8] c"Cannot open output file - exiting!\0A\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 %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 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 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %30, i32** %6
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %14
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %14
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %39, i32** %7
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %35
br label %45
45: ; preds = %50, %44
%46 = load i32*, i32** %6
%47 = call i32 @getc(i32* %46)
store i32 %47, i32* %8
%48 = load i32, i32* @EOF
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %54
50: ; preds = %45
%51 = load i32, i32* %8
%52 = load i32*, i32** %7
%53 = call i32 @putc(i32 %51, i32* %52)
br label %45
54: ; preds = %45
%55 = load i32*, i32** %6
%56 = call i32 @fclose(i32* %55)
%57 = load i32*, i32** %7
%58 = call i32 @fclose(i32* %57)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [24 x i8] c"first argument was %s\0A\00"
@.str.2 = [24 x i8] c"second argument was %s\0A\00"
@.str.3 = [24 x i8] c"third argument was %s\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.6 = [2 x i8] c"w\00"
@EOF = global i32 0
@str = [35 x i8] c"Cannot open output file - exiting!\00"
@str.8 = [34 x i8] c"Cannot open input file - exiting!\00"
@str.9 = [41 x i8] c"Incorrect number of arguments - exiting!\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 ([41 x i8], [41 x i8]* @str.9, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %10
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %7
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.8, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %7
%23 = load i8*, i8** %13
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = tail call i32 @getc(i32* %17)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %39, label %33
30: ; preds = %22
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %26, %33
%34 = phi i32 [ %36, %33 ], [ %27, %26 ]
%35 = tail call i32 @putc(i32 %34, i32* %24)
%36 = tail call i32 @getc(i32* %17)
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %33
39: ; preds = %33, %26
%40 = tail call i32 @fclose(i32* %17)
%41 = tail call i32 @fclose(i32* %24)
ret i32 0
}