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


x86 assembly (clang, -O0):
<itoa_recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    114a <itoa_recursive+0x2a>
mov    -0x10(%rbp),%rax
movb   $0x2d,(%rax)
movl   $0x1,0x2eea(%rip)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <abs@plt>
cmp    $0x0,%eax
je     1182 <itoa_recursive+0x62>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <abs@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1040 <itoa_recursive@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <abs@plt>
add    $0x30,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    0x2e91(%rip),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,0x2e86(%rip)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq 0x2e75(%rip),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa_recursive>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
test   %edi,%edi
jns    112c <itoa_recursive+0x1c>
movb   $0x2d,(%r14)
movl   $0x1,0x2f00(%rip)
lea    0x9(%rbx),%eax
movslq %ebx,%r15
cmp    $0x13,%eax
jb     115a <itoa_recursive+0x4a>
imul   $0x66666667,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
mov    %eax,%edi
neg    %edi
cmovs  %eax,%edi
mov    %r14,%rsi
call   1030 <itoa_recursive@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,%eax
neg    %eax
cmovs  %ebx,%eax
add    $0x30,%al
movslq 0x2ea7(%rip),%rcx
lea    0x1(%rcx),%rdx
mov    %edx,0x2e9d(%rip)
mov    %al,(%r14,%rcx,1)
movb   $0x0,0x1(%r14,%rcx,1)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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