char *itoa(n, base)
long n;
int base;
{
  register char *p;
  register int minus;
  static char buf[36];
  p = &buf[36];
  *--p = '\0';
  if (n < 0) {
    minus = 1;
    n = -n;
  } else
    minus = 0;
  if (n == 0)
    *--p = '0';
  else
    while (n > 0) {
      *--p = "0123456789abcdef"[n % base];
      n /= base;
    }
  if (minus)
    *--p = '-';
  return p;
}


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0x2f1e(%rip),%rax
add    $0x24,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,-0x1(%rax)
cmpq   $0x0,-0x8(%rbp)
jge    114e <itoa+0x4e>
movl   $0x1,-0x1c(%rbp)
xor    %eax,%eax
sub    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1155 <itoa+0x55>
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1178 <itoa+0x78>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x30,-0x1(%rax)
jmp    11cc <itoa+0xcc>
jmp    117d <itoa+0x7d>
cmpq   $0x0,-0x8(%rbp)
jle    11c7 <itoa+0xc7>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cqto
idiv   %rcx
lea    0xe64(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,-0x1(%rax)
movslq -0xc(%rbp),%rcx
mov    -0x8(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x8(%rbp)
jmp    117d <itoa+0x7d>
jmp    11cc <itoa+0xcc>
cmpl   $0x0,-0x1c(%rbp)
je     11e9 <itoa+0xe9>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2d,-0x1(%rax)
mov    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
movb   $0x0,0x2f4c(%rip)
mov    %rdi,%rax
neg    %rax
cmovs  %rdi,%rax
test   %rax,%rax
je     1158 <itoa+0x58>
movslq %esi,%r8
lea    0x2f33(%rip),%rcx
lea    0xed9(%rip),%r9
jmp    1146 <itoa+0x46>
nopl   0x0(%rax)
cqto
idiv   %r8
movzbl (%rdx,%r9,1),%edx
mov    %dl,-0x1(%rcx)
add    $0xffffffffffffffff,%rcx
test   %rax,%rax
jle    1166 <itoa+0x66>
mov    %rax,%rdx
or     %r8,%rdx
shr    $0x20,%rdx
jne    1130 <itoa+0x30>
xor    %edx,%edx
div    %esi
jmp    1135 <itoa+0x35>
movb   $0x30,0x2ef3(%rip)
lea    0x2eec(%rip),%rcx
test   %rdi,%rdi
js     116f <itoa+0x6f>
mov    %rcx,%rax
ret
movb   $0x2d,-0x1(%rcx)
add    $0xffffffffffffffff,%rcx
mov    %rcx,%rax
ret

LLVM IR (-O0):
@itoa.buf = internal global [36 x i8] zeroinitializer
@.str = [17 x i8] c"0123456789abcdef\00"
define i8* @itoa(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i64 %0, i64* %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @itoa.buf, i64 1, i64 0), i8** %5
%7 = load i8*, i8** %5
%8 = getelementptr inbounds i8, i8* %7, i32 -1
store i8* %8, i8** %5
store i8 0, i8* %8
%9 = load i64, i64* %3
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
store i32 1, i32* %6
%12 = load i64, i64* %3
%13 = sub nsw i64 0, %12
store i64 %13, i64* %3
br label %15
14: ; preds = %2
store i32 0, i32* %6
br label %15
15: ; preds = %14, %11
%16 = load i64, i64* %3
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i32 -1
store i8* %20, i8** %5
store i8 48, i8* %20
br label %39
21: ; preds = %15
br label %22
22: ; preds = %25, %21
%23 = load i64, i64* %3
%24 = icmp sgt i64 %23, 0
br i1 %24, label %25, label %38
25: ; preds = %22
%26 = load i64, i64* %3
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = srem i64 %26, %28
%30 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 -1
store i8* %33, i8** %5
store i8 %31, i8* %33
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = load i64, i64* %3
%37 = sdiv i64 %36, %35
store i64 %37, i64* %3
br label %22
38: ; preds = %22
br label %39
39: ; preds = %38, %18
%40 = load i32, i32* %6
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i32 -1
store i8* %44, i8** %5
store i8 45, i8* %44
br label %45
45: ; preds = %42, %39
%46 = load i8*, i8** %5
ret i8* %46
}

LLVM IR (-O2):
@itoa.buf = internal global [36 x i8] zeroinitializer
@.str = [17 x i8] c"0123456789abcdef\00"
define i8* @itoa(i64 %0, i32 %1) {
store i8 0, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @itoa.buf, i64 0, i64 35)
%3 = icmp slt i64 %0, 0
%4 = sub nsw i64 0, %0
%5 = select i1 %3, i64 %4, i64 %0
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = sext i32 %1 to i64
br label %10
9: ; preds = %2
store i8 48, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @itoa.buf, i64 0, i64 34)
br label %19
10: ; preds = %7, %10
%11 = phi i8* [ %16, %10 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @itoa.buf, i64 0, i64 35), %7 ]
%12 = phi i64 [ %17, %10 ], [ %5, %7 ]
%13 = srem i64 %12, %8
%14 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = getelementptr inbounds i8, i8* %11, i64 -1
store i8 %15, i8* %16
%17 = sdiv i64 %12, %8
%18 = icmp sgt i64 %17, 0
br i1 %18, label %10, label %19
19: ; preds = %10, %9
%20 = phi i8* [ getelementptr inbounds ([36 x i8], [36 x i8]* @itoa.buf, i64 0, i64 34), %9 ], [ %16, %10 ]
br i1 %3, label %21, label %23
21: ; preds = %19
%22 = getelementptr inbounds i8, i8* %20, i64 -1
store i8 45, i8* %22
br label %23
23: ; preds = %21, %19
%24 = phi i8* [ %22, %21 ], [ %20, %19 ]
ret i8* %24
}