#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 */
char EOF;
int /*<<< orphan*/ exit(int);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int copyfile(char *infile, char *outfile) {
  FILE *fin, *fout;
  char ch;
  fin = fopen(infile, "rb");
  fout = fopen(outfile, "wb");
  if (fin == NULL) {
    printf("Error in open File: %s\n", infile);
    exit(1);
  }
  while ((ch = fgetc(fin)) != EOF)
    fputc(ch, fout);
  return 0;
}


x86 assembly (clang, -O0):
<copyfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ad <copyfile+0x5d>
mov    -0x8(%rbp),%rsi
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11b2 <copyfile+0x62>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
mov    0x2e20(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11e7 <copyfile+0x97>
mov    -0x21(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    11b2 <copyfile+0x62>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyfile>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe92(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
test   %rbx,%rbx
je     11c0 <copyfile+0x70>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    0x2e58(%rip),%r15
cmp    (%r15),%al
je     11b8 <copyfile+0x68>
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%al
jne    11a0 <copyfile+0x50>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe3f(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [24 x i8] c"Error in open File: %s\0A\00"
@EOF = global i8 0
define i32 @copyfile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %5
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
br label %19
19: ; preds = %26, %18
%20 = load i32*, i32** %5
%21 = call signext i8 @fgetc(i32* %20)
store i8 %21, i8* %7
%22 = sext i8 %21 to i32
%23 = load i8, i8* @EOF
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %22, %24
br i1 %25, label %26, label %30
26: ; preds = %19
%27 = load i8, i8* %7
%28 = load i32*, i32** %6
%29 = call i32 @fputc(i8 signext %27, i32* %28)
br label %19
30: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [24 x i8] c"Error in open File: %s\0A\00"
@EOF = global i8 0
define i32 @copyfile(i8* %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %3, null
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call signext i8 @fgetc(i32* %3)
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %19, label %13
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %6, %13
%14 = phi i8 [ %16, %13 ], [ %7, %6 ]
%15 = tail call i32 @fputc(i8 signext %14, i32* %4)
%16 = tail call signext i8 @fgetc(i32* %3)
%17 = load i8, i8* @EOF
%18 = icmp eq i8 %16, %17
br i1 %18, label %19, label %13
19: ; preds = %13, %6
ret i32 0
}