char *number(char *buf, int i) {
  char *_t = "0123456789ABCDEF";
  unsigned int mask = 0x0F;
  int pos = 8;
  do {
    buf[--pos] = _t[i & mask];
    i >>= 4;
  } while (pos);
  buf = buf + 8;
  return buf;
}


x86 assembly (clang, -O0):
<number>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeee(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0xf,-0x1c(%rbp)
movl   $0x8,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
and    -0x1c(%rbp),%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1124 <number+0x24>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

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

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

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