#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*/ line(unsigned char *, unsigned int, unsigned int);
int /*<<< orphan*/ output(char *, ...);
void hexdump(unsigned char *pointer, unsigned long displayStart,
             unsigned long length) {
  unsigned long position;
  unsigned long extra;
  unsigned long display;
  unsigned spacesAtStart;
  spacesAtStart = displayStart & 0x0F;
  extra = length + spacesAtStart;
  if (extra > 0x10) {
    extra = 0x10;
  }
  output("%08lX  ", displayStart);
  line(pointer, spacesAtStart, (unsigned)extra);
  output("\n");
  for (position = extra; position < length; position += 0x10) {
    extra = length - position;
    if (extra > 0x10) {
      extra = 0x10;
    }
    display = displayStart + position - spacesAtStart;
    output("%08lX  ", display);
    line(pointer + position, 0, (unsigned)extra);
    output("\n");
  }
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
and    $0xf,%rax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x10,-0x28(%rbp)
jbe    1160 <hexdump+0x40>
movq   $0x10,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <output@plt>
mov    -0x8(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x28(%rbp),%rax
mov    %eax,%edx
call   1040 <line@plt>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <output@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    121f <hexdump+0xff>
mov    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x10,-0x28(%rbp)
jbe    11c7 <hexdump+0xa7>
movq   $0x10,-0x28(%rbp)
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <output@plt>
mov    -0x8(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <line@plt>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <output@plt>
mov    -0x20(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
jmp    119a <hexdump+0x7a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,%r15
mov    %r12d,%ebp
and    $0xf,%ebp
lea    (%rdx,%rbp,1),%rax
cmp    $0x10,%rax
mov    $0x10,%ebx
cmovb  %rax,%rbx
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1030 <output@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <line@plt>
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1030 <output@plt>
cmp    %r13,%rbx
jae    11d7 <hexdump+0xb7>
mov    %r13,%r14
sub    %rbx,%r14
and    $0xfffffffffffffff0,%r12
mov    %r14,%rbp
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r12,%rbx,1),%rsi
lea    0xe65(%rip),%rdi
xor    %eax,%eax
call   1030 <output@plt>
lea    (%r15,%rbx,1),%rdi
sub    $0x10,%rbp
mov    $0x10,%eax
cmovae %eax,%r14d
xor    %esi,%esi
mov    %r14d,%edx
call   1040 <line@plt>
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1030 <output@plt>
add    $0x10,%rbx
mov    %rbp,%r14
cmp    %r13,%rbx
jb     1190 <hexdump+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%08lX \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @hexdump(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%11 = load i64, i64* %5
%12 = and i64 %11, 15
%13 = trunc i64 %12 to i32
store i32 %13, i32* %10
%14 = load i64, i64* %6
%15 = load i32, i32* %10
%16 = zext i32 %15 to i64
%17 = add i64 %14, %16
store i64 %17, i64* %8
%18 = load i64, i64* %8
%19 = icmp ugt i64 %18, 16
br i1 %19, label %20, label %21
20: ; preds = %3
store i64 16, i64* %8
br label %21
21: ; preds = %20, %3
%22 = load i64, i64* %5
%23 = call i32 (i8*, ...) @output(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %22)
%24 = load i8*, i8** %4
%25 = load i32, i32* %10
%26 = load i64, i64* %8
%27 = trunc i64 %26 to i32
%28 = call i32 @line(i8* %24, i32 %25, i32 %27)
%29 = call i32 (i8*, ...) @output(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = load i64, i64* %8
store i64 %30, i64* %7
br label %31
31: ; preds = %58, %21
%32 = load i64, i64* %7
%33 = load i64, i64* %6
%34 = icmp ult i64 %32, %33
br i1 %34, label %35, label %61
35: ; preds = %31
%36 = load i64, i64* %6
%37 = load i64, i64* %7
%38 = sub i64 %36, %37
store i64 %38, i64* %8
%39 = load i64, i64* %8
%40 = icmp ugt i64 %39, 16
br i1 %40, label %41, label %42
41: ; preds = %35
store i64 16, i64* %8
br label %42
42: ; preds = %41, %35
%43 = load i64, i64* %5
%44 = load i64, i64* %7
%45 = add i64 %43, %44
%46 = load i32, i32* %10
%47 = zext i32 %46 to i64
%48 = sub i64 %45, %47
store i64 %48, i64* %9
%49 = load i64, i64* %9
%50 = call i32 (i8*, ...) @output(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %49)
%51 = load i8*, i8** %4
%52 = load i64, i64* %7
%53 = getelementptr inbounds i8, i8* %51, i64 %52
%54 = load i64, i64* %8
%55 = trunc i64 %54 to i32
%56 = call i32 @line(i8* %53, i32 0, i32 %55)
%57 = call i32 (i8*, ...) @output(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %58
58: ; preds = %42
%59 = load i64, i64* %7
%60 = add i64 %59, 16
store i64 %60, i64* %7
br label %31
61: ; preds = %31
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%08lX \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @hexdump(i8* %0, i64 %1, i64 %2) {
%4 = trunc i64 %1 to i32
%5 = and i32 %4, 15
%6 = zext i32 %5 to i64
%7 = add i64 %6, %2
%8 = icmp ult i64 %7, 16
%9 = select i1 %8, i64 %7, i64 16
%10 = tail call i32 (i8*, ...) @output(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %1)
%11 = trunc i64 %9 to i32
%12 = tail call i32 @line(i8* %0, i32 %5, i32 %11)
%13 = tail call i32 (i8*, ...) @output(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp ult i64 %9, %2
br i1 %14, label %15, label %30
15: ; preds = %3
%16 = sub i64 %1, %6
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ %9, %15 ], [ %28, %17 ]
%19 = sub i64 %2, %18
%20 = icmp ult i64 %19, 16
%21 = select i1 %20, i64 %19, i64 16
%22 = add i64 %16, %18
%23 = tail call i32 (i8*, ...) @output(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %22)
%24 = getelementptr inbounds i8, i8* %0, i64 %18
%25 = trunc i64 %21 to i32
%26 = tail call i32 @line(i8* %24, i32 0, i32 %25)
%27 = tail call i32 (i8*, ...) @output(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = add i64 %18, 16
%29 = icmp ult i64 %28, %2
br i1 %29, label %17, label %30
30: ; preds = %17, %3
ret void
}