#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 shexstr(char *outstr, void *buff, size_t len) {
  unsigned char *data = buff;
  size_t j;
  for (j = 0; j < len; ++j)
    sprintf(&outstr[j * 2], "%02X", data[j]);
}


x86 assembly (clang, -O0):
<shexstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    117a <shexstr+0x6a>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rax
shl    $0x1,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
lea    0xea0(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1030 <sprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1134 <shexstr+0x24>
add    $0x30,%rsp
pop    %rbp
ret

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

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

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