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

/* Variables and functions */
void uint8_2_cstr(char *cstr, uint8_t integer) {
  uint8_t frac;
  uint8_t res;
  uint8_t count = 0;
  for (frac = 100; frac >= 1; frac = frac / 10) {
    res = integer / frac;
    cstr[count] = (char)(res + '0');
    integer = integer - (res * frac);
    count++;
  }
  cstr[count] = '\0';
}


x86 assembly (clang, -O0):
<uint8_2_cstr>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x64,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jl     116b <uint8_2_cstr+0x6b>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x10(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
jmp    1119 <uint8_2_cstr+0x19>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
pop    %rbp
ret

x86 assembly (clang, -O2):
<uint8_2_cstr>:
movslq %esi,%rax
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
lea    0x30(%rcx),%edx
mov    %dl,(%rdi)
imul   $0xffffff9c,%ecx,%ecx
add    %ecx,%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
lea    0x30(%rcx),%edx
mov    %dl,0x1(%rdi)
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
add    $0x30,%al
mov    %al,0x2(%rdi)
movb   $0x0,0x3(%rdi)
ret

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

LLVM IR (-O2):
define void @uint8_2_cstr(i8* nocapture writeonly %0, i32 %1) {
%3 = sdiv i32 %1, 100
%4 = trunc i32 %3 to i8
%5 = add i8 %4, 48
store i8 %5, i8* %0
%6 = mul nsw i32 %3, -100
%7 = add i32 %6, %1
%8 = sdiv i32 %7, 10
%9 = trunc i32 %8 to i8
%10 = add i8 %9, 48
%11 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %10, i8* %11
%12 = mul nsw i32 %8, -10
%13 = add i32 %12, %7
%14 = trunc i32 %13 to i8
%15 = add i8 %14, 48
%16 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %15, i8* %16
%17 = getelementptr inbounds i8, i8* %0, i64 3
store i8 0, i8* %17
ret void
}