#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 /*<<< orphan*/ reverse(char *);
void itoa(int i, char *s) {
  int sign = i < 0 ? -1 : 1;
  unsigned int n = i > 0 ? i : -i;
  char *str = s;
  do {
    *s++ = n % 10 + '0';
  } while (n /= 10);
  if (sign < 0)
    *s++ = '-';
  *s = '\0';
  reverse(str);
}


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edx
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    114a <itoa+0x3a>
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1152 <itoa+0x42>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    1160 <itoa+0x50>
cmpl   $0x0,-0x14(%rbp)
jge    11b6 <itoa+0xa6>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x2d,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <reverse@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
mov    %rsi,%r8
mov    %edi,%r10d
neg    %r10d
cmovs  %edi,%r10d
mov    $0xcccccccd,%r9d
mov    %rsi,%rax
cs nopw 0x0(%rax,%rax,1)
mov    %r10d,%esi
imul   %r9,%rsi
shr    $0x23,%rsi
lea    (%rsi,%rsi,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %r10d,%ecx
sub    %edx,%ecx
or     $0x30,%cl
mov    %cl,(%rax)
add    $0x1,%rax
cmp    $0x9,%r10d
mov    %esi,%r10d
ja     1130 <itoa+0x20>
test   %edi,%edi
jns    1163 <itoa+0x53>
movb   $0x2d,(%rax)
add    $0x1,%rax
movb   $0x0,(%rax)
mov    %r8,%rdi
jmp    1030 <reverse@plt>

LLVM IR (-O0):
define void @itoa(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%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* %5
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %3
br label %19
16: ; preds = %2
%17 = load i32, i32* %3
%18 = sub nsw i32 0, %17
br label %19
19: ; preds = %16, %14
%20 = phi i32 [ %15, %14 ], [ %18, %16 ]
store i32 %20, i32* %6
%21 = load i8*, i8** %4
store i8* %21, i8** %7
br label %22
22: ; preds = %29, %19
%23 = load i32, i32* %6
%24 = urem i32 %23, 10
%25 = add i32 %24, 48
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %4
store i8 %26, i8* %27
br label %29
29: ; preds = %22
%30 = load i32, i32* %6
%31 = udiv i32 %30, 10
store i32 %31, i32* %6
%32 = icmp ne i32 %31, 0
br i1 %32, label %22, label %33
33: ; preds = %29
%34 = load i32, i32* %5
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %4
store i8 45, i8* %37
br label %39
39: ; preds = %36, %33
%40 = load i8*, i8** %4
store i8 0, i8* %40
%41 = load i8*, i8** %7
%42 = call i32 @reverse(i8* %41)
ret void
}

LLVM IR (-O2):
define void @itoa(i32 %0, i8* %1) {
%3 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
br label %4
4: ; preds = %4, %2
%5 = phi i32 [ %3, %2 ], [ %11, %4 ]
%6 = phi i8* [ %1, %2 ], [ %10, %4 ]
%7 = urem i32 %5, 10
%8 = trunc i32 %7 to i8
%9 = or i8 %8, 48
%10 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %9, i8* %6
%11 = udiv i32 %5, 10
%12 = icmp ult i32 %5, 10
br i1 %12, label %13, label %4
13: ; preds = %4
%14 = icmp slt i32 %0, 0
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = getelementptr inbounds i8, i8* %6, i64 2
store i8 45, i8* %10
br label %17
17: ; preds = %15, %13
%18 = phi i8* [ %16, %15 ], [ %10, %13 ]
store i8 0, i8* %18
%19 = tail call i32 @reverse(i8* %1)
ret void
}