#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*/ snprintf(char *, int, char *, void *);
int strlen(char *);
void pointer_to_string(void *ptr, int *length, char *string) {
  int i;
  snprintf(string, *length, "%p", ptr);
  for (i = strlen(string); i < *length; i++) {
    string[i] = ' ';
  }
}


x86 assembly (clang, -O0):
<pointer_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
lea    0xeb7(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    1183 <pointer_to_string+0x63>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115a <pointer_to_string+0x3a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pointer_to_string>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rcx
mov    (%rsi),%esi
lea    0xeca(%rip),%rdx
mov    %r14,%rdi
call   1040 <snprintf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    (%rbx),%eax
jge    1161 <pointer_to_string+0x41>
cltq
nopl   0x0(%rax)
movb   $0x20,(%r14,%rax,1)
add    $0x1,%rax
movslq (%rbx),%rcx
cmp    %rcx,%rax
jl     1150 <pointer_to_string+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%p\00"
define void @pointer_to_string(i8* %0, i32* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = load i8*, i8** %4
%12 = call i32 @snprintf(i8* %8, i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %6
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %7
br label %15
15: ; preds = %25, %3
%16 = load i32, i32* %7
%17 = load i32*, i32** %5
%18 = load i32, i32* %17
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %28
20: ; preds = %15
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 32, i8* %24
br label %25
25: ; preds = %20
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %15
28: ; preds = %15
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%p\00"
define void @pointer_to_string(i8* %0, i32* nocapture %1, i8* %2) {
%4 = load i32, i32* %1
%5 = tail call i32 @snprintf(i8* %2, i32 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = tail call i32 @strlen(i8* %2)
%7 = load i32, i32* %1
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %18
9: ; preds = %3
%10 = sext i32 %6 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ %10, %9 ], [ %14, %11 ]
%13 = getelementptr inbounds i8, i8* %2, i64 %12
store i8 32, i8* %13
%14 = add nsw i64 %12, 1
%15 = load i32, i32* %1
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %14, %16
br i1 %17, label %11, label %18
18: ; preds = %11, %3
ret void
}