#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 abs(int);
void itoa(int n, char s[]) {
  int static i = 0;
  if (n / 10)
    itoa(n / 10, s);
  else {
    i = 0;
    if (n < 0)
      s[i++] = '-';
  }
  s[i++] = abs(n % 10) + '0';
  s[i] = '\0';
}


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
je     115e <itoa+0x3e>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1040 <itoa@plt>
jmp    1193 <itoa+0x73>
movl   $0x0,0x2ecc(%rip)
cmpl   $0x0,-0x4(%rbp)
jge    118e <itoa+0x6e>
mov    -0x10(%rbp),%rax
mov    0x2eb8(%rip),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,0x2ead(%rip)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
jmp    1193 <itoa+0x73>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <abs@plt>
movsbl %al,%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    0x2e7d(%rip),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,0x2e72(%rip)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq 0x2e61(%rip),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x9(%rbx),%eax
movslq %edi,%r15
cmp    $0x13,%eax
jae    1153 <itoa+0x33>
movl   $0x0,0x2ef5(%rip)
test   %ebx,%ebx
jns    116f <itoa+0x4f>
movl   $0x1,0x2ee7(%rip)
movb   $0x2d,(%r14)
jmp    116f <itoa+0x4f>
imul   $0x66666667,%r15,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x22,%rdi
add    %eax,%edi
mov    %r14,%rsi
call   1040 <itoa@plt>
imul   $0x66666667,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
mov    %ebx,%edi
call   1030 <abs@plt>
add    $0x30,%al
movslq 0x2e9a(%rip),%rcx
lea    0x1(%rcx),%rdx
mov    %edx,0x2e90(%rip)
mov    %al,(%r14,%rcx,1)
movb   $0x0,0x1(%r14,%rcx,1)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@itoa.i = internal unnamed_addr global i32 0
define void @itoa(i32 %0, i8* nocapture writeonly %1) {
%3 = add i32 %0, 9
%4 = icmp ult i32 %3, 19
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = sdiv i32 %0, 10
tail call void @itoa(i32 %6, i8* %1)
br label %10
7: ; preds = %2
store i32 0, i32* @itoa.i
%8 = icmp slt i32 %0, 0
br i1 %8, label %9, label %10
9: ; preds = %7
store i32 1, i32* @itoa.i
store i8 45, i8* %1
br label %10
10: ; preds = %7, %9, %5
%11 = srem i32 %0, 10
%12 = tail call signext i8 @abs(i32 %11)
%13 = add i8 %12, 48
%14 = load i32, i32* @itoa.i
%15 = add nsw i32 %14, 1
store i32 %15, i32* @itoa.i
%16 = sext i32 %14 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 %13, i8* %17
%18 = sext i32 %15 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 0, i8* %19
ret void
}