#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*/ sprintf(char *, char *, unsigned char);
void hexdumpraw(void *ptr, char *result, int buflen) {
  unsigned char *buf = (unsigned char *)ptr;
  int a = 0;
  for (a = 0; a < buflen; a++) {
    sprintf(result + (a * 2), "%02X", buf[a]);
  }
}


x86 assembly (clang, -O0):
<hexdumpraw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117a <hexdumpraw+0x6a>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
lea    0xe9d(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1030 <sprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1139 <hexdumpraw+0x29>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdumpraw>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %edx,%edx
jle    114d <hexdumpraw+0x3d>
mov    %rsi,%r13
mov    %rdi,%r14
mov    %edx,%r12d
xor    %ebx,%ebx
lea    0xed1(%rip),%r15
nop
movzbl (%r14,%rbx,1),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1030 <sprintf@plt>
add    $0x1,%rbx
add    $0x2,%r13
cmp    %rbx,%r12
jne    1130 <hexdumpraw+0x20>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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