#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 */
char *BinString(char, char *, int);
scalar_t__ isprint(unsigned char);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
void DumpImageDataWide(const char *data, const int sz, const int cols) {
  int idx = 0;
  char c = 0;
  char buf[9];
  if (data == NULL) {
    printf("Invalid data\n");
    return;
  }
  if (sz < 1) {
    printf("Not enough data.\n");
    return;
  }
  memset(buf, 0, 9 * sizeof(char));
  for (idx = 0; idx < sz; ++idx) {
    c = data[idx];
    if ((idx % cols) == 0) {
      printf("\n");
    }
    printf("\t[%3d] 0x%02x '%c' %s\t", idx, c,
           (isprint((unsigned char)c) ? c : '.'), BinString(c, buf, 8));
  }
}


x86 assembly (clang, -O0):
<DumpImageDataWide>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117b <DumpImageDataWide+0x3b>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1262 <DumpImageDataWide+0x122>
cmpl   $0x1,-0xc(%rbp)
jge    1198 <DumpImageDataWide+0x58>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1262 <DumpImageDataWide+0x122>
lea    -0x1e(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1040 <memset@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1262 <DumpImageDataWide+0x122>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
mov    -0x14(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    11e7 <DumpImageDataWide+0xa7>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
movsbl -0x15(%rbp),%eax
mov    %eax,-0x24(%rbp)
movzbl -0x15(%rbp),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
je     1213 <DumpImageDataWide+0xd3>
movsbl -0x15(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1220 <DumpImageDataWide+0xe0>
mov    $0x2e,%eax
mov    %eax,-0x2c(%rbp)
jmp    1220 <DumpImageDataWide+0xe0>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x15(%rbp),%al
lea    -0x1e(%rbp),%rsi
mov    $0x8,%edx
movsbl %al,%edi
call   1050 <BinString@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    %rax,%r8
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11af <DumpImageDataWide+0x6f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DumpImageDataWide>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
je     1215 <DumpImageDataWide+0xb5>
mov    %esi,%ebx
test   %esi,%esi
jle    121e <DumpImageDataWide+0xbe>
mov    %edx,%r12d
mov    %rdi,%r13
lea    0xf(%rsp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1060 <memset@plt>
mov    %ebx,%r15d
xor    %ebp,%ebp
jmp    11ea <DumpImageDataWide+0x8a>
nop
movzbl %r14b,%edi
call   1080 <isprint@plt>
test   %rax,%rax
mov    %r14d,%ebx
mov    $0x2e,%eax
cmove  %eax,%ebx
mov    %r14d,%edi
lea    0xf(%rsp),%rsi
mov    $0x8,%edx
call   1070 <BinString@plt>
lea    0xe30(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %ebx,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
je     1206 <DumpImageDataWide+0xa6>
movsbl 0x0(%r13,%rbp,1),%r14d
mov    %ebp,%eax
cltd
idiv   %r12d
test   %edx,%edx
jne    11a0 <DumpImageDataWide+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11a0 <DumpImageDataWide+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0c(%rip),%rdi
jmp    1225 <DumpImageDataWide+0xc5>
lea    0xdf2(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Invalid data\0A\00"
@.str.1 = [18 x i8] c"Not enough data.\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [23 x i8] c"\09[%3d] 0x%02x '%c' %s\09\00"
define void @DumpImageDataWide(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca [9 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i8 0, i8* %8
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %58
14: ; preds = %3
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %58
19: ; preds = %14
%20 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 0
%21 = call i32 @memset(i8* %20, i32 0, i32 9)
store i32 0, i32* %7
br label %22
22: ; preds = %55, %19
%23 = load i32, i32* %7
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %58
26: ; preds = %22
%27 = load i8*, i8** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
store i8 %31, i8* %8
%32 = load i32, i32* %7
%33 = load i32, i32* %6
%34 = srem i32 %32, %33
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %26
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %26
%39 = load i32, i32* %7
%40 = load i8, i8* %8
%41 = sext i8 %40 to i32
%42 = load i8, i8* %8
%43 = call i64 @isprint(i8 zeroext %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = load i8, i8* %8
%47 = sext i8 %46 to i32
br label %49
48: ; preds = %38
br label %49
49: ; preds = %48, %45
%50 = phi i32 [ %47, %45 ], [ 46, %48 ]
%51 = load i8, i8* %8
%52 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 0
%53 = call i8* @BinString(i8 signext %51, i8* %52, i32 8)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %39, i32 %41, i32 %50, i8* %53)
br label %55
55: ; preds = %49
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
br label %22
58: ; preds = %12, %17, %22
ret void
}

LLVM IR (-O2):
@.str.3 = [23 x i8] c"\09[%3d] 0x%02x '%c' %s\09\00"
@str = [17 x i8] c"Not enough data.\00"
@str.4 = [13 x i8] c"Invalid data\00"
define void @DumpImageDataWide(i8* %0, i32 %1, i32 %2) {
%4 = alloca [9 x i8]
%5 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%6 = icmp eq i8* %0, null
br i1 %6, label %30, label %7
7: ; preds = %3
%8 = icmp slt i32 %1, 1
br i1 %8, label %30, label %9
9: ; preds = %7
%10 = call i32 @memset(i8* %5, i32 0, i32 9)
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %9, %21
%13 = phi i64 [ 0, %9 ], [ %28, %21 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = trunc i64 %13 to i32
%17 = srem i32 %16, %2
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 @putchar(i32 10)
br label %21
21: ; preds = %19, %12
%22 = sext i8 %15 to i32
%23 = call i64 @isprint(i8 zeroext %15)
%24 = icmp eq i64 %23, 0
%25 = select i1 %24, i32 46, i32 %22
%26 = call i8* @BinString(i8 signext %15, i8* %5, i32 8)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %16, i32 %22, i32 %25, i8* %26)
%28 = add nuw nsw i64 %13, 1
%29 = icmp eq i64 %28, %11
br i1 %29, label %33, label %12
30: ; preds = %7, %3
%31 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.4, i64 0, i64 0), %3 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0), %7 ]
%32 = tail call i32 @puts(i8* dereferenceable(1) %31)
br label %33
33: ; preds = %21, %30
ret void
}