#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 uint8_t;
typedef size_t uint16_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void hexdump(uint8_t *data, uint16_t len) {
  uint16_t x;
  printf("0000: ");
  for (x = 0; x < len; x++) {
    printf("%02x ", data[x]);
    if (!((x + 1) % 16))
      printf("\n%04x: ", x + 1);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    119f <hexdump+0x8f>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    1189 <hexdump+0x79>
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118e <hexdump+0x7e>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1136 <hexdump+0x26>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r15,%r15
je     1195 <hexdump+0x75>
neg    %r15
mov    $0x1,%ebx
lea    0xeb6(%rip),%r12
lea    0xeb5(%rip),%r13
jmp    1172 <hexdump+0x52>
nopw   0x0(%rax,%rax,1)
lea    (%r15,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     1195 <hexdump+0x75>
mov    -0x4(%r14,%rbx,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0xf,%bl
jne    1160 <hexdump+0x40>
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <hexdump+0x40>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"0000: \00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [8 x i8] c"\0A%04x: \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @hexdump(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %5
br label %7
7: ; preds = %26, %2
%8 = load i64, i64* %5
%9 = load i64, i64* %4
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %29
11: ; preds = %7
%12 = load i32*, i32** %3
%13 = load i64, i64* %5
%14 = getelementptr inbounds i32, i32* %12, i64 %13
%15 = load i32, i32* %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i64, i64* %5
%18 = add i64 %17, 1
%19 = urem i64 %18, 16
%20 = icmp ne i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %11
%22 = load i64, i64* %5
%23 = add i64 %22, 1
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 %23)
br label %25
25: ; preds = %21, %11
br label %26
26: ; preds = %25
%27 = load i64, i64* %5
%28 = add i64 %27, 1
store i64 %28, i64* %5
br label %7
29: ; preds = %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"0000: \00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [8 x i8] c"\0A%04x: \00"
define void @hexdump(i32* nocapture %0, i64 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %1, 0
br i1 %4, label %17, label %5
5: ; preds = %2, %15
%6 = phi i64 [ %10, %15 ], [ 0, %2 ]
%7 = getelementptr inbounds i32, i32* %0, i64 %6
%8 = load i32, i32* %7
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = add nuw i64 %6, 1
%11 = and i64 %10, 15
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 %10)
br label %15
15: ; preds = %5, %13
%16 = icmp eq i64 %10, %1
br i1 %16, label %17, label %5
17: ; preds = %15, %2
%18 = tail call i32 @putchar(i32 10)
ret void
}