#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);
void itoa(int n, char s[]) {
  static int i;
  static int sign = 0;
  if (sign == 0) {
    sign = (n < 0) ? -1 : 1;
    i = 0;
  }
  if (n / 10) {
    itoa(n / 10, s);
  }
  if (sign != 0) {
    if (sign < 0) {
      s[i++] = '-';
    }
    sign = 0;
  }
  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,0x2f02(%rip)
jne    115f <itoa+0x3f>
mov    -0x4(%rbp),%edx
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %eax,0x2ee3(%rip)
movl   $0x0,0x2ed5(%rip)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
je     1189 <itoa+0x69>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1040 <itoa@plt>
cmpl   $0x0,0x2ea8(%rip)
je     11c9 <itoa+0xa9>
cmpl   $0x0,0x2e9b(%rip)
jge    11bf <itoa+0x9f>
mov    -0x10(%rbp),%rax
mov    0x2e87(%rip),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,0x2e7c(%rip)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
movl   $0x0,0x2e6f(%rip)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <abs@plt>
movsbl %al,%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    0x2e47(%rip),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,0x2e3c(%rip)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq 0x2e2b(%rip),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2f08(%rip),%eax
test   %eax,%eax
jne    114c <itoa+0x2c>
mov    %ebx,%eax
sar    $0x1f,%eax
or     $0x1,%eax
mov    %eax,0x2ef6(%rip)
movl   $0x0,0x2ee8(%rip)
lea    0x9(%rbx),%ecx
movslq %ebx,%r15
cmp    $0x13,%ecx
jb     1179 <itoa+0x59>
imul   $0x66666667,%r15,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x22,%rdi
add    %eax,%edi
mov    %r14,%rsi
call   1040 <itoa@plt>
mov    0x2ebf(%rip),%eax
test   %eax,%eax
je     119e <itoa+0x7e>
jns    1194 <itoa+0x74>
movslq 0x2eae(%rip),%rax
lea    0x1(%rax),%ecx
mov    %ecx,0x2ea5(%rip)
movb   $0x2d,(%r14,%rax,1)
movl   $0x0,0x2e9a(%rip)
imul   $0x66666667,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
mov    %ebx,%edi
call   1030 <abs@plt>
add    $0x30,%al
movslq 0x2e6b(%rip),%rcx
lea    0x1(%rcx),%rdx
mov    %edx,0x2e61(%rip)
mov    %al,(%r14,%rcx,1)
movb   $0x0,0x1(%r14,%rcx,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@itoa.i = internal global i32 0
@itoa.sign = 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* @itoa.sign
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
%10 = zext i1 %9 to i64
%11 = select i1 %9, i32 -1, i32 1
store i32 %11, i32* @itoa.sign
store i32 0, i32* @itoa.i
br label %12
12: ; preds = %7, %2
%13 = load i32, i32* %3
%14 = sdiv i32 %13, 10
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32, i32* %3
%18 = sdiv i32 %17, 10
%19 = load i8*, i8** %4
br label %20
20: ; preds = %16, %12
%21 = load i32, i32* @itoa.sign
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = load i32, i32* @itoa.sign
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i8*, i8** %4
%28 = load i32, i32* @itoa.i
%29 = add nsw i32 %28, 1
store i32 %29, i32* @itoa.i
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
store i8 45, i8* %31
br label %32
32: ; preds = %26, %23
store i32 0, i32* @itoa.sign
br label %33
33: ; preds = %32, %20
%34 = load i32, i32* %3
%35 = srem i32 %34, 10
%36 = call signext i8 @abs(i32 %35)
%37 = sext i8 %36 to i32
%38 = add nsw i32 %37, 48
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %4
%41 = load i32, i32* @itoa.i
%42 = add nsw i32 %41, 1
store i32 %42, i32* @itoa.i
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %40, i64 %43
store i8 %39, i8* %44
%45 = load i8*, i8** %4
%46 = load i32, i32* @itoa.i
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 0, i8* %48
ret void
}

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