#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(short *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  FILE *f0, *f1;
  int dif = 0;
  if (argc != 3) {
    printf("compare <file1> <file2>\n");
    exit(2);
  }
  f0 = fopen(argv[1], "rb");
  f1 = fopen(argv[2], "rb");
  for (;;) {
    short c0;
    short c1;
    int d;
    int e0 = fread(&c0, 2, 1, f0);
    int e1 = fread(&c1, 2, 1, f1);
    d = c0 - c1;
    if (e0 == 0 && e1 == 0)
      break;
    if (e0 == 0 || e1 == 0) {
      printf("FATAL error, files have different size!\n");
      exit(1);
    }
    if (d < 0)
      d = -d;
    if (d > 1) {
      printf("FATAL error, too large differnce found (%d)!\n", d);
      exit(1);
    }
    if (d)
      dif++;
  }
  fclose(f0);
  fclose(f1);
  printf("%d (+/-1)differences found\n", dif);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118f <main+0x3f>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe63(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x26(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x34(%rbp)
movswl -0x26(%rbp),%eax
movswl -0x28(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x30(%rbp)
jne    1219 <main+0xc9>
cmpl   $0x0,-0x34(%rbp)
jne    1219 <main+0xc9>
jmp    1294 <main+0x144>
cmpl   $0x0,-0x30(%rbp)
je     122d <main+0xdd>
cmpl   $0x0,-0x34(%rbp)
jne    1245 <main+0xf5>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x2c(%rbp)
jge    1257 <main+0x107>
xor    %eax,%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jle    127c <main+0x12c>
mov    -0x2c(%rbp),%esi
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x2c(%rbp)
je     128f <main+0x13f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11bf <main+0x6f>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%esi
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    127b <main+0x11b>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe7e(%rip),%rbp
mov    %rbp,%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
mov    %rbp,%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
lea    0x6(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %eax,%ebx
lea    0x4(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
xor    %ebp,%ebp
mov    %eax,%ecx
or     %ebx,%ecx
je     1254 <main+0xf4>
movswl 0x6(%rsp),%ecx
movswl 0x4(%rsp),%edx
sub    %edx,%ecx
xor    %ebp,%ebp
lea    0x6(%rsp),%r15
lea    0x4(%rsp),%r13
test   %ebx,%ebx
je     1291 <main+0x131>
test   %eax,%eax
je     1291 <main+0x131>
mov    %ecx,%esi
neg    %esi
cmovs  %ecx,%esi
cmp    $0x2,%esi
jae    12a7 <main+0x147>
cmp    $0x1,%ecx
sbb    $0xffffffff,%ebp
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %eax,%ebx
mov    %r13,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
movswl 0x6(%rsp),%ecx
movswl 0x4(%rsp),%edx
sub    %edx,%ecx
mov    %eax,%edx
or     %ebx,%edx
jne    11f0 <main+0x90>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
lea    0xdc6(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xdf3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
lea    0xdb5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xd55(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"compare <file1> <file2>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [41 x i8] c"FATAL error, files have different size!\0A\00"
@.str.3 = [46 x i8] c"FATAL error, too large differnce found (%d)!\0A\00"
@.str.4 = [28 x i8] c"%d (+/-1)differences found\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 i16
%10 = alloca i16
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 2)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %7
br label %28
28: ; preds = %72, %19
%29 = load i32*, i32** %6
%30 = call i32 @fread(i16* %9, i32 2, i32 1, i32* %29)
store i32 %30, i32* %12
%31 = load i32*, i32** %7
%32 = call i32 @fread(i16* %10, i32 2, i32 1, i32* %31)
store i32 %32, i32* %13
%33 = load i16, i16* %9
%34 = sext i16 %33 to i32
%35 = load i16, i16* %10
%36 = sext i16 %35 to i32
%37 = sub nsw i32 %34, %36
store i32 %37, i32* %11
%38 = load i32, i32* %12
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %28
%41 = load i32, i32* %13
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %40
br label %73
44: ; preds = %40, %28
%45 = load i32, i32* %12
%46 = icmp eq i32 %45, 0
br i1 %46, label %50, label %47
47: ; preds = %44
%48 = load i32, i32* %13
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %47, %44
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %47
%54 = load i32, i32* %11
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i32, i32* %11
%58 = sub nsw i32 0, %57
store i32 %58, i32* %11
br label %59
59: ; preds = %56, %53
%60 = load i32, i32* %11
%61 = icmp sgt i32 %60, 1
br i1 %61, label %62, label %66
62: ; preds = %59
%63 = load i32, i32* %11
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %63)
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %59
%67 = load i32, i32* %11
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load i32, i32* %8
%71 = add nsw i32 %70, 1
store i32 %71, i32* %8
br label %72
72: ; preds = %69, %66
br label %28
73: ; preds = %43
%74 = load i32*, i32** %6
%75 = call i32 @fclose(i32* %74)
%76 = load i32*, i32** %7
%77 = call i32 @fclose(i32* %76)
%78 = load i32, i32* %8
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %78)
%80 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.3 = [46 x i8] c"FATAL error, too large differnce found (%d)!\0A\00"
@.str.4 = [28 x i8] c"%d (+/-1)differences found\0A\00"
@str = [40 x i8] c"FATAL error, files have different size!\00"
@str.5 = [24 x i8] c"compare <file1> <file2>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = alloca i16
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0))
%8 = tail call i32 @exit(i32 2)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = bitcast i16* %3 to i8*
%17 = bitcast i16* %4 to i8*
%18 = call i32 @fread(i16* %3, i32 2, i32 1, i32* %12)
%19 = call i32 @fread(i16* %4, i32 2, i32 1, i32* %15)
%20 = or i32 %19, %18
%21 = icmp eq i32 %20, 0
br i1 %21, label %58, label %22
22: ; preds = %9
%23 = load i16, i16* %3
%24 = sext i16 %23 to i32
%25 = load i16, i16* %4
%26 = sext i16 %25 to i32
%27 = sub nsw i32 %24, %26
br label %28
28: ; preds = %22, %45
%29 = phi i32 [ %55, %45 ], [ %27, %22 ]
%30 = phi i32 [ %50, %45 ], [ %19, %22 ]
%31 = phi i32 [ %49, %45 ], [ %18, %22 ]
%32 = phi i32 [ %48, %45 ], [ 0, %22 ]
%33 = icmp eq i32 %30, 0
%34 = icmp eq i32 %31, 0
%35 = or i1 %34, %33
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %28
%40 = tail call i32 @llvm.abs.i32(i32 %29, i1 true)
%41 = icmp ugt i32 %40, 1
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %39
%46 = icmp ne i32 %29, 0
%47 = zext i1 %46 to i32
%48 = add nuw nsw i32 %32, %47
%49 = call i32 @fread(i16* %3, i32 2, i32 1, i32* %12)
%50 = call i32 @fread(i16* %4, i32 2, i32 1, i32* %15)
%51 = load i16, i16* %3
%52 = sext i16 %51 to i32
%53 = load i16, i16* %4
%54 = sext i16 %53 to i32
%55 = sub nsw i32 %52, %54
%56 = or i32 %50, %49
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %28
58: ; preds = %45, %9
%59 = phi i32 [ 0, %9 ], [ %48, %45 ]
%60 = tail call i32 @fclose(i32* %12)
%61 = tail call i32 @fclose(i32* %15)
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %59)
%63 = tail call i32 @exit(i32 0)
unreachable
}