#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 intmax_t;

/* Variables and functions */
int countDigits(int);
char *intToCharTable(intmax_t input) {
  int iter = countDigits(input);
  char result[iter];
  for (int i = 0; i < iter; i++) {
    result[iter - i - 1] = input % 10;
    input /= 10;
  }
  return result;
}


x86 assembly (clang, -O0):
<intToCharTable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <countDigits@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1199 <intToCharTable+0x89>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1153 <intToCharTable+0x43>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intToCharTable>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    %edi,%ebx
call   1030 <countDigits@plt>
mov    %eax,%ecx
mov    %eax,%edx
mov    %rsp,%rax
lea    0xf(%rdx),%rsi
and    $0xfffffffffffffff0,%rsi
sub    %rsi,%rax
mov    %rax,%rsp
test   %ecx,%ecx
jle    116b <intToCharTable+0x5b>
cs nopw 0x0(%rax,%rax,1)
movslq %ebx,%rcx
imul   $0x66666667,%rcx,%rbx
mov    %rbx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rbx
add    %esi,%ebx
lea    (%rbx,%rbx,1),%esi
lea    (%rsi,%rsi,4),%esi
sub    %esi,%ecx
add    $0xffffffffffffffff,%rdx
movslq %edx,%rsi
mov    %cl,(%rax,%rsi,1)
jne    1140 <intToCharTable+0x30>
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @intToCharTable(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @countDigits(i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
store i32 0, i32* %6
br label %13
13: ; preds = %29, %1
%14 = load i32, i32* %6
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %32
17: ; preds = %13
%18 = load i32, i32* %2
%19 = srem i32 %18, 10
%20 = trunc i32 %19 to i8
%21 = load i32, i32* %3
%22 = load i32, i32* %6
%23 = sub nsw i32 %21, %22
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %12, i64 %25
store i8 %20, i8* %26
%27 = load i32, i32* %2
%28 = sdiv i32 %27, 10
store i32 %28, i32* %2
br label %29
29: ; preds = %17
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %13
32: ; preds = %13
%33 = load i8*, i8** %4
ret i8* %12
}

LLVM IR (-O2):
define noalias i8* @intToCharTable(i32 %0) {
%2 = tail call i32 @countDigits(i32 %0)
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = icmp sgt i32 %2, 0
br i1 %5, label %7, label %6
6: ; preds = %7, %1
ret i8* %4
7: ; preds = %1, %7
%8 = phi i64 [ %18, %7 ], [ 0, %1 ]
%9 = phi i32 [ %17, %7 ], [ %0, %1 ]
%10 = srem i32 %9, 10
%11 = trunc i32 %10 to i8
%12 = trunc i64 %8 to i32
%13 = xor i32 %12, -1
%14 = add i32 %2, %13
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %4, i64 %15
store i8 %11, i8* %16
%17 = sdiv i32 %9, 10
%18 = add nuw nsw i64 %8, 1
%19 = icmp eq i64 %18, %3
br i1 %19, label %6, label %7
}