#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 EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int main(int argc, char *argv[]) {
  FILE *inFilePtr;
  FILE *outFilePtr;
  int c;
  int int1 = 1;
  int int2 = 2;
  if (argc != 3) {
    puts("Usage: mycopy infile outfile");
  } else {
    if ((inFilePtr = fopen(argv[int1], "r")) != NULL) {
      if ((outFilePtr = fopen(argv[int2], "w")) != NULL) {
        while ((c = fgetc(inFilePtr)) != EOF) {
          fputc(c, outFilePtr);
        }
        fclose(outFilePtr);
      } else {
        printf("File \"%s\" could not be opened\n", argv[int2]);
      }
      fclose(inFilePtr);
    } else {
      printf("File \"%s\" could not be opened\n", argv[int1]);
    }
  }
  return (EXIT_SUCCESS);
}


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)
movl   $0x1,-0x28(%rbp)
movl   $0x2,-0x2c(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119f <main+0x3f>
lea    0xe6b(%rip),%rdi
call   1030 <puts@plt>
jmp    126d <main+0x10d>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe6b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1250 <main+0xf0>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe47(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     122a <main+0xca>
jmp    11f0 <main+0x90>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2de5(%rip),%rcx
cmp    (%rcx),%eax
je     121c <main+0xbc>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <fputc@plt>
jmp    11f0 <main+0x90>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1242 <main+0xe2>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xde4(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1268 <main+0x108>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdbe(%rip),%rdi
call   1050 <printf@plt>
jmp    126d <main+0x10d>
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x3,%edi
jne    11e1 <main+0x81>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xea5(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ef <main+0x8f>
mov    %rax,%r14
mov    0x10(%r15),%rdi
lea    0xe8f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1201 <main+0xa1>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    0x2e3c(%rip),%r15
cmp    (%r15),%eax
je     11d7 <main+0x77>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
mov    %r14,%rdi
call   1060 <fgetc@plt>
cmp    (%r15),%eax
jne    11c0 <main+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1211 <main+0xb1>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
jmp    1219 <main+0xb9>
mov    0x8(%r15),%rsi
lea    0xe27(%rip),%rdi
call   1050 <printf@plt>
jmp    1219 <main+0xb9>
mov    0x10(%r15),%rsi
lea    0xe15(%rip),%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Usage: mycopy infile outfile\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@EOF = global i32 0
@.str.3 = [31 x i8] c"File \22%s\22 could not be opened\0A\00"
@EXIT_SUCCESS = 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
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %9
store i32 2, i32* %10
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %62
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%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** %6
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %54
23: ; preds = %15
%24 = load i8**, i8*** %5
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%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** %7
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %44
31: ; preds = %23
br label %32
32: ; preds = %37, %31
%33 = load i32*, i32** %6
%34 = call i32 @fgetc(i32* %33)
store i32 %34, i32* %8
%35 = load i32, i32* @EOF
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = load i32, i32* %8
%39 = load i32*, i32** %7
%40 = call i32 @fputc(i32 %38, i32* %39)
br label %32
41: ; preds = %32
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
br label %51
44: ; preds = %23
%45 = load i8**, i8*** %5
%46 = load i32, i32* %10
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %44, %41
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
br label %61
54: ; preds = %15
%55 = load i8**, i8*** %5
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
%60 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %59)
br label %61
61: ; preds = %54, %51
br label %62
62: ; preds = %61, %13
%63 = load i32, i32* @EXIT_SUCCESS
ret i32 %63
}

LLVM IR (-O2):
@.str = [29 x i8] c"Usage: mycopy infile outfile\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@EOF = global i32 0
@.str.3 = [31 x i8] c"File \22%s\22 could not be opened\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %36
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 = icmp eq i32* %9, null
br i1 %10, label %33, label %11
11: ; preds = %6
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %28, label %16
16: ; preds = %11
%17 = tail call i32 @fgetc(i32* %9)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %26, label %20
20: ; preds = %16, %20
%21 = phi i32 [ %23, %20 ], [ %17, %16 ]
%22 = tail call i32 @fputc(i32 %21, i32* %14)
%23 = tail call i32 @fgetc(i32* %9)
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %20
26: ; preds = %20, %16
%27 = tail call i32 @fclose(i32* %14)
br label %31
28: ; preds = %11
%29 = load i8*, i8** %12
%30 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %28, %26
%32 = tail call i32 @fclose(i32* %9)
br label %36
33: ; preds = %6
%34 = load i8*, i8** %7
%35 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %31, %33, %4
%37 = load i32, i32* @EXIT_SUCCESS
ret i32 %37
}