#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 /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void hex_dump(uint8_t *buf, int size) {
  int i;
  int sep;
  for (i = 0; i < size; ++i) {
    sep = ' ';
    if (!(i & 0x3))
      sep = '\t';
    if (!(i & 0xf))
      sep = '\n';
    printf("%c%02x", sep, buf[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118f <hex_dump+0x7f>
movl   $0x20,-0x14(%rbp)
mov    -0x10(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
jne    114f <hex_dump+0x3f>
movl   $0x9,-0x14(%rbp)
mov    -0x10(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    1165 <hex_dump+0x55>
movl   $0xa,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <hex_dump+0x16>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    117c <hex_dump+0x5c>
mov    %rdi,%r15
mov    %esi,%ebx
mov    $0x9,%r12d
mov    $0xa,%r13d
lea    0xeb9(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax)
test   $0x3,%bpl
mov    $0x20,%esi
cmove  %r12d,%esi
test   $0xf,%bpl
cmove  %r13d,%esi
mov    (%r15,%rbp,4),%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1150 <hex_dump+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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