#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 sprintf(char *, char *, ...);
char *dump(char *dest, char *title, char *buf, int len) {
  int pos = 0;
  int i;
  pos = sprintf(dest, "%s", title);
  for (i = 0; i < len; i++) {
    pos += sprintf(dest + pos, " %02X", buf[i] & 0xff);
  }
  return dest;
}


x86 assembly (clang, -O0):
<dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xec3(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1199 <dump+0x89>
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
and    $0xff,%edx
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114e <dump+0x3e>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rdi,%r15
call   1030 <stpcpy@plt>
test   %ebp,%ebp
jle    1171 <dump+0x51>
mov    %rax,%rbx
sub    %r15d,%ebx
mov    %ebp,%r13d
lea    0xeb4(%rip),%r12
xor    %ebp,%ebp
xchg   %ax,%ax
movslq %ebx,%rbx
lea    (%r15,%rbx,1),%rdi
movzbl (%r14,%rbp,1),%edx
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
add    %eax,%ebx
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1150 <dump+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [6 x i8] c" %02X\00"
define i8* @dump(i8* returned %0, i8* nocapture %1, i8* nocapture %2, i32 %3) {
%5 = tail call i8* @stpcpy(i8* %0, i8* %1)
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %25
7: ; preds = %4
%8 = ptrtoint i8* %5 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = trunc i64 %10 to i32
%12 = zext i32 %3 to i64
br label %13
13: ; preds = %7, %13
%14 = phi i64 [ 0, %7 ], [ %23, %13 ]
%15 = phi i32 [ %11, %7 ], [ %22, %13 ]
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = getelementptr inbounds i8, i8* %2, i64 %14
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = add nsw i32 %21, %15
%23 = add nuw nsw i64 %14, 1
%24 = icmp eq i64 %23, %12
br i1 %24, label %25, label %13
25: ; preds = %13, %4
ret i8* %0
}