#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*/ printf(char *, ...);
void hexdump(char *title, unsigned char *data, long size) {
  int line = 0;
  int i = 0;
  while (i < size) {
    while (0 == i % 16) {
      if (0 == i) {
        printf("\n<%s>\n", title);
        printf("%08x\t", line);
        break;
      }
      line += 0x10;
      printf("\n%08x\t", line);
      break;
    }
    printf("%02x ", *(data + i));
    i++;
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11cf <hexdump+0xbf>
jmp    1145 <hexdump+0x35>
mov    -0x20(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
cmp    %edx,%eax
jne    11a7 <hexdump+0x97>
xor    %eax,%eax
cmp    -0x20(%rbp),%eax
jne    118d <hexdump+0x7d>
mov    -0x8(%rbp),%rsi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a7 <hexdump+0x97>
mov    -0x1c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1132 <hexdump+0x22>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
jle    116f <hexdump+0x4f>
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%rsi
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeba(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%r14),%esi
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%r13
jne    1189 <hexdump+0x69>
lea    0xe8f(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
mov    $0x1,%ebx
lea    0xe72(%rip),%r15
lea    0xe72(%rip),%r12
xor    %ebp,%ebp
jmp    11b8 <hexdump+0x98>
movzbl (%r14,%rbx,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
je     116f <hexdump+0x4f>
test   $0xf,%bl
jne    11a0 <hexdump+0x80>
add    $0x10,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a0 <hexdump+0x80>

LLVM IR (-O0):
@.str = [7 x i8] c"\0A<%s>\0A\00"
@.str.1 = [6 x i8] c"%08x\09\00"
@.str.2 = [7 x i8] c"\0A%08x\09\00"
@.str.3 = [6 x i8] c"%02x \00"
@.str.4 = [3 x i8] c"\0A\0A\00"
define void @hexdump(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %32, %3
%10 = load i32, i32* %8
%11 = sext i32 %10 to i64
%12 = load i64, i64* %6
%13 = icmp slt i64 %11, %12
br i1 %13, label %14, label %42
14: ; preds = %9
br label %15
15: ; preds = %14
%16 = load i32, i32* %8
%17 = srem i32 %16, 16
%18 = icmp eq i32 0, %17
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i32, i32* %8
%21 = icmp eq i32 0, %20
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %7
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %32
27: ; preds = %19
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 16
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %27, %22, %15
%33 = load i8*, i8** %5
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %9
42: ; preds = %9
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"\0A<%s>\0A\00"
@.str.1 = [6 x i8] c"%08x\09\00"
@.str.2 = [7 x i8] c"\0A%08x\09\00"
@.str.3 = [6 x i8] c"%02x \00"
@str = [2 x i8] c"\0A\00"
define void @hexdump(i8* %0, i8* nocapture %1, i64 %2) {
%4 = icmp sgt i64 %2, 0
br i1 %4, label %5, label %28
5: ; preds = %3
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 0)
%8 = load i8, i8* %1
%9 = zext i8 %8 to i32
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = icmp eq i64 %2, 1
br i1 %11, label %28, label %12
12: ; preds = %5, %20
%13 = phi i64 [ %26, %20 ], [ 1, %5 ]
%14 = phi i32 [ %21, %20 ], [ 0, %5 ]
%15 = and i64 %13, 15
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = add nsw i32 %14, 16
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17, %12
%21 = phi i32 [ %18, %17 ], [ %14, %12 ]
%22 = getelementptr inbounds i8, i8* %1, i64 %13
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = add nuw nsw i64 %13, 1
%27 = icmp eq i64 %26, %2
br i1 %27, label %28, label %12
28: ; preds = %20, %5, %3
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}