#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 char *pfx, void *b, size_t n) {
  unsigned char *p;
  size_t i;
  p = b;
  printf("%s\n", pfx);
  for (i = 0; i < n; i++) {
    printf("%x ", p[i]);
    if ((i & 15) == 15)
      printf("\n");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a4 <hexdump+0x94>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
and    $0xf,%rax
cmp    $0xf,%rax
jne    118e <hexdump+0x7e>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1193 <hexdump+0x83>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1146 <hexdump+0x36>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
call   1040 <puts@plt>
test   %r12,%r12
je     118c <hexdump+0x5c>
lea    0xeb1(%rip),%r15
xor    %ebx,%ebx
jmp    1169 <hexdump+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
cmp    %rbx,%r12
je     118c <hexdump+0x5c>
movzbl (%r14,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
not    %eax
test   $0xf,%al
jne    1160 <hexdump+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1160 <hexdump+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

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