#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*/ puts(char *);
size_t sprintf(char *, char *, unsigned char);
void dump(unsigned char *data, size_t len) {
  char buf[80], *p;
  size_t cn, n;
  for (cn = 0, p = buf; cn < len; cn++, p += 2) {
    n = sprintf(p, "%02X", data[cn]);
  }
  puts(buf);
}


x86 assembly (clang, -O0):
<dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x70(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x70(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    118e <dump+0x6e>
mov    -0x68(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x70(%rbp),%rcx
lea    0xe9c(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1040 <sprintf@plt>
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x70(%rbp)
mov    -0x68(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x68(%rbp)
jmp    1143 <dump+0x23>
lea    -0x60(%rbp),%rdi
call   1030 <puts@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
test   %rsi,%rsi
je     116d <dump+0x4d>
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsp,%r13
xor    %ebx,%ebx
lea    0xebc(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r14,%rbx,1),%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <sprintf@plt>
add    $0x1,%rbx
add    $0x2,%r13
cmp    %rbx,%r15
jne    1150 <dump+0x30>
mov    %rsp,%rdi
call   1030 <puts@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02X\00"
define void @dump(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [80 x i8]
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %7
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
store i8* %9, i8** %6
br label %10
10: ; preds = %21, %2
%11 = load i64, i64* %7
%12 = load i64, i64* %4
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %26
14: ; preds = %10
%15 = load i8*, i8** %6
%16 = load i8*, i8** %3
%17 = load i64, i64* %7
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i8, i8* %18
%20 = call i64 @sprintf(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %19)
store i64 %20, i64* %8
br label %21
21: ; preds = %14
%22 = load i64, i64* %7
%23 = add i64 %22, 1
store i64 %23, i64* %7
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 2
store i8* %25, i8** %6
br label %10
26: ; preds = %10
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%28 = call i32 @puts(i8* %27)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
define void @dump(i8* nocapture %0, i64 %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = icmp eq i64 %1, 0
br i1 %5, label %15, label %6
6: ; preds = %2, %6
%7 = phi i8* [ %13, %6 ], [ %4, %2 ]
%8 = phi i64 [ %12, %6 ], [ 0, %2 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = call i64 @sprintf(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %10)
%12 = add nuw i64 %8, 1
%13 = getelementptr inbounds i8, i8* %7, i64 2
%14 = icmp eq i64 %12, %1
br i1 %14, label %15, label %6
15: ; preds = %6, %2
%16 = call i32 @puts(i8* %4)
ret void
}