#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*/ fprintf(int /*<<< orphan*/, char *, int);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *fp1, *fp2;
  int ch1, ch2;
  int chcount = 1;
  if (argc != 3)
    printf("Please enter two filenames as arguments.\n");
  else {
    fp1 = fopen(argv[1], "r");
    fp2 = fopen(argv[2], "r");
    if (fp1 == NULL) {
      printf("Cannot open %s for reading\n ", argv[1]);
      return (1);
    } else if (fp2 == NULL) {
      printf("Cannot open %s for reading\n ", argv[2]);
      fclose(fp1);
      return (1);
    } else {
      ch1 = getc(fp1);
      ch2 = getc(fp2);
      while ((ch1 != EOF) && (ch2 != EOF) && (ch1 == ch2)) {
        ch1 = getc(fp1);
        ch2 = getc(fp2);
        chcount++;
      }
      if (ch1 == ch2) {
        printf("Files are identical\n");
        fclose(fp1);
        fclose(fp2);
        return (0);
      } else if (ch1 != ch2) {
        fprintf(stderr, "Files start to differ after byte %d.\n", chcount);
        fclose(fp1);
        fclose(fp2);
        return (1);
      }
    }
  }
}


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,-0x2c(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118a <main+0x3a>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1333 <main+0x1e3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe79(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e7 <main+0x97>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1333 <main+0x1e3>
cmpq   $0x0,-0x20(%rbp)
jne    121d <main+0xcd>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1333 <main+0x1e3>
mov    -0x18(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
mov    0x2da7(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x2d(%rbp)
je     126f <main+0x11f>
mov    -0x28(%rbp),%ecx
xor    %eax,%eax
mov    0x2d90(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x2d(%rbp)
je     126f <main+0x11f>
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
sete   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    127f <main+0x12f>
jmp    12a5 <main+0x155>
mov    -0x18(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1235 <main+0xe5>
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jne    12dd <main+0x18d>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1333 <main+0x1e3>
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     131f <main+0x1cf>
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xd62(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1333 <main+0x1e3>
jmp    1324 <main+0x1d4>
jmp    1329 <main+0x1d9>
jmp    132e <main+0x1de>
jmp    1333 <main+0x1e3>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    123c <main+0xdc>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe7e(%rip),%rbx
mov    %rbx,%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    0x10(%rbp),%rdi
mov    %rbx,%rsi
call   1070 <fopen@plt>
test   %r14,%r14
je     124c <main+0xec>
mov    %rax,%r12
test   %rax,%rax
je     1260 <main+0x100>
mov    %r14,%rdi
call   1080 <getc@plt>
mov    %eax,%r15d
mov    %r12,%rdi
call   1080 <getc@plt>
mov    $0x1,%ebp
cmp    %eax,%r15d
sete   %cl
jne    1218 <main+0xb8>
mov    0x2e13(%rip),%r13
mov    0x0(%r13),%edx
cmp    %edx,%r15d
je     1218 <main+0xb8>
cmp    %edx,%eax
je     1218 <main+0xb8>
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1080 <getc@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1080 <getc@plt>
add    $0x1,%ebp
cmp    %eax,%ebx
sete   %cl
jne    1218 <main+0xb8>
mov    0x0(%r13),%edx
cmp    %edx,%ebx
je     1218 <main+0xb8>
cmp    %edx,%eax
jne    11f0 <main+0x90>
test   %cl,%cl
je     1277 <main+0x117>
lea    0xe22(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    12a3 <main+0x143>
lea    0xe16(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    12a3 <main+0x143>
mov    0x8(%rbp),%rsi
lea    0xdab(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    129e <main+0x13e>
mov    0x10(%rbp),%rsi
lea    0xd97(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
jmp    1299 <main+0x139>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
mov    %ebp,%edx
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Please enter two filenames as arguments.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"Cannot open %s for reading\0A \00"
@EOF = global i32 0
@.str.3 = [21 x i8] c"Files are identical\0A\00"
@stderr = global i32 0
@.str.4 = [38 x i8] c"Files start to differ after byte %d.\0A\00"
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* %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 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %93
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %7
%24 = load i32*, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %31
26: ; preds = %15
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %29)
store i32 1, i32* %3
br label %93
31: ; preds = %15
%32 = load i32*, i32** %7
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
store i32 1, i32* %3
br label %93
41: ; preds = %31
%42 = load i32*, i32** %6
%43 = call i32 @getc(i32* %42)
store i32 %43, i32* %8
%44 = load i32*, i32** %7
%45 = call i32 @getc(i32* %44)
store i32 %45, i32* %9
br label %46
46: ; preds = %60, %41
%47 = load i32, i32* %8
%48 = load i32, i32* @EOF
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %58
50: ; preds = %46
%51 = load i32, i32* %9
%52 = load i32, i32* @EOF
%53 = icmp ne i32 %51, %52
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = load i32, i32* %8
%56 = load i32, i32* %9
%57 = icmp eq i32 %55, %56
br label %58
58: ; preds = %54, %50, %46
%59 = phi i1 [ false, %50 ], [ false, %46 ], [ %57, %54 ]
br i1 %59, label %60, label %67
60: ; preds = %58
%61 = load i32*, i32** %6
%62 = call i32 @getc(i32* %61)
store i32 %62, i32* %8
%63 = load i32*, i32** %7
%64 = call i32 @getc(i32* %63)
store i32 %64, i32* %9
%65 = load i32, i32* %10
%66 = add nsw i32 %65, 1
store i32 %66, i32* %10
br label %46
67: ; preds = %58
%68 = load i32, i32* %8
%69 = load i32, i32* %9
%70 = icmp eq i32 %68, %69
br i1 %70, label %71, label %77
71: ; preds = %67
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%73 = load i32*, i32** %6
%74 = call i32 @fclose(i32* %73)
%75 = load i32*, i32** %7
%76 = call i32 @fclose(i32* %75)
store i32 0, i32* %3
br label %93
77: ; preds = %67
%78 = load i32, i32* %8
%79 = load i32, i32* %9
%80 = icmp ne i32 %78, %79
br i1 %80, label %81, label %89
81: ; preds = %77
%82 = load i32, i32* @stderr
%83 = load i32, i32* %10
%84 = call i32 @fprintf(i32 %82, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %83)
%85 = load i32*, i32** %6
%86 = call i32 @fclose(i32* %85)
%87 = load i32*, i32** %7
%88 = call i32 @fclose(i32* %87)
store i32 1, i32* %3
br label %93
89: ; preds = %77
br label %90
90: ; preds = %89
br label %91
91: ; preds = %90
br label %92
92: ; preds = %91
br label %93
93: ; preds = %26, %34, %71, %81, %92, %13
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"Cannot open %s for reading\0A \00"
@EOF = global i32 0
@stderr = global i32 0
@.str.4 = [38 x i8] c"Files start to differ after byte %d.\0A\00"
@str = [20 x i8] c"Files are identical\00"
@str.5 = [41 x i8] c"Please enter two filenames as arguments.\00"
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 ([41 x i8], [41 x i8]* @str.5, i64 0, i64 0))
br label %55
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 %17
14: ; preds = %6
%15 = load i8*, i8** %7
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %55
17: ; preds = %6
%18 = icmp eq i32* %12, null
br i1 %18, label %19, label %23
19: ; preds = %17
%20 = load i8*, i8** %10
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = tail call i32 @fclose(i32* %9)
br label %55
23: ; preds = %17
%24 = tail call i32 @getc(i32* %9)
%25 = tail call i32 @getc(i32* %12)
%26 = load i32, i32* @EOF
%27 = icmp ne i32 %24, %26
%28 = icmp ne i32 %25, %26
%29 = and i1 %27, %28
%30 = icmp eq i32 %24, %25
%31 = and i1 %30, %29
br i1 %31, label %32, label %43
32: ; preds = %23, %32
%33 = phi i32 [ %36, %32 ], [ 1, %23 ]
%34 = tail call i32 @getc(i32* %9)
%35 = tail call i32 @getc(i32* %12)
%36 = add nuw nsw i32 %33, 1
%37 = load i32, i32* @EOF
%38 = icmp ne i32 %34, %37
%39 = icmp ne i32 %35, %37
%40 = and i1 %38, %39
%41 = icmp eq i32 %34, %35
%42 = and i1 %41, %40
br i1 %42, label %32, label %43
43: ; preds = %32, %23
%44 = phi i32 [ 1, %23 ], [ %36, %32 ]
%45 = phi i1 [ %30, %23 ], [ %41, %32 ]
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%48 = tail call i32 @fclose(i32* %9)
%49 = tail call i32 @fclose(i32* %12)
br label %55
50: ; preds = %43
%51 = load i32, i32* @stderr
%52 = tail call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%53 = tail call i32 @fclose(i32* %9)
%54 = tail call i32 @fclose(i32* %12)
br label %55
55: ; preds = %4, %50, %46, %19, %14
%56 = phi i32 [ 0, %4 ], [ 1, %14 ], [ 1, %19 ], [ 0, %46 ], [ 1, %50 ]
ret i32 %56
}