char *to3dig(i)
register int i;
{
  static char buf[4];
  register char *s = buf;
  *s++ = (i % 1000) / 100 + '0';
  *s++ = (i % 100) / 10 + '0';
  *s++ = (i % 10) + '0';
  *s = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<to3dig>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
lea    0x2f13(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x30,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e8a(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<to3dig>:
movslq %edi,%rcx
imul   $0x10624dd3,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
shr    $0x26,%rax
add    %edx,%eax
imul   $0x3e8,%eax,%eax
mov    %ecx,%edx
sub    %eax,%edx
movswl %dx,%eax
imul   $0x147b,%eax,%eax
mov    %eax,%edx
shr    $0x1f,%edx
shr    $0x13,%eax
add    %edx,%eax
add    $0x30,%al
mov    %al,0x2ee5(%rip)
lea    0x2ede(%rip),%rax
imul   $0x51eb851f,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
shr    $0x25,%rdx
add    %esi,%edx
imul   $0x64,%edx,%edx
mov    %ecx,%esi
sub    %edx,%esi
movsbl %sil,%edx
imul   $0x67,%edx,%edx
movzwl %dx,%edx
movswl %dx,%esi
shr    $0xf,%edx
shr    $0xa,%esi
add    %dl,%sil
add    $0x30,%sil
mov    %sil,0x2ea3(%rip)
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
shr    $0x22,%rdx
add    %esi,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ecx
add    $0x30,%cl
mov    %cl,0x2e80(%rip)
movb   $0x0,0x2e7a(%rip)
ret

LLVM IR (-O0):
@to3dig.buf = internal global [4 x i8] zeroinitializer
define i8* @to3dig(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @to3dig.buf, i64 0, i64 0), i8** %3
%4 = load i32, i32* %2
%5 = srem i32 %4, 1000
%6 = sdiv i32 %5, 100
%7 = add nsw i32 %6, 48
%8 = trunc i32 %7 to i8
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %3
store i8 %8, i8* %9
%11 = load i32, i32* %2
%12 = srem i32 %11, 100
%13 = sdiv i32 %12, 10
%14 = add nsw i32 %13, 48
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %3
store i8 %15, i8* %16
%18 = load i32, i32* %2
%19 = srem i32 %18, 10
%20 = add nsw i32 %19, 48
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %3
store i8 %21, i8* %22
%24 = load i8*, i8** %3
store i8 0, i8* %24
ret i8* getelementptr inbounds ([4 x i8], [4 x i8]* @to3dig.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@to3dig.buf = internal global [4 x i8] zeroinitializer
define i8* @to3dig(i32 %0) {
%2 = srem i32 %0, 1000
%3 = trunc i32 %2 to i16
%4 = sdiv i16 %3, 100
%5 = trunc i16 %4 to i8
%6 = add nsw i8 %5, 48
store i8 %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @to3dig.buf, i64 0, i64 0)
%7 = srem i32 %0, 100
%8 = trunc i32 %7 to i8
%9 = sdiv i8 %8, 10
%10 = add nsw i8 %9, 48
store i8 %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @to3dig.buf, i64 0, i64 1)
%11 = srem i32 %0, 10
%12 = trunc i32 %11 to i8
%13 = add nsw i8 %12, 48
store i8 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @to3dig.buf, i64 0, i64 2)
store i8 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @to3dig.buf, i64 0, i64 3)
ret i8* getelementptr inbounds ([4 x i8], [4 x i8]* @to3dig.buf, i64 0, i64 0)
}