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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void dump_ptr(void *ptr, int size, FILE *stream) {
  int i, j, val;
  for (i = 0; i < size; i++, ptr++) {
    for (j = 0; j < 2; j++) {
      val = j ? *(unsigned char *)ptr & 0xf : *(unsigned char *)ptr >> 4;
      if (val < 10)
        fprintf(stream, "%d", val);
      else
        fprintf(stream, "%c", val - 10 + 'a');
    }
    fprintf(stream, " ");
  }
}


x86 assembly (clang, -O0):
<dump_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f4 <dump_ptr+0xe4>
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
jge    11c8 <dump_ptr+0xb8>
cmpl   $0x0,-0x20(%rbp)
je     1163 <dump_ptr+0x53>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0xf,%eax
mov    %eax,-0x28(%rbp)
jmp    1170 <dump_ptr+0x60>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
sar    $0x4,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0xa,-0x24(%rbp)
jge    119a <dump_ptr+0x8a>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11b5 <dump_ptr+0xa5>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%edx
sub    $0xa,%edx
add    $0x61,%edx
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11ba <dump_ptr+0xaa>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113d <dump_ptr+0x2d>
mov    -0x18(%rbp),%rdi
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112a <dump_ptr+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_ptr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %esi,%esi
jle    11c9 <dump_ptr+0xa9>
mov    %rdx,%r13
mov    %rdi,%r14
mov    %esi,%r12d
lea    0xebf(%rip),%r15
xor    %ebx,%ebx
jmp    1173 <dump_ptr+0x53>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x20,%edi
mov    %r13,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbx
cmp    %ebx,%r12d
je     11c9 <dump_ptr+0xa9>
movzbl (%r14,%rbx,1),%eax
mov    %eax,%edx
shr    $0x4,%edx
cmp    $0x9f,%eax
ja     11a0 <dump_ptr+0x80>
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11ad <dump_ptr+0x8d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x57,%edx
mov    %edx,%edi
mov    %r13,%rsi
call   1030 <fputc@plt>
movzbl (%r14,%rbx,1),%edx
and    $0xf,%edx
cmp    $0xa,%dl
jb     1150 <dump_ptr+0x30>
add    $0x57,%edx
mov    %edx,%edi
mov    %r13,%rsi
call   1030 <fputc@plt>
jmp    115d <dump_ptr+0x3d>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c" \00"
define void @dump_ptr(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
br label %10
10: ; preds = %52, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %57
14: ; preds = %10
store i32 0, i32* %8
br label %15
15: ; preds = %46, %14
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %49
18: ; preds = %15
%19 = load i32, i32* %8
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = and i32 %24, 15
br label %31
26: ; preds = %18
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = ashr i32 %29, 4
br label %31
31: ; preds = %26, %21
%32 = phi i32 [ %25, %21 ], [ %30, %26 ]
store i32 %32, i32* %9
%33 = load i32, i32* %9
%34 = icmp slt i32 %33, 10
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i32*, i32** %6
%37 = load i32, i32* %9
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %37)
br label %45
39: ; preds = %31
%40 = load i32*, i32** %6
%41 = load i32, i32* %9
%42 = sub nsw i32 %41, 10
%43 = add nsw i32 %42, 97
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %39, %35
br label %46
46: ; preds = %45
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %15
49: ; preds = %15
%50 = load i32*, i32** %6
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %49
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %4
br label %10
57: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define void @dump_ptr(i8* nocapture %0, i32 %1, i32* nocapture %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %32
5: ; preds = %3, %27
%6 = phi i8* [ %30, %27 ], [ %0, %3 ]
%7 = phi i32 [ %29, %27 ], [ 0, %3 ]
%8 = load i8, i8* %6
%9 = lshr i8 %8, 4
%10 = zext i8 %9 to i32
%11 = icmp ult i8 %8, -96
br i1 %11, label %12, label %14
12: ; preds = %5
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %17
14: ; preds = %5
%15 = add nuw nsw i32 %10, 87
%16 = tail call i32 @fputc(i32 %15, i32* %2)
br label %17
17: ; preds = %12, %14
%18 = load i8, i8* %6
%19 = and i8 %18, 15
%20 = zext i8 %19 to i32
%21 = icmp ult i8 %19, 10
br i1 %21, label %25, label %22
22: ; preds = %17
%23 = add nuw nsw i32 %20, 87
%24 = tail call i32 @fputc(i32 %23, i32* %2)
br label %27
25: ; preds = %17
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %27
27: ; preds = %25, %22
%28 = tail call i32 @fputc(i32 32, i32* %2)
%29 = add nuw nsw i32 %7, 1
%30 = getelementptr inbounds i8, i8* %6, i64 1
%31 = icmp eq i32 %29, %1
br i1 %31, label %32, label %5
32: ; preds = %27, %3
ret void
}