#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);
int /*<<< orphan*/ reverse_ptr(char *);
void itoa_alt_ptr(int n, char *s) {
  int sign = n;
  char *p = s;
  do {
    *p++ = abs(n % 10) + '0';
  } while ((abs(n /= 10)) > 0);
  if (sign < 0)
    *p++ = '-';
  *p = '\0';
  reverse_ptr(s);
}


x86 assembly (clang, -O0):
<itoa_alt_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <abs@plt>
add    $0x30,%rax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    %edi,-0x4(%rbp)
call   1030 <abs@plt>
cmp    $0x0,%rax
jg     113d <itoa_alt_ptr+0x1d>
cmpl   $0x0,-0x14(%rbp)
jge    11a1 <itoa_alt_ptr+0x81>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2d,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <reverse_ptr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa_alt_ptr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    %edi,%ebx
mov    %rsi,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %ebx,%rdi
imul   $0x66666667,%rdi,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x22,%rbx
add    %eax,%ebx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
call   1030 <abs@plt>
add    $0x30,%al
mov    %al,0x0(%rbp)
add    $0x1,%rbp
mov    %ebx,%edi
call   1030 <abs@plt>
test   %rax,%rax
jg     1140 <itoa_alt_ptr+0x20>
test   %r15d,%r15d
jns    1186 <itoa_alt_ptr+0x66>
movb   $0x2d,0x0(%rbp)
add    $0x1,%rbp
movb   $0x0,0x0(%rbp)
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <reverse_ptr@plt>

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

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