#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int parse_symbol_by_addr(unsigned long, char *, int);
int /*<<< orphan*/ printf(char *, unsigned long, char *);
int /*<<< orphan*/ sscanf(char *, char *, unsigned long *);
int /*<<< orphan*/ stdin;
int main(int argc, const char *argv[]) {
  char buffer[256];
  char addrbuffer[64];
  unsigned long addr;
  int ret;
  while (fgets(addrbuffer, 64, stdin)) {
    sscanf(addrbuffer, "%lx", &addr);
    ret = parse_symbol_by_addr(addr, buffer, 256);
    if (ret > 0)
      printf("addr:0x%lx, buffer:%s\n", addr, buffer);
    buffer[0] = '\0';
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x150(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
mov    $0x40,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11e8 <main+0xa8>
lea    -0x150(%rbp),%rdi
lea    0xe75(%rip),%rsi
lea    -0x158(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x158(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1030 <parse_symbol_by_addr@plt>
mov    %eax,-0x15c(%rbp)
cmpl   $0x0,-0x15c(%rbp)
jle    11dc <main+0x9c>
mov    -0x158(%rbp),%rsi
lea    -0x110(%rbp),%rdx
lea    0xe2d(%rip),%rdi
call   1040 <printf@plt>
movb   $0x0,-0x110(%rbp)
jmp    1159 <main+0x19>
xor    %eax,%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
mov    0x2e90(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0x10(%rsp),%rdi
mov    $0x40,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11e0 <main+0xa0>
lea    0xe8a(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r15
lea    0x50(%rsp),%r12
lea    0xe78(%rip),%r13
jmp    11aa <main+0x6a>
xchg   %ax,%ax
movb   $0x0,0x50(%rsp)
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11e0 <main+0xa0>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <sscanf@plt>
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    $0x100,%edx
call   1030 <parse_symbol_by_addr@plt>
test   %eax,%eax
jle    1190 <main+0x50>
mov    0x8(%rsp),%rsi
mov    %r13,%rdi
mov    %r12,%rdx
call   1040 <printf@plt>
jmp    1190 <main+0x50>
xor    %eax,%eax
add    $0x158,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"%lx\00"
@.str.1 = [23 x i8] c"addr:0x%lx, buffer:%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca [64 x i8]
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %10
10: ; preds = %27, %2
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i64 @fgets(i8* %11, i32 64, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %10
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %8)
%18 = load i64, i64* %8
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%20 = call i32 @parse_symbol_by_addr(i64 %18, i8* %19, i32 256)
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %15
%24 = load i64, i64* %8
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %24, i8* %25)
br label %27
27: ; preds = %23, %15
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
store i8 0, i8* %28
br label %10
29: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%lx\00"
@.str.1 = [23 x i8] c"addr:0x%lx, buffer:%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca [64 x i8]
%5 = alloca i64
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%8 = bitcast i64* %5 to i8*
%9 = load i32, i32* @stdin
%10 = call i64 @fgets(i8* %7, i32 64, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %2, %20
%13 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %5)
%14 = load i64, i64* %5
%15 = call i32 @parse_symbol_by_addr(i64 %14, i8* %6, i32 256)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i64, i64* %5
%19 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %18, i8* %6)
br label %20
20: ; preds = %17, %12
store i8 0, i8* %6
%21 = load i32, i32* @stdin
%22 = call i64 @fgets(i8* %7, i32 64, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %12
24: ; preds = %20, %2
ret i32 0
}