#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 */

/* Variables and functions */
int /*<<< orphan*/ find_reference(unsigned char *, int, unsigned int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ print_usage();
int read_file(char *, unsigned char **);
int /*<<< orphan*/ stderr;
unsigned int strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  unsigned char *data;
  char *fname;
  unsigned int addr;
  int len;
  int i;
  if (argc < 3) {
    print_usage();
    return 1;
  }
  fname = argv[1];
  len = read_file(fname, &data);
  if (len > 0) {
    for (i = 2; i < argc; i++) {
      addr = strtoul(argv[i], NULL, 16);
      find_reference(data, len, addr);
    }
  } else {
    fprintf(stderr, "Error opening/reading \"%s\"\n", fname);
    return 1;
  }
  return 0;
}


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   $0x3,-0x8(%rbp)
jge    1183 <main+0x33>
mov    $0x0,%al
call   1070 <print_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1227 <main+0xd7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <read_file@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    11fb <main+0xab>
movl   $0x2,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f6 <main+0xa6>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1050 <find_reference@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b0 <main+0x60>
jmp    1220 <main+0xd0>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdf1(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1227 <main+0xd7>
movl   $0x0,-0x4(%rbp)
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
cmp    $0x2,%edi
jg     116a <main+0x1a>
xor    %eax,%eax
call   1070 <print_usage@plt>
jmp    11d4 <main+0x84>
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x8(%rsi),%r15
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1040 <read_file@plt>
test   %eax,%eax
jle    11bc <main+0x6c>
mov    %eax,%r12d
mov    %ebx,%r15d
mov    $0x2,%ebp
nop
mov    (%r14,%rbp,8),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    0x8(%rsp),%rdi
mov    %r12d,%esi
mov    %eax,%edx
call   1050 <find_reference@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1190 <main+0x40>
jmp    11d9 <main+0x89>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
mov    %r15,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Error opening/reading \22%s\22\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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (...) @print_usage()
store i32 1, i32* %3
br label %48
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = call i32 @read_file(i8* %19, i8** %6)
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %43
23: ; preds = %15
store i32 2, i32* %10
br label %24
24: ; preds = %39, %23
%25 = load i32, i32* %10
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %42
28: ; preds = %24
%29 = load i8**, i8*** %5
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 @strtoul(i8* %33, i32* null, i32 16)
store i32 %34, i32* %8
%35 = load i8*, i8** %6
%36 = load i32, i32* %9
%37 = load i32, i32* %8
%38 = call i32 @find_reference(i8* %35, i32 %36, i32 %37)
br label %39
39: ; preds = %28
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
br label %24
42: ; preds = %24
br label %47
43: ; preds = %15
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %7
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %45)
store i32 1, i32* %3
br label %48
47: ; preds = %42
store i32 0, i32* %3
br label %48
48: ; preds = %47, %43, %13
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Error opening/reading \22%s\22\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (...) @print_usage()
br label %27
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @read_file(i8* %10, i8** %3)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %8
%14 = zext i32 %0 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 2, %13 ], [ %22, %15 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = call i32 @strtoul(i8* nocapture %18, i32* null, i32 16)
%20 = load i8*, i8** %3
%21 = call i32 @find_reference(i8* %20, i32 %11, i32 %19)
%22 = add nuw nsw i64 %16, 1
%23 = icmp eq i64 %22, %14
br i1 %23, label %27, label %15
24: ; preds = %8
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %27
27: ; preds = %15, %24, %6
%28 = phi i32 [ 1, %6 ], [ 1, %24 ], [ 0, %15 ]
ret i32 %28
}