#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 getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int CompareFiles(char *file1, char *file2) {
  FILE *fp1, *fp2;
  int ch1, ch2;
  fp1 = fopen(file1, "rb");
  fp2 = fopen(file2, "rb");
  if (fp1 == NULL || fp2 == NULL) {
    printf("Can not open files.\n");
    return 1;
  }
  ch1 = getc(fp1);
  ch2 = getc(fp2);
  while ((ch1 != EOF) && (ch2 != EOF) && (ch1 == ch2)) {
    ch1 = getc(fp1);
    ch2 = getc(fp2);
  }
  if (ch1 != ch2) {
    return 1;
  }
  fclose(fp1);
  fclose(fp2);
  return 0;
}


x86 assembly (clang, -O0):
<CompareFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     118e <CompareFiles+0x4e>
cmpq   $0x0,-0x28(%rbp)
jne    11a6 <CompareFiles+0x66>
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1256 <CompareFiles+0x116>
mov    -0x20(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
mov    0x2e1e(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x31(%rbp)
je     11f8 <CompareFiles+0xb8>
mov    -0x30(%rbp),%ecx
xor    %eax,%eax
mov    0x2e07(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x31(%rbp)
je     11f8 <CompareFiles+0xb8>
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1208 <CompareFiles+0xc8>
jmp    1225 <CompareFiles+0xe5>
mov    -0x20(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x30(%rbp)
jmp    11be <CompareFiles+0x7e>
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
je     123d <CompareFiles+0xfd>
movl   $0x1,-0x4(%rbp)
jmp    1256 <CompareFiles+0x116>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CompareFiles>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
lea    0xeaf(%rip),%r14
mov    %r14,%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
test   %rbx,%rbx
je     11e1 <CompareFiles+0xa1>
mov    %rax,%r14
test   %rax,%rax
je     11e1 <CompareFiles+0xa1>
mov    %rbx,%rdi
call   1060 <getc@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <getc@plt>
cmp    %eax,%ebp
sete   %cl
jne    11c4 <CompareFiles+0x84>
mov    0x2e54(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15),%edx
cmp    %edx,%ebp
je     11c4 <CompareFiles+0x84>
cmp    %edx,%eax
je     11c4 <CompareFiles+0x84>
mov    %rbx,%rdi
call   1060 <getc@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <getc@plt>
cmp    %eax,%ebp
sete   %cl
je     11a0 <CompareFiles+0x60>
mov    $0x1,%eax
test   %cl,%cl
je     11f2 <CompareFiles+0xb2>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11f2 <CompareFiles+0xb2>
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [21 x i8] c"Can not open files.\0A\00"
@EOF = global i32 0
define i32 @CompareFiles(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %7
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %2
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %16, %2
%20 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %55
21: ; preds = %16
%22 = load i32*, i32** %6
%23 = call i32 @getc(i32* %22)
store i32 %23, i32* %8
%24 = load i32*, i32** %7
%25 = call i32 @getc(i32* %24)
store i32 %25, i32* %9
br label %26
26: ; preds = %40, %21
%27 = load i32, i32* %8
%28 = load i32, i32* @EOF
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = load i32, i32* %9
%32 = load i32, i32* @EOF
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i32, i32* %8
%36 = load i32, i32* %9
%37 = icmp eq i32 %35, %36
br label %38
38: ; preds = %34, %30, %26
%39 = phi i1 [ false, %30 ], [ false, %26 ], [ %37, %34 ]
br i1 %39, label %40, label %45
40: ; preds = %38
%41 = load i32*, i32** %6
%42 = call i32 @getc(i32* %41)
store i32 %42, i32* %8
%43 = load i32*, i32** %7
%44 = call i32 @getc(i32* %43)
store i32 %44, i32* %9
br label %26
45: ; preds = %38
%46 = load i32, i32* %8
%47 = load i32, i32* %9
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %50
49: ; preds = %45
store i32 1, i32* %3
br label %55
50: ; preds = %45
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
store i32 0, i32* %3
br label %55
55: ; preds = %50, %49, %19
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
@str = [20 x i8] c"Can not open files.\00"
define i32 @CompareFiles(i8* nocapture %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, i64 0, i64 0))
%5 = icmp eq i32* %3, null
%6 = icmp eq i32* %4, null
%7 = or i1 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %33
10: ; preds = %2
%11 = tail call i32 @getc(i32* %3)
%12 = tail call i32 @getc(i32* %4)
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %11, %13
%15 = icmp ne i32 %12, %13
%16 = and i1 %14, %15
%17 = icmp eq i32 %11, %12
%18 = and i1 %17, %16
br i1 %18, label %19, label %28
19: ; preds = %10, %19
%20 = tail call i32 @getc(i32* %3)
%21 = tail call i32 @getc(i32* %4)
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %20, %22
%24 = icmp ne i32 %21, %22
%25 = and i1 %23, %24
%26 = icmp eq i32 %20, %21
%27 = and i1 %26, %25
br i1 %27, label %19, label %28
28: ; preds = %19, %10
%29 = phi i1 [ %17, %10 ], [ %26, %19 ]
br i1 %29, label %30, label %33
30: ; preds = %28
%31 = tail call i32 @fclose(i32* %3)
%32 = tail call i32 @fclose(i32* %4)
br label %33
33: ; preds = %28, %30, %8
%34 = phi i32 [ 1, %8 ], [ 0, %30 ], [ 1, %28 ]
ret i32 %34
}