#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 *attr, int size, int level) {
  int i, j;
  for (i = 0; i < size; i += 16) {
    if (level)
      printf("%*c", level, ' ');
    printf("%06x ", i);
    for (j = i; (j < (i + 16)) && (j < size); j++)
      printf((j & 3 ? "%02x" : " %02x"), attr[j] & 255);
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fc <hexdump+0xec>
cmpl   $0x0,-0x10(%rbp)
je     1155 <hexdump+0x45>
mov    -0x10(%rbp),%esi
lea    0xeb7(%rip),%rdi
mov    $0x20,%edx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%edx
add    $0x10,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x19(%rbp)
jge    118e <hexdump+0x7e>
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    119e <hexdump+0x8e>
jmp    11e0 <hexdump+0xd0>
mov    -0x18(%rbp),%ecx
and    $0x3,%ecx
lea    0xe5f(%rip),%rdi
lea    0xe59(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116c <hexdump+0x5c>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <hexdump+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11e8 <hexdump+0xc8>
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r13
movl   $0x1,(%rsp)
lea    0xec2(%rip),%r14
xor    %ebx,%ebx
mov    %edx,0x4(%rsp)
jmp    117b <hexdump+0x5b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
addl   $0x10,(%rsp)
mov    %r12,%rbx
cmp    %ebp,%r12d
mov    0x4(%rsp),%r15d
jge    11e8 <hexdump+0xc8>
test   %r15d,%r15d
je     1196 <hexdump+0x76>
lea    0xe79(%rip),%rdi
mov    %r15d,%esi
mov    $0x20,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe67(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rbx),%r12
mov    (%rsp),%eax
mov    %eax,%r15d
test   $0x3,%bl
mov    %r14,%rdi
lea    0xe4d(%rip),%rax
cmove  %rax,%rdi
movzbl 0x0(%r13,%rbx,1),%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %r12,%rbx
jae    1160 <hexdump+0x40>
lea    0x1(%r15),%eax
cmp    %ebp,%r15d
mov    %eax,%r15d
jl     11b0 <hexdump+0x90>
jmp    1160 <hexdump+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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