#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*/ assert(int);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ skiboot_snprintf(char *, int, int, char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
scalar_t__ strncmp(char *, char *, int);
void test_printf_p(void) {
  char *buf = (char *)malloc(32);
  char buf2[32];
  skiboot_snprintf(buf, 32, 32, "%p", buf);
  snprintf(buf2, 32, "%p", buf);
  assert(0 == strncmp(buf, buf2, 32));
  free(buf);
}


x86 assembly (clang, -O0):
<test_printf_p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%r8
mov    $0x20,%edx
lea    0xe76(%rip),%rcx
mov    %edx,%esi
call   1040 <skiboot_snprintf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x20,%esi
lea    0xe5b(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1050 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_printf_p>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe83(%rip),%r14
mov    %rax,%rdi
mov    $0x20,%esi
mov    $0x20,%edx
mov    %r14,%rcx
mov    %rax,%r8
call   1040 <skiboot_snprintf@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x20,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1060 <snprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x20,%edx
call   1050 <strncmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%p\00"
define void @test_printf_p() {
%1 = alloca i8*
%2 = alloca [32 x i8]
%3 = call i64 @malloc(i32 32)
%4 = inttoptr i64 %3 to i8*
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = load i8*, i8** %1
%7 = call i32 @skiboot_snprintf(i8* %5, i32 32, i32 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%9 = load i8*, i8** %1
%10 = call i32 @snprintf(i8* %8, i32 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %1
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%13 = call i64 @strncmp(i8* %11, i8* %12, i32 32)
%14 = icmp eq i64 0, %13
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8*, i8** %1
%18 = call i32 @free(i8* %17)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%p\00"
define void @test_printf_p() {
%1 = alloca [32 x i8]
%2 = tail call i64 @malloc(i32 32)
%3 = inttoptr i64 %2 to i8*
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%5 = tail call i32 @skiboot_snprintf(i8* %3, i32 32, i32 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%6 = call i32 @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%7 = call i64 @strncmp(i8* %3, i8* %4, i32 32)
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = call i32 @free(i8* %3)
ret void
}