#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 */
typedef int uint8_t;
typedef size_t uint32_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int);
char *dump(uint8_t *data, uint32_t len) {
  static char buffer[1024];
  char *cp = &buffer[0];
  uint32_t i;
  for (i = 0; i < len; i++)
    cp += sprintf((char *)cp, "%02X ", data[i]);
  *--cp = '\0';
  return &buffer[0];
}


x86 assembly (clang, -O0):
<dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0x2f19(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    117d <dump+0x6d>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xea9(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1133 <dump+0x23>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,-0x1(%rax)
lea    0x2ea9(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
je     115f <dump+0x4f>
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x2f15(%rip),%r13
xor    %ebx,%ebx
lea    0xecc(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15,%rbx,4),%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   1030 <sprintf@plt>
cltq
add    %rax,%r13
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <dump+0x30>
jmp    1166 <dump+0x56>
lea    0x2eda(%rip),%r13
movb   $0x0,-0x1(%r13)
lea    0x2ece(%rip),%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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