#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 /*<<< orphan*/ charmap;

/* Variables and functions */
int /*<<< orphan*/ err_log(int, int, char *, char *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
void util_hexdump(unsigned char *block, int len) {
  char charmap[256];
  int index;
  int row, offset;
  char output[80];
  char tmp[20];
  memset(charmap, '.', sizeof(charmap));
  for (index = ' '; index < '~'; index++)
    charmap[index] = index;
  for (row = 0; row < (len + 15) / 16; row++) {
    sprintf(output, "%04X: ", row * 16);
    for (offset = 0; offset < 16; offset++) {
      if (row * 16 + offset < len) {
        sprintf(tmp, "%02X ", block[row * 16 + offset]);
      } else {
        sprintf(tmp, "   ");
      }
      strcat(output, tmp);
    }
    for (offset = 0; offset < 16; offset++) {
      if (row * 16 + offset < len) {
        sprintf(tmp, "%c", charmap[block[row * 16 + offset]]);
      } else {
        sprintf(tmp, " ");
      }
      strcat(output, tmp);
    }
    err_log(1, 0x80000000, "%s\n", output);
  }
}


x86 assembly (clang, -O0):
<util_hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1a0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x110(%rbp),%rdi
mov    $0x2e,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
movl   $0x20,-0x114(%rbp)
cmpl   $0x7e,-0x114(%rbp)
jge    11a9 <util_hexdump+0x69>
mov    -0x114(%rbp),%eax
mov    %al,%cl
movslq -0x114(%rbp),%rax
mov    %cl,-0x110(%rbp,%rax,1)
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    1172 <util_hexdump+0x32>
movl   $0x0,-0x118(%rbp)
mov    -0x118(%rbp),%eax
mov    %eax,-0x194(%rbp)
mov    -0xc(%rbp),%eax
add    $0xf,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x194(%rbp),%eax
cmp    %ecx,%eax
jge    1372 <util_hexdump+0x232>
lea    -0x170(%rbp),%rdi
mov    -0x118(%rbp),%edx
shl    $0x4,%edx
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
movl   $0x0,-0x11c(%rbp)
cmpl   $0x10,-0x11c(%rbp)
jge    129a <util_hexdump+0x15a>
mov    -0x118(%rbp),%eax
shl    $0x4,%eax
add    -0x11c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    125e <util_hexdump+0x11e>
lea    -0x190(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x118(%rbp),%ecx
shl    $0x4,%ecx
add    -0x11c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    1273 <util_hexdump+0x133>
lea    -0x190(%rbp),%rdi
lea    0xda1(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x170(%rbp),%rdi
lea    -0x190(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x11c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x11c(%rbp)
jmp    1205 <util_hexdump+0xc5>
movl   $0x0,-0x11c(%rbp)
cmpl   $0x10,-0x11c(%rbp)
jge    1341 <util_hexdump+0x201>
mov    -0x118(%rbp),%eax
shl    $0x4,%eax
add    -0x11c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1305 <util_hexdump+0x1c5>
lea    -0x190(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x118(%rbp),%ecx
shl    $0x4,%ecx
add    -0x11c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
movsbl -0x110(%rbp,%rax,1),%edx
ff
lea    0xd18(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    131a <util_hexdump+0x1da>
lea    -0x190(%rbp),%rdi
lea    0xcfc(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x170(%rbp),%rdi
lea    -0x190(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x11c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x11c(%rbp)
jmp    12a4 <util_hexdump+0x164>
lea    -0x170(%rbp),%rcx
mov    $0x1,%edi
mov    $0x80000000,%esi
lea    0xcbb(%rip),%rdx
call   1030 <err_log@plt>
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    11b3 <util_hexdump+0x73>
add    $0x1a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x198,%rsp
mov    %esi,%ebx
mov    %rdi,0x8(%rsp)
lea    0x40(%rsp),%rdi
mov    $0x2e,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
movaps 0xe8d(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe91(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe95(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe96(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xe97(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movabs $0x7776757473727170,%rax
75 76 77
mov    %rax,0xb0(%rsp)
movl   $0x7b7a7978,0xb8(%rsp)
78 79 7a 7b
movw   $0x7d7c,0xbc(%rsp)
test   %ebx,%ebx
jle    131e <util_hexdump+0x1de>
lea    0xf(%rbx),%eax
shr    $0x4,%eax
mov    %rax,0x30(%rsp)
mov    %ebx,%r13d
lea    0x140(%rsp),%rbx
lea    0xe5a(%rip),%rbp
lea    0x10(%rsp),%r15
xor    %r14d,%r14d
xor    %eax,%eax
jmp    124b <util_hexdump+0x10b>
nopl   0x0(%rax)
mov    $0x1,%edi
mov    $0x80000000,%esi
lea    0xe3c(%rip),%rdx
mov    %r14,%rbx
mov    %r14,%rcx
call   1030 <err_log@plt>
mov    0x38(%rsp),%rax
add    $0x1,%rax
mov    (%rsp),%r14
add    $0x10,%r14
cmp    0x30(%rsp),%rax
mov    %r12,%rbp
je     131e <util_hexdump+0x1de>
mov    %rax,0x38(%rsp)
mov    %eax,%edx
shl    $0x4,%edx
mov    %rbx,%rdi
lea    0xdf1(%rip),%rsi
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    $0x10,%r12d
mov    %r14,(%rsp)
jmp    129d <util_hexdump+0x15d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movl   $0x202020,0x10(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
add    $0x1,%r14
add    $0xffffffffffffffff,%r12
je     12c0 <util_hexdump+0x180>
cmp    %r13,%r14
jae    1280 <util_hexdump+0x140>
mov    0x8(%rsp),%rax
movzbl (%rax,%r14,1),%edx
mov    %r15,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <sprintf@plt>
jmp    1288 <util_hexdump+0x148>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%r12
mov    %rbx,%r14
mov    $0x10,%ebx
mov    (%rsp),%rbp
jmp    1300 <util_hexdump+0x1c0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movw   $0x20,0x10(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
add    $0x1,%rbp
add    $0xffffffffffffffff,%rbx
je     1210 <util_hexdump+0xd0>
cmp    %r13,%rbp
jae    12e0 <util_hexdump+0x1a0>
mov    0x8(%rsp),%rax
movzbl (%rax,%rbp,1),%eax
movzbl 0x40(%rsp,%rax,1),%eax
mov    %al,0x10(%rsp)
movb   $0x0,0x11(%rsp)
jmp    12e7 <util_hexdump+0x1a7>
add    $0x198,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%04X: \00"
@.str.1 = [6 x i8] c"%02X \00"
@.str.2 = [4 x i8] c" \00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [4 x i8] c"%s\0A\00"
define void @util_hexdump(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [80 x i8]
%10 = alloca [20 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i8 signext 46, i32 256)
store i32 32, i32* %6
br label %13
13: ; preds = %22, %2
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 126
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = load i32, i32* %6
%18 = trunc i32 %17 to i8
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %20
store i8 %18, i8* %21
br label %22
22: ; preds = %16
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %13
25: ; preds = %13
store i32 0, i32* %7
br label %26
26: ; preds = %108, %25
%27 = load i32, i32* %7
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 15
%30 = sdiv i32 %29, 16
%31 = icmp slt i32 %27, %30
br i1 %31, label %32, label %111
32: ; preds = %26
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%34 = load i32, i32* %7
%35 = mul nsw i32 %34, 16
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %35)
store i32 0, i32* %8
br label %37
37: ; preds = %66, %32
%38 = load i32, i32* %8
%39 = icmp slt i32 %38, 16
br i1 %39, label %40, label %69
40: ; preds = %37
%41 = load i32, i32* %7
%42 = mul nsw i32 %41, 16
%43 = load i32, i32* %8
%44 = add nsw i32 %42, %43
%45 = load i32, i32* %4
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %59
47: ; preds = %40
%48 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%49 = load i8*, i8** %3
%50 = load i32, i32* %7
%51 = mul nsw i32 %50, 16
%52 = load i32, i32* %8
%53 = add nsw i32 %51, %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %49, i64 %54
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = call i32 (i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %57)
br label %62
59: ; preds = %40
%60 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%61 = call i32 (i8*, i8*, ...) @sprintf(i8* %60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %62
62: ; preds = %59, %47
%63 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%64 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%65 = call i32 @strcat(i8* %63, i8* %64)
br label %66
66: ; preds = %62
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
br label %37
69: ; preds = %37
store i32 0, i32* %8
br label %70
70: ; preds = %102, %69
%71 = load i32, i32* %8
%72 = icmp slt i32 %71, 16
br i1 %72, label %73, label %105
73: ; preds = %70
%74 = load i32, i32* %7
%75 = mul nsw i32 %74, 16
%76 = load i32, i32* %8
%77 = add nsw i32 %75, %76
%78 = load i32, i32* %4
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %95
80: ; preds = %73
%81 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%82 = load i8*, i8** %3
%83 = load i32, i32* %7
%84 = mul nsw i32 %83, 16
%85 = load i32, i32* %8
%86 = add nsw i32 %84, %85
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %82, i64 %87
%89 = load i8, i8* %88
%90 = zext i8 %89 to i64
%91 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %90
%92 = load i8, i8* %91
%93 = sext i8 %92 to i32
%94 = call i32 (i8*, i8*, ...) @sprintf(i8* %81, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %93)
br label %98
95: ; preds = %73
%96 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%97 = call i32 (i8*, i8*, ...) @sprintf(i8* %96, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %98
98: ; preds = %95, %80
%99 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%100 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%101 = call i32 @strcat(i8* %99, i8* %100)
br label %102
102: ; preds = %98
%103 = load i32, i32* %8
%104 = add nsw i32 %103, 1
store i32 %104, i32* %8
br label %70
105: ; preds = %70
%106 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%107 = call i32 @err_log(i32 1, i32 -2147483648, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %106)
br label %108
108: ; preds = %105
%109 = load i32, i32* %7
%110 = add nsw i32 %109, 1
store i32 %110, i32* %7
br label %26
111: ; preds = %26
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%04X: \00"
@.str.1 = [6 x i8] c"%02X \00"
@.str.5 = [4 x i8] c"%s\0A\00"
define void @util_hexdump(i8* nocapture %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = alloca [80 x i8]
%5 = alloca [20 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%9 = call i32 @memset(i8* %6, i8 signext 46, i32 256)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 32
%11 = bitcast i8* %10 to <16 x i8>*
store <16 x i8> <i8 32, i8 33, i8 34, i8 35, i8 36, i8 37, i8 38, i8 39, i8 40, i8 41, i8 42, i8 43, i8 44, i8 45, i8 46, i8 47>, <16 x i8>* %11
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 48
%13 = bitcast i8* %12 to <16 x i8>*
store <16 x i8> <i8 48, i8 49, i8 50, i8 51, i8 52, i8 53, i8 54, i8 55, i8 56, i8 57, i8 58, i8 59, i8 60, i8 61, i8 62, i8 63>, <16 x i8>* %13
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 64
%15 = bitcast i8* %14 to <16 x i8>*
store <16 x i8> <i8 64, i8 65, i8 66, i8 67, i8 68, i8 69, i8 70, i8 71, i8 72, i8 73, i8 74, i8 75, i8 76, i8 77, i8 78, i8 79>, <16 x i8>* %15
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 80
%17 = bitcast i8* %16 to <16 x i8>*
store <16 x i8> <i8 80, i8 81, i8 82, i8 83, i8 84, i8 85, i8 86, i8 87, i8 88, i8 89, i8 90, i8 91, i8 92, i8 93, i8 94, i8 95>, <16 x i8>* %17
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 96
%19 = bitcast i8* %18 to <16 x i8>*
store <16 x i8> <i8 96, i8 97, i8 98, i8 99, i8 100, i8 101, i8 102, i8 103, i8 104, i8 105, i8 106, i8 107, i8 108, i8 109, i8 110, i8 111>, <16 x i8>* %19
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 112
store i8 112, i8* %20
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 113
store i8 113, i8* %21
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 114
store i8 114, i8* %22
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 115
store i8 115, i8* %23
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 116
store i8 116, i8* %24
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 117
store i8 117, i8* %25
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 118
store i8 118, i8* %26
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 119
store i8 119, i8* %27
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 120
store i8 120, i8* %28
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 121
store i8 121, i8* %29
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 122
store i8 122, i8* %30
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 123
store i8 123, i8* %31
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 124
store i8 124, i8* %32
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 125
store i8 125, i8* %33
%34 = icmp sgt i32 %1, 0
br i1 %34, label %35, label %81
35: ; preds = %2
%36 = add nuw nsw i32 %1, 15
%37 = lshr i32 %36, 4
%38 = bitcast [20 x i8]* %5 to i32*
%39 = bitcast [20 x i8]* %5 to i16*
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 1
%41 = zext i32 %1 to i64
%42 = zext i32 %37 to i64
br label %43
43: ; preds = %35, %77
%44 = phi i64 [ 0, %35 ], [ %79, %77 ]
%45 = shl nsw i64 %44, 4
%46 = trunc i64 %45 to i32
%47 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %43, %58
%49 = phi i64 [ 0, %43 ], [ %60, %58 ]
%50 = add nuw nsw i64 %49, %45
%51 = icmp ult i64 %50, %41
br i1 %51, label %52, label %57
52: ; preds = %48
%53 = getelementptr inbounds i8, i8* %0, i64 %50
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %55)
br label %58
57: ; preds = %48
store i32 2105376, i32* %38
br label %58
58: ; preds = %57, %52
%59 = call i32 @strcat(i8* %7, i8* %8)
%60 = add nuw nsw i64 %49, 1
%61 = icmp eq i64 %60, 16
br i1 %61, label %62, label %48
62: ; preds = %58, %73
%63 = phi i64 [ %75, %73 ], [ 0, %58 ]
%64 = add nuw nsw i64 %63, %45
%65 = icmp ult i64 %64, %41
br i1 %65, label %66, label %72
66: ; preds = %62
%67 = getelementptr inbounds i8, i8* %0, i64 %64
%68 = load i8, i8* %67
%69 = zext i8 %68 to i64
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %69
%71 = load i8, i8* %70
store i8 %71, i8* %8
store i8 0, i8* %40
br label %73
72: ; preds = %62
store i16 32, i16* %39
br label %73
73: ; preds = %72, %66
%74 = call i32 @strcat(i8* %7, i8* %8)
%75 = add nuw nsw i64 %63, 1
%76 = icmp eq i64 %75, 16
br i1 %76, label %77, label %62
77: ; preds = %73
%78 = call i32 @err_log(i32 1, i32 -2147483648, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%79 = add nuw nsw i64 %44, 1
%80 = icmp eq i64 %79, %42
br i1 %80, label %81, label %43
81: ; preds = %77, %2
ret void
}