void appendHEX8(char **pDstStr, int n) {
  int i = 0;
  for (; i < 8; i++)
    *((*pDstStr)++) = "0123456789ABCDEF"[(n >> ((7 - i) << 2)) & 0xf];
  --(*pDstStr);
  **pDstStr = 0;
}


x86 assembly (clang, -O0):
<appendHEX8>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    115d <appendHEX8+0x5d>
mov    -0xc(%rbp),%eax
mov    $0x7,%ecx
sub    -0x10(%rbp),%ecx
shl    $0x2,%ecx
sar    %cl,%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xec7(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1112 <appendHEX8+0x12>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<appendHEX8>:
mov    %esi,%r9d
mov    %r9,%rdx
shr    $0x1c,%rdx
lea    0xeef(%rip),%r8
mov    (%rdx,%r8,1),%dl
mov    (%rdi),%rcx
lea    0x1(%rcx),%rax
mov    %rax,(%rdi)
mov    %dl,(%rcx)
mov    %esi,%eax
shr    $0x18,%eax
and    $0xf,%eax
mov    (%rax,%r8,1),%al
mov    (%rdi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rdi)
mov    %al,(%rcx)
mov    %esi,%eax
shr    $0x14,%eax
and    $0xf,%eax
mov    (%rax,%r8,1),%al
mov    (%rdi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rdi)
mov    %al,(%rcx)
mov    %esi,%eax
shr    $0x10,%eax
and    $0xf,%eax
mov    (%rax,%r8,1),%al
mov    (%rdi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rdi)
mov    %al,(%rcx)
mov    %esi,%eax
shr    $0xc,%eax
and    $0xf,%eax
mov    (%rax,%r8,1),%al
mov    (%rdi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rdi)
mov    %al,(%rcx)
mov    %esi,%eax
shr    $0x8,%eax
and    $0xf,%eax
mov    (%rax,%r8,1),%al
mov    (%rdi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rdi)
mov    %al,(%rcx)
shr    $0x4,%esi
and    $0xf,%esi
mov    (%rsi,%r8,1),%al
mov    (%rdi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rdi)
mov    %al,(%rcx)
and    $0xf,%r9d
mov    (%r9,%r8,1),%al
mov    (%rdi),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rdi)
mov    %al,(%rcx)
mov    (%rdi),%rax
lea    -0x1(%rax),%rcx
mov    %rcx,(%rdi)
movb   $0x0,-0x1(%rax)
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789ABCDEF\00"
define void @appendHEX8(i8** nocapture %0, i32 %1) {
%3 = lshr i32 %1, 28
%4 = zext i32 %3 to i64
%5 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %4
%6 = load i8, i8* %5
%7 = load i8*, i8** %0
%8 = getelementptr inbounds i8, i8* %7, i64 1
store i8* %8, i8** %0
store i8 %6, i8* %7
%9 = lshr i32 %1, 24
%10 = and i32 %9, 15
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = load i8*, i8** %0
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8* %15, i8** %0
store i8 %13, i8* %14
%16 = lshr i32 %1, 20
%17 = and i32 %16, 15
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = load i8*, i8** %0
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %0
store i8 %20, i8* %21
%23 = lshr i32 %1, 16
%24 = and i32 %23, 15
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = load i8*, i8** %0
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8* %29, i8** %0
store i8 %27, i8* %28
%30 = lshr i32 %1, 12
%31 = and i32 %30, 15
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = load i8*, i8** %0
%36 = getelementptr inbounds i8, i8* %35, i64 1
store i8* %36, i8** %0
store i8 %34, i8* %35
%37 = lshr i32 %1, 8
%38 = and i32 %37, 15
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = load i8*, i8** %0
%43 = getelementptr inbounds i8, i8* %42, i64 1
store i8* %43, i8** %0
store i8 %41, i8* %42
%44 = lshr i32 %1, 4
%45 = and i32 %44, 15
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = load i8*, i8** %0
%50 = getelementptr inbounds i8, i8* %49, i64 1
store i8* %50, i8** %0
store i8 %48, i8* %49
%51 = and i32 %1, 15
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = load i8*, i8** %0
%56 = getelementptr inbounds i8, i8* %55, i64 1
store i8* %56, i8** %0
store i8 %54, i8* %55
%57 = load i8*, i8** %0
%58 = getelementptr inbounds i8, i8* %57, i64 -1
store i8* %58, i8** %0
store i8 0, i8* %58
ret void
}