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

/* Variables and functions */
int /*<<< orphan*/ assertStringsEqual(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, void *, ...);
void test_pointer() {
  char buffer[100];
  sprintf(buffer, "%p", (void *)0x1234U);
  if (sizeof(void *) == 4U) {
    assertStringsEqual(buffer, "00001234");
  } else {
    assertStringsEqual(buffer, "0000000000001234");
  }
  sprintf(buffer, "%p", (void *)0x12345678U);
  if (sizeof(void *) == 4U) {
    assertStringsEqual(buffer, "12345678");
  } else {
    assertStringsEqual(buffer, "0000000012345678");
  }
  sprintf(buffer, "%p-%p", (void *)0x12345678U, (void *)0x7EDCBA98U);
  if (sizeof(void *) == 4U) {
    assertStringsEqual(buffer, "12345678-7EDCBA98");
  } else {
    assertStringsEqual(buffer, "0000000012345678-000000007EDCBA98");
  }
  if (sizeof(uintptr_t) == sizeof(uint64_t)) {
    sprintf(buffer, "%p", (void *)(uintptr_t)0xFFFFFFFFU);
    assertStringsEqual(buffer, "00000000FFFFFFFF");
  } else {
    sprintf(buffer, "%p", (void *)(uintptr_t)0xFFFFFFFFU);
    assertStringsEqual(buffer, "FFFFFFFF");
  }
}


x86 assembly (clang, -O0):
<test_pointer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    -0x70(%rbp),%rdi
lea    0xef2(%rip),%rsi
mov    $0x1234,%edx
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1030 <assertStringsEqual@plt>
lea    -0x70(%rbp),%rdi
lea    0xecb(%rip),%rsi
mov    $0x12345678,%edx
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1030 <assertStringsEqual@plt>
lea    -0x70(%rbp),%rdi
lea    0xea1(%rip),%rsi
mov    $0x12345678,%edx
mov    $0x7edcba98,%ecx
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1030 <assertStringsEqual@plt>
lea    -0x70(%rbp),%rdi
lea    0xe78(%rip),%rsi
mov    $0xffffffff,%edx
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1030 <assertStringsEqual@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_pointer>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xef7(%rip),%r14
mov    %rsp,%rbx
mov    $0x1234,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
call   1030 <assertStringsEqual@plt>
mov    $0x12345678,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
call   1030 <assertStringsEqual@plt>
lea    0xea8(%rip),%rsi
mov    $0x12345678,%edx
mov    $0x7edcba98,%ecx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
call   1030 <assertStringsEqual@plt>
mov    $0xffffffff,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
call   1030 <assertStringsEqual@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%p\00"
@.str.1 = [17 x i8] c"0000000000001234\00"
@.str.2 = [17 x i8] c"0000000012345678\00"
@.str.3 = [6 x i8] c"%p-%p\00"
@.str.4 = [34 x i8] c"0000000012345678-000000007EDCBA98\00"
@.str.5 = [9 x i8] c"FFFFFFFF\00"
define void @test_pointer() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* inttoptr (i64 4660 to i8*))
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = call i32 @assertStringsEqual(i8* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%7 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* inttoptr (i64 305419896 to i8*))
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%9 = call i32 @assertStringsEqual(i8* %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%11 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* inttoptr (i64 305419896 to i8*), i8* inttoptr (i64 2128394904 to i8*))
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%13 = call i32 @assertStringsEqual(i8* %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%15 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* inttoptr (i64 4294967295 to i8*))
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%17 = call i32 @assertStringsEqual(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%p\00"
@.str.1 = [17 x i8] c"0000000000001234\00"
@.str.2 = [17 x i8] c"0000000012345678\00"
@.str.3 = [6 x i8] c"%p-%p\00"
@.str.4 = [34 x i8] c"0000000012345678-000000007EDCBA98\00"
@.str.5 = [9 x i8] c"FFFFFFFF\00"
define void @test_pointer() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* inttoptr (i64 4660 to i8*))
%4 = call i32 @assertStringsEqual(i8* %2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* inttoptr (i64 305419896 to i8*))
%6 = call i32 @assertStringsEqual(i8* %2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* inttoptr (i64 305419896 to i8*), i8* inttoptr (i64 2128394904 to i8*))
%8 = call i32 @assertStringsEqual(i8* %2, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* inttoptr (i64 4294967295 to i8*))
%10 = call i32 @assertStringsEqual(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
ret void
}