#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 */
typedef scalar_t__ uint16_t;

/* Variables and functions */
unsigned long addr_to_global(scalar_t__);
scalar_t__ is_global(scalar_t__);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long);
const char *addrstring(uint16_t addr) {
  static char str[8];
  if (is_global(addr))
    snprintf(str, sizeof str, "G%02lx", addr_to_global(addr));
  else
    snprintf(str, sizeof str, "0x%lx", (unsigned long)addr);
  return str;
}


x86 assembly (clang, -O0):
<addrstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <is_global@plt>
cmp    $0x0,%rax
je     1178 <addrstring+0x48>
mov    -0x8(%rbp),%rdi
call   1030 <addr_to_global@plt>
mov    %rax,%rcx
lea    0x2ed7(%rip),%rdi
mov    $0x8,%esi
lea    0xe92(%rip),%rdx
call   1040 <snprintf@plt>
jmp    1194 <addrstring+0x64>
mov    -0x8(%rbp),%rcx
lea    0x2eb6(%rip),%rdi
mov    $0x8,%esi
lea    0xe78(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2e9e(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addrstring>:
push   %rbx
mov    %rdi,%rbx
call   1050 <is_global@plt>
test   %rax,%rax
je     115e <addrstring+0x2e>
mov    %rbx,%rdi
call   1030 <addr_to_global@plt>
lea    0x2eec(%rip),%rdi
lea    0xeac(%rip),%rdx
mov    $0x8,%esi
mov    %rax,%rcx
jmp    1174 <addrstring+0x44>
lea    0x2ed4(%rip),%rdi
lea    0xe9b(%rip),%rdx
mov    $0x8,%esi
mov    %rbx,%rcx
call   1040 <snprintf@plt>
lea    0x2eb9(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@addrstring.str = internal global [8 x i8] zeroinitializer
@.str = [7 x i8] c"G%02lx\00"
@.str.1 = [6 x i8] c"0x%lx\00"
define i8* @addrstring(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = call i64 @is_global(i64 %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i64, i64* %2
%8 = call i64 @addr_to_global(i64 %7)
%9 = call i32 @snprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @addrstring.str, i64 0, i64 0), i32 8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %8)
br label %13
10: ; preds = %1
%11 = load i64, i64* %2
%12 = call i32 @snprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @addrstring.str, i64 0, i64 0), i32 8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %11)
br label %13
13: ; preds = %10, %6
ret i8* getelementptr inbounds ([8 x i8], [8 x i8]* @addrstring.str, i64 0, i64 0)
}

LLVM IR (-O2):
@addrstring.str = internal global [8 x i8] zeroinitializer
@.str = [7 x i8] c"G%02lx\00"
@.str.1 = [6 x i8] c"0x%lx\00"
define i8* @addrstring(i64 %0) {
%2 = tail call i64 @is_global(i64 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i64 @addr_to_global(i64 %0)
%6 = tail call i32 @snprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @addrstring.str, i64 0, i64 0), i32 8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %5)
br label %9
7: ; preds = %1
%8 = tail call i32 @snprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @addrstring.str, i64 0, i64 0), i32 8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %0)
br label %9
9: ; preds = %7, %4
ret i8* getelementptr inbounds ([8 x i8], [8 x i8]* @addrstring.str, i64 0, i64 0)
}