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

/* Variables and functions */
int /*<<< orphan*/ strreverse(char *, char *);
char *modp_uitoa10(uint32_t value, char *str) {
  char *wstr = str;
  do
    *wstr++ = (char)(48 + (value % 10));
  while (value /= 10);
  *wstr = '\0';
  strreverse(str, wstr - 1);
  return wstr;
}


x86 assembly (clang, -O0):
<modp_uitoa10>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%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)
cmp    $0x0,%eax
jne    1127 <modp_uitoa10+0x17>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <strreverse@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<modp_uitoa10>:
push   %rbx
mov    %rsi,%rax
mov    %rsi,%rbx
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
mov    %ecx,%esi
sub    %edx,%esi
add    $0x30,%sil
mov    %sil,(%rbx)
add    $0x1,%rbx
add    $0x9,%ecx
cmp    $0x12,%ecx
ja     1120 <modp_uitoa10+0x10>
movb   $0x0,(%rbx)
lea    -0x1(%rbx),%rsi
mov    %rax,%rdi
call   1030 <strreverse@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @modp_uitoa10(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
store i8* %6, i8** %5
br label %7
7: ; preds = %14, %2
%8 = load i32, i32* %3
%9 = srem i32 %8, 10
%10 = add nsw i32 48, %9
%11 = trunc i32 %10 to i8
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %5
store i8 %11, i8* %12
br label %14
14: ; preds = %7
%15 = load i32, i32* %3
%16 = sdiv i32 %15, 10
store i32 %16, i32* %3
%17 = icmp ne i32 %16, 0
br i1 %17, label %7, label %18
18: ; preds = %14
%19 = load i8*, i8** %5
store i8 0, i8* %19
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 -1
%23 = call i32 @strreverse(i8* %20, i8* %22)
%24 = load i8*, i8** %5
ret i8* %24
}

LLVM IR (-O2):
define i8* @modp_uitoa10(i32 %0, i8* %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i32 [ %0, %2 ], [ %10, %3 ]
%5 = phi i8* [ %1, %2 ], [ %9, %3 ]
%6 = srem i32 %4, 10
%7 = trunc i32 %6 to i8
%8 = add nsw i8 %7, 48
%9 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %8, i8* %5
%10 = sdiv i32 %4, 10
%11 = add i32 %4, 9
%12 = icmp ult i32 %11, 19
br i1 %12, label %13, label %3
13: ; preds = %3
store i8 0, i8* %9
%14 = tail call i32 @strreverse(i8* %1, i8* %5)
ret i8* %9
}