#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(const void *buf, size_t len) {
  size_t x;
  printf("%d bytes @ %p \n", (int)len, buf);
  for (x = 0; x < len; x++) {
    printf(" %02x", (((char *)buf)[x]) & 0xff);
    if (((x + 1) % 16) == 0)
      printf("\n");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a8 <hexdump+0x98>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    1192 <hexdump+0x82>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1197 <hexdump+0x87>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1140 <hexdump+0x30>
lea    0xe5f(%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   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
lea    0xecb(%rip),%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
test   %r12,%r12
je     1193 <hexdump+0x73>
neg    %r12
mov    $0x1,%ebx
lea    0xebd(%rip),%r15
jmp    1172 <hexdump+0x52>
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r12,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     1193 <hexdump+0x73>
movzbl -0x1(%r14,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0xf,%bl
jne    1160 <hexdump+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1160 <hexdump+0x40>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

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