#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 dump_hex_line(char *buf_ptr, int buf_len) {
  int idx;
  char ch;
  for (idx = 0; idx < 16; idx++) {
    if (idx < buf_len)
      printf("%02x ", ((int)buf_ptr[idx]) & 0xff);
    else
      printf("   ");
  }
  printf("  ");
  for (idx = 0; idx < 16; idx++) {
    if (idx < buf_len) {
      ch = buf_ptr[idx];
      if ((ch < 0x20) || (ch > 0x7e))
        printf(".");
      else
        printf("%c", buf_ptr[idx]);
    }
  }
}


x86 assembly (clang, -O0):
<dump_hex_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x10,-0x10(%rbp)
jge    1182 <dump_hex_line+0x72>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1161 <dump_hex_line+0x51>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    116f <dump_hex_line+0x5f>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1174 <dump_hex_line+0x64>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <dump_hex_line+0x16>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x10,-0x10(%rbp)
jge    121a <dump_hex_line+0x10a>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1207 <dump_hex_line+0xf7>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x20,%eax
jl     11d5 <dump_hex_line+0xc5>
movsbl -0x11(%rbp),%eax
cmp    $0x7e,%eax
jle    11e8 <dump_hex_line+0xd8>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1202 <dump_hex_line+0xf2>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1207 <dump_hex_line+0xf7>
jmp    120c <dump_hex_line+0xfc>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1197 <dump_hex_line+0x87>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_hex_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
movslq %esi,%r13
lea    0xec8(%rip),%r14
lea    0xec7(%rip),%r15
xor    %ebx,%ebx
jmp    1164 <dump_hex_line+0x44>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x10,%rbx
je     117a <dump_hex_line+0x5a>
cmp    %r13,%rbx
jge    1150 <dump_hex_line+0x30>
movzbl (%r12,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    115a <dump_hex_line+0x3a>
lea    0xe86(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2e,%ebp
jmp    11aa <dump_hex_line+0x8a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    $0x10,%rbx
je     11c7 <dump_hex_line+0xa7>
cmp    %r13,%rbx
jge    11a0 <dump_hex_line+0x80>
movzbl (%r12,%rbx,1),%eax
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
cmovb  %ebp,%eax
movzbl %al,%edi
call   1030 <putchar@plt>
jmp    11a0 <dump_hex_line+0x80>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%02x \00"
@.str.1 = [4 x i8] c" \00"
@.str.2 = [3 x i8] c" \00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [3 x i8] c"%c\00"
define void @dump_hex_line(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
store i32 0, i32* %5
br label %7
7: ; preds = %26, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 16
br i1 %9, label %10, label %29
10: ; preds = %7
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = and i32 %20, 255
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %25
23: ; preds = %10
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %14
br label %26
26: ; preds = %25
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %7
29: ; preds = %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %31
31: ; preds = %63, %29
%32 = load i32, i32* %5
%33 = icmp slt i32 %32, 16
br i1 %33, label %34, label %66
34: ; preds = %31
%35 = load i32, i32* %5
%36 = load i32, i32* %4
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %62
38: ; preds = %34
%39 = load i8*, i8** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
store i8 %43, i8* %6
%44 = load i8, i8* %6
%45 = sext i8 %44 to i32
%46 = icmp slt i32 %45, 32
br i1 %46, label %51, label %47
47: ; preds = %38
%48 = load i8, i8* %6
%49 = sext i8 %48 to i32
%50 = icmp sgt i32 %49, 126
br i1 %50, label %51, label %53
51: ; preds = %47, %38
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %61
53: ; preds = %47
%54 = load i8*, i8** %3
%55 = load i32, i32* %5
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %53, %51
br label %62
62: ; preds = %61, %34
br label %63
63: ; preds = %62
%64 = load i32, i32* %5
%65 = add nsw i32 %64, 1
store i32 %65, i32* %5
br label %31
66: ; preds = %31
ret void
}

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