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


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1155 <itoa+0x35>
mov    -0x10(%rbp),%rax
mov    0x2ef1(%rip),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,0x2ee6(%rip)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
je     1184 <itoa+0x64>
mov    -0x4(%rbp),%edi
call   1030 <abs@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1040 <itoa@plt>
mov    -0x4(%rbp),%edi
call   1030 <abs@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x10(%rbp),%rax
mov    0x2e93(%rip),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,0x2e88(%rip)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq 0x2e77(%rip),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
test   %edi,%edi
jns    1130 <itoa+0x20>
movslq 0x2f0a(%rip),%rax
lea    0x1(%rax),%ecx
mov    %ecx,0x2f01(%rip)
movb   $0x2d,(%r14,%rax,1)
lea    0x9(%rdi),%eax
mov    %edi,%ebp
neg    %ebp
cmovs  %edi,%ebp
mov    %ebp,%ebx
cmp    $0x13,%eax
jb     1156 <itoa+0x46>
mov    $0xcccccccd,%edi
imul   %rbx,%rdi
shr    $0x23,%rdi
mov    %r14,%rsi
call   1030 <itoa@plt>
mov    $0xcccccccd,%eax
imul   %rbx,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebp
or     $0x30,%bpl
movslq 0x2eb7(%rip),%rax
lea    0x1(%rax),%rcx
mov    %ecx,0x2ead(%rip)
mov    %bpl,(%r14,%rax,1)
movb   $0x0,0x1(%r14,%rax,1)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@itoa.i = internal unnamed_addr global i32 0
define void @itoa(i32 %0, i8* nocapture writeonly %1) {
%3 = icmp slt i32 %0, 0
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @itoa.i
%6 = add nsw i32 %5, 1
store i32 %6, i32* @itoa.i
%7 = sext i32 %5 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
store i8 45, i8* %8
br label %9
9: ; preds = %4, %2
%10 = add i32 %0, 9
%11 = icmp ult i32 %10, 19
%12 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
br i1 %11, label %15, label %13
13: ; preds = %9
%14 = udiv i32 %12, 10
tail call void @itoa(i32 %14, i8* %1)
br label %15
15: ; preds = %9, %13
%16 = urem i32 %12, 10
%17 = trunc i32 %16 to i8
%18 = or i8 %17, 48
%19 = load i32, i32* @itoa.i
%20 = add nsw i32 %19, 1
store i32 %20, i32* @itoa.i
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %1, i64 %21
store i8 %18, i8* %22
%23 = sext i32 %20 to i64
%24 = getelementptr inbounds i8, i8* %1, i64 %23
store i8 0, i8* %24
ret void
}