#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 */
scalar_t__ isprint(char);
int /*<<< orphan*/ printf(char *, ...);
void hexdump_ascii(const void *data, size_t length, size_t count) {
  const unsigned char *ptr = data;
  int i;
  printf("|");
  for (i = 0; i < length; ++i) {
    char ch = *ptr++;
    printf("%c", isprint(ch) ? ch : '.');
  }
  printf("|");
}


x86 assembly (clang, -O0):
<hexdump_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11be <hexdump_ascii+0x9e>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%al
mov    %al,-0x25(%rbp)
movsbl -0x25(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     1192 <hexdump_ascii+0x72>
movsbl -0x25(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    119f <hexdump_ascii+0x7f>
mov    $0x2e,%eax
mov    %eax,-0x2c(%rbp)
jmp    119f <hexdump_ascii+0x7f>
mov    -0x2c(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1151 <hexdump_ascii+0x31>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump_ascii>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x7c,%edi
call   1030 <putchar@plt>
test   %r15,%r15
je     1173 <hexdump_ascii+0x53>
xor    %ebx,%ebx
mov    $0x2e,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r14,%rbx,1),%ebp
mov    %ebp,%edi
call   1040 <isprint@plt>
test   %rax,%rax
cmove  %r12d,%ebp
mov    %ebp,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <hexdump_ascii+0x30>
mov    $0x7c,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"|\00"
@.str.1 = [3 x i8] c"%c\00"
define void @hexdump_ascii(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%10 = load i8*, i8** %4
store i8* %10, i8** %7
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %12
12: ; preds = %31, %3
%13 = load i32, i32* %8
%14 = sext i32 %13 to i64
%15 = load i64, i64* %5
%16 = icmp ult i64 %14, %15
br i1 %16, label %17, label %34
17: ; preds = %12
%18 = load i8*, i8** %7
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %7
%20 = load i8, i8* %18
store i8 %20, i8* %9
%21 = load i8, i8* %9
%22 = call i64 @isprint(i8 signext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i8, i8* %9
%26 = sext i8 %25 to i32
br label %28
27: ; preds = %17
br label %28
28: ; preds = %27, %24
%29 = phi i32 [ %26, %24 ], [ 46, %27 ]
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %28
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %12
34: ; preds = %12
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
define void @hexdump_ascii(i8* nocapture %0, i64 %1, i64 %2) {
%4 = tail call i32 @putchar(i32 124)
%5 = icmp eq i64 %1, 0
br i1 %5, label %18, label %6
6: ; preds = %3, %6
%7 = phi i64 [ %16, %6 ], [ 0, %3 ]
%8 = phi i8* [ %9, %6 ], [ %0, %3 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %8
%11 = tail call i64 @isprint(i8 signext %10)
%12 = icmp eq i64 %11, 0
%13 = sext i8 %10 to i32
%14 = select i1 %12, i32 46, i32 %13
%15 = tail call i32 @putchar(i32 %14)
%16 = add nuw i64 %7, 1
%17 = icmp eq i64 %16, %1
br i1 %17, label %18, label %6
18: ; preds = %6, %3
%19 = tail call i32 @putchar(i32 124)
ret void
}