#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 *buffer, size_t len) {
  int all_aa = 0;
  for (size_t i = 0; i < len; ++i) {
    if (i % 16 == 0) {
      if (all_aa == 16) {
      }
      all_aa = 0;
      printf("\n%04lx | ", i);
    }
    printf("%02hhx ", buffer[i]);
    if ((unsigned char)buffer[i] == 0xaa) {
      all_aa++;
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11c7 <hexdump+0xb7>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    1177 <hexdump+0x67>
cmpl   $0x10,-0x14(%rbp)
jne    115e <hexdump+0x4e>
jmp    115e <hexdump+0x4e>
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0xaa,%eax
jne    11b1 <hexdump+0xa1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b6 <hexdump+0xa6>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112f <hexdump+0x1f>
lea    0xe44(%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
test   %rsi,%rsi
je     117c <hexdump+0x5c>
mov    %rsi,%r13
mov    %rdi,%r14
lea    0xec5(%rip),%r15
lea    0xec8(%rip),%r12
xor    %ebx,%ebx
jmp    1168 <hexdump+0x48>
cs nopw 0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
je     117c <hexdump+0x5c>
test   $0xf,%bl
jne    1150 <hexdump+0x30>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1150 <hexdump+0x30>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

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

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