void uint_to_string(unsigned int foo, unsigned char *bar) {
  char hexdigit[16] = "0123456789abcdef";
  int i;
  for (i = 7; i >= 0; i--) {
    bar[i] = hexdigit[(foo & 0x0f)];
    foo = foo >> 4;
  }
  bar[8] = 0;
}


x86 assembly (clang, -O0):
<uint_to_string>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeee(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeeb(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x7,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1160 <uint_to_string+0x60>
mov    -0x4(%rbp),%eax
and    $0xf,%eax
mov    %eax,%eax
mov    -0x20(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1128 <uint_to_string+0x28>
mov    -0x10(%rbp),%rax
movb   $0x0,0x8(%rax)
pop    %rbp
ret

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

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

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