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


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1040 <abs@plt>
movsbl %al,%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jne    113c <itoa+0x1c>
cmpl   $0x0,-0x18(%rbp)
jge    11a2 <itoa+0x82>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <reverse@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %edi,%r14d
xor    %r12d,%r12d
mov    %edi,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %ebx,%rbp
imul   $0x66666667,%rbp,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x22,%rbx
add    %eax,%ebx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ebp,%edi
sub    %eax,%edi
call   1040 <abs@plt>
add    $0x30,%al
mov    %al,(%r15,%r12,1)
add    $0x1,%r12
add    $0x9,%ebp
cmp    $0x12,%ebp
ja     1140 <itoa+0x20>
test   %r14d,%r14d
jns    1189 <itoa+0x69>
mov    %r12d,%eax
add    $0x1,%r12
movb   $0x2d,(%r15,%rax,1)
movslq %r12d,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <reverse@plt>

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

LLVM IR (-O2):
define void @itoa(i32 %0, i8* %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ %9, %3 ], [ 0, %2 ]
%5 = phi i32 [ %11, %3 ], [ %0, %2 ]
%6 = srem i32 %5, 10
%7 = tail call signext i8 @abs(i32 %6)
%8 = add i8 %7, 48
%9 = add nuw i64 %4, 1
%10 = getelementptr inbounds i8, i8* %1, i64 %4
store i8 %8, i8* %10
%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 %20
16: ; preds = %14
%17 = add i64 %4, 2
%18 = and i64 %9, 4294967295
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 45, i8* %19
br label %20
20: ; preds = %16, %14
%21 = phi i64 [ %17, %16 ], [ %9, %14 ]
%22 = shl i64 %21, 32
%23 = ashr exact i64 %22, 32
%24 = getelementptr inbounds i8, i8* %1, i64 %23
store i8 0, i8* %24
%25 = tail call i32 @reverse(i8* %1)
ret void
}