#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;
  do {
    s[i++] = abs(n % 10) + '0';
  } while (n /= 10);
  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)
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    1135 <itoa+0x15>
cmpl   $0x0,-0x18(%rbp)
jge    119b <itoa+0x7b>
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   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
xor    %r13d,%r13d
movabs $0x100000000,%r12
xor    %ebp,%ebp
mov    %edi,0x4(%rsp)
mov    %edi,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %r12,%r13
movslq %ebx,%r14
imul   $0x66666667,%r14,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x22,%rbx
add    %eax,%ebx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %r14d,%edi
sub    %eax,%edi
call   1040 <abs@plt>
add    $0x30,%al
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
add    $0x9,%r14d
cmp    $0x12,%r14d
ja     1150 <itoa+0x30>
cmpl   $0x0,0x4(%rsp)
jns    11a2 <itoa+0x82>
add    $0x1,%rbp
sar    $0x20,%r13
movb   $0x2d,(%r15,%r13,1)
movslq %ebp,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
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
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 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 %21
16: ; preds = %14
%17 = add i64 %4, 2
%18 = shl i64 %9, 32
%19 = ashr exact i64 %18, 32
%20 = getelementptr inbounds i8, i8* %1, i64 %19
store i8 45, i8* %20
br label %21
21: ; preds = %16, %14
%22 = phi i64 [ %17, %16 ], [ %9, %14 ]
%23 = shl i64 %22, 32
%24 = ashr exact i64 %23, 32
%25 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 0, i8* %25
%26 = tail call i32 @reverse(i8* %1)
ret void
}