#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 *, ...);
void hexdump(unsigned char *ptr, int size, FILE *out, const char *title) {
  unsigned char *lptr = ptr;
  int count = 0;
  long start = 0;
  if (title)
    fprintf(out, "%s\n", title);
  while (size-- > 0) {
    if ((count % 16) == 0)
      fprintf(out, "\t%08lx:", start);
    fprintf(out, " %02x", *ptr++);
    count++;
    start++;
    if (size == 0) {
      while ((count % 16) != 0) {
        fprintf(out, "   ");
        count++;
      }
    }
    if ((count % 16) == 0) {
      fprintf(out, " ");
      while (lptr < ptr) {
        unsigned char c = ((*lptr & 0x7f) < 32) ? '.' : (*lptr & 0x7f);
        fprintf(out, "%c", c);
        lptr++;
      }
      fprintf(out, "\n");
    }
  }
  if ((count % 16) != 0)
    fprintf(out, "\n");
  fflush(out);
  return;
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     116f <hexdump+0x4f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1174 <hexdump+0x54>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    12d8 <hexdump+0x1b8>
mov    -0x2c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11b2 <hexdump+0x92>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%edx
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1233 <hexdump+0x113>
jmp    11fa <hexdump+0xda>
mov    -0x2c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     122e <hexdump+0x10e>
mov    -0x18(%rbp),%rdi
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11fa <hexdump+0xda>
jmp    1233 <hexdump+0x113>
mov    -0x2c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12d3 <hexdump+0x1b3>
mov    -0x18(%rbp),%rdi
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    12c1 <hexdump+0x1a1>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
and    $0x7f,%eax
cmp    $0x20,%eax
jge    1287 <hexdump+0x167>
mov    $0x2e,%eax
mov    %eax,-0x40(%rbp)
jmp    1294 <hexdump+0x174>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
and    $0x7f,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %al,-0x39(%rbp)
mov    -0x18(%rbp),%rdi
movzbl -0x39(%rbp),%edx
lea    0xd6d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1259 <hexdump+0x139>
mov    -0x18(%rbp),%rdi
lea    0xd36(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1174 <hexdump+0x54>
mov    -0x2c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12fe <hexdump+0x1de>
mov    -0x18(%rbp),%rdi
lea    0xd0b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fflush@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbx
mov    %esi,%r13d
mov    %rdi,%r15
test   %rcx,%rcx
je     1170 <hexdump+0x30>
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
mov    %rcx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %r13d,%r13d
jle    12c0 <hexdump+0x180>
mov    %r13d,%eax
mov    %rax,0x20(%rsp)
lea    0xe8a(%rip),%rbp
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %r14d,%r14d
mov    %r15,%r12
jmp    11ce <hexdump+0x8e>
mov    %r12,%rbp
mov    $0xa,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
mov    %rbp,%r12
mov    0x14(%rsp),%r13d
lea    0xe5c(%rip),%rbp
mov    0x18(%rsp),%rax
mov    %rax,%r15
mov    0x8(%rsp),%rax
cmp    0x20(%rsp),%rax
je     12ad <hexdump+0x16d>
add    $0xffffffff,%r13d
test   $0xf,%r14b
jne    11ee <hexdump+0xae>
mov    %rbx,%rdi
lea    0xe22(%rip),%rsi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
movzbl (%r15),%edx
mov    %rbx,%rdi
lea    0xe10(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%r14d
test   %r13d,%r13d
jne    123f <hexdump+0xff>
mov    %r14d,%eax
and    $0xf,%eax
je     123f <hexdump+0xff>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %rbx,%rcx
call   1060 <fwrite@plt>
add    $0x1,%r14d
test   $0xf,%r14b
jne    1220 <hexdump+0xe0>
lea    0x1(%r15),%rax
addq   $0x1,0x8(%rsp)
test   $0xf,%r14b
jne    11bb <hexdump+0x7b>
mov    $0x20,%edi
mov    %rbx,%rsi
mov    %rax,0x18(%rsp)
call   1030 <fputc@plt>
cmp    0x18(%rsp),%r12
mov    %r13d,0x14(%rsp)
jae    1197 <hexdump+0x57>
mov    $0x2e,%r13d
nopl   0x0(%rax,%rax,1)
movzbl (%r12),%eax
and    $0x7f,%al
cmp    $0x20,%al
movzbl %al,%eax
cmovb  %r13d,%eax
movzbl %al,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
lea    0x1(%r12),%rbp
cmp    %r15,%r12
mov    %rbp,%r12
jb     1280 <hexdump+0x140>
jmp    119a <hexdump+0x5a>
test   $0xf,%r14b
je     12c0 <hexdump+0x180>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
mov    %rbx,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fflush@plt>

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

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