#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 */
typedef int uint32_t;

/* Variables and functions */
char *simple_itoa(uint32_t i) {
  static char local[22];
  char *p = &local[21];
  *p-- = '\0';
  do {
    *p-- = '0' + i % 10;
    i /= 10;
  } while (i > 0);
  return p + 1;
}


x86 assembly (clang, -O0):
<simple_itoa>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
lea    0x2f22(%rip),%rax
add    $0x15,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%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    $0xffffffffffffffff,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     1128 <simple_itoa+0x28>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<simple_itoa>:
movb   $0x0,0x2f3e(%rip)
lea    0x2f37(%rip),%rax
xchg   %ax,%ax
movslq %edi,%rcx
imul   $0x66666667,%rcx,%rdi
mov    %rdi,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rdi
add    %edx,%edi
lea    (%rdi,%rdi,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%esi
sub    %edx,%esi
add    $0x30,%sil
mov    %sil,-0x1(%rax)
add    $0xffffffffffffffff,%rax
cmp    $0x9,%ecx
jg     1110 <simple_itoa+0x10>
ret

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

LLVM IR (-O2):
@simple_itoa.local = internal global [22 x i8] zeroinitializer
define i8* @simple_itoa(i32 %0) {
store i8 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @simple_itoa.local, i64 0, i64 21)
br label %2
2: ; preds = %2, %1
%3 = phi i32 [ %0, %1 ], [ %9, %2 ]
%4 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @simple_itoa.local, i64 0, i64 20), %1 ], [ %8, %2 ]
%5 = srem i32 %3, 10
%6 = trunc i32 %5 to i8
%7 = add nsw i8 %6, 48
%8 = getelementptr inbounds i8, i8* %4, i64 -1
store i8 %7, i8* %4
%9 = sdiv i32 %3, 10
%10 = icmp sgt i32 %3, 9
br i1 %10, label %2, label %11
11: ; preds = %2
ret i8* %4
}