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

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int svz_hexdump(FILE *out, char *action, int from, char *buffer, int len,
                int max) {
  int row, col, x, max_col;
  if (!max)
    max = len;
  if (max > len)
    max = len;
  max_col = max / 16;
  if ((max % 16) != 0)
    max_col++;
  fprintf(out, "%s [ FROM:0x%08X SIZE:%d ]\n", action, (unsigned)from, len);
  for (x = row = 0; row < max_col && x < max; row++) {
    fprintf(out, "%04X   ", x);
    for (col = 0; col < 16; col++, x++) {
      if (x < max)
        fprintf(out, "%02X ", (unsigned char)buffer[x]);
      else
        fprintf(out, "   ");
    }
    x -= 16;
    fprintf(out, "  ");
    for (col = 0; col < 16 && x < max; col++, x++) {
      fprintf(out, "%c", buffer[x] >= ' ' ? buffer[x] : '.');
    }
    fprintf(out, "\n");
  }
  fflush(out);
  return 0;
}


x86 assembly (clang, -O0):
<svz_hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    114f <svz_hexdump+0x2f>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    1161 <svz_hexdump+0x41>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     118c <svz_hexdump+0x6c>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x38(%rbp),%ecx
mov    %al,-0x39(%rbp)
jge    11d4 <svz_hexdump+0xb4>
mov    -0x34(%rbp),%eax
cmp    -0x28(%rbp),%eax
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11e4 <svz_hexdump+0xc4>
jmp    133e <svz_hexdump+0x21e>
mov    -0x8(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x30(%rbp)
cmpl   $0x10,-0x30(%rbp)
jge    1267 <svz_hexdump+0x147>
mov    -0x34(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1239 <svz_hexdump+0x119>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    124b <svz_hexdump+0x12b>
mov    -0x8(%rbp),%rdi
lea    0xddc(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1250 <svz_hexdump+0x130>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1200 <svz_hexdump+0xe0>
mov    -0x34(%rbp),%eax
sub    $0x10,%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x30(%rbp)
xor    %eax,%eax
cmpl   $0x10,-0x30(%rbp)
mov    %al,-0x3a(%rbp)
jge    12a4 <svz_hexdump+0x184>
mov    -0x34(%rbp),%eax
cmp    -0x28(%rbp),%eax
setl   %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
test   $0x1,%al
jne    12b4 <svz_hexdump+0x194>
jmp    131e <svz_hexdump+0x1fe>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     12e5 <svz_hexdump+0x1c5>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x4c(%rbp)
jmp    12f2 <svz_hexdump+0x1d2>
mov    $0x2e,%eax
mov    %eax,-0x4c(%rbp)
jmp    12f2 <svz_hexdump+0x1d2>
mov    -0x48(%rbp),%rdi
mov    -0x4c(%rbp),%edx
lea    0xd2a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1289 <svz_hexdump+0x169>
mov    -0x8(%rbp),%rdi
lea    0xcf1(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b7 <svz_hexdump+0x97>
mov    -0x8(%rbp),%rdi
call   1040 <fflush@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<svz_hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r12d
test   %r9d,%r9d
cmove  %r8d,%r12d
mov    %rcx,0x10(%rsp)
mov    %edx,%ecx
mov    %rsi,%rdx
cmp    %r8d,%r12d
cmovg  %r8d,%r12d
lea    0xf(%r12),%ebx
test   %r12d,%r12d
cmovns %r12d,%ebx
sar    $0x4,%ebx
xor    %ebp,%ebp
test   $0xf,%r12b
setne  %bpl
lea    0xe77(%rip),%rsi
mov    %rdi,(%rsp)
xor    %eax,%eax
call   1040 <fprintf@plt>
add    %ebx,%ebp
mov    %ebp,0x8(%rsp)
jle    12d5 <svz_hexdump+0x195>
test   %r12d,%r12d
jle    12d5 <svz_hexdump+0x195>
mov    %r12d,%r14d
xor    %r13d,%r13d
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,0xc(%rsp)
mov    %r12,%rbx
mov    (%rsp),%rdi
lea    0xe4a(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
movslq %r13d,%r12
lea    -0x10(%r12),%ebp
mov    $0x10,%r15d
jmp    1217 <svz_hexdump+0xd7>
nopl   0x0(%rax)
mov    $0x3,%esi
mov    $0x1,%edx
lea    0xe1f(%rip),%rdi
mov    (%rsp),%rcx
call   1060 <fwrite@plt>
add    $0x1,%r12
add    $0x1,%ebp
add    $0xffffffff,%r15d
je     1240 <svz_hexdump+0x100>
cmp    %r14,%r12
jge    11f0 <svz_hexdump+0xb0>
mov    0x10(%rsp),%rax
movzbl (%rax,%r12,1),%edx
mov    (%rsp),%rdi
lea    0xdf3(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    120a <svz_hexdump+0xca>
nopw   0x0(%rax,%rax,1)
sub    %r15d,%r13d
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xdcd(%rip),%rdi
mov    (%rsp),%rcx
call   1060 <fwrite@plt>
mov    %rbx,%r12
cmp    %r12d,%r13d
jge    12b1 <svz_hexdump+0x171>
movslq %ebp,%rbx
mov    0x10(%rsp),%rax
lea    (%rax,%rbx,1),%r15
add    $0x1,%rbx
mov    %ebp,%r13d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbp,1),%eax
cmp    $0x20,%al
mov    $0x2e,%ecx
cmovl  %ecx,%eax
movzbl %al,%edi
mov    (%rsp),%rsi
call   1030 <fputc@plt>
add    $0x1,%r13d
cmp    $0xe,%ebp
ja     12b1 <svz_hexdump+0x171>
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rbp
cmp    %r14,%rax
jl     1280 <svz_hexdump+0x140>
mov    $0xa,%edi
mov    (%rsp),%rsi
call   1030 <fputc@plt>
mov    0xc(%rsp),%eax
add    $0x1,%eax
cmp    0x8(%rsp),%eax
jge    12d5 <svz_hexdump+0x195>
cmp    %r12d,%r13d
jl     11c0 <svz_hexdump+0x80>
mov    (%rsp),%rdi
call   1050 <fflush@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"%s [ FROM:0x%08X SIZE:%d ]\0A\00"
@.str.1 = [8 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"\0A\00"
define i32 @svz_hexdump(i32* %0, i8* %1, i32 %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32* %0, i32** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%17 = load i32, i32* %12
%18 = icmp ne i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %6
%20 = load i32, i32* %11
store i32 %20, i32* %12
br label %21
21: ; preds = %19, %6
%22 = load i32, i32* %12
%23 = load i32, i32* %11
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i32, i32* %11
store i32 %26, i32* %12
br label %27
27: ; preds = %25, %21
%28 = load i32, i32* %12
%29 = sdiv i32 %28, 16
store i32 %29, i32* %16
%30 = load i32, i32* %12
%31 = srem i32 %30, 16
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = load i32, i32* %16
%35 = add nsw i32 %34, 1
store i32 %35, i32* %16
br label %36
36: ; preds = %33, %27
%37 = load i32*, i32** %7
%38 = load i8*, i8** %8
%39 = load i32, i32* %9
%40 = load i32, i32* %11
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %38, i32 %39, i32 %40)
store i32 0, i32* %13
store i32 0, i32* %15
br label %42
42: ; preds = %123, %36
%43 = load i32, i32* %13
%44 = load i32, i32* %16
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i32, i32* %15
%48 = load i32, i32* %12
%49 = icmp slt i32 %47, %48
br label %50
50: ; preds = %46, %42
%51 = phi i1 [ false, %42 ], [ %49, %46 ]
br i1 %51, label %52, label %126
52: ; preds = %50
%53 = load i32*, i32** %7
%54 = load i32, i32* %15
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %54)
store i32 0, i32* %14
br label %56
56: ; preds = %76, %52
%57 = load i32, i32* %14
%58 = icmp slt i32 %57, 16
br i1 %58, label %59, label %81
59: ; preds = %56
%60 = load i32, i32* %15
%61 = load i32, i32* %12
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %72
63: ; preds = %59
%64 = load i32*, i32** %7
%65 = load i8*, i8** %10
%66 = load i32, i32* %15
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = call i32 (i32*, i8*, ...) @fprintf(i32* %64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %70)
br label %75
72: ; preds = %59
%73 = load i32*, i32** %7
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %75
75: ; preds = %72, %63
br label %76
76: ; preds = %75
%77 = load i32, i32* %14
%78 = add nsw i32 %77, 1
store i32 %78, i32* %14
%79 = load i32, i32* %15
%80 = add nsw i32 %79, 1
store i32 %80, i32* %15
br label %56
81: ; preds = %56
%82 = load i32, i32* %15
%83 = sub nsw i32 %82, 16
store i32 %83, i32* %15
%84 = load i32*, i32** %7
%85 = call i32 (i32*, i8*, ...) @fprintf(i32* %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %14
br label %86
86: ; preds = %115, %81
%87 = load i32, i32* %14
%88 = icmp slt i32 %87, 16
br i1 %88, label %89, label %93
89: ; preds = %86
%90 = load i32, i32* %15
%91 = load i32, i32* %12
%92 = icmp slt i32 %90, %91
br label %93
93: ; preds = %89, %86
%94 = phi i1 [ false, %86 ], [ %92, %89 ]
br i1 %94, label %95, label %120
95: ; preds = %93
%96 = load i32*, i32** %7
%97 = load i8*, i8** %10
%98 = load i32, i32* %15
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i8, i8* %97, i64 %99
%101 = load i8, i8* %100
%102 = sext i8 %101 to i32
%103 = icmp sge i32 %102, 32
br i1 %103, label %104, label %111
104: ; preds = %95
%105 = load i8*, i8** %10
%106 = load i32, i32* %15
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i8, i8* %105, i64 %107
%109 = load i8, i8* %108
%110 = sext i8 %109 to i32
br label %112
111: ; preds = %95
br label %112
112: ; preds = %111, %104
%113 = phi i32 [ %110, %104 ], [ 46, %111 ]
%114 = call i32 (i32*, i8*, ...) @fprintf(i32* %96, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %113)
br label %115
115: ; preds = %112
%116 = load i32, i32* %14
%117 = add nsw i32 %116, 1
store i32 %117, i32* %14
%118 = load i32, i32* %15
%119 = add nsw i32 %118, 1
store i32 %119, i32* %15
br label %86
120: ; preds = %93
%121 = load i32*, i32** %7
%122 = call i32 (i32*, i8*, ...) @fprintf(i32* %121, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %123
123: ; preds = %120
%124 = load i32, i32* %13
%125 = add nsw i32 %124, 1
store i32 %125, i32* %13
br label %42
126: ; preds = %50
%127 = load i32*, i32** %7
%128 = call i32 @fflush(i32* %127)
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"%s [ FROM:0x%08X SIZE:%d ]\0A\00"
@.str.1 = [8 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"
define i32 @svz_hexdump(i32* nocapture %0, i8* %1, i32 %2, i8* nocapture %3, i32 %4, i32 %5) {
%7 = icmp eq i32 %5, 0
%8 = select i1 %7, i32 %4, i32 %5
%9 = icmp sgt i32 %8, %4
%10 = select i1 %9, i32 %4, i32 %8
%11 = sdiv i32 %10, 16
%12 = and i32 %10, 15
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i32
%15 = add nsw i32 %11, %14
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %2, i32 %4)
%17 = icmp sgt i32 %15, 0
%18 = icmp sgt i32 %10, 0
%19 = and i1 %17, %18
br i1 %19, label %20, label %72
20: ; preds = %6
%21 = zext i32 %10 to i64
br label %22
22: ; preds = %20, %65
%23 = phi i32 [ %66, %65 ], [ 0, %20 ]
%24 = phi i32 [ %68, %65 ], [ 0, %20 ]
%25 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%26 = sext i32 %23 to i64
br label %27
27: ; preds = %22, %38
%28 = phi i64 [ %26, %22 ], [ %40, %38 ]
%29 = phi i32 [ 0, %22 ], [ %39, %38 ]
%30 = icmp slt i64 %28, %21
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = getelementptr inbounds i8, i8* %3, i64 %28
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %38
36: ; preds = %27
%37 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 3, i64 1, i32* %0)
br label %38
38: ; preds = %31, %36
%39 = add nuw nsw i32 %29, 1
%40 = add nsw i64 %28, 1
%41 = icmp eq i32 %39, 16
br i1 %41, label %42, label %27
42: ; preds = %38
%43 = trunc i64 %28 to i32
%44 = add i32 %43, -15
%45 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 2, i64 1, i32* %0)
%46 = icmp slt i32 %44, %10
br i1 %46, label %47, label %65
47: ; preds = %42
%48 = sext i32 %44 to i64
br label %49
49: ; preds = %47, %49
%50 = phi i64 [ %48, %47 ], [ %59, %49 ]
%51 = phi i32 [ 0, %47 ], [ %58, %49 ]
%52 = getelementptr inbounds i8, i8* %3, i64 %50
%53 = load i8, i8* %52
%54 = icmp sgt i8 %53, 31
%55 = select i1 %54, i8 %53, i8 46
%56 = zext i8 %55 to i32
%57 = tail call i32 @fputc(i32 %56, i32* %0)
%58 = add nuw nsw i32 %51, 1
%59 = add nsw i64 %50, 1
%60 = icmp ult i32 %51, 15
%61 = icmp slt i64 %59, %21
%62 = select i1 %60, i1 %61, i1 false
br i1 %62, label %49, label %63
63: ; preds = %49
%64 = trunc i64 %59 to i32
br label %65
65: ; preds = %63, %42
%66 = phi i32 [ %44, %42 ], [ %64, %63 ]
%67 = tail call i32 @fputc(i32 10, i32* %0)
%68 = add nuw nsw i32 %24, 1
%69 = icmp slt i32 %68, %15
%70 = icmp slt i32 %66, %10
%71 = select i1 %69, i1 %70, i1 false
br i1 %71, label %22, label %72
72: ; preds = %65, %6
%73 = tail call i32 @fflush(i32* %0)
ret i32 0
}