#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
void Hex2Str(const char *sSrc, char *sDest, int nSrcLen) {
  int i;
  char szTmp[3];
  for (i = 0; i < nSrcLen; i++) {
    sprintf(szTmp, "%02X", (unsigned char)sSrc[i]);
    memcpy(&sDest[i * 2], szTmp, 2);
  }
  return;
}


x86 assembly (clang, -O0):
<Hex2Str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118d <Hex2Str+0x6d>
lea    -0x1b(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xea7(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
lea    -0x1b(%rbp),%rsi
mov    $0x2,%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <Hex2Str+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Hex2Str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    117d <Hex2Str+0x5d>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%r13d
xor    %ebp,%ebp
lea    0xebf(%rip),%r15
lea    0x5(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
movzbl (%r14,%rbp,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x2,%edx
call   1030 <memcpy@plt>
add    $0x1,%rbp
add    $0x2,%rbx
cmp    %rbp,%r13
jne    1150 <Hex2Str+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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