#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 */
int /*<<< orphan*/ cc_asprintf(char **, char *, int, void const *);
char *cc_strdup(char *);
char *cc_string_alloc_from_ptr(void const *value) {
  if (!value)
    return cc_strdup("NULL");
  int const width_of_0x_prefix = 2;
  int const bytes_in_ptr = sizeof value;
  int const width_of_each_byte = 2;
  int width = width_of_0x_prefix + (bytes_in_ptr * width_of_each_byte);
  char *string;
  cc_asprintf(&string, "%0*p", width, value);
  return string;
}


x86 assembly (clang, -O0):
<cc_string_alloc_from_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114c <cc_string_alloc_from_ptr+0x2c>
lea    0xec2(%rip),%rdi
call   1030 <cc_strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1187 <cc_string_alloc_from_ptr+0x67>
movl   $0x2,-0x14(%rbp)
movl   $0x8,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
movl   $0x12,-0x20(%rbp)
mov    -0x20(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1040 <cc_asprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cc_string_alloc_from_ptr>:
test   %rdi,%rdi
je     1143 <cc_string_alloc_from_ptr+0x23>
push   %rax
mov    %rdi,%rcx
lea    0xed5(%rip),%rsi
mov    %rsp,%rdi
mov    $0x12,%edx
call   1040 <cc_asprintf@plt>
mov    (%rsp),%rax
pop    %rcx
ret
lea    0xeb6(%rip),%rdi
jmp    1030 <cc_strdup@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"NULL\00"
@.str.1 = [5 x i8] c"%0*p\00"
define i8* @cc_string_alloc_from_ptr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = call i8* @cc_strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %2
br label %18
13: ; preds = %1
store i32 2, i32* %4
store i32 8, i32* %5
store i32 2, i32* %6
store i32 18, i32* %7
%14 = load i32, i32* %7
%15 = load i8*, i8** %3
%16 = call i32 @cc_asprintf(i8** %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %14, i8* %15)
%17 = load i8*, i8** %8
store i8* %17, i8** %2
br label %18
18: ; preds = %13, %11
%19 = load i8*, i8** %2
ret i8* %19
}

LLVM IR (-O2):
@.str = [5 x i8] c"NULL\00"
@.str.1 = [5 x i8] c"%0*p\00"
define i8* @cc_string_alloc_from_ptr(i8* %0) {
%2 = alloca i8*
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i8* @cc_strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %10
6: ; preds = %1
%7 = bitcast i8** %2 to i8*
%8 = call i32 @cc_asprintf(i8** %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 18, i8* %0)
%9 = load i8*, i8** %2
br label %10
10: ; preds = %6, %4
%11 = phi i8* [ %9, %6 ], [ %5, %4 ]
ret i8* %11
}