#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*/ close_bfd_executable();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ find_src_loc(void *, char **, int *, char **);
int /*<<< orphan*/ open_bfd_executable(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, void **);
main(int ac, char **av) {
  void *pc;
  char *filename;
  char *functname;
  int lineno;
  if (ac != 3) {
    printf("usage: %s <exe file> <hex pc>\n", av[0]);
    exit(1);
  }
  open_bfd_executable(av[1]);
  sscanf(av[2], "%x", &pc);
  find_src_loc(pc, &filename, &lineno, &functname);
  printf("\npc = %x (%d) -> %s:%d:%s\n", (long)pc, (long)pc, filename, lineno,
         functname);
  close_bfd_executable();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x4(%rbp)
je     1198 <main+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <open_bfd_executable@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe6b(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1060 <find_src_loc@plt>
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
mov    -0x28(%rbp),%r9
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <close_bfd_executable@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11d8 <main+0x78>
mov    0x8(%rbx),%rdi
call   1050 <open_bfd_executable@plt>
mov    0x10(%rbx),%rdi
lea    0xe9e(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1070 <sscanf@plt>
mov    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
lea    0x4(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1060 <find_src_loc@plt>
mov    0x8(%rsp),%rdx
mov    0x18(%rsp),%rcx
mov    0x4(%rsp),%r8d
mov    0x10(%rsp),%r9
lea    0xe63(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <close_bfd_executable@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
mov    (%rbx),%rsi
lea    0xe1e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"usage: %s <exe file> <hex pc>\0A\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [27 x i8] c"\0Apc = %x (%d) -> %s:%d:%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %4
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @open_bfd_executable(i8* %20)
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @sscanf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %5)
%26 = load i8*, i8** %5
%27 = call i32 @find_src_loc(i8* %26, i8** %6, i32* %8, i8** %7)
%28 = load i8*, i8** %5
%29 = ptrtoint i8* %28 to i64
%30 = load i8*, i8** %5
%31 = ptrtoint i8* %30 to i64
%32 = load i8*, i8** %6
%33 = load i32, i32* %8
%34 = load i8*, i8** %7
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %29, i64 %31, i8* %32, i32 %33, i8* %34)
%36 = call i32 (...) @close_bfd_executable()
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"usage: %s <exe file> <hex pc>\0A\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [27 x i8] c"\0Apc = %x (%d) -> %s:%d:%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = bitcast i8** %3 to i8*
%8 = bitcast i8** %4 to i8*
%9 = bitcast i8** %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = icmp eq i32 %0, 3
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @open_bfd_executable(i8* %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %3)
%23 = load i8*, i8** %3
%24 = call i32 @find_src_loc(i8* %23, i8** %4, i32* %6, i8** %5)
%25 = load i8*, i8** %3
%26 = ptrtoint i8* %25 to i64
%27 = load i8*, i8** %4
%28 = load i32, i32* %6
%29 = load i8*, i8** %5
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %26, i64 %26, i8* %27, i32 %28, i8* %29)
%31 = call i32 (...) @close_bfd_executable()
ret i32 0
}