#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 int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void hexdump(uint8_t *buf, uint32_t bufLen) {
  uint32_t i;
  for (i = 0; i < bufLen; i++) {
    if (i % 16 == 0) {
      printf("0x%04x | ", i);
    }
    printf("%02x ", buf[i]);
    if (i % 8 == 7) {
      printf(" ");
    }
    if (i % 16 == 15) {
      printf("\n");
    }
  }
  if (i % 16 != 15) {
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c7 <hexdump+0xb7>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1157 <hexdump+0x47>
mov    -0x10(%rbp),%esi
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x7,%edx
jne    1192 <hexdump+0x82>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    11b4 <hexdump+0xa4>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b9 <hexdump+0xa9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <hexdump+0x16>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
je     11e9 <hexdump+0xd9>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
test   %esi,%esi
jle    11bb <hexdump+0x9b>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
mov    %esi,0x4(%rsp)
mov    %esi,%ebx
lea    0xebd(%rip),%r15
lea    0xec0(%rip),%r12
xor    %ebp,%ebp
jmp    1159 <hexdump+0x39>
xchg   %ax,%ax
add    $0x1,%rbp
cmp    %rbp,%rbx
je     11a1 <hexdump+0x81>
mov    %ebp,%r14d
and    $0xf,%r14d
jne    116e <hexdump+0x4e>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
not    %eax
test   $0x7,%al
jne    118f <hexdump+0x6f>
mov    $0x20,%edi
call   1030 <putchar@plt>
cmp    $0xf,%r14d
jne    1150 <hexdump+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1150 <hexdump+0x30>
mov    0x4(%rsp),%eax
not    %eax
test   $0xf,%al
lea    0x8(%rsp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jne    11bb <hexdump+0x9b>
ret
mov    $0xa,%edi
jmp    1030 <putchar@plt>

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

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