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


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

x86 assembly (clang, -O2):
<itoa>:
mov    %rsi,%r8
mov    %rsi,%r10
mov    %edi,%ecx
nopl   0x0(%rax,%rax,1)
movslq %ecx,%rdx
imul   $0x66666667,%rdx,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rcx
add    %esi,%ecx
lea    (%rcx,%rcx,1),%esi
lea    (%rsi,%rsi,4),%r9d
mov    %edx,%eax
sub    %r9d,%eax
mov    %eax,%esi
neg    %esi
cmovs  %eax,%esi
add    $0x30,%sil
mov    %sil,(%r10)
add    $0x1,%r10
add    $0x9,%edx
cmp    $0x12,%edx
ja     1120 <itoa+0x10>
test   %edi,%edi
jns    1169 <itoa+0x59>
movb   $0x2d,(%r10)
add    $0x1,%r10
movb   $0x0,(%r10)
mov    %r8,%rdi
jmp    1030 <reverse@plt>

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

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