#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 unsigned int int32_t;

/* Variables and functions */
int /*<<< orphan*/ strreverse(char *, char *);
void modp_itoa10(int32_t value, char *str) {
  char *wstr = str;
  unsigned int uvalue = (value < 0) ? -value : value;
  do
    *wstr++ = (char)(48 + (uvalue % 10));
  while (uvalue /= 10);
  if (value < 0)
    *wstr++ = '-';
  *wstr = '\0';
  strreverse(str, wstr - 1);
}


x86 assembly (clang, -O0):
<modp_itoa10>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jae    113e <modp_itoa10+0x2e>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1144 <modp_itoa10+0x34>
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %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    -0x1c(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    114a <modp_itoa10+0x3a>
cmpl   $0x0,-0x4(%rbp)
jae    11a0 <modp_itoa10+0x90>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2d,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <strreverse@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<modp_itoa10>:
mov    %rsi,%r8
add    $0xffffffffffffffff,%rsi
mov    $0xcccccccd,%r9d
nopl   (%rax)
mov    %edi,%edx
imul   %r9,%rdx
shr    $0x23,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %edi,%ecx
sub    %eax,%ecx
or     $0x30,%cl
mov    %cl,0x1(%rsi)
add    $0x1,%rsi
cmp    $0x9,%edi
mov    %edx,%edi
ja     1120 <modp_itoa10+0x10>
movb   $0x0,0x1(%rsi)
mov    %r8,%rdi
jmp    1030 <strreverse@plt>

LLVM IR (-O0):
define void @modp_itoa10(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
store i8* %7, i8** %5
%8 = load i32, i32* %3
%9 = icmp ult i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* %3
%12 = sub i32 0, %11
br label %15
13: ; preds = %2
%14 = load i32, i32* %3
br label %15
15: ; preds = %13, %10
%16 = phi i32 [ %12, %10 ], [ %14, %13 ]
store i32 %16, i32* %6
br label %17
17: ; preds = %24, %15
%18 = load i32, i32* %6
%19 = urem i32 %18, 10
%20 = add i32 48, %19
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %5
store i8 %21, i8* %22
br label %24
24: ; preds = %17
%25 = load i32, i32* %6
%26 = udiv i32 %25, 10
store i32 %26, i32* %6
%27 = icmp ne i32 %26, 0
br i1 %27, label %17, label %28
28: ; preds = %24
%29 = load i32, i32* %3
%30 = icmp ult i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %5
store i8 45, i8* %32
br label %34
34: ; preds = %31, %28
%35 = load i8*, i8** %5
store i8 0, i8* %35
%36 = load i8*, i8** %4
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 -1
%39 = call i32 @strreverse(i8* %36, i8* %38)
ret void
}

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