#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 */
size_t abs(int);
char *intToString(int value, char *buffer) {
  static const char *DIGITS = "0123456789";
  char *pdig = buffer;
  while (value != 0) {
    *pdig++ = DIGITS[abs(value % 10)];
    value /= 10;
  }
  *pdig = '\0';
  for (char *begin = buffer, *end = pdig; begin < end--; ++begin) {
    const char temp = *begin;
    *begin = *end;
    *end = temp;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<intToString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     117c <intToString+0x6c>
mov    0x2ef0(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <abs@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1127 <intToString+0x17>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x28(%rbp)
cmp    %rcx,%rax
jae    11de <intToString+0xce>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x29(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1193 <intToString+0x83>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intToString>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
test   %edi,%edi
je     11a2 <intToString+0x92>
mov    %edi,%ebx
lea    0xed3(%rip),%r12
mov    %r14,%r15
movslq %ebx,%r13
imul   $0x66666667,%r13,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x22,%rbx
add    %eax,%ebx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %r13d,%edi
sub    %eax,%edi
call   1030 <abs@plt>
movzbl (%rax,%r12,1),%eax
mov    %al,(%r15)
add    $0x1,%r15
add    $0x9,%r13d
cmp    $0x12,%r13d
ja     1130 <intToString+0x20>
movb   $0x0,(%r15)
cmp    %r14,%r15
jbe    11a6 <intToString+0x96>
lea    0x1(%r14),%rax
nopw   0x0(%rax,%rax,1)
movzbl -0x1(%rax),%ecx
movzbl -0x1(%r15),%edx
mov    %dl,-0x1(%rax)
mov    %cl,-0x1(%r15)
add    $0xffffffffffffffff,%r15
lea    0x1(%rax),%rcx
cmp    %r15,%rax
mov    %rcx,%rax
jb     1180 <intToString+0x70>
jmp    11a6 <intToString+0x96>
movb   $0x0,(%r14)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@intToString.DIGITS = internal global i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0)
@.str = [11 x i8] c"0123456789\00"
define i8* @intToString(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
store i8* %9, i8** %5
br label %10
10: ; preds = %13, %2
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %10
%14 = load i8*, i8** @intToString.DIGITS
%15 = load i32, i32* %3
%16 = srem i32 %15, 10
%17 = call i64 @abs(i32 %16)
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = load i8, i8* %18
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
store i8 %19, i8* %20
%22 = load i32, i32* %3
%23 = sdiv i32 %22, 10
store i32 %23, i32* %3
br label %10
24: ; preds = %10
%25 = load i8*, i8** %5
store i8 0, i8* %25
%26 = load i8*, i8** %4
store i8* %26, i8** %6
%27 = load i8*, i8** %5
store i8* %27, i8** %7
br label %28
28: ; preds = %41, %24
%29 = load i8*, i8** %6
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %7
%32 = icmp ult i8* %29, %30
br i1 %32, label %33, label %44
33: ; preds = %28
%34 = load i8*, i8** %6
%35 = load i8, i8* %34
store i8 %35, i8* %8
%36 = load i8*, i8** %7
%37 = load i8, i8* %36
%38 = load i8*, i8** %6
store i8 %37, i8* %38
%39 = load i8, i8* %8
%40 = load i8*, i8** %7
store i8 %39, i8* %40
br label %41
41: ; preds = %33
%42 = load i8*, i8** %6
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %6
br label %28
44: ; preds = %28
%45 = load i8*, i8** %4
ret i8* %45
}

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
define i8* @intToString(i32 %0, i8* returned %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %4, label %5
4: ; preds = %2
store i8 0, i8* %1
br label %18
5: ; preds = %2, %5
%6 = phi i32 [ %13, %5 ], [ %0, %2 ]
%7 = phi i8* [ %12, %5 ], [ %1, %2 ]
%8 = srem i32 %6, 10
%9 = tail call i64 @abs(i32 %8)
%10 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %11, i8* %7
%13 = sdiv i32 %6, 10
%14 = add i32 %6, 9
%15 = icmp ult i32 %14, 19
br i1 %15, label %16, label %5
16: ; preds = %5
store i8 0, i8* %12
%17 = icmp ugt i8* %12, %1
br i1 %17, label %19, label %18
18: ; preds = %19, %4, %16
ret i8* %1
19: ; preds = %16, %19
%20 = phi i8* [ %22, %19 ], [ %12, %16 ]
%21 = phi i8* [ %25, %19 ], [ %1, %16 ]
%22 = getelementptr inbounds i8, i8* %20, i64 -1
%23 = load i8, i8* %21
%24 = load i8, i8* %22
store i8 %24, i8* %21
store i8 %23, i8* %22
%25 = getelementptr inbounds i8, i8* %21, i64 1
%26 = icmp ult i8* %25, %22
br i1 %26, label %19, label %18
}