#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 */
typedef int time_t;
typedef size_t ssize_t;

/* Variables and functions */
int time_abs(int);
ssize_t numberToString(char *buffer, time_t value) {
  value = time_abs(value);
  ssize_t index = 0;
  buffer[0] = '\0';
  do {
    index++;
    buffer[-index] = "0123456789"[value % 10];
    value /= 10;
  } while (value);
  return index;
}


x86 assembly (clang, -O0):
<numberToString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <time_abs@plt>
mov    %eax,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0xea6(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
xor    %ecx,%ecx
sub    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1139 <numberToString+0x29>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numberToString>:
push   %rbx
mov    %rdi,%rbx
mov    %esi,%edi
call   1030 <time_abs@plt>
mov    %eax,%ecx
movb   $0x0,(%rbx)
xor    %eax,%eax
lea    0xed7(%rip),%r8
nopl   0x0(%rax)
movslq %ecx,%rsi
imul   $0x66666667,%rsi,%rcx
mov    %rcx,%rdi
shr    $0x3f,%rdi
sar    $0x22,%rcx
add    %edi,%ecx
lea    (%rcx,%rcx,1),%edi
lea    (%rdi,%rdi,4),%edi
mov    %esi,%edx
sub    %edi,%edx
movslq %edx,%rdx
movzbl (%rdx,%r8,1),%edx
mov    %dl,-0x1(%rbx,%rax,1)
add    $0x9,%esi
add    $0xffffffffffffffff,%rax
cmp    $0x12,%esi
ja     1130 <numberToString+0x20>
neg    %rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"0123456789\00"
define i64 @numberToString(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = call i32 @time_abs(i32 %6)
store i32 %7, i32* %4
store i64 0, i64* %5
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
store i8 0, i8* %9
br label %10
10: ; preds = %24, %2
%11 = load i64, i64* %5
%12 = add i64 %11, 1
store i64 %12, i64* %5
%13 = load i32, i32* %4
%14 = srem i32 %13, 10
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = load i8*, i8** %3
%19 = load i64, i64* %5
%20 = sub i64 0, %19
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 %17, i8* %21
%22 = load i32, i32* %4
%23 = sdiv i32 %22, 10
store i32 %23, i32* %4
br label %24
24: ; preds = %10
%25 = load i32, i32* %4
%26 = icmp ne i32 %25, 0
br i1 %26, label %10, label %27
27: ; preds = %24
%28 = load i64, i64* %5
ret i64 %28
}

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
define i64 @numberToString(i8* nocapture writeonly %0, i32 %1) {
%3 = tail call i32 @time_abs(i32 %1)
store i8 0, i8* %0
br label %4
4: ; preds = %4, %2
%5 = phi i32 [ %3, %2 ], [ %14, %4 ]
%6 = phi i64 [ 0, %2 ], [ %7, %4 ]
%7 = add i64 %6, 1
%8 = srem i32 %5, 10
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = xor i64 %6, -1
%13 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 %11, i8* %13
%14 = sdiv i32 %5, 10
%15 = add i32 %5, 9
%16 = icmp ult i32 %15, 19
br i1 %16, label %17, label %4
17: ; preds = %4
ret i64 %7
}