__attribute__((unused)) const char *ltoa(long in) {
  static char buffer[21];
  char *pos = buffer + sizeof(buffer) - 1;
  int neg = in < 0;
  unsigned long n = neg ? -in : in;
  *pos-- = '\0';
  do {
    *pos-- = '0' + n % 10;
    n /= 10;
    if (pos < buffer)
      return pos + 1;
  } while (n);
  if (neg)
    *pos-- = '-';
  return pos + 1;
}


x86 assembly (clang, -O0):
<ltoa>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
lea    0x2f21(%rip),%rax
add    $0x14,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1140 <ltoa+0x40>
xor    %eax,%eax
sub    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1148 <ltoa+0x48>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
add    $0x30,%rdx
mov    %dl,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x28(%rbp)
lea    0x2e90(%rip),%rax
cmp    %rax,-0x18(%rbp)
jae    11bb <ltoa+0xbb>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11f3 <ltoa+0xf3>
jmp    11c0 <ltoa+0xc0>
cmpq   $0x0,-0x28(%rbp)
jne    1162 <ltoa+0x62>
cmpl   $0x0,-0x1c(%rbp)
je     11e7 <ltoa+0xe7>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2d,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ltoa>:
mov    %rdi,%rcx
neg    %rcx
cmovs  %rdi,%rcx
movb   $0x0,0x2f33(%rip)
lea    0x2f2c(%rip),%r9
movabs $0xcccccccccccccccd,%r10
cc cc cc
lea    0x2f07(%rip),%r8
movabs $0x28f5c28f5c28f5c3,%r11
c2 f5 28
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rcx,%rax
mul    %r10
mov    %rdx,%rsi
shr    $0x3,%rsi
lea    (%rsi,%rsi,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ecx,%edx
sub    %eax,%edx
or     $0x30,%dl
mov    %dl,-0x1(%r9)
cmp    $0xa,%rcx
jb     11aa <ltoa+0xaa>
mov    %rsi,%rax
mul    %r10
shr    $0x2,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%esi
or     $0x30,%sil
lea    -0x3(%r9),%rax
mov    %sil,-0x2(%r9)
cmp    %r8,%rax
jb     11c6 <ltoa+0xc6>
mov    %rcx,%rax
shr    $0x2,%rax
mul    %r11
shr    $0x2,%rdx
add    $0xfffffffffffffffe,%r9
cmp    $0x64,%rcx
mov    %rdx,%rcx
jae    1140 <ltoa+0x40>
mov    %r9,%r8
add    $0xffffffffffffffff,%r9
jmp    11b2 <ltoa+0xb2>
lea    -0x1(%r9),%r8
add    $0xfffffffffffffffe,%r9
mov    $0xffffffffffffffff,%rax
test   %rdi,%rdi
js     11d5 <ltoa+0xd5>
add    %r8,%rax
add    $0x1,%rax
ret
mov    $0xffffffffffffffff,%rax
add    %r8,%rax
add    $0x1,%rax
ret
movb   $0x2d,(%r9)
mov    $0xfffffffffffffffe,%rax
add    %r8,%rax
add    $0x1,%rax
ret

LLVM IR (-O0):
@ltoa.buffer = internal global [21 x i8] zeroinitializer
define i8* @ltoa(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
store i64 %0, i64* %3
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @ltoa.buffer, i64 1, i64 -1), i8** %4
%7 = load i64, i64* %3
%8 = icmp slt i64 %7, 0
%9 = zext i1 %8 to i32
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i64, i64* %3
%14 = sub nsw i64 0, %13
br label %17
15: ; preds = %1
%16 = load i64, i64* %3
br label %17
17: ; preds = %15, %12
%18 = phi i64 [ %14, %12 ], [ %16, %15 ]
store i64 %18, i64* %6
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 -1
store i8* %20, i8** %4
store i8 0, i8* %19
br label %21
21: ; preds = %36, %17
%22 = load i64, i64* %6
%23 = urem i64 %22, 10
%24 = add i64 48, %23
%25 = trunc i64 %24 to i8
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 -1
store i8* %27, i8** %4
store i8 %25, i8* %26
%28 = load i64, i64* %6
%29 = udiv i64 %28, 10
store i64 %29, i64* %6
%30 = load i8*, i8** %4
%31 = icmp ult i8* %30, getelementptr inbounds ([21 x i8], [21 x i8]* @ltoa.buffer, i64 0, i64 0)
br i1 %31, label %32, label %35
32: ; preds = %21
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %2
br label %48
35: ; preds = %21
br label %36
36: ; preds = %35
%37 = load i64, i64* %6
%38 = icmp ne i64 %37, 0
br i1 %38, label %21, label %39
39: ; preds = %36
%40 = load i32, i32* %5
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i32 -1
store i8* %44, i8** %4
store i8 45, i8* %43
br label %45
45: ; preds = %42, %39
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i64 1
store i8* %47, i8** %2
br label %48
48: ; preds = %45, %32
%49 = load i8*, i8** %2
ret i8* %49
}

LLVM IR (-O2):
@ltoa.buffer = internal global [21 x i8] zeroinitializer
define i8* @ltoa(i64 %0) {
%2 = icmp slt i64 %0, 0
%3 = sub nsw i64 0, %0
%4 = select i1 %2, i64 %3, i64 %0
store i8 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @ltoa.buffer, i64 0, i64 20)
br label %5
5: ; preds = %20, %1
%6 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @ltoa.buffer, i64 0, i64 19), %1 ], [ %18, %20 ]
%7 = phi i64 [ %4, %1 ], [ %21, %20 ]
%8 = urem i64 %7, 10
%9 = udiv i64 %7, 10
%10 = trunc i64 %8 to i8
%11 = or i8 %10, 48
%12 = getelementptr inbounds i8, i8* %6, i64 -1
store i8 %11, i8* %6
%13 = icmp ult i64 %7, 10
br i1 %13, label %23, label %14
14: ; preds = %5
%15 = urem i64 %9, 10
%16 = trunc i64 %15 to i8
%17 = or i8 %16, 48
%18 = getelementptr inbounds i8, i8* %6, i64 -2
store i8 %17, i8* %12
%19 = icmp ult i8* %18, getelementptr inbounds ([21 x i8], [21 x i8]* @ltoa.buffer, i64 0, i64 0)
br i1 %19, label %27, label %20
20: ; preds = %14
%21 = udiv i64 %7, 100
%22 = icmp ult i64 %7, 100
br i1 %22, label %23, label %5
23: ; preds = %20, %5
%24 = phi i8* [ %6, %5 ], [ %12, %20 ]
%25 = phi i8* [ %12, %5 ], [ %18, %20 ]
br i1 %2, label %26, label %27
26: ; preds = %23
store i8 45, i8* %25
br label %27
27: ; preds = %14, %23, %26
%28 = phi i8* [ %24, %26 ], [ %24, %23 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @ltoa.buffer, i64 0, i64 0), %14 ]
%29 = phi i64 [ -2, %26 ], [ -1, %23 ], [ -1, %14 ]
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = getelementptr inbounds i8, i8* %30, i64 1
ret i8* %31
}