#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 */
scalar_t__ abs(int);
void itoa(int n, char s[]) {
  static int i = 0;
  if ((n / 10) != 0)
    itoa(n / 10, s);
  else {
    i = 0;
    if (n < 0)
      s[i++] = '-';
  }
  s[i++] = (char)(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>
add    $0x30,%rax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    0x2e7f(%rip),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,0x2e74(%rip)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq 0x2e63(%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 i64 @abs(i32 %24)
%26 = add nsw i64 %25, 48
%27 = trunc i64 %26 to i8
%28 = load i8*, i8** %4
%29 = load i32, i32* @itoa.i
%30 = add nsw i32 %29, 1
store i32 %30, i32* @itoa.i
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
store i8 %27, i8* %32
%33 = load i8*, i8** %4
%34 = load i32, i32* @itoa.i
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 0, i8* %36
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 i64 @abs(i32 %11)
%13 = trunc i64 %12 to i8
%14 = add i8 %13, 48
%15 = load i32, i32* @itoa.i
%16 = add nsw i32 %15, 1
store i32 %16, i32* @itoa.i
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds i8, i8* %1, i64 %17
store i8 %14, i8* %18
%19 = sext i32 %16 to i64
%20 = getelementptr inbounds i8, i8* %1, i64 %19
store i8 0, i8* %20
ret void
}