#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 uint8_t;
typedef size_t int8_t;

/* Variables and functions */
char *ui8ToA(uint8_t number, char *buffer, uint8_t digits) {
  int8_t i;
  for (i = (digits - 1); i >= 0; i--) {
    buffer[i] = (number % 10) + '0';
    number /= 10;
  }
  buffer[digits] = 0;
  return buffer;
}


x86 assembly (clang, -O0):
<ui8ToA>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jb     115d <ui8ToA+0x5d>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    111a <ui8ToA+0x1a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ui8ToA>:
movslq %edx,%rax
add    %rsi,%rax
add    $0xffffffffffffffff,%rax
nopw   0x0(%rax,%rax,1)
movslq %edi,%rcx
imul   $0x66666667,%rcx,%rdi
mov    %rdi,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rdi
add    %edx,%edi
lea    (%rdi,%rdi,1),%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ecx
add    $0x30,%cl
mov    %cl,(%rax)
add    $0xffffffffffffffff,%rax
jmp    1110 <ui8ToA+0x10>

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

LLVM IR (-O2):
define noalias i8* @ui8ToA(i32 %0, i8* nocapture writeonly %1, i32 %2) {
%4 = add nsw i32 %2, -1
%5 = sext i32 %4 to i64
br label %6
6: ; preds = %6, %3
%7 = phi i32 [ %0, %3 ], [ %13, %6 ]
%8 = phi i64 [ %5, %3 ], [ %14, %6 ]
%9 = srem i32 %7, 10
%10 = trunc i32 %9 to i8
%11 = add nsw i8 %10, 48
%12 = getelementptr inbounds i8, i8* %1, i64 %8
store i8 %11, i8* %12
%13 = sdiv i32 %7, 10
%14 = add i64 %8, -1
br label %6
}