#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ prnlog(char *);
int snprintf(char *, size_t, char *, ...);
int strlen(char *);
void printarr_human_readable(char *title, uint8_t *arr, int len) {
  int cx;
  size_t outsize = 100 + strlen(title) + len * 4;
  char *output = malloc(outsize);
  memset(output, 0, outsize);
  int i;
  cx = snprintf(output, outsize, "\n\t%s\n", title);
  for (i = 0; i < len; i++) {
    if (i % 16 == 0)
      cx += snprintf(output + cx, outsize - cx, "\n%02x| ", i);
    cx += snprintf(output + cx, outsize - cx, "%02x ", *(arr + i));
  }
  prnlog(output);
  free(output);
}


x86 assembly (clang, -O0):
<printarr_human_readable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x64,%eax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rcx
lea    0xe44(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    125d <printarr_human_readable+0xfd>
mov    -0x2c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    121a <printarr_human_readable+0xba>
mov    -0x28(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
movslq -0x18(%rbp),%rax
sub    %rax,%rsi
mov    -0x2c(%rbp),%ecx
lea    0xdf9(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
movslq -0x18(%rbp),%rax
sub    %rax,%rsi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xdcc(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11cd <printarr_human_readable+0x6d>
mov    -0x28(%rbp),%rdi
call   1040 <prnlog@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printarr_human_readable>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <strlen@plt>
lea    (%rax,%rbp,4),%eax
add    $0x64,%eax
movslq %eax,%r15
mov    %r15,%rdi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1070 <memset@plt>
lea    0xe60(%rip),%rdx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
test   %ebp,%ebp
jle    1212 <printarr_human_readable+0xb2>
mov    %eax,%ebx
mov    %ebp,%ebp
xor    %r13d,%r13d
jmp    11ea <printarr_human_readable+0x8a>
nopl   (%rax)
movslq %ebx,%rbx
lea    (%r12,%rbx,1),%rdi
mov    %r15,%rsi
sub    %rbx,%rsi
mov    (%r14,%r13,4),%ecx
lea    0xe36(%rip),%rdx
xor    %eax,%eax
call   1060 <snprintf@plt>
add    %eax,%ebx
add    $0x1,%r13
cmp    %r13,%rbp
je     1212 <printarr_human_readable+0xb2>
test   $0xf,%r13b
jne    11c0 <printarr_human_readable+0x60>
movslq %ebx,%rbx
lea    (%r12,%rbx,1),%rdi
mov    %r15,%rsi
sub    %rbx,%rsi
lea    0xe02(%rip),%rdx
mov    %r13d,%ecx
xor    %eax,%eax
call   1060 <snprintf@plt>
add    %eax,%ebx
jmp    11c0 <printarr_human_readable+0x60>
mov    %r12,%rdi
call   1040 <prnlog@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"\0A\09%s\0A\00"
@.str.1 = [8 x i8] c"\0A%02x| \00"
@.str.2 = [6 x i8] c"%02x \00"
define void @printarr_human_readable(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 100, %12
%14 = load i32, i32* %6
%15 = mul nsw i32 %14, 4
%16 = add nsw i32 %13, %15
%17 = sext i32 %16 to i64
store i64 %17, i64* %8
%18 = load i64, i64* %8
%19 = call i8* @malloc(i64 %18)
store i8* %19, i8** %9
%20 = load i8*, i8** %9
%21 = load i64, i64* %8
%22 = call i32 @memset(i8* %20, i32 0, i64 %21)
%23 = load i8*, i8** %9
%24 = load i64, i64* %8
%25 = load i8*, i8** %4
%26 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %23, i64 %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 %26, i32* %7
store i32 0, i32* %10
br label %27
27: ; preds = %65, %3
%28 = load i32, i32* %10
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %68
31: ; preds = %27
%32 = load i32, i32* %10
%33 = srem i32 %32, 16
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %31
%36 = load i8*, i8** %9
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i64, i64* %8
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = sub i64 %40, %42
%44 = load i32, i32* %10
%45 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %39, i64 %43, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %7
%47 = add nsw i32 %46, %45
store i32 %47, i32* %7
br label %48
48: ; preds = %35, %31
%49 = load i8*, i8** %9
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i64, i64* %8
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = sub i64 %53, %55
%57 = load i32*, i32** %5
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
%61 = load i32, i32* %60
%62 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %52, i64 %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %61)
%63 = load i32, i32* %7
%64 = add nsw i32 %63, %62
store i32 %64, i32* %7
br label %65
65: ; preds = %48
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 1
store i32 %67, i32* %10
br label %27
68: ; preds = %27
%69 = load i8*, i8** %9
%70 = call i32 @prnlog(i8* %69)
%71 = load i8*, i8** %9
%72 = call i32 @free(i8* %71)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"\0A\09%s\0A\00"
@.str.1 = [8 x i8] c"\0A%02x| \00"
@.str.2 = [6 x i8] c"%02x \00"
define void @printarr_human_readable(i8* %0, i32* nocapture %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = shl nsw i32 %2, 2
%6 = add i32 %5, 100
%7 = add i32 %6, %4
%8 = sext i32 %7 to i64
%9 = tail call i8* @malloc(i64 %8)
%10 = tail call i32 @memset(i8* %9, i32 0, i64 %8)
%11 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %9, i64 %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %38
13: ; preds = %3
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %13, %27
%16 = phi i64 [ 0, %13 ], [ %36, %27 ]
%17 = phi i32 [ %11, %13 ], [ %35, %27 ]
%18 = trunc i64 %16 to i32
%19 = and i32 %18, 15
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %15
%22 = sext i32 %17 to i64
%23 = getelementptr inbounds i8, i8* %9, i64 %22
%24 = sub nsw i64 %8, %22
%25 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %23, i64 %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%26 = add nsw i32 %25, %17
br label %27
27: ; preds = %21, %15
%28 = phi i32 [ %26, %21 ], [ %17, %15 ]
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %9, i64 %29
%31 = sub nsw i64 %8, %29
%32 = getelementptr inbounds i32, i32* %1, i64 %16
%33 = load i32, i32* %32
%34 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %30, i64 %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = add nsw i32 %34, %28
%36 = add nuw nsw i64 %16, 1
%37 = icmp eq i64 %36, %14
br i1 %37, label %38, label %15
38: ; preds = %27, %3
%39 = tail call i32 @prnlog(i8* %9)
%40 = tail call i32 @free(i8* %9)
ret void
}