#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*/ printf(char *, ...);
void hex_dump(void *ptr, int size) {
  int i;
  unsigned char *cur = (unsigned char *)ptr;
  for (i = 0; i < size; i++) {
    printf("%02X ", *cur);
    cur++;
  }
  cur = (unsigned char *)ptr;
  for (i = 0; i < size; i++) {
    if (*cur >= ' ' && *cur <= '~')
      printf("%c", *cur);
    else
      printf(".");
    cur++;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1169 <hex_dump+0x59>
mov    -0x18(%rbp),%rax
movzbl (%rax),%esi
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112e <hex_dump+0x1e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e6 <hex_dump+0xd6>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
jl     11be <hex_dump+0xae>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7e,%eax
jg     11be <hex_dump+0xae>
mov    -0x18(%rbp),%rax
movzbl (%rax),%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cc <hex_dump+0xbc>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1178 <hex_dump+0x68>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    118f <hex_dump+0x6f>
mov    %esi,%r14d
mov    %rdi,%r12
mov    %esi,%ebp
lea    0xec5(%rip),%r15
xor    %ebx,%ebx
nopl   (%rax)
movzbl (%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    1140 <hex_dump+0x20>
test   %r14d,%r14d
jle    118f <hex_dump+0x6f>
xor    %ebx,%ebx
mov    $0x2e,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r12,%rbx,1),%eax
lea    -0x20(%rax),%ecx
cmp    $0x5f,%cl
cmovae %r14d,%eax
movzbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    1170 <hex_dump+0x50>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [6 x i8] c"%02X \00"
define void @hex_dump(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %5, label %26
4: ; preds = %5
br i1 %3, label %14, label %26
5: ; preds = %2, %5
%6 = phi i8* [ %11, %5 ], [ %0, %2 ]
%7 = phi i32 [ %12, %5 ], [ 0, %2 ]
%8 = load i8, i8* %6
%9 = zext i8 %8 to i32
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds i8, i8* %6, i64 1
%12 = add nuw nsw i32 %7, 1
%13 = icmp eq i32 %12, %1
br i1 %13, label %4, label %5
14: ; preds = %4, %14
%15 = phi i8* [ %23, %14 ], [ %0, %4 ]
%16 = phi i32 [ %24, %14 ], [ 0, %4 ]
%17 = load i8, i8* %15
%18 = add i8 %17, -32
%19 = icmp ult i8 %18, 95
%20 = select i1 %19, i8 %17, i8 46
%21 = zext i8 %20 to i32
%22 = tail call i32 @putchar(i32 %21)
%23 = getelementptr inbounds i8, i8* %15, i64 1
%24 = add nuw nsw i32 %16, 1
%25 = icmp eq i32 %24, %1
br i1 %25, label %26, label %14
26: ; preds = %14, %2, %4
%27 = tail call i32 @putchar(i32 10)
ret void
}