#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 dump(unsigned char *ptr, int len) {
  int start = 0x180;
  int index = 0;
  while (index < len) {
    printf("%04x ", start + index);
    for (int i = 0; i < 8; i++) {
      printf("%02x ", ptr[index]);
      index++;
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x180,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a2 <dump+0x92>
mov    -0x10(%rbp),%esi
add    -0x14(%rbp),%esi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    118f <dump+0x7f>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1154 <dump+0x44>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    112d <dump+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    121a <dump+0xfa>
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xec3(%rip),%r14
lea    0xec2(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
lea    0x180(%rbp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movslq %ebp,%rbp
movzbl (%rbx,%rbp,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rax
or     $0x1,%rax
movzbl (%rbx,%rax,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rax
or     $0x2,%rax
movzbl (%rbx,%rax,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rax
or     $0x3,%rax
movzbl (%rbx,%rax,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rax
or     $0x4,%rax
movzbl (%rbx,%rax,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rax
or     $0x5,%rax
movzbl (%rbx,%rax,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rax
or     $0x6,%rax
movzbl (%rbx,%rax,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rax
or     $0x7,%rax
movzbl (%rbx,%rax,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%ebp
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    %r15d,%ebp
jl     1150 <dump+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%04x \00"
@.str.1 = [6 x i8] c"%02x \00"
define void @dump(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %51
4: ; preds = %2, %4
%5 = phi i32 [ %48, %4 ], [ 0, %2 ]
%6 = add nsw i32 %5, 384
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = sext i32 %5 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = or i64 %8, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = or i64 %8, 2
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = or i64 %8, 3
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = or i64 %8, 4
%29 = getelementptr inbounds i8, i8* %0, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = or i64 %8, 5
%34 = getelementptr inbounds i8, i8* %0, i64 %33
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = or i64 %8, 6
%39 = getelementptr inbounds i8, i8* %0, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %41)
%43 = or i64 %8, 7
%44 = getelementptr inbounds i8, i8* %0, i64 %43
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = add i32 %5, 8
%49 = tail call i32 @putchar(i32 10)
%50 = icmp slt i32 %48, %1
br i1 %50, label %4, label %51
51: ; preds = %4, %2
ret void
}