#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*/ putchar(char);
void itoa(int n) {
  static int sign;
  if (!sign && n < 0) {
    sign = 1;
    putchar('-');
  }
  if (n / 10)
    itoa(n / 10);
  putchar(abs(n % 10) + '0');
}


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,0x2efa(%rip)
jne    1166 <itoa+0x36>
cmpl   $0x0,-0x4(%rbp)
jge    1166 <itoa+0x36>
movl   $0x1,0x2ee0(%rip)
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
je     118c <itoa+0x5c>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <itoa@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1040 <abs@plt>
movsbl %al,%eax
add    $0x30,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
test   %edi,%edi
jns    1154 <itoa+0x24>
testb  $0x1,0x2efb(%rip)
jne    1154 <itoa+0x24>
movb   $0x1,0x2ef2(%rip)
mov    $0x2d,%edi
call   1030 <putchar@plt>
lea    0x9(%rbx),%eax
movslq %ebx,%r14
cmp    $0x13,%eax
jb     1178 <itoa+0x48>
imul   $0x66666667,%r14,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x22,%rdi
add    %eax,%edi
call   1050 <itoa@plt>
imul   $0x66666667,%r14,%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   1040 <abs@plt>
add    $0x30,%al
movsbl %al,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@itoa.sign = internal global i32 0
define void @itoa(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* @itoa.sign
%4 = icmp ne i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
store i32 1, i32* @itoa.sign
%9 = call i32 @putchar(i8 signext 45)
br label %10
10: ; preds = %8, %5, %1
%11 = load i32, i32* %2
%12 = sdiv i32 %11, 10
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* %2
%16 = sdiv i32 %15, 10
br label %17
17: ; preds = %14, %10
%18 = load i32, i32* %2
%19 = srem i32 %18, 10
%20 = call signext i8 @abs(i32 %19)
%21 = sext i8 %20 to i32
%22 = add nsw i32 %21, 48
%23 = trunc i32 %22 to i8
%24 = call i32 @putchar(i8 signext %23)
ret void
}

LLVM IR (-O2):
@itoa.sign = internal unnamed_addr global i1 false
define void @itoa(i32 %0) {
%2 = load i1, i1* @itoa.sign
%3 = icmp sgt i32 %0, -1
%4 = or i1 %3, %2
br i1 %4, label %7, label %5
5: ; preds = %1
store i1 true, i1* @itoa.sign
%6 = tail call i32 @putchar(i8 signext 45)
br label %7
7: ; preds = %5, %1
%8 = add i32 %0, 9
%9 = icmp ult i32 %8, 19
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = sdiv i32 %0, 10
tail call void @itoa(i32 %11)
br label %12
12: ; preds = %10, %7
%13 = srem i32 %0, 10
%14 = tail call signext i8 @abs(i32 %13)
%15 = add i8 %14, 48
%16 = tail call i32 @putchar(i8 signext %15)
ret void
}