#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 printimage(char *image_data, int data_length) {
  int idx = 0;
  char c = 0;
  for (idx; idx < data_length; ++idx) {
    c = image_data[idx];
    printf("(0x%02x) ", c);
    if (isprint(c)) {
      printf("%c", c);
    } else {
      printf(".");
    }
  }
}


x86 assembly (clang, -O0):
<printimage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b1 <printimage+0x91>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%esi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x11(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     1190 <printimage+0x70>
movsbl -0x11(%rbp),%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119e <printimage+0x7e>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a3 <printimage+0x83>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113a <printimage+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printimage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    118f <printimage+0x5f>
mov    %rdi,%r15
mov    %esi,%r13d
lea    0xeb4(%rip),%r14
mov    $0x2e,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r15,%rbx,1),%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <isprint@plt>
test   %rax,%rax
cmove  %r12d,%ebp
mov    %ebp,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1160 <printimage+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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