#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 atoi(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc < 2 || argc > 3) {
    printf("usage: %s filename [count]\n", argv[0]);
    return -1;
  }
  FILE *file = fopen(argv[1], "r");
  unsigned i, count = argc == 3 ? atoi(argv[2]) : 1024;
  for (i = 0; i < count; ++i) {
    unsigned short sig;
    fread((void *)&sig, 2, 1, file);
    if (sig == 0xEF53)
      printf("%u: %X\n", i / 512, sig);
  }
}


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)
cmpl   $0x2,-0x8(%rbp)
jl     116a <main+0x2a>
cmpl   $0x3,-0x8(%rbp)
jle    118b <main+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <main+0xf9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe82(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    11c2 <main+0x82>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x28(%rbp)
jmp    11cf <main+0x8f>
mov    $0x400,%eax
mov    %eax,-0x28(%rbp)
jmp    11cf <main+0x8f>
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    1239 <main+0xf9>
lea    -0x22(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
movzwl -0x22(%rbp),%eax
cmp    $0xef53,%eax
jne    1226 <main+0xe6>
mov    -0x1c(%rbp),%esi
shr    $0x9,%esi
movzwl -0x22(%rbp),%edx
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122b <main+0xeb>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11dc <main+0x9c>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
lea    -0x4(%r15),%eax
cmp    $0xfffffffd,%eax
ja     1173 <main+0x33>
mov    (%r14),%rsi
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
jmp    11f0 <main+0xb0>
mov    0x8(%r14),%rdi
lea    0xe9e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r12
mov    $0x400,%ebp
cmp    $0x3,%r15d
jne    11a0 <main+0x60>
mov    0x10(%r14),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11ee <main+0xae>
lea    0xe(%rsp),%r14
lea    0xe72(%rip),%r15
xor    %ebx,%ebx
jmp    11b7 <main+0x77>
add    $0x1,%ebx
cmp    %ebx,%ebp
je     11ee <main+0xae>
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
movzwl 0xe(%rsp),%eax
cmp    $0xef53,%eax
jne    11b0 <main+0x70>
mov    %ebx,%esi
shr    $0x9,%esi
mov    %r15,%rdi
mov    $0xef53,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b0 <main+0x70>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"usage: %s filename [count]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"%u: %X\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 3
br i1 %14, label %15, label %20
15: ; preds = %12, %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 -1, i32* %3
br label %56
20: ; preds = %12
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 3
br i1 %26, label %27, label %32
27: ; preds = %20
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
br label %33
32: ; preds = %20
br label %33
33: ; preds = %32, %27
%34 = phi i32 [ %31, %27 ], [ 1024, %32 ]
store i32 %34, i32* %8
store i32 0, i32* %7
br label %35
35: ; preds = %53, %33
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = icmp ult i32 %36, %37
br i1 %38, label %39, label %56
39: ; preds = %35
%40 = bitcast i16* %9 to i8*
%41 = load i32*, i32** %6
%42 = call i32 @fread(i8* %40, i32 2, i32 1, i32* %41)
%43 = load i16, i16* %9
%44 = zext i16 %43 to i32
%45 = icmp eq i32 %44, 61267
br i1 %45, label %46, label %52
46: ; preds = %39
%47 = load i32, i32* %7
%48 = udiv i32 %47, 512
%49 = load i16, i16* %9
%50 = zext i16 %49 to i32
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %48, i32 %50)
br label %52
52: ; preds = %46, %39
br label %53
53: ; preds = %52
%54 = load i32, i32* %7
%55 = add i32 %54, 1
store i32 %55, i32* %7
br label %35
56: ; preds = %15, %35
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [28 x i8] c"usage: %s filename [count]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"%u: %X\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = add i32 %0, -4
%5 = icmp ult i32 %4, -2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %33
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 ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32 %0, 3
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %33, label %19
19: ; preds = %9, %14
%20 = phi i32 [ %17, %14 ], [ 1024, %9 ]
%21 = bitcast i16* %3 to i8*
br label %22
22: ; preds = %19, %30
%23 = phi i32 [ 0, %19 ], [ %31, %30 ]
%24 = call i32 @fread(i8* %21, i32 2, i32 1, i32* %12)
%25 = load i16, i16* %3
%26 = icmp eq i16 %25, -4269
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = lshr i32 %23, 9
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 61267)
br label %30
30: ; preds = %27, %22
%31 = add nuw i32 %23, 1
%32 = icmp eq i32 %31, %20
br i1 %32, label %33, label %22
33: ; preds = %30, %14, %6
%34 = phi i32 [ -1, %6 ], [ 0, %14 ], [ 0, %30 ]
ret i32 %34
}