char *itoa7(val)
register int val;
{
  register char *ptr;
  static char buffer[16];
  ptr = buffer + sizeof(buffer);
  *--ptr = '\0';
  if (val == 0) {
    *--ptr = '0';
  } else
    while (val != 0) {
      *--ptr = (val % 10) + '0';
      val /= 10;
    }
  while (ptr > buffer + sizeof(buffer) - 7) {
    *--ptr = ' ';
  }
  return (ptr);
}


x86 assembly (clang, -O0):
<itoa7>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
lea    0x2f22(%rip),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,-0x1(%rax)
cmpl   $0x0,-0x4(%rbp)
jne    114b <itoa7+0x4b>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x30,-0x1(%rax)
jmp    1194 <itoa7+0x94>
jmp    1150 <itoa7+0x50>
cmpl   $0x0,-0x4(%rbp)
je     118f <itoa7+0x8f>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1150 <itoa7+0x50>
jmp    1194 <itoa7+0x94>
jmp    1199 <itoa7+0x99>
lea    0x2e90(%rip),%rax
add    $0x9,%rax
cmp    %rax,-0x10(%rbp)
jbe    11c6 <itoa7+0xc6>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x20,-0x1(%rax)
jmp    1199 <itoa7+0x99>
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa7>:
push   %rbx
movb   $0x0,0x2f37(%rip)
test   %edi,%edi
je     1177 <itoa7+0x67>
lea    0x2f2c(%rip),%rdx
mov    %rdx,%rbx
cs nopw 0x0(%rax,%rax,1)
movslq %edi,%rax
imul   $0x66666667,%rax,%rdi
mov    %rdi,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rdi
add    %ecx,%edi
lea    (%rdi,%rdi,1),%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%esi
sub    %ecx,%esi
add    $0x30,%sil
mov    %sil,-0x1(%rbx)
add    $0xffffffffffffffff,%rbx
add    $0x9,%eax
add    $0xffffffffffffffff,%rdx
cmp    $0x12,%eax
ja     1130 <itoa7+0x20>
lea    0x2ed9(%rip),%rax
cmp    %rax,%rbx
ja     1188 <itoa7+0x78>
jmp    11b0 <itoa7+0xa0>
movb   $0x30,0x2ed0(%rip)
lea    0x2ec9(%rip),%rdx
mov    %rdx,%rbx
lea    0x2eb1(%rip),%rax
mov    %rax,%rcx
sub    %rdx,%rcx
add    %rcx,%rbx
add    $0x9,%rbx
sub    %rax,%rdx
add    $0xfffffffffffffff7,%rdx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <memset@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@itoa7.buffer = internal global [16 x i8] zeroinitializer
define i8* @itoa7(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @itoa7.buffer, i64 1, i64 0), i8** %3
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8, i8* %4, i32 -1
store i8* %5, i8** %3
store i8 0, i8* %5
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i32 -1
store i8* %10, i8** %3
store i8 48, i8* %10
br label %25
11: ; preds = %1
br label %12
12: ; preds = %15, %11
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load i32, i32* %2
%17 = srem i32 %16, 10
%18 = add nsw i32 %17, 48
%19 = trunc i32 %18 to i8
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 -1
store i8* %21, i8** %3
store i8 %19, i8* %21
%22 = load i32, i32* %2
%23 = sdiv i32 %22, 10
store i32 %23, i32* %2
br label %12
24: ; preds = %12
br label %25
25: ; preds = %24, %8
br label %26
26: ; preds = %29, %25
%27 = load i8*, i8** %3
%28 = icmp ugt i8* %27, getelementptr inbounds ([16 x i8], [16 x i8]* @itoa7.buffer, i64 1, i64 -7)
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %3
store i8 32, i8* %31
br label %26
32: ; preds = %26
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
@itoa7.buffer = internal global [16 x i8] zeroinitializer
define i8* @itoa7(i32 %0) {
store i8 0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @itoa7.buffer, i64 0, i64 15)
%2 = icmp eq i32 %0, 0
br i1 %2, label %3, label %4
3: ; preds = %1
store i8 48, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @itoa7.buffer, i64 0, i64 14)
br label %17
4: ; preds = %1, %4
%5 = phi i8* [ %10, %4 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @itoa7.buffer, i64 0, i64 15), %1 ]
%6 = phi i32 [ %11, %4 ], [ %0, %1 ]
%7 = srem i32 %6, 10
%8 = trunc i32 %7 to i8
%9 = add nsw i8 %8, 48
%10 = getelementptr inbounds i8, i8* %5, i64 -1
store i8 %9, i8* %10
%11 = sdiv i32 %6, 10
%12 = add i32 %6, 9
%13 = icmp ult i32 %12, 19
br i1 %13, label %14, label %4
14: ; preds = %4
%15 = ptrtoint i8* %10 to i64
%16 = icmp ugt i8* %10, getelementptr inbounds ([16 x i8], [16 x i8]* @itoa7.buffer, i64 0, i64 9)
br i1 %16, label %17, label %24
17: ; preds = %3, %14
%18 = phi i64 [ ptrtoint (i8* getelementptr inbounds ([16 x i8], [16 x i8]* @itoa7.buffer, i64 0, i64 14) to i64), %3 ], [ %15, %14 ]
%19 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @itoa7.buffer, i64 0, i64 14), %3 ], [ %10, %14 ]
%20 = sub i64 add (i64 ptrtoint ([16 x i8]* @itoa7.buffer to i64), i64 9), %18
%21 = getelementptr i8, i8* %19, i64 %20
%22 = add i64 %18, -9
%23 = sub i64 %22, ptrtoint ([16 x i8]* @itoa7.buffer to i64)
br label %24
24: ; preds = %17, %14
%25 = phi i8* [ %10, %14 ], [ %21, %17 ]
ret i8* %25
}