#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 */
char **backtrace_symbols(void **, int);
int /*<<< orphan*/ free(char **);
char *strchr(char const *, char);
char *strdup(char *);
const char *resolve_addr(const void *addr) {
  char **strings;
  char *p;
  const char *name = NULL;
  if (addr == NULL)
    return "(other)";
  if (addr == (void *)-1)
    return "(total)";
  strings = backtrace_symbols((void **)&addr, 1);
  name = strdup(strings[0]);
  p = strchr(name, '\t');
  if (p)
    name = p + 1;
  free(strings);
  return name;
}


x86 assembly (clang, -O0):
<resolve_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116f <resolve_addr+0x2f>
lea    0xe9a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ec <resolve_addr+0xac>
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x10(%rbp)
jne    1190 <resolve_addr+0x50>
lea    0xe81(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ec <resolve_addr+0xac>
lea    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x9,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11db <resolve_addr+0x9b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve_addr>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,0x8(%rsp)
test   %rdi,%rdi
je     1162 <resolve_addr+0x22>
cmp    $0xffffffffffffffff,%rdi
jne    116b <resolve_addr+0x2b>
lea    0xea8(%rip),%rbx
jmp    11a8 <resolve_addr+0x68>
lea    0xe97(%rip),%rbx
jmp    11a8 <resolve_addr+0x68>
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,%r14
mov    (%rax),%rdi
call   1060 <strdup@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x9,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %r15,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"(other)\00"
@.str.1 = [8 x i8] c"(total)\00"
define i8* @resolve_addr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %6
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %2
br label %31
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = icmp eq i8* %11, inttoptr (i64 -1 to i8*)
br i1 %12, label %13, label %14
13: ; preds = %10
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %31
14: ; preds = %10
%15 = call i8** @backtrace_symbols(i8** %3, i32 1)
store i8** %15, i8*** %4
%16 = load i8**, i8*** %4
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i8* @strdup(i8* %18)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = call i8* @strchr(i8* %20, i8 signext 9)
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %14
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8* %26, i8** %6
br label %27
27: ; preds = %24, %14
%28 = load i8**, i8*** %4
%29 = call i32 @free(i8** %28)
%30 = load i8*, i8** %6
store i8* %30, i8** %2
br label %31
31: ; preds = %27, %13, %9
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
@.str = [8 x i8] c"(other)\00"
@.str.1 = [8 x i8] c"(total)\00"
define i8* @resolve_addr(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = ptrtoint i8* %0 to i64
switch i64 %3, label %5 [
i64 0, label %14
i64 -1, label %4
]
4: ; preds = %1
br label %14
5: ; preds = %1
%6 = call i8** @backtrace_symbols(i8** %2, i32 1)
%7 = load i8*, i8** %6
%8 = call i8* @strdup(i8* %7)
%9 = call i8* @strchr(i8* dereferenceable(1) %8, i8 signext 9)
%10 = icmp eq i8* %9, null
%11 = getelementptr inbounds i8, i8* %9, i64 1
%12 = select i1 %10, i8* %8, i8* %11
%13 = call i32 @free(i8** %6)
br label %14
14: ; preds = %1, %5, %4
%15 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %4 ], [ %12, %5 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %15
}