#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_ptr(int n, char *s) {
  static char *p;
  if (n < 0) {
    *s++ = '-';
  }
  p = s;
  if (abs(n / 10))
    itoa_recursive_ptr(abs(n / 10), s);
  *p++ = abs(n % 10) + '0';
  *p = '\0';
}


x86 assembly (clang, -O0):
<itoa_recursive_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    114b <itoa_recursive_ptr+0x2b>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x2d,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,0x2ee2(%rip)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <abs@plt>
cmp    $0x0,%eax
je     118e <itoa_recursive_ptr+0x6e>
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_ptr@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <abs@plt>
add    $0x30,%eax
mov    %al,%cl
mov    0x2e8c(%rip),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,0x2e7e(%rip)
mov    %cl,(%rax)
mov    0x2e75(%rip),%rax
movb   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa_recursive_ptr>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
test   %edi,%edi
jns    1121 <itoa_recursive_ptr+0x11>
movb   $0x2d,(%rsi)
add    $0x1,%rsi
mov    %rsi,0x2f08(%rip)
lea    0x9(%rbx),%eax
movslq %ebx,%r14
cmp    $0x13,%eax
jb     115a <itoa_recursive_ptr+0x4a>
imul   $0x66666667,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
mov    %eax,%edi
neg    %edi
cmovs  %eax,%edi
call   1030 <itoa_recursive_ptr@plt>
mov    0x2ed6(%rip),%rsi
imul   $0x66666667,%r14,%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
lea    0x1(%rsi),%rcx
mov    %rcx,0x2ea7(%rip)
mov    %al,(%rsi)
movb   $0x0,0x1(%rsi)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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