#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*/ printf(char *, int, int);
int /*<<< orphan*/ reverse(char *);
void itoa(int n, char s[]) {
  int i, sign;
  sign = n;
  i = 0;
  do {
    s[i++] = abs(n % 10) + '0';
    printf("%d %d\n", n % 10, n / 10);
  } 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)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%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    %edx,%esi
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xe64(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jne    114c <itoa+0x1c>
cmpl   $0x0,-0x18(%rbp)
jge    11d8 <itoa+0xa8>
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,%r12
xor    %r13d,%r13d
lea    0xeb8(%rip),%r15
mov    %edi,0x4(%rsp)
mov    %edi,%ebp
xchg   %ax,%ax
movslq %ebp,%r14
imul   $0x66666667,%r14,%rbp
mov    %rbp,%rax
shr    $0x3f,%rax
sar    $0x22,%rbp
add    %eax,%ebp
lea    0x0(%rbp,%rbp,1),%eax
lea    (%rax,%rax,4),%eax
mov    %r14d,%ebx
sub    %eax,%ebx
mov    %ebx,%edi
call   1040 <abs@plt>
add    $0x30,%al
mov    %al,(%r12,%r13,1)
add    $0x1,%r13
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1050 <printf@plt>
add    $0x9,%r14d
cmp    $0x12,%r14d
ja     1150 <itoa+0x20>
cmpl   $0x0,0x4(%rsp)
jns    11ad <itoa+0x7d>
mov    %r13d,%eax
add    $0x1,%r13
movb   $0x2d,(%r12,%rax,1)
movslq %r13d,%rax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <reverse@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%d %d\0A\00"
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
store i32 0, i32* %5
br label %8
8: ; preds = %25, %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
%20 = load i32, i32* %3
%21 = srem i32 %20, 10
%22 = load i32, i32* %3
%23 = sdiv i32 %22, 10
%24 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %23)
br label %25
25: ; preds = %8
%26 = load i32, i32* %3
%27 = sdiv i32 %26, 10
store i32 %27, i32* %3
%28 = icmp ne i32 %27, 0
br i1 %28, label %8, label %29
29: ; preds = %25
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
store i8 45, i8* %37
br label %38
38: ; preds = %32, %29
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 0, i8* %42
%43 = load i8*, i8** %4
%44 = call i32 @reverse(i8* %43)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d %d\0A\00"
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 nuw i64 %4, 1
%10 = getelementptr inbounds i8, i8* %1, i64 %4
store i8 %8, i8* %10
%11 = sdiv i32 %5, 10
%12 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %11)
%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 %21
17: ; preds = %15
%18 = add i64 %4, 2
%19 = and i64 %9, 4294967295
%20 = getelementptr inbounds i8, i8* %1, i64 %19
store i8 45, i8* %20
br label %21
21: ; preds = %17, %15
%22 = phi i64 [ %18, %17 ], [ %9, %15 ]
%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
}