#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("Expected usage: exe file1 file2\n");
    return 1;
  }
  FILE *input;
  FILE *output;
  input = fopen(argv[1], "r");
  output = fopen(argv[2], "r");
  int ch;
  if (input == NULL) {
    printf("Input file does not exist.\n");
  } else if (output != NULL) {
    printf("Output file already exists.\n");
  } else {
    output = fopen(argv[2], "a");
    while ((ch = getc(input)) != EOF) {
      fputc(ch, output);
    }
    fclose(input);
    fclose(output);
  }
  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)
jge    1188 <main+0x38>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1252 <main+0x102>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe72(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d4 <main+0x84>
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
jmp    124b <main+0xfb>
cmpq   $0x0,-0x20(%rbp)
je     11f0 <main+0xa0>
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
jmp    1246 <main+0xf6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe5d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dcd(%rip),%rcx
cmp    (%rcx),%eax
je     1234 <main+0xe4>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <fputc@plt>
jmp    1208 <main+0xb8>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    124b <main+0xfb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jg     1170 <main+0x20>
lea    0xeda(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    1218 <main+0xc8>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe82(%rip),%r14
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
test   %r15,%r15
je     11ad <main+0x5d>
test   %rax,%rax
je     11bb <main+0x6b>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
jmp    1216 <main+0xc6>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
jmp    1216 <main+0xc6>
mov    0x10(%rbx),%rdi
lea    0xe3c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1070 <getc@plt>
mov    0x2e0b(%rip),%rbx
cmp    (%rbx),%eax
je     1206 <main+0xb6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %r15,%rdi
call   1070 <getc@plt>
cmp    (%rbx),%eax
jne    11f0 <main+0xa0>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Expected usage: exe file1 file2\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"Input file does not exist.\0A\00"
@.str.3 = [29 x i8] c"Output file already exists.\0A\00"
@.str.4 = [2 x i8] c"a\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 slt i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %52
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %7
%22 = load i32*, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %13
%25 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %51
26: ; preds = %13
%27 = load i32*, i32** %7
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %50
31: ; preds = %26
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %35, i32** %7
br label %36
36: ; preds = %41, %31
%37 = load i32*, i32** %6
%38 = call i32 @getc(i32* %37)
store i32 %38, i32* %8
%39 = load i32, i32* @EOF
%40 = icmp ne i32 %38, %39
br i1 %40, label %41, label %45
41: ; preds = %36
%42 = load i32, i32* %8
%43 = load i32*, i32** %7
%44 = call i32 @fputc(i32 %42, i32* %43)
br label %36
45: ; preds = %36
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
%48 = load i32*, i32** %7
%49 = call i32 @fclose(i32* %48)
br label %50
50: ; preds = %45, %29
br label %51
51: ; preds = %50, %24
store i32 0, i32* %3
br label %52
52: ; preds = %51, %11
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"a\00"
@EOF = global i32 0
@str = [28 x i8] c"Output file already exists.\00"
@str.5 = [27 x i8] c"Input file does not exist.\00"
@str.6 = [32 x i8] c"Expected usage: exe file1 file2\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.6, i64 0, i64 0))
br label %35
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %9, null
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %35
16: ; preds = %6
%17 = icmp eq i32* %12, null
br i1 %17, label %20, label %18
18: ; preds = %16
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %35
20: ; preds = %16
%21 = load i8*, i8** %10
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%23 = tail call i32 @getc(i32* %9)
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %32, label %26
26: ; preds = %20, %26
%27 = phi i32 [ %29, %26 ], [ %23, %20 ]
%28 = tail call i32 @fputc(i32 %27, i32* %22)
%29 = tail call i32 @getc(i32* %9)
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %26
32: ; preds = %26, %20
%33 = tail call i32 @fclose(i32* %9)
%34 = tail call i32 @fclose(i32* %22)
br label %35
35: ; preds = %14, %32, %18, %4
%36 = phi i32 [ 1, %4 ], [ 0, %18 ], [ 0, %32 ], [ 0, %14 ]
ret i32 %36
}