#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(unsigned char *data, unsigned int size) {
  unsigned int i;
  printf("\n");
  for (i = 0; i < size; i++) {
    printf("%02x", data[i]);
    if (size >= 16 && (i + 1) % 2 == 0)
      printf(" ");
    if (size >= 32 && (i + 1) % 16 == 0)
      printf("\n");
    if (size == 20 && (i + 1) % 10 == 0)
      printf("\n");
  }
  printf("(%d bytes)", size);
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11f0 <hexdump+0xe0>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movzbl (%rax,%rcx,1),%esi
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x10,-0xc(%rbp)
jb     1183 <hexdump+0x73>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1183 <hexdump+0x73>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x20,-0xc(%rbp)
jb     11ad <hexdump+0x9d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    11ad <hexdump+0x9d>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x14,-0xc(%rbp)
jne    11dd <hexdump+0xcd>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
cmp    $0x0,%edx
jne    11dd <hexdump+0xcd>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e2 <hexdump+0xd2>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1134 <hexdump+0x24>
mov    -0xc(%rbp),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %ebx,%ebx
je     11de <hexdump+0xbe>
mov    %ebx,%r12d
mov    $0x1,%ebp
xor    %r13d,%r13d
jmp    1165 <hexdump+0x45>
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
mov    %r15,%r13
cmp    %r15,%r12
je     11de <hexdump+0xbe>
movzbl (%r14,%r13,1),%esi
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x10,%ebx
jb     1192 <hexdump+0x72>
mov    %r13d,%eax
and    $0x1,%eax
test   %rax,%rax
je     1192 <hexdump+0x72>
mov    $0x20,%edi
call   1030 <putchar@plt>
lea    0x1(%r13),%r15
cmp    $0x20,%ebx
jb     11b0 <hexdump+0x90>
test   $0xf,%r15b
jne    115a <hexdump+0x3a>
jmp    1150 <hexdump+0x30>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x14,%ebx
jne    115a <hexdump+0x3a>
mov    %ebp,%eax
mov    $0xcccccccd,%ecx
imul   %rcx,%rax
shr    $0x23,%rax
lea    (%rax,%rax,4),%eax
add    %eax,%eax
add    $0xfffffffe,%eax
or     $0x1,%rax
cmp    %r13d,%eax
je     1150 <hexdump+0x30>
jmp    115a <hexdump+0x3a>
lea    0xe20(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [11 x i8] c"(%d bytes)\00"
define void @hexdump(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %7
7: ; preds = %49, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp ult i32 %8, %9
br i1 %10, label %11, label %52
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = load i32, i32* %5
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %4
%20 = icmp uge i32 %19, 16
br i1 %20, label %21, label %28
21: ; preds = %11
%22 = load i32, i32* %5
%23 = add i32 %22, 1
%24 = urem i32 %23, 2
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%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, %21, %11
%29 = load i32, i32* %4
%30 = icmp uge i32 %29, 32
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = load i32, i32* %5
%33 = add i32 %32, 1
%34 = urem i32 %33, 16
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %38
38: ; preds = %36, %31, %28
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 20
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = load i32, i32* %5
%43 = add i32 %42, 1
%44 = urem i32 %43, 10
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %48
48: ; preds = %46, %41, %38
br label %49
49: ; preds = %48
%50 = load i32, i32* %5
%51 = add i32 %50, 1
store i32 %51, i32* %5
br label %7
52: ; preds = %7
%53 = load i32, i32* %4
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %53)
ret void
}

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