#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 hex_dump(void *buf, size_t size) {
  unsigned char *p = buf;
  size_t n;
  for (n = 0; n < size; ++n) {
    if (n != 0) {
      if (n % 8 == 0)
        printf("\n");
      else if (n % 4 == 0)
        printf(" ");
    }
    printf("%02x", p[n]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11c3 <hex_dump+0xb3>
cmpq   $0x0,-0x20(%rbp)
je     1198 <hex_dump+0x88>
mov    -0x20(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    116e <hex_dump+0x5e>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1193 <hex_dump+0x83>
mov    -0x20(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
jne    118e <hex_dump+0x7e>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1193 <hex_dump+0x83>
jmp    1198 <hex_dump+0x88>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1130 <hex_dump+0x20>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     114a <hex_dump+0x2a>
mov    %rsi,%r12
mov    %rdi,%r14
movzbl (%rdi),%esi
lea    0xec3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%r12
jne    115f <hex_dump+0x3f>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>
mov    $0x1,%ebx
lea    0xe95(%rip),%r15
jmp    1192 <hex_dump+0x72>
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
movzbl (%r14,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
je     114a <hex_dump+0x2a>
test   $0x7,%bl
je     1170 <hex_dump+0x50>
test   $0x3,%bl
jne    117a <hex_dump+0x5a>
mov    $0x20,%edi
jmp    1175 <hex_dump+0x55>

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

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