#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
unsigned char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *n1, *n2;
  FILE *f1, *f2;
  unsigned long ptr;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s file1 file2\n", argv[0]);
    return 1;
  }
  n1 = argv[1];
  n2 = argv[2];
  f1 = fopen(n1, "rb");
  if (f1 == NULL) {
    fprintf(stderr, "Error opening '%s'\n", n1);
    return 2;
  }
  f2 = fopen(n2, "rb");
  if (f2 == NULL) {
    fprintf(stderr, "Error opening '%s'\n", n2);
    fclose(f1);
    return 3;
  }
  ptr = 0;
  printf("/*\n * This is the list of neccessary changes in the form <offset, "
         "value>\n * for patching the original TOS 4.04 for 68040 "
         "compatibility.\n *\n * Autogenerated by tools/romdiff.c tool\n "
         "*/\n\n#include \"romdiff.h\"\n\n");
  printf("ROMdiff tosdiff[] = {\n");
  while (!feof(f1) && !feof(f2)) {
    unsigned char c1, c2;
    c1 = fgetc(f1);
    c2 = fgetc(f2);
    if (c1 != c2)
      printf("\t{0x%lx, 0x%02x},\n", ptr, c2);
    ptr++;
  }
  printf("\t{-1, 0}\n};\n");
  fclose(f1);
  fclose(f2);
}


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)
cmpl   $0x3,-0x8(%rbp)
je     11a8 <main+0x48>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1321 <main+0x1c1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1204 <main+0xa4>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe27(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1321 <main+0x1c1>
mov    -0x20(%rbp),%rdi
lea    0xe08(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1251 <main+0xf1>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xde3(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x3,-0x4(%rbp)
jmp    1321 <main+0x1c1>
movq   $0x0,-0x38(%rbp)
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x3b(%rbp)
jne    12a2 <main+0x142>
mov    -0x30(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x3b(%rbp)
mov    -0x3b(%rbp),%al
test   $0x1,%al
jne    12b2 <main+0x152>
jmp    1301 <main+0x1a1>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x39(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x3a(%rbp)
movzbl -0x39(%rbp),%eax
movzbl -0x3a(%rbp),%ecx
cmp    %ecx,%eax
je     12f0 <main+0x190>
mov    -0x38(%rbp),%rsi
movzbl -0x3a(%rbp),%edx
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1275 <main+0x115>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x3,%edi
jne    1207 <main+0x97>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%r15
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1226 <main+0xb6>
mov    %rax,%r12
lea    0xe6c(%rip),%rsi
mov    %r15,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1245 <main+0xd5>
mov    %rax,%r14
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
lea    0xf3e(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1273 <main+0x103>
lea    0xf38(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    126a <main+0xfa>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xde6(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%eax
jmp    126a <main+0xfa>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    $0x2,%eax
jmp    126a <main+0xfa>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
mov    %r15,%rdx
call   1070 <fprintf@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    $0x3,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb4(%rip),%r15
xor    %ebx,%ebx
jmp    1294 <main+0x124>
xchg   %ax,%ax
add    $0x1,%rbx
mov    %r12,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    11e7 <main+0x77>
mov    %r14,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    11e7 <main+0x77>
mov    %r12,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <fgetc@plt>
cmp    %al,%bpl
je     1280 <main+0x110>
movzbl %al,%edx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1280 <main+0x110>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s file1 file2\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [20 x i8] c"Error opening '%s'\0A\00"
@.str.3 = [208 x i8] c"/*\0A * This is the list of neccessary changes in the form <offset, value>\0A * for patching the original TOS 4.04 for 68040 compatibility.\0A *\0A * Autogenerated by tools/romdiff.c tool\0A */\0A\0A#include \22romdiff.h\22\0A\0A\00"
@.str.4 = [23 x i8] c"ROMdiff tosdiff[] = {\0A\00"
@.str.5 = [19 x i8] c"\09{0x%lx, 0x%02x},\0A\00"
@.str.6 = [13 x i8] c"\09{-1, 0}\0A};\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i8
%12 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %85
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
store i8* %27, i8** %7
%28 = load i8*, i8** %6
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %8
%30 = load i32*, i32** %8
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %36
32: ; preds = %21
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %6
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %34)
store i32 2, i32* %3
br label %85
36: ; preds = %21
%37 = load i8*, i8** %7
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %38, i32** %9
%39 = load i32*, i32** %9
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %47
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %7
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %43)
%45 = load i32*, i32** %8
%46 = call i32 @fclose(i32* %45)
store i32 3, i32* %3
br label %85
47: ; preds = %36
store i64 0, i64* %10
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([208 x i8], [208 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %76, %47
%51 = load i32*, i32** %8
%52 = call i32 @feof(i32* %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %59, label %54
54: ; preds = %50
%55 = load i32*, i32** %9
%56 = call i32 @feof(i32* %55)
%57 = icmp ne i32 %56, 0
%58 = xor i1 %57, true
br label %59
59: ; preds = %54, %50
%60 = phi i1 [ false, %50 ], [ %58, %54 ]
br i1 %60, label %61, label %79
61: ; preds = %59
%62 = load i32*, i32** %8
%63 = call zeroext i8 @fgetc(i32* %62)
store i8 %63, i8* %11
%64 = load i32*, i32** %9
%65 = call zeroext i8 @fgetc(i32* %64)
store i8 %65, i8* %12
%66 = load i8, i8* %11
%67 = zext i8 %66 to i32
%68 = load i8, i8* %12
%69 = zext i8 %68 to i32
%70 = icmp ne i32 %67, %69
br i1 %70, label %71, label %76
71: ; preds = %61
%72 = load i64, i64* %10
%73 = load i8, i8* %12
%74 = zext i8 %73 to i32
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i64 %72, i32 %74)
br label %76
76: ; preds = %71, %61
%77 = load i64, i64* %10
%78 = add i64 %77, 1
store i64 %78, i64* %10
br label %50
79: ; preds = %59
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%81 = load i32*, i32** %8
%82 = call i32 @fclose(i32* %81)
%83 = load i32*, i32** %9
%84 = call i32 @fclose(i32* %83)
br label %85
85: ; preds = %79, %41, %32, %15
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s file1 file2\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [20 x i8] c"Error opening '%s'\0A\00"
@.str.5 = [19 x i8] c"\09{0x%lx, 0x%02x},\0A\00"
@str = [207 x i8] c"/*\0A * This is the list of neccessary changes in the form <offset, value>\0A * for patching the original TOS 4.04 for 68040 compatibility.\0A *\0A * Autogenerated by tools/romdiff.c tool\0A */\0A\0A#include \22romdiff.h\22\0A\00"
@str.7 = [22 x i8] c"ROMdiff tosdiff[] = {\00"
@str.8 = [12 x i8] c"\09{-1, 0}\0A};\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %49
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %10)
br label %49
18: ; preds = %8
%19 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%24 = tail call i32 @fclose(i32* %13)
br label %49
25: ; preds = %18
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([207 x i8], [207 x i8]* @str, i64 0, i64 0))
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
%28 = tail call i32 @feof(i32* %13)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %45
30: ; preds = %25, %41
%31 = phi i64 [ %42, %41 ], [ 0, %25 ]
%32 = tail call i32 @feof(i32* %19)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %30
%35 = tail call zeroext i8 @fgetc(i32* %13)
%36 = tail call zeroext i8 @fgetc(i32* %19)
%37 = icmp eq i8 %35, %36
br i1 %37, label %41, label %38
38: ; preds = %34
%39 = zext i8 %36 to i32
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i64 %31, i32 %39)
br label %41
41: ; preds = %38, %34
%42 = add i64 %31, 1
%43 = tail call i32 @feof(i32* %13)
%44 = icmp eq i32 %43, 0
br i1 %44, label %30, label %45
45: ; preds = %30, %41, %25
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
%47 = tail call i32 @fclose(i32* %13)
%48 = tail call i32 @fclose(i32* %19)
br label %49
49: ; preds = %45, %21, %15, %4
%50 = phi i32 [ 1, %4 ], [ 2, %15 ], [ 3, %21 ], [ 0, %45 ]
ret i32 %50
}