#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 *getbaseaddress(long, long *);
int /*<<< orphan*/ getindexfromoffset(long);
char const *getoffsetstr(long, int /*<<< orphan*/);
char const *strf(char *, char const *, char const *);
char const *strhex(long);
char const *straddress(long address) {
  char const *name, *offset;
  long base;
  if (address == 0)
    return "0";
  name = getbaseaddress(address, &base);
  if (!name)
    return strhex(address);
  if (!*name)
    return getoffsetstr(address, getindexfromoffset(address));
  if (address == base)
    return name;
  offset = getoffsetstr(address - base, getindexfromoffset(address - base));
  return strf("%s + %s", name, offset);
}


x86 assembly (clang, -O0):
<straddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1177 <straddress+0x27>
lea    0xe92(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1232 <straddress+0xe2>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <getbaseaddress@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a5 <straddress+0x55>
mov    -0x10(%rbp),%rdi
call   1040 <strhex@plt>
mov    %rax,-0x8(%rbp)
jmp    1232 <straddress+0xe2>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11d7 <straddress+0x87>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getindexfromoffset@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1060 <getoffsetstr@plt>
mov    %rax,-0x8(%rbp)
jmp    1232 <straddress+0xe2>
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    11f2 <straddress+0xa2>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1232 <straddress+0xe2>
mov    -0x10(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
sub    -0x28(%rbp),%rdi
call   1030 <getindexfromoffset@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1060 <getoffsetstr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xdd9(%rip),%rdi
call   1050 <strf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<straddress>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a3 <straddress+0x53>
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1070 <getbaseaddress@plt>
test   %rax,%rax
je     11ac <straddress+0x5c>
mov    %rax,%r14
cmpb   $0x0,(%rax)
je     11b6 <straddress+0x66>
mov    (%rsp),%rax
cmp    %rbx,%rax
je     11cb <straddress+0x7b>
sub    %rax,%rbx
mov    %rbx,%rdi
call   1030 <getindexfromoffset@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <getoffsetstr@plt>
lea    0xe6c(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1050 <strf@plt>
jmp    11c8 <straddress+0x78>
lea    0xe56(%rip),%r14
jmp    11cb <straddress+0x7b>
mov    %rbx,%rdi
call   1040 <strhex@plt>
jmp    11c8 <straddress+0x78>
mov    %rbx,%rdi
call   1030 <getindexfromoffset@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <getoffsetstr@plt>
mov    %rax,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [8 x i8] c"%s + %s\00"
define i8* @straddress(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i64 %0, i64* %3
%7 = load i64, i64* %3
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2
br label %45
10: ; preds = %1
%11 = load i64, i64* %3
%12 = call i8* @getbaseaddress(i64 %11, i64* %6)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = load i64, i64* %3
%17 = call i8* @strhex(i64 %16)
store i8* %17, i8** %2
br label %45
18: ; preds = %10
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = icmp ne i8 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %18
%23 = load i64, i64* %3
%24 = load i64, i64* %3
%25 = call i32 @getindexfromoffset(i64 %24)
%26 = call i8* @getoffsetstr(i64 %23, i32 %25)
store i8* %26, i8** %2
br label %45
27: ; preds = %18
%28 = load i64, i64* %3
%29 = load i64, i64* %6
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = load i8*, i8** %4
store i8* %32, i8** %2
br label %45
33: ; preds = %27
%34 = load i64, i64* %3
%35 = load i64, i64* %6
%36 = sub nsw i64 %34, %35
%37 = load i64, i64* %3
%38 = load i64, i64* %6
%39 = sub nsw i64 %37, %38
%40 = call i32 @getindexfromoffset(i64 %39)
%41 = call i8* @getoffsetstr(i64 %36, i32 %40)
store i8* %41, i8** %5
%42 = load i8*, i8** %4
%43 = load i8*, i8** %5
%44 = call i8* @strf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* %43)
store i8* %44, i8** %2
br label %45
45: ; preds = %33, %31, %22, %15, %9
%46 = load i8*, i8** %2
ret i8* %46
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
@.str.1 = [8 x i8] c"%s + %s\00"
define i8* @straddress(i64 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = icmp eq i64 %0, 0
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = call i8* @getbaseaddress(i64 %0, i64* %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = call i8* @strhex(i64 %0)
br label %24
10: ; preds = %5
%11 = load i8, i8* %6
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 @getindexfromoffset(i64 %0)
%15 = call i8* @getoffsetstr(i64 %0, i32 %14)
br label %24
16: ; preds = %10
%17 = load i64, i64* %2
%18 = icmp eq i64 %17, %0
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = sub nsw i64 %0, %17
%21 = call i32 @getindexfromoffset(i64 %20)
%22 = call i8* @getoffsetstr(i64 %20, i32 %21)
%23 = call i8* @strf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %22)
br label %24
24: ; preds = %16, %1, %19, %13, %8
%25 = phi i8* [ %23, %19 ], [ %15, %13 ], [ %9, %8 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %1 ], [ %6, %16 ]
ret i8* %25
}