#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 /*<<< orphan*/ str_pointer;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long);
const char *plugin_script_ptr2str(void *pointer) {
  static char str_pointer[32][32];
  static int index_pointer = 0;
  index_pointer = (index_pointer + 1) % 32;
  str_pointer[index_pointer][0] = '\0';
  if (!pointer)
    return str_pointer[index_pointer];
  snprintf(str_pointer[index_pointer], sizeof(str_pointer[index_pointer]),
           "0x%lx", (long unsigned int)pointer);
  return str_pointer[index_pointer];
}


x86 assembly (clang, -O0):
<plugin_script_ptr2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x331e(%rip),%eax
add    $0x1,%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %edx,0x330d(%rip)
movslq 0x3306(%rip),%rcx
lea    0x2eff(%rip),%rax
shl    $0x5,%rcx
add    %rcx,%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
jne    1174 <plugin_script_ptr2str+0x64>
movslq 0x32e3(%rip),%rcx
lea    0x2edc(%rip),%rax
shl    $0x5,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11b7 <plugin_script_ptr2str+0xa7>
movslq 0x32c5(%rip),%rax
lea    0x2ebe(%rip),%rdi
shl    $0x5,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rcx
mov    $0x20,%esi
lea    0xe67(%rip),%rdx
call   1030 <snprintf@plt>
movslq 0x329b(%rip),%rcx
lea    0x2e94(%rip),%rax
shl    $0x5,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plugin_script_ptr2str>:
push   %rbx
mov    %rdi,%rcx
mov    0x3326(%rip),%eax
lea    0x1(%rax),%edx
lea    0x20(%rax),%esi
test   %edx,%edx
cmovns %edx,%esi
and    $0xffffffe0,%esi
neg    %esi
add    %esi,%eax
add    $0x1,%eax
mov    %eax,0x330b(%rip)
cltq
mov    %rax,%rdi
shl    $0x5,%rdi
lea    0x2efb(%rip),%rbx
movb   $0x0,(%rdi,%rbx,1)
test   %rcx,%rcx
je     1169 <plugin_script_ptr2str+0x59>
add    %rbx,%rdi
lea    0xea8(%rip),%rdx
mov    $0x20,%esi
call   1030 <snprintf@plt>
movslq 0x32d7(%rip),%rax
shl    $0x5,%rax
add    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@plugin_script_ptr2str.str_pointer = internal global [32 x [32 x i8]] zeroinitializer
@plugin_script_ptr2str.index_pointer = internal global i32 0
@.str = [6 x i8] c"0x%lx\00"
define i8* @plugin_script_ptr2str(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i32, i32* @plugin_script_ptr2str.index_pointer
%5 = add nsw i32 %4, 1
%6 = srem i32 %5, 32
store i32 %6, i32* @plugin_script_ptr2str.index_pointer
%7 = load i32, i32* @plugin_script_ptr2str.index_pointer
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [32 x [32 x i8]], [32 x [32 x i8]]* @plugin_script_ptr2str.str_pointer, i64 0, i64 %8
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
store i8 0, i8* %10
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %1
%14 = load i32, i32* @plugin_script_ptr2str.index_pointer
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [32 x [32 x i8]], [32 x [32 x i8]]* @plugin_script_ptr2str.str_pointer, i64 0, i64 %15
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 0
store i8* %17, i8** %2
br label %30
18: ; preds = %1
%19 = load i32, i32* @plugin_script_ptr2str.index_pointer
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [32 x [32 x i8]], [32 x [32 x i8]]* @plugin_script_ptr2str.str_pointer, i64 0, i64 %20
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %21, i64 0, i64 0
%23 = load i8*, i8** %3
%24 = ptrtoint i8* %23 to i64
%25 = call i32 @snprintf(i8* %22, i32 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %24)
%26 = load i32, i32* @plugin_script_ptr2str.index_pointer
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [32 x [32 x i8]], [32 x [32 x i8]]* @plugin_script_ptr2str.str_pointer, i64 0, i64 %27
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %28, i64 0, i64 0
store i8* %29, i8** %2
br label %30
30: ; preds = %18, %13
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
@plugin_script_ptr2str.str_pointer = internal global [32 x [32 x i8]] zeroinitializer
@plugin_script_ptr2str.index_pointer = internal unnamed_addr global i32 0
@.str = [6 x i8] c"0x%lx\00"
define i8* @plugin_script_ptr2str(i8* %0) {
%2 = load i32, i32* @plugin_script_ptr2str.index_pointer
%3 = add nsw i32 %2, 1
%4 = srem i32 %3, 32
store i32 %4, i32* @plugin_script_ptr2str.index_pointer
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds [32 x [32 x i8]], [32 x [32 x i8]]* @plugin_script_ptr2str.str_pointer, i64 0, i64 %5, i64 0
store i8 0, i8* %6
%7 = icmp eq i8* %0, null
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = ptrtoint i8* %0 to i64
%10 = tail call i32 @snprintf(i8* %6, i32 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %9)
%11 = load i32, i32* @plugin_script_ptr2str.index_pointer
%12 = sext i32 %11 to i64
br label %13
13: ; preds = %1, %8
%14 = phi i64 [ %5, %1 ], [ %12, %8 ]
%15 = getelementptr inbounds [32 x [32 x i8]], [32 x [32 x i8]]* @plugin_script_ptr2str.str_pointer, i64 0, i64 %14, i64 0
ret i8* %15
}