char *itoa10(unsigned long num) {
  static char buf[12];
  int i;
  buf[10] = 0;
  for (i = 9; i >= 0; --i) {
    buf[i] = (char)((num % 10) + '0');
    num /= 10;
  }
  return buf;
}


x86 assembly (clang, -O0):
<itoa10>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movb   $0x0,0x2f1c(%rip)
movl   $0x9,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1160 <itoa10+0x60>
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
add    $0x30,%rdx
movslq -0xc(%rbp),%rcx
lea    0x2ee4(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1116 <itoa10+0x16>
lea    0x2eba(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa10>:
movb   $0x0,0x2f24(%rip)
lea    0x2f13(%rip),%r8
movabs $0xcccccccccccccccd,%r9
cc cc cc
mov    %rdi,%rax
mul    %r9
mov    %rdx,%rsi
shr    $0x3,%rsi
lea    (%rsi,%rsi,1),%eax
lea    (%rax,%rax,4),%eax
mov    %edi,%ecx
sub    %eax,%ecx
or     $0x30,%cl
mov    %cl,0x2ef2(%rip)
mov    %rsi,%rax
mul    %r9
shr    $0x2,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%esi
or     $0x30,%sil
mov    %sil,0x2ed5(%rip)
mov    %rdi,%rax
shr    $0x2,%rax
movabs $0x28f5c28f5c28f5c3,%rcx
c2 f5 28
mul    %rcx
mov    %rdx,%rsi
shr    $0x2,%rsi
mov    %rsi,%rax
mul    %r9
shr    $0x2,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%esi
or     $0x30,%sil
mov    %rdi,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mul    %rcx
mov    %rdx,%rcx
mov    %sil,0x2e86(%rip)
shr    $0x4,%rcx
mov    %rcx,%rax
mul    %r9
shr    $0x2,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%ecx
or     $0x30,%cl
movabs $0x346dc5d63886594b,%rdx
c5 6d 34
mov    %rdi,%rax
mul    %rdx
mov    %rdx,%rsi
mov    %cl,0x2e54(%rip)
shr    $0xb,%rsi
mov    %rsi,%rax
mul    %r9
shr    $0x2,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%esi
mov    %rdi,%rax
shr    $0x5,%rax
movabs $0xa7c5ac471b47843,%rcx
5a 7c 0a
mul    %rcx
mov    %rdx,%rcx
or     $0x30,%sil
shr    $0x7,%rcx
mov    %rcx,%rax
mul    %r9
mov    %sil,0x2e12(%rip)
shr    $0x2,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%ecx
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %rdi,%rax
mul    %rdx
mov    %rdx,%rsi
or     $0x30,%cl
shr    $0x12,%rsi
mov    %rsi,%rax
mul    %r9
mov    %cl,0x2de0(%rip)
shr    $0x2,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%esi
movabs $0xd6bf94d5e57a42bd,%rcx
94 bf d6
mov    %rdi,%rax
mul    %rcx
mov    %rdx,%rcx
or     $0x30,%sil
shr    $0x17,%rcx
mov    %rcx,%rax
mul    %r9
mov    %sil,0x2dac(%rip)
shr    $0x2,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%ecx
movabs $0xabcc77118461cefd,%rdx
77 cc ab
mov    %rdi,%rax
mul    %rdx
mov    %rdx,%rsi
or     $0x30,%cl
shr    $0x1a,%rsi
mov    %rsi,%rax
mul    %r9
mov    %cl,0x2d7a(%rip)
shr    $0x2,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%esi
or     $0x30,%sil
mov    %sil,0x2d63(%rip)
shr    $0x9,%rdi
movabs $0x44b82fa09b5a53,%rcx
mov    %rdi,%rax
mul    %rcx
mov    %rdx,%rcx
shr    $0xb,%rcx
mov    %rcx,%rax
mul    %r9
shr    $0x2,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%ecx
or     $0x30,%cl
mov    %cl,0x2d2d(%rip)
mov    %r8,%rax
ret

LLVM IR (-O0):
@itoa10.buf = internal global [12 x i8] zeroinitializer
define i8* @itoa10(i64 %0) {
%2 = alloca i64
%3 = alloca i32
store i64 %0, i64* %2
store i8 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 10)
store i32 9, i32* %3
br label %4
4: ; preds = %17, %1
%5 = load i32, i32* %3
%6 = icmp sge i32 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %4
%8 = load i64, i64* %2
%9 = urem i64 %8, 10
%10 = add i64 %9, 48
%11 = trunc i64 %10 to i8
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 %13
store i8 %11, i8* %14
%15 = load i64, i64* %2
%16 = udiv i64 %15, 10
store i64 %16, i64* %2
br label %17
17: ; preds = %7
%18 = load i32, i32* %3
%19 = add nsw i32 %18, -1
store i32 %19, i32* %3
br label %4
20: ; preds = %4
ret i8* getelementptr inbounds ([12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@itoa10.buf = internal global [12 x i8] zeroinitializer
define i8* @itoa10(i64 %0) {
store i8 0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 10)
%2 = urem i64 %0, 10
%3 = trunc i64 %2 to i8
%4 = or i8 %3, 48
store i8 %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 9)
%5 = udiv i64 %0, 10
%6 = urem i64 %5, 10
%7 = trunc i64 %6 to i8
%8 = or i8 %7, 48
store i8 %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 8)
%9 = udiv i64 %0, 100
%10 = urem i64 %9, 10
%11 = trunc i64 %10 to i8
%12 = or i8 %11, 48
store i8 %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 7)
%13 = udiv i64 %0, 1000
%14 = urem i64 %13, 10
%15 = trunc i64 %14 to i8
%16 = or i8 %15, 48
store i8 %16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 6)
%17 = udiv i64 %0, 10000
%18 = urem i64 %17, 10
%19 = trunc i64 %18 to i8
%20 = or i8 %19, 48
store i8 %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 5)
%21 = udiv i64 %0, 100000
%22 = urem i64 %21, 10
%23 = trunc i64 %22 to i8
%24 = or i8 %23, 48
store i8 %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 4)
%25 = udiv i64 %0, 1000000
%26 = urem i64 %25, 10
%27 = trunc i64 %26 to i8
%28 = or i8 %27, 48
store i8 %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 3)
%29 = udiv i64 %0, 10000000
%30 = urem i64 %29, 10
%31 = trunc i64 %30 to i8
%32 = or i8 %31, 48
store i8 %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 2)
%33 = udiv i64 %0, 100000000
%34 = urem i64 %33, 10
%35 = trunc i64 %34 to i8
%36 = or i8 %35, 48
store i8 %36, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 1)
%37 = udiv i64 %0, 1000000000
%38 = urem i64 %37, 10
%39 = trunc i64 %38 to i8
%40 = or i8 %39, 48
store i8 %40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 0)
ret i8* getelementptr inbounds ([12 x i8], [12 x i8]* @itoa10.buf, i64 0, i64 0)
}