#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void log_hexdump(char *txt, unsigned char *data, int len) {
  int i, j;
  if (len == 0)
    return;
  fprintf(stderr, "+-------| %s len=%d |-------\n", txt, len);
  for (i = 0; i < len; i += 16) {
    fprintf(stderr, "| %04X  ", i);
    for (j = i; (j < i + 16); j++) {
      if (j < len) {
        fprintf(stderr, "%02X ", (unsigned char)*(data + j));
      } else {
        fprintf(stderr, "   ");
      }
    }
    fprintf(stderr, "  ");
    for (j = i; (j < i + 16) && (j < len); j++) {
      if ((*(data + j) >= 32) && (*(data + j) <= 127)) {
        fprintf(stderr, "%c", *(data + j));
      } else {
        fprintf(stderr, ".");
      }
    }
    fprintf(stderr, "\n");
  }
}


x86 assembly (clang, -O0):
<log_hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1132 <log_hexdump+0x22>
jmp    12e2 <log_hexdump+0x1d2>
mov    0x2ea7(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xeb7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12e2 <log_hexdump+0x1d2>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%ecx
add    $0x10,%ecx
cmp    %ecx,%eax
jge    11f2 <log_hexdump+0xe2>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c8 <log_hexdump+0xb8>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11df <log_hexdump+0xcf>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11e4 <log_hexdump+0xd4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1183 <log_hexdump+0x73>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%edx
add    $0x10,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x1d(%rbp)
jge    1231 <log_hexdump+0x121>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1241 <log_hexdump+0x131>
jmp    12bd <log_hexdump+0x1ad>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     1293 <log_hexdump+0x183>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7f,%eax
jg     1293 <log_hexdump+0x183>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xdaa(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12aa <log_hexdump+0x19a>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    0xd91(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12af <log_hexdump+0x19f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120f <log_hexdump+0xff>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xd4f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x18(%rbp)
jmp    1157 <log_hexdump+0x47>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
test   %edx,%edx
je     128e <log_hexdump+0x17e>
mov    %rsi,%r13
mov    %rdi,%rdx
mov    0x2eab(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xec1(%rip),%rsi
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
test   %ebx,%ebx
jle    128e <log_hexdump+0x17e>
mov    %ebx,%r12d
mov    $0x1,%eax
mov    %rax,0x10(%rsp)
xor    %r15d,%r15d
mov    %ebx,0xc(%rsp)
jmp    1190 <log_hexdump+0x80>
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
lea    0xea2(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
addq   $0x10,0x10(%rsp)
cmp    %ebx,%r15d
jge    128e <log_hexdump+0x17e>
mov    %rbp,%r14
mov    0x0(%rbp),%edi
lea    0xe81(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x10,%ebp
mov    %r15,%rbx
jmp    11d8 <log_hexdump+0xc8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe66(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%rbx
add    $0xffffffffffffffff,%rbp
je     1200 <log_hexdump+0xf0>
mov    (%r14),%edi
cmp    %r12,%rbx
jge    11c0 <log_hexdump+0xb0>
movzbl 0x0(%r13,%rbx,1),%edx
lea    0xe3a(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11ce <log_hexdump+0xbe>
cs nopw 0x0(%rax,%rax,1)
add    $0x10,%r15
mov    %r14,%rbp
mov    (%r14),%edi
lea    0xe1d(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x10(%rsp),%r14
mov    0xc(%rsp),%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%r13,%r14,1),%edx
cmp    $0x20,%dl
jl     1260 <log_hexdump+0x150>
mov    0x0(%rbp),%edi
lea    0xdec(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    %r15,%r14
jb     127a <log_hexdump+0x16a>
jmp    1170 <log_hexdump+0x60>
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
lea    0xdca(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    %r15,%r14
jae    1170 <log_hexdump+0x60>
mov    %r14,%rax
add    $0x1,%rax
cmp    %ebx,%r14d
mov    %rax,%r14
jl     1230 <log_hexdump+0x120>
jmp    1170 <log_hexdump+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"+-------| %s len=%d |-------\0A\00"
@.str.1 = [9 x i8] c"| %04X \00"
@.str.2 = [6 x i8] c"%02X \00"
@.str.3 = [4 x i8] c" \00"
@.str.4 = [3 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"\0A\00"
define void @log_hexdump(i8* %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %59, label %5
5: ; preds = %3
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %2)
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %59
9: ; preds = %5
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %9, %53
%12 = phi i64 [ 16, %9 ], [ %58, %53 ]
%13 = phi i64 [ 0, %9 ], [ %32, %53 ]
%14 = load i32, i32* @stderr
%15 = trunc i64 %13 to i32
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %11, %28
%18 = phi i64 [ %13, %11 ], [ %29, %28 ]
%19 = icmp slt i64 %18, %10
%20 = load i32, i32* @stderr
br i1 %19, label %21, label %26
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %1, i64 %18
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %28
26: ; preds = %17
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %21, %26
%29 = add nuw i64 %18, 1
%30 = icmp eq i64 %29, %12
br i1 %30, label %31, label %17
31: ; preds = %28
%32 = add nuw i64 %13, 16
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %31, %47
%36 = phi i64 [ %13, %31 ], [ %48, %47 ]
%37 = getelementptr inbounds i8, i8* %1, i64 %36
%38 = load i8, i8* %37
%39 = icmp sgt i8 %38, 31
br i1 %39, label %40, label %44
40: ; preds = %35
%41 = zext i8 %38 to i32
%42 = load i32, i32* @stderr
%43 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %41)
br label %47
44: ; preds = %35
%45 = load i32, i32* @stderr
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %47
47: ; preds = %40, %44
%48 = add nuw i64 %36, 1
%49 = icmp ult i64 %48, %32
%50 = trunc i64 %48 to i32
%51 = icmp slt i32 %50, %2
%52 = and i1 %49, %51
br i1 %52, label %35, label %53
53: ; preds = %47
%54 = load i32, i32* @stderr
%55 = tail call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%56 = trunc i64 %32 to i32
%57 = icmp slt i32 %56, %2
%58 = add i64 %12, 16
br i1 %57, label %11, label %59
59: ; preds = %53, %5, %3
ret void
}