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

/* Variables and functions */
int /*<<< orphan*/ log_write(char *, ...);
int /*<<< orphan*/ log_writeln(char *);
int /*<<< orphan*/ memcpy(unsigned char *, char *, size_t);
void log_hexdump(void *buf, size_t len) {
  unsigned char b[16];
  size_t i, j, l;
  for (i = 0; i < len; i += l) {
    log_write("%4zi:", i);
    l = sizeof(b) < len - i ? sizeof(b) : len - i;
    memcpy(b, (char *)buf + i, l);
    for (j = 0; j < sizeof(b); j++) {
      if (j % 2 == 0)
        log_write(" ");
      if (j % 8 == 0)
        log_write(" ");
      if (j < l)
        log_write("%02x", (int)b[j]);
      else
        log_write("  ");
    }
    log_write("  |");
    for (j = 0; j < l; j++) {
      if (b[j] >= 0x20 && b[j] <= 0x7e)
        log_write("%c", b[j]);
      else
        log_write(".");
    }
    log_writeln("|");
  }
}


x86 assembly (clang, -O0):
<log_hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    12fb <log_hexdump+0x1cb>
mov    -0x28(%rbp),%rsi
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
mov    -0x10(%rbp),%rcx
sub    -0x28(%rbp),%rcx
mov    $0x10,%eax
cmp    %rcx,%rax
jae    118c <log_hexdump+0x5c>
mov    $0x10,%eax
mov    %rax,-0x40(%rbp)
jmp    1198 <log_hexdump+0x68>
mov    -0x10(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <memcpy@plt>
movq   $0x0,-0x30(%rbp)
cmpq   $0x10,-0x30(%rbp)
jae    1256 <log_hexdump+0x126>
mov    -0x30(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    11e8 <log_hexdump+0xb8>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
mov    -0x30(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    1208 <log_hexdump+0xd8>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    1232 <log_hexdump+0x102>
mov    -0x30(%rbp),%rax
movzbl -0x20(%rbp,%rax,1),%esi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
jmp    1240 <log_hexdump+0x110>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
jmp    1245 <log_hexdump+0x115>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11bd <log_hexdump+0x8d>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    12de <log_hexdump+0x1ae>
mov    -0x30(%rbp),%rax
movzbl -0x20(%rbp,%rax,1),%eax
cmp    $0x20,%eax
jl     12ba <log_hexdump+0x18a>
mov    -0x30(%rbp),%rax
movzbl -0x20(%rbp,%rax,1),%eax
cmp    $0x7e,%eax
jg     12ba <log_hexdump+0x18a>
mov    -0x30(%rbp),%rax
movzbl -0x20(%rbp,%rax,1),%esi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
jmp    12c8 <log_hexdump+0x198>
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
jmp    12cd <log_hexdump+0x19d>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    126c <log_hexdump+0x13c>
lea    0xd2b(%rip),%rdi
call   1030 <log_writeln@plt>
mov    -0x38(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1148 <log_hexdump+0x18>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,0x8(%rsp)
test   %rsi,%rsi
je     12af <log_hexdump+0x17f>
mov    %rsi,%r15
lea    0xeb6(%rip),%r14
lea    0xeb5(%rip),%r12
xor    %r13d,%r13d
mov    %rsi,(%rsp)
jmp    118c <log_hexdump+0x5c>
cs nopw 0x0(%rax,%rax,1)
lea    0xe99(%rip),%rdi
call   1030 <log_writeln@plt>
add    %r15,%r13
mov    (%rsp),%r15
cmp    %r15,%r13
jae    12af <log_hexdump+0x17f>
mov    %r12,%rbx
lea    0xe6a(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <log_write@plt>
sub    %r13,%r15
cmp    $0x10,%r15
mov    $0x10,%eax
cmovae %rax,%r15
mov    0x8(%rsp),%rax
lea    (%rax,%r13,1),%rsi
lea    0x10(%rsp),%rdi
mov    %r15,%rdx
call   1040 <memcpy@plt>
xor    %r12d,%r12d
lea    0xe36(%rip),%rbp
jmp    11f8 <log_hexdump+0xc8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe24(%rip),%rdi
xor    %eax,%eax
call   1050 <log_write@plt>
add    $0x1,%r12
cmp    $0x10,%r12
je     1250 <log_hexdump+0x120>
test   $0x1,%r12b
je     1210 <log_hexdump+0xe0>
test   $0x7,%r12b
je     1220 <log_hexdump+0xf0>
cmp    %r15,%r12
jae    11e0 <log_hexdump+0xb0>
jmp    122f <log_hexdump+0xff>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <log_write@plt>
test   $0x7,%r12b
jne    1204 <log_hexdump+0xd4>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <log_write@plt>
cmp    %r15,%r12
jae    11e0 <log_hexdump+0xb0>
movzbl 0x10(%rsp,%r12,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <log_write@plt>
jmp    11ee <log_hexdump+0xbe>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xdb7(%rip),%rdi
xor    %eax,%eax
call   1050 <log_write@plt>
test   %r15,%r15
mov    %rbx,%r12
lea    0xdaa(%rip),%rbx
je     1170 <log_hexdump+0x40>
xor    %ebp,%ebp
jmp    1297 <log_hexdump+0x167>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <log_write@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
je     1170 <log_hexdump+0x40>
movzbl 0x10(%rsp,%rbp,1),%esi
lea    -0x20(%rsi),%eax
cmp    $0x5e,%al
ja     1280 <log_hexdump+0x150>
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <log_write@plt>
jmp    128a <log_hexdump+0x15a>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%4zi:\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [5 x i8] c"%02x\00"
@.str.3 = [3 x i8] c" \00"
@.str.4 = [4 x i8] c" |\00"
@.str.5 = [3 x i8] c"%c\00"
@.str.6 = [2 x i8] c".\00"
@.str.7 = [2 x i8] c"|\00"
define void @log_hexdump(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [16 x i8]
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %6
br label %9
9: ; preds = %96, %2
%10 = load i64, i64* %6
%11 = load i64, i64* %4
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %100
13: ; preds = %9
%14 = load i64, i64* %6
%15 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %14)
%16 = load i64, i64* %4
%17 = load i64, i64* %6
%18 = sub i64 %16, %17
%19 = icmp ult i64 16, %18
br i1 %19, label %20, label %21
20: ; preds = %13
br label %25
21: ; preds = %13
%22 = load i64, i64* %4
%23 = load i64, i64* %6
%24 = sub i64 %22, %23
br label %25
25: ; preds = %21, %20
%26 = phi i64 [ 16, %20 ], [ %24, %21 ]
store i64 %26, i64* %8
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%28 = load i8*, i8** %3
%29 = load i64, i64* %6
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = load i64, i64* %8
%32 = call i32 @memcpy(i8* %27, i8* %30, i64 %31)
store i64 0, i64* %7
br label %33
33: ; preds = %61, %25
%34 = load i64, i64* %7
%35 = icmp ult i64 %34, 16
br i1 %35, label %36, label %64
36: ; preds = %33
%37 = load i64, i64* %7
%38 = urem i64 %37, 2
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %42
42: ; preds = %40, %36
%43 = load i64, i64* %7
%44 = urem i64 %43, 8
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %48
48: ; preds = %46, %42
%49 = load i64, i64* %7
%50 = load i64, i64* %8
%51 = icmp ult i64 %49, %50
br i1 %51, label %52, label %58
52: ; preds = %48
%53 = load i64, i64* %7
%54 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %56)
br label %60
58: ; preds = %48
%59 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %58, %52
br label %61
61: ; preds = %60
%62 = load i64, i64* %7
%63 = add i64 %62, 1
store i64 %63, i64* %7
br label %33
64: ; preds = %33
%65 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i64 0, i64* %7
br label %66
66: ; preds = %91, %64
%67 = load i64, i64* %7
%68 = load i64, i64* %8
%69 = icmp ult i64 %67, %68
br i1 %69, label %70, label %94
70: ; preds = %66
%71 = load i64, i64* %7
%72 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 %71
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = icmp sge i32 %74, 32
br i1 %75, label %76, label %88
76: ; preds = %70
%77 = load i64, i64* %7
%78 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 %77
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = icmp sle i32 %80, 126
br i1 %81, label %82, label %88
82: ; preds = %76
%83 = load i64, i64* %7
%84 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 %83
%85 = load i8, i8* %84
%86 = zext i8 %85 to i32
%87 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %86)
br label %90
88: ; preds = %76, %70
%89 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %90
90: ; preds = %88, %82
br label %91
91: ; preds = %90
%92 = load i64, i64* %7
%93 = add i64 %92, 1
store i64 %93, i64* %7
br label %66
94: ; preds = %66
%95 = call i32 @log_writeln(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %96
96: ; preds = %94
%97 = load i64, i64* %8
%98 = load i64, i64* %6
%99 = add i64 %98, %97
store i64 %99, i64* %6
br label %9
100: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%4zi:\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [5 x i8] c"%02x\00"
@.str.3 = [3 x i8] c" \00"
@.str.4 = [4 x i8] c" |\00"
@.str.5 = [3 x i8] c"%c\00"
@.str.6 = [2 x i8] c".\00"
@.str.7 = [2 x i8] c"|\00"
define void @log_hexdump(i8* %0, i64 %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = icmp eq i64 %1, 0
br i1 %5, label %58, label %6
6: ; preds = %2, %54
%7 = phi i64 [ %56, %54 ], [ 0, %2 ]
%8 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %7)
%9 = sub i64 %1, %7
%10 = icmp ult i64 %9, 16
%11 = select i1 %10, i64 %9, i64 16
%12 = getelementptr inbounds i8, i8* %0, i64 %7
%13 = call i32 @memcpy(i8* %4, i8* %12, i64 %11)
br label %14
14: ; preds = %6, %34
%15 = phi i64 [ 0, %6 ], [ %35, %34 ]
%16 = and i64 %15, 1
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = and i64 %15, 7
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = icmp ult i64 %15, %11
br i1 %26, label %27, label %32
27: ; preds = %25
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %15
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %34
32: ; preds = %25
%33 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %27, %32
%35 = add nuw nsw i64 %15, 1
%36 = icmp eq i64 %35, 16
br i1 %36, label %37, label %14
37: ; preds = %34
%38 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%39 = icmp eq i64 %11, 0
br i1 %39, label %54, label %40
40: ; preds = %37, %51
%41 = phi i64 [ %52, %51 ], [ 0, %37 ]
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = add i8 %43, -32
%45 = icmp ult i8 %44, 95
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = zext i8 %43 to i32
%48 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %47)
br label %51
49: ; preds = %40
%50 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %51
51: ; preds = %46, %49
%52 = add nuw nsw i64 %41, 1
%53 = icmp eq i64 %52, %11
br i1 %53, label %54, label %40
54: ; preds = %51, %37
%55 = call i32 @log_writeln(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%56 = add i64 %11, %7
%57 = icmp ult i64 %56, %1
br i1 %57, label %6, label %58
58: ; preds = %54, %2
ret void
}