#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
char *malloc(int);
char *itoa(int number) {
  char *buffer = malloc(6);
  int register i = 9;
  buffer[i--] = '\0';
  while (number) {
    buffer[i--] = number - (number / 10) * 10 + 48;
    number /= 10;
  }
  return buffer + i + 1;
}


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x6,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x9,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x4(%rbp)
je     1198 <itoa+0x88>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
imul   $0xa,%ecx,%ecx
sub    %ecx,%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0xffffffff,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1146 <itoa+0x36>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %rbx
mov    %edi,%ebx
mov    $0x6,%edi
call   1030 <malloc@plt>
movb   $0x0,0x9(%rax)
test   %ebx,%ebx
je     117f <itoa+0x6f>
lea    0x8(%rax),%rdx
movabs $0x800000000,%rcx
movabs $0xffffffff00000000,%r8
ff ff ff
nopl   (%rax)
add    %r8,%rcx
movslq %ebx,%rdi
imul   $0x66666667,%rdi,%rbx
mov    %rbx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rbx
add    %esi,%ebx
lea    (%rbx,%rbx,1),%esi
lea    (%rsi,%rsi,4),%r9d
mov    %edi,%esi
sub    %r9d,%esi
add    $0x30,%sil
mov    %sil,(%rdx)
add    $0x9,%edi
add    $0xffffffffffffffff,%rdx
cmp    $0x12,%edi
ja     1140 <itoa+0x30>
sar    $0x20,%rcx
jmp    1184 <itoa+0x74>
mov    $0x8,%ecx
add    %rcx,%rax
add    $0x1,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @itoa(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i8* @malloc(i32 6)
store i8* %5, i8** %3
store i32 9, i32* %4
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = add nsw i32 %7, -1
store i32 %8, i32* %4
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
store i8 0, i8* %10
br label %11
11: ; preds = %14, %1
%12 = load i32, i32* %2
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = load i32, i32* %2
%16 = load i32, i32* %2
%17 = sdiv i32 %16, 10
%18 = mul nsw i32 %17, 10
%19 = sub nsw i32 %15, %18
%20 = add nsw i32 %19, 48
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %3
%23 = load i32, i32* %4
%24 = add nsw i32 %23, -1
store i32 %24, i32* %4
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 %21, i8* %26
%27 = load i32, i32* %2
%28 = sdiv i32 %27, 10
store i32 %28, i32* %2
br label %11
29: ; preds = %11
%30 = load i8*, i8** %3
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 1
ret i8* %34
}

LLVM IR (-O2):
define noalias i8* @itoa(i32 %0) {
%2 = tail call dereferenceable_or_null(6) i8* @malloc(i32 6)
%3 = getelementptr inbounds i8, i8* %2, i64 9
store i8 0, i8* %3
%4 = icmp eq i32 %0, 0
br i1 %4, label %20, label %5
5: ; preds = %1, %5
%6 = phi i64 [ %13, %5 ], [ 8, %1 ]
%7 = phi i32 [ %8, %5 ], [ %0, %1 ]
%8 = sdiv i32 %7, 10
%9 = mul nsw i32 %8, -10
%10 = add i32 %9, %7
%11 = trunc i32 %10 to i8
%12 = add i8 %11, 48
%13 = add i64 %6, -1
%14 = getelementptr inbounds i8, i8* %2, i64 %6
store i8 %12, i8* %14
%15 = add i32 %7, 9
%16 = icmp ult i32 %15, 19
br i1 %16, label %17, label %5
17: ; preds = %5
%18 = shl i64 %13, 32
%19 = ashr exact i64 %18, 32
br label %20
20: ; preds = %17, %1
%21 = phi i64 [ 8, %1 ], [ %19, %17 ]
%22 = getelementptr inbounds i8, i8* %2, i64 %21
%23 = getelementptr inbounds i8, i8* %22, i64 1
ret i8* %23
}