#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 / 10)
    itoa(n / 10, s);
  else {
    i = 0;
    if (n < 0)
      s[i++] = '-';
  }
  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)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
je     115e <itoa+0x3e>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1040 <itoa@plt>
jmp    1193 <itoa+0x73>
movl   $0x0,0x2ecc(%rip)
cmpl   $0x0,-0x4(%rbp)
jge    118e <itoa+0x6e>
mov    -0x10(%rbp),%rax
mov    0x2eb8(%rip),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,0x2ead(%rip)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
jmp    1193 <itoa+0x73>
mov    -0x4(%rbp),%edi
call   1030 <abs@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x10(%rbp),%rax
mov    0x2e84(%rip),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,0x2e79(%rip)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq 0x2e68(%rip),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x9(%rbx),%eax
cmp    $0x13,%eax
jae    1132 <itoa+0x22>
xor    %eax,%eax
test   %ebx,%ebx
jns    1157 <itoa+0x47>
movb   $0x2d,(%r14)
mov    $0x1,%eax
jmp    1157 <itoa+0x47>
movslq %ebx,%rax
imul   $0x66666667,%rax,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x22,%rdi
add    %eax,%edi
mov    %r14,%rsi
call   1030 <itoa@plt>
mov    0x2ed5(%rip),%eax
mov    %ebx,%ecx
neg    %ecx
cmovs  %ebx,%ecx
mov    $0xcccccccd,%edx
imul   %rcx,%rdx
shr    $0x23,%rdx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ecx
or     $0x30,%cl
cltq
lea    0x1(%rax),%rdx
mov    %edx,0x2eab(%rip)
mov    %cl,(%r14,%rax,1)
movb   $0x0,0x1(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
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 = sdiv i32 %5, 10
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* %3
%10 = sdiv i32 %9, 10
%11 = load i8*, i8** %4
br label %22
12: ; preds = %2
store i32 0, i32* @itoa.i
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = load i32, i32* @itoa.i
%18 = add nsw i32 %17, 1
store i32 %18, i32* @itoa.i
%19 = sext i32 %17 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
store i8 45, i8* %20
br label %21
21: ; preds = %15, %12
br label %22
22: ; preds = %21, %8
%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 = add i32 %0, 9
%4 = icmp ult i32 %3, 19
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = sdiv i32 %0, 10
tail call void @itoa(i32 %6, i8* %1)
%7 = load i32, i32* @itoa.i
br label %11
8: ; preds = %2
%9 = icmp slt i32 %0, 0
br i1 %9, label %10, label %11
10: ; preds = %8
store i8 45, i8* %1
br label %11
11: ; preds = %8, %10, %5
%12 = phi i32 [ 0, %8 ], [ 1, %10 ], [ %7, %5 ]
%13 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%14 = urem i32 %13, 10
%15 = trunc i32 %14 to i8
%16 = or i8 %15, 48
%17 = add nsw i32 %12, 1
store i32 %17, i32* @itoa.i
%18 = sext i32 %12 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 %16, i8* %19
%20 = sext i32 %17 to i64
%21 = getelementptr inbounds i8, i8* %1, i64 %20
store i8 0, i8* %21
ret void
}