#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 int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int);
char *sym_by_value(int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sym_is_redefinable(char const *);
const char *ram(uint8_t addr) {
  static char buf[2][5];
  static int buf_sel = 0;
  const char *sym;
  sym = sym_by_value(addr, 0x0002, NULL);
  if (sym && !sym_is_redefinable(sym))
    return sym;
  buf_sel = !buf_sel;
  sprintf(buf[buf_sel], "0x%02X", addr);
  return buf[buf_sel];
}


x86 assembly (clang, -O0):
<ram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x2,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sym_by_value@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     117a <ram+0x4a>
mov    -0x18(%rbp),%rdi
call   1030 <sym_is_redefinable@plt>
cmp    $0x0,%eax
jne    117a <ram+0x4a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ce <ram+0x9e>
cmpl   $0x0,0x2ec7(%rip)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,0x2eb7(%rip)
movslq 0x2eb0(%rip),%rax
lea    0x2e9d(%rip),%rdi
imul   $0x5,%rax,%rax
add    %rax,%rdi
mov    -0xc(%rbp),%edx
lea    0xe50(%rip),%rsi
call   1050 <sprintf@plt>
movslq 0x2e8c(%rip),%rcx
lea    0x2e79(%rip),%rax
imul   $0x5,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ram>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <sym_by_value@plt>
test   %rax,%rax
je     1156 <ram+0x26>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <sym_is_redefinable@plt>
test   %eax,%eax
je     1191 <ram+0x61>
xor    %eax,%eax
cmpl   $0x0,0x2ee9(%rip)
sete   %al
mov    %eax,0x2ee0(%rip)
lea    (%rax,%rax,4),%rdi
lea    0x2ec9(%rip),%r14
add    %r14,%rdi
lea    0xe83(%rip),%rsi
mov    %ebp,%edx
call   1050 <sprintf@plt>
mov    0x2ebe(%rip),%eax
lea    (%rax,%rax,4),%rbx
add    %r14,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@ram.buf = internal global [2 x [5 x i8]] zeroinitializer
@ram.buf_sel = internal global i32 0
@.str = [7 x i8] c"0x%02X\00"
define i8* @ram(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i8* @sym_by_value(i32 %5, i32 2, i32* null)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = call i32 @sym_is_redefinable(i8* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = load i8*, i8** %4
store i8* %14, i8** %2
br label %30
15: ; preds = %9, %1
%16 = load i32, i32* @ram.buf_sel
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
%19 = zext i1 %18 to i32
store i32 %19, i32* @ram.buf_sel
%20 = load i32, i32* @ram.buf_sel
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [2 x [5 x i8]], [2 x [5 x i8]]* @ram.buf, i64 0, i64 %21
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %22, i64 0, i64 0
%24 = load i32, i32* %3
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i32, i32* @ram.buf_sel
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [2 x [5 x i8]], [2 x [5 x i8]]* @ram.buf, i64 0, i64 %27
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %28, i64 0, i64 0
store i8* %29, i8** %2
br label %30
30: ; preds = %15, %13
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
@ram.buf = internal global [2 x [5 x i8]] zeroinitializer
@ram.buf_sel = internal unnamed_addr global i32 0
@.str = [7 x i8] c"0x%02X\00"
define i8* @ram(i32 %0) {
%2 = tail call i8* @sym_by_value(i32 %0, i32 2, i32* null)
%3 = icmp eq i8* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i32 @sym_is_redefinable(i8* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %4, %1
%8 = load i32, i32* @ram.buf_sel
%9 = icmp eq i32 %8, 0
%10 = zext i1 %9 to i32
store i32 %10, i32* @ram.buf_sel
%11 = zext i1 %9 to i64
%12 = getelementptr inbounds [2 x [5 x i8]], [2 x [5 x i8]]* @ram.buf, i64 0, i64 %11, i64 0
%13 = tail call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %0)
%14 = load i32, i32* @ram.buf_sel
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [2 x [5 x i8]], [2 x [5 x i8]]* @ram.buf, i64 0, i64 %15, i64 0
br label %17
17: ; preds = %4, %7
%18 = phi i8* [ %16, %7 ], [ %2, %4 ]
ret i8* %18
}