#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*/ *fopen(char *, char *);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, unsigned char, unsigned char, char *);
int main() {
  FILE *f1 = fopen("bnk1.bnk", "rb");
  FILE *f2 = fopen("bnk2.bnk", "rb");
  unsigned char byte1 = 0, byte2 = 0;
  int count = 0;
  int insCount = 0;
  int dataPos = 4;
  int valid1 = 1;
  int valid2 = 1;
  int drumMode = 0;
  while (valid1 && valid2) {
    valid1 = (fread(&byte1, 1, 1, f1) != 0);
    valid2 = (fread(&byte2, 1, 1, f2) != 0);
    if (!valid1 && !valid2)
      break;
    printf("%03X: {0x%02x == 0x%02x}%s\n", count, byte1, byte2,
           (byte1 == byte2) ? "" : " <- NOT SAME!!!");
    count++;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xeaf(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
movb   $0x0,-0x1a(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x4,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x2c(%rbp)
mov    %al,-0x35(%rbp)
je     11b8 <main+0x88>
cmpl   $0x0,-0x30(%rbp)
setne  %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    11c8 <main+0x98>
jmp    126e <main+0x13e>
mov    -0x10(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x1a(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1227 <main+0xf7>
cmpl   $0x0,-0x30(%rbp)
jne    1227 <main+0xf7>
jmp    126e <main+0x13e>
mov    -0x20(%rbp),%esi
mov    -0x19(%rbp),%cl
mov    -0x1a(%rbp),%al
movzbl -0x19(%rbp),%edi
movzbl -0x1a(%rbp),%r9d
lea    0xdf1(%rip),%r8
lea    0xde9(%rip),%rdx
cmp    %r9d,%edi
cmove  %rdx,%r8
lea    0xdc0(%rip),%rdi
movzbl %cl,%edx
movzbl %al,%ecx
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119f <main+0x6f>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
lea    0xec0(%rip),%rbx
mov    %rbx,%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
lea    0xeb1(%rip),%rdi
mov    %rbx,%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
movb   $0x0,0x7(%rsp)
movb   $0x0,0x6(%rsp)
xor    %ebp,%ebp
lea    0xe9c(%rip),%r13
nopl   0x0(%rax)
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %rax,%r15
lea    0x6(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rax,%r12
or     %r15,%rax
je     11ee <main+0xbe>
movzbl 0x7(%rsp),%edx
movzbl 0x6(%rsp),%ecx
cmp    %cl,%dl
lea    0xe65(%rip),%r8
lea    0xe5d(%rip),%rax
cmove  %rax,%r8
mov    %r13,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
test   %r15,%r15
je     11ee <main+0xbe>
add    $0x1,%ebp
test   %r12,%r12
jne    1180 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"bnk1.bnk\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [9 x i8] c"bnk2.bnk\00"
@.str.3 = [28 x i8] c"%03X: {0x%02x == 0x%02x}%s\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [16 x i8] c" <- NOT SAME!!!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
%12 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %2
%13 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %3
store i8 0, i8* %4
store i8 0, i8* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 4, i32* %8
store i32 1, i32* %9
store i32 1, i32* %10
store i32 0, i32* %11
br label %14
14: ; preds = %37, %0
%15 = load i32, i32* %9
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %10
%19 = icmp ne i32 %18, 0
br label %20
20: ; preds = %17, %14
%21 = phi i1 [ false, %14 ], [ %19, %17 ]
br i1 %21, label %22, label %51
22: ; preds = %20
%23 = load i32*, i32** %2
%24 = call i64 @fread(i8* %4, i32 1, i32 1, i32* %23)
%25 = icmp ne i64 %24, 0
%26 = zext i1 %25 to i32
store i32 %26, i32* %9
%27 = load i32*, i32** %3
%28 = call i64 @fread(i8* %5, i32 1, i32 1, i32* %27)
%29 = icmp ne i64 %28, 0
%30 = zext i1 %29 to i32
store i32 %30, i32* %10
%31 = load i32, i32* %9
%32 = icmp ne i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %22
%34 = load i32, i32* %10
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %33
br label %51
37: ; preds = %33, %22
%38 = load i32, i32* %6
%39 = load i8, i8* %4
%40 = load i8, i8* %5
%41 = load i8, i8* %4
%42 = zext i8 %41 to i32
%43 = load i8, i8* %5
%44 = zext i8 %43 to i32
%45 = icmp eq i32 %42, %44
%46 = zext i1 %45 to i64
%47 = select i1 %45, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0)
%48 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %38, i8 zeroext %39, i8 zeroext %40, i8* %47)
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %14
51: ; preds = %36, %20
%52 = load i32, i32* %1
ret i32 %52
}

LLVM IR (-O2):
@.str = [9 x i8] c"bnk1.bnk\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [9 x i8] c"bnk2.bnk\00"
@.str.3 = [28 x i8] c"%03X: {0x%02x == 0x%02x}%s\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [16 x i8] c" <- NOT SAME!!!\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i8
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8 0, i8* %1
store i8 0, i8* %2
br label %5
5: ; preds = %0, %11
%6 = phi i32 [ 0, %0 ], [ %19, %11 ]
%7 = call i64 @fread(i8* %1, i32 1, i32 1, i32* %3)
%8 = call i64 @fread(i8* %2, i32 1, i32 1, i32* %4)
%9 = or i64 %8, %7
%10 = icmp eq i64 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %5
%12 = icmp ne i64 %8, 0
%13 = icmp ne i64 %7, 0
%14 = load i8, i8* %1
%15 = load i8, i8* %2
%16 = icmp eq i8 %14, %15
%17 = select i1 %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %6, i8 zeroext %14, i8 zeroext %15, i8* %17)
%19 = add nuw nsw i32 %6, 1
%20 = and i1 %13, %12
br i1 %20, label %5, label %21
21: ; preds = %5, %11
ret i32 0
}