void htoa(unsigned int value, char s[]) {
  int i = 8;
  int ptr = 0;
  while (i-- > 0) {
    s[ptr++] = "0123456789abcdef"[(value >> (i * 4)) & 0xf];
  }
  s[ptr] = 0;
}


x86 assembly (clang, -O0):
<htoa>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x8,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jle    1163 <htoa+0x63>
mov    -0x4(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
shr    %cl,%eax
and    $0xf,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0xeba(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1119 <htoa+0x19>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
pop    %rbp
ret

x86 assembly (clang, -O2):
<htoa>:
mov    %edi,%eax
mov    %rax,%rdx
shr    $0x1c,%rdx
lea    0xef0(%rip),%rcx
mov    (%rdx,%rcx,1),%dl
mov    %dl,(%rsi)
mov    %edi,%edx
shr    $0x18,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x1(%rsi)
mov    %edi,%edx
shr    $0x14,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x2(%rsi)
mov    %edi,%edx
shr    $0x10,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x3(%rsi)
mov    %edi,%edx
shr    $0xc,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x4(%rsi)
mov    %edi,%edx
shr    $0x8,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x5(%rsi)
shr    $0x4,%edi
and    $0xf,%edi
mov    (%rdi,%rcx,1),%dl
mov    %dl,0x6(%rsi)
and    $0xf,%eax
mov    (%rax,%rcx,1),%al
mov    %al,0x7(%rsi)
movb   $0x0,0x8(%rsi)
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789abcdef\00"
define void @htoa(i32 %0, i8* nocapture writeonly %1) {
%3 = lshr i32 %0, 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
store i8 %6, i8* %1
%7 = lshr i32 %0, 24
%8 = and i32 %7, 15
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %11, i8* %12
%13 = lshr i32 %0, 20
%14 = and i32 %13, 15
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %17, i8* %18
%19 = lshr i32 %0, 16
%20 = and i32 %19, 15
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %23, i8* %24
%25 = lshr i32 %0, 12
%26 = and i32 %25, 15
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %29, i8* %30
%31 = lshr i32 %0, 8
%32 = and i32 %31, 15
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %35, i8* %36
%37 = lshr i32 %0, 4
%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 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %41, i8* %42
%43 = and i32 %0, 15
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = getelementptr inbounds i8, i8* %1, i64 7
store i8 %46, i8* %47
%48 = getelementptr inbounds i8, i8* %1, i64 8
store i8 0, i8* %48
ret void
}