#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(char *);
void itoa(int n, char s[]) {
  size_t i = 0;
  int sign;
  sign = n;
  do {
    s[i++] = (char)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)
movq   $0x0,-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>
movsbl %al,%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x18(%rbp)
mov    %dl,(%rax,%rcx,1)
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    11a5 <itoa+0x85>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
movb   $0x2d,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x18(%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    1186 <itoa+0x66>
movb   $0x2d,(%r15,%r12,1)
add    $0x1,%r12
movb   $0x0,(%r15,%r12,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 i64
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i64 0, i64* %5
%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 i64 @abs(i32 %10)
%12 = trunc i64 %11 to i8
%13 = sext i8 %12 to i32
%14 = add nsw i32 %13, 48
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %4
%17 = load i64, i64* %5
%18 = add i64 %17, 1
store i64 %18, i64* %5
%19 = getelementptr inbounds i8, i8* %16, i64 %17
store i8 %15, 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 %32
27: ; preds = %24
%28 = load i8*, i8** %4
%29 = load i64, i64* %5
%30 = add i64 %29, 1
store i64 %30, i64* %5
%31 = getelementptr inbounds i8, i8* %28, i64 %29
store i8 45, i8* %31
br label %32
32: ; preds = %27, %24
%33 = load i8*, i8** %4
%34 = load i64, i64* %5
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %4
%37 = call i32 @reverse(i8* %36)
ret void
}

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