#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, ...);
int main() {
  FILE *f1 = fopen("duke1.tmb", "rb");
  FILE *f2 = fopen("duke2.tmb", "rb");
  unsigned char byte1 = 0, byte2 = 0;
  int count = 0;
  int insCount = 0;
  int dataPos = 0;
  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;
    if (count >= dataPos) {
      if ((count - dataPos) % 13 == 0) {
        if (drumMode)
          printf("DRUM!!! %d\n", (insCount++) - 128);
        else
          printf("INSTRUMENT!!! %d\n", insCount++);
        if (insCount == 128)
          drumMode = 1;
      }
    }
    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    0xebd(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xeb0(%rip),%rdi
lea    0xea6(%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   $0x0,-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    12f4 <main+0x1c4>
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    12f4 <main+0x1c4>
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
jl     12af <main+0x17f>
mov    -0x20(%rbp),%eax
sub    -0x28(%rbp),%eax
mov    $0xd,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12aa <main+0x17a>
cmpl   $0x0,-0x34(%rbp)
je     1278 <main+0x148>
mov    -0x24(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
sub    $0x80,%esi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1291 <main+0x161>
mov    -0x24(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x80,-0x24(%rbp)
jne    12a5 <main+0x175>
movl   $0x1,-0x34(%rbp)
jmp    12aa <main+0x17a>
jmp    12af <main+0x17f>
mov    -0x20(%rbp),%esi
movzbl -0x19(%rbp),%edx
movzbl -0x1a(%rbp),%ecx
movzbl -0x19(%rbp),%edi
movzbl -0x1a(%rbp),%r9d
lea    0xd87(%rip),%r8
lea    0xd51(%rip),%rax
cmp    %r9d,%edi
cmove  %rax,%r8
lea    0xd56(%rip),%rdi
mov    $0x0,%al
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
sub    $0x18,%rsp
lea    0xebb(%rip),%rdi
lea    0xebe(%rip),%rbx
mov    %rbx,%rsi
call   1050 <fopen@plt>
mov    %rax,0x10(%rsp)
lea    0xead(%rip),%rdi
mov    %rbx,%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
movb   $0x0,0xf(%rsp)
movb   $0x0,0xe(%rsp)
xor    %r14d,%r14d
xor    %ebp,%ebp
xor    %r15d,%r15d
nopl   (%rax)
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    0x10(%rsp),%rcx
call   1030 <fread@plt>
mov    %rax,%r12
lea    0xe(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rax,%r13
or     %r12,%rax
je     124c <main+0x11c>
mov    %ebp,%eax
imul   $0x4ec4ec4f,%rax,%rax
shr    $0x22,%rax
lea    (%rax,%rax,2),%ecx
lea    (%rax,%rcx,4),%eax
cmp    %ebp,%eax
jne    120d <main+0xdd>
test   %r14d,%r14d
je     11e8 <main+0xb8>
lea    -0x80(%r15),%esi
lea    0xe31(%rip),%rdi
jmp    11f2 <main+0xc2>
lea    0xe34(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15d
cmp    $0x80,%r15d
mov    $0x1,%eax
cmove  %eax,%r14d
movzbl 0xf(%rsp),%edx
movzbl 0xe(%rsp),%ecx
cmp    %cl,%dl
lea    0xe31(%rip),%r8
lea    0xdfb(%rip),%rax
cmove  %rax,%r8
lea    0xe03(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r12,%r12
je     124c <main+0x11c>
add    $0x1,%ebp
test   %r13,%r13
jne    1180 <main+0x50>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"duke1.tmb\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [10 x i8] c"duke2.tmb\00"
@.str.3 = [12 x i8] c"DRUM!!! %d\0A\00"
@.str.4 = [18 x i8] c"INSTRUMENT!!! %d\0A\00"
@.str.5 = [28 x i8] c"%03X: {0x%02x == 0x%02x}%s\0A\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [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 ([10 x i8], [10 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 ([10 x i8], [10 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 0, i32* %8
store i32 1, i32* %9
store i32 1, i32* %10
store i32 0, i32* %11
br label %14
14: ; preds = %65, %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 %81
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 %81
37: ; preds = %33, %22
%38 = load i32, i32* %6
%39 = load i32, i32* %8
%40 = icmp sge i32 %38, %39
br i1 %40, label %41, label %65
41: ; preds = %37
%42 = load i32, i32* %6
%43 = load i32, i32* %8
%44 = sub nsw i32 %42, %43
%45 = srem i32 %44, 13
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %64
47: ; preds = %41
%48 = load i32, i32* %11
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
%53 = sub nsw i32 %51, 128
%54 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %53)
br label %59
55: ; preds = %47
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
%58 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %56)
br label %59
59: ; preds = %55, %50
%60 = load i32, i32* %7
%61 = icmp eq i32 %60, 128
br i1 %61, label %62, label %63
62: ; preds = %59
store i32 1, i32* %11
br label %63
63: ; preds = %62, %59
br label %64
64: ; preds = %63, %41
br label %65
65: ; preds = %64, %37
%66 = load i32, i32* %6
%67 = load i8, i8* %4
%68 = zext i8 %67 to i32
%69 = load i8, i8* %5
%70 = zext i8 %69 to i32
%71 = load i8, i8* %4
%72 = zext i8 %71 to i32
%73 = load i8, i8* %5
%74 = zext i8 %73 to i32
%75 = icmp eq i32 %72, %74
%76 = zext i1 %75 to i64
%77 = select i1 %75, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0)
%78 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %66, i32 %68, i32 %70, i8* %77)
%79 = load i32, i32* %6
%80 = add nsw i32 %79, 1
store i32 %80, i32* %6
br label %14
81: ; preds = %36, %20
%82 = load i32, i32* %1
ret i32 %82
}

LLVM IR (-O2):
@.str = [10 x i8] c"duke1.tmb\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [10 x i8] c"duke2.tmb\00"
@.str.3 = [12 x i8] c"DRUM!!! %d\0A\00"
@.str.4 = [18 x i8] c"INSTRUMENT!!! %d\0A\00"
@.str.5 = [28 x i8] c"%03X: {0x%02x == 0x%02x}%s\0A\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [16 x i8] c" <- NOT SAME!!!\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i8
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 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 ([10 x i8], [10 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, %29
%6 = phi i32 [ 0, %0 ], [ %31, %29 ]
%7 = phi i32 [ 0, %0 ], [ %39, %29 ]
%8 = phi i32 [ 0, %0 ], [ %30, %29 ]
%9 = call i64 @fread(i8* %1, i32 1, i32 1, i32* %3)
%10 = icmp ne i64 %9, 0
%11 = call i64 @fread(i8* %2, i32 1, i32 1, i32* %4)
%12 = icmp ne i64 %11, 0
%13 = or i64 %11, %9
%14 = icmp eq i64 %13, 0
br i1 %14, label %41, label %15
15: ; preds = %5
%16 = urem i32 %7, 13
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = icmp eq i32 %6, 0
br i1 %19, label %23, label %20
20: ; preds = %18
%21 = add nsw i32 %8, -128
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %25
23: ; preds = %18
%24 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %8)
br label %25
25: ; preds = %23, %20
%26 = add nsw i32 %8, 1
%27 = icmp eq i32 %26, 128
%28 = select i1 %27, i32 1, i32 %6
br label %29
29: ; preds = %25, %15
%30 = phi i32 [ %8, %15 ], [ %26, %25 ]
%31 = phi i32 [ %6, %15 ], [ %28, %25 ]
%32 = load i8, i8* %1
%33 = zext i8 %32 to i32
%34 = load i8, i8* %2
%35 = zext i8 %34 to i32
%36 = icmp eq i8 %32, %34
%37 = select i1 %36, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0)
%38 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %7, i32 %33, i32 %35, i8* %37)
%39 = add nuw nsw i32 %7, 1
%40 = and i1 %10, %12
br i1 %40, label %5, label %41
41: ; preds = %5, %29
ret i32 0
}